-
Notifications
You must be signed in to change notification settings - Fork 890
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ashwin P Chandran <[email protected]>
- Loading branch information
Showing
10 changed files
with
114 additions
and
58 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
53 changes: 53 additions & 0 deletions
53
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,53 @@ | ||
/* | ||
* 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 { WizardServices } from '../../../types'; | ||
import { useTypedSelector, useTypedDispatch } from '../state_management'; | ||
import { useIndexPatterns } from './use_index_pattern'; | ||
|
||
export const useAggs = () => { | ||
const { | ||
services: { | ||
data: { | ||
search: { aggs: aggService }, | ||
query: { | ||
timefilter: { timefilter }, | ||
}, | ||
}, | ||
}, | ||
} = useOpenSearchDashboards<WizardServices>(); | ||
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