Skip to content

Commit

Permalink
[Vis Builder] Add metric to metric, bucket to bucket aggregation pers…
Browse files Browse the repository at this point in the history
…istence (#3495)

* Add metric to metric, bucket to bucket aggregation persistance

Signed-off-by: abbyhu2000 <[email protected]>

* Add logics to avoid exceeding the max count for each schema field

Signed-off-by: abbyhu2000 <[email protected]>

* Add changelog entry

Signed-off-by: abbyhu2000 <[email protected]>

* addressing comments

Signed-off-by: abbyhu2000 <[email protected]>

* Add unit tests for functions in use_persisted_agg_params

Signed-off-by: abbyhu2000 <[email protected]>

* rewrite unit tests to test the entire functionality

Signed-off-by: abbyhu2000 <[email protected]>

---------

Signed-off-by: abbyhu2000 <[email protected]>
Co-authored-by: Anan Zhuang <[email protected]>
  • Loading branch information
abbyhu2000 and ananzh authored Mar 10, 2023
1 parent c35dadb commit 525b033
Show file tree
Hide file tree
Showing 7 changed files with 468 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Make build scripts find and use the latest version of Node.js that satisfies `engines.node` ([#3467](https://github.com/opensearch-project/OpenSearch-Dashboards/issues/3467))
- [Multiple DataSource] Refactor test connection to support SigV4 auth type ([#3456](https://github.com/opensearch-project/OpenSearch-Dashboards/issues/3456))
- [Darwin] Add support for Darwin for running OpenSearch snapshots with `yarn opensearch snapshot` ([#3537](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3537))
- [Vis Builder] Add metric to metric, bucket to bucket aggregation persistence ([#3495](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3495))

### 🐛 Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import { useVisualizationType } from '../utils/use';
import './side_nav.scss';
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
import { VisBuilderServices } from '../../types';
import { setActiveVisualization, useTypedDispatch } from '../utils/state_management';
import {
setActiveVisualization,
useTypedDispatch,
useTypedSelector,
} from '../utils/state_management';
import { usePersistedAggParams } from '../utils/use/use_persisted_agg_params';

export const RightNav = () => {
const [newVisType, setNewVisType] = useState<string>();
Expand All @@ -28,6 +33,15 @@ export const RightNav = () => {
const dispatch = useTypedDispatch();
const StyleSection = ui.containerConfig.style.render;

const { activeVisualization } = useTypedSelector((state) => state.visualization);
const aggConfigParams = activeVisualization?.aggConfigParams ?? [];
const persistedAggParams = usePersistedAggParams(
types,
aggConfigParams,
activeVisName,
newVisType
);

const options: Array<EuiSuperSelectOption<string>> = types.all().map(({ name, icon, title }) => ({
value: name,
inputDisplay: <OptionItem icon={icon} title={title} />,
Expand Down Expand Up @@ -68,6 +82,7 @@ export const RightNav = () => {
setActiveVisualization({
name: newVisType,
style: types.get(newVisType)?.ui.containerConfig.style.defaults,
aggConfigParams: persistedAggParams,
})
);

Expand Down
1 change: 1 addition & 0 deletions src/plugins/vis_builder/public/application/utils/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const createVisBuilderServicesMock = () => {
},
},
],
get: jest.fn(),
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
*/

import { createAction } from '@reduxjs/toolkit';
import { CreateAggConfigParams } from '../../../../../data/common';
import { VisualizationType } from '../../../services/type_service/visualization_type';

interface ActiveVisPayload {
name: VisualizationType['name'];
style: VisualizationType['ui']['containerConfig']['style']['defaults'];
aggConfigParams: CreateAggConfigParams[];
}

export const setActiveVisualization = createAction<ActiveVisPayload>('setActiveVisualzation');
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const slice = createSlice({
builder.addCase(setActiveVisualization, (state, action) => {
state.activeVisualization = {
name: action.payload.name,
aggConfigParams: [],
aggConfigParams: action.payload.aggConfigParams,
};
});
},
Expand Down
Loading

0 comments on commit 525b033

Please sign in to comment.