forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Vis Builder] Bug fixes for datasource picker and auto time interval (o…
…pensearch-project#2632) * Fixes auto time interval Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com> * Fixes change datasource while editing agg Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com> * Misc fixes Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com> * Updates Changelog Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com> * Correctly sets timerange Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com> * Fixes rebase Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com> Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com> Signed-off-by: Sergey V. Osipov <sipopo@yandex.ru>
- Loading branch information
Showing
19 changed files
with
166 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/plugins/vis_builder/public/application/utils/use/use_aggs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { cloneDeep } from 'lodash'; | ||
import { useLayoutEffect, useMemo, useState } from 'react'; | ||
import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public'; | ||
import { VisBuilderServices } from '../../../types'; | ||
import { useTypedSelector, useTypedDispatch } from '../state_management'; | ||
import { useIndexPatterns } from './use_index_pattern'; | ||
|
||
/** | ||
* Returns common agg parameters from the store and app context | ||
* @returns { indexPattern, aggConfigs, aggs, timeRange } | ||
*/ | ||
export const useAggs = () => { | ||
const { | ||
services: { | ||
data: { | ||
search: { aggs: aggService }, | ||
query: { | ||
timefilter: { timefilter }, | ||
}, | ||
}, | ||
}, | ||
} = useOpenSearchDashboards<VisBuilderServices>(); | ||
const indexPattern = useIndexPatterns().selected; | ||
const [timeRange, setTimeRange] = useState(timefilter.getTime()); | ||
const aggConfigParams = useTypedSelector( | ||
(state) => state.visualization.activeVisualization?.aggConfigParams | ||
); | ||
const dispatch = useTypedDispatch(); | ||
|
||
const aggConfigs = useMemo(() => { | ||
const configs = | ||
indexPattern && aggService.createAggConfigs(indexPattern, cloneDeep(aggConfigParams)); | ||
return configs; | ||
}, [aggConfigParams, aggService, indexPattern]); | ||
|
||
useLayoutEffect(() => { | ||
const subscription = timefilter.getTimeUpdate$().subscribe(() => { | ||
setTimeRange(timefilter.getTime()); | ||
}); | ||
|
||
return () => { | ||
subscription.unsubscribe(); | ||
}; | ||
}, [dispatch, timefilter]); | ||
|
||
return { | ||
indexPattern, | ||
aggConfigs, | ||
aggs: aggConfigs?.aggs ?? [], | ||
timeRange, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.