-
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.
[Vis Builder] Bug fixes for datasource picker and auto time interval (#…
…2632) * Fixes auto time interval Signed-off-by: Ashwin P Chandran <[email protected]> * Fixes change datasource while editing agg Signed-off-by: Ashwin P Chandran <[email protected]> * Misc fixes Signed-off-by: Ashwin P Chandran <[email protected]> * Updates Changelog Signed-off-by: Ashwin P Chandran <[email protected]> * Correctly sets timerange Signed-off-by: Ashwin P Chandran <[email protected]> * Fixes rebase Signed-off-by: Ashwin P Chandran <[email protected]> Signed-off-by: Ashwin P Chandran <[email protected]> (cherry picked from commit 7a41d94) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
19656d6
commit 556bf3d
Showing
18 changed files
with
165 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
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.