('_g', queryState, { useHash }, url);
diff --git a/src/plugins/vis_builder/public/application/components/top_nav.tsx b/src/plugins/vis_builder/public/application/components/top_nav.tsx
index 768f2db35465..f99551179bdb 100644
--- a/src/plugins/vis_builder/public/application/components/top_nav.tsx
+++ b/src/plugins/vis_builder/public/application/components/top_nav.tsx
@@ -13,6 +13,7 @@ import { VisBuilderServices } from '../../types';
import './top_nav.scss';
import { useIndexPatterns, useSavedVisBuilderVis } from '../utils/use';
import { useTypedSelector, useTypedDispatch } from '../utils/state_management';
+import { setSavedQuery, setState } from '../utils/state_management/visualization_slice';
import { setEditorState } from '../utils/state_management/metadata_slice';
import { useCanSave } from '../utils/use/use_can_save';
import { saveStateToSavedObject } from '../../saved_visualizations/transforms';
@@ -29,6 +30,7 @@ export const TopNav = () => {
ui: { TopNavMenu },
},
appName,
+ capabilities,
} = services;
const rootState = useTypedSelector((state) => state);
const dispatch = useTypedDispatch();
@@ -78,6 +80,18 @@ export const TopNav = () => {
dispatch(setEditorState({ state: 'loading' }));
});
+ const updateSavedQueryId = (newSavedQueryId: string | undefined) => {
+ if (newSavedQueryId) {
+ dispatch(setSavedQuery(newSavedQueryId));
+ } else {
+ // remove savedQueryId from state
+ const newState = rootState;
+ delete newState.visualization.savedQuery;
+ dispatch(setState(newState.visualization));
+ }
+ };
+ const showSaveQuery=!!capabilities['visualization-visbuilder']?.saveQuery;
+
return (
{
indexPatterns={indexPattern ? [indexPattern] : []}
showDatePicker={!!indexPattern?.timeFieldName ?? true}
showSearchBar
- showSaveQuery
+ showSaveQuery={showSaveQuery}
useDefaultBehaviors
+ savedQueryId={rootState.visualization.savedQuery}
+ onSavedQueryIdChange={updateSavedQueryId}
/>
);
diff --git a/src/plugins/vis_builder/public/application/utils/state_management/visualization_slice.ts b/src/plugins/vis_builder/public/application/utils/state_management/visualization_slice.ts
index 6662f9f43d71..537ba002e423 100644
--- a/src/plugins/vis_builder/public/application/utils/state_management/visualization_slice.ts
+++ b/src/plugins/vis_builder/public/application/utils/state_management/visualization_slice.ts
@@ -16,6 +16,7 @@ export interface VisualizationState {
aggConfigParams: CreateAggConfigParams[];
draftAgg?: CreateAggConfigParams;
};
+ savedQuery?: string
}
const initialState: VisualizationState = {
@@ -115,6 +116,12 @@ export const slice = createSlice({
[action.payload.paramName]: action.payload.value,
};
},
+ setSavedQuery(state, action: PayloadAction) {
+ return {
+ ...state,
+ savedQuery: action.payload,
+ }
+ },
setState: (_state, action: PayloadAction) => {
return action.payload;
},
@@ -138,5 +145,6 @@ export const {
updateAggConfigParams,
setAggParamValue,
reorderAgg,
+ setSavedQuery,
setState,
} = slice.actions;
diff --git a/src/plugins/vis_builder/public/plugin.ts b/src/plugins/vis_builder/public/plugin.ts
index 4e8f020d1fe8..89366b618431 100644
--- a/src/plugins/vis_builder/public/plugin.ts
+++ b/src/plugins/vis_builder/public/plugin.ts
@@ -159,6 +159,7 @@ export class VisBuilderPlugin
embeddable: pluginsStart.embeddable,
dashboard: pluginsStart.dashboard,
uiActions: pluginsStart.uiActions,
+ capabilities: coreStart.application.capabilities,
};
// Instantiate the store
diff --git a/src/plugins/vis_builder/public/types.ts b/src/plugins/vis_builder/public/types.ts
index 1ba8843e016a..61088400d92d 100644
--- a/src/plugins/vis_builder/public/types.ts
+++ b/src/plugins/vis_builder/public/types.ts
@@ -17,6 +17,7 @@ import { AppMountParameters, CoreStart, ToastsStart, ScopedHistory } from '../..
import { IOsdUrlStateStorage } from '../../opensearch_dashboards_utils/public';
import { DataPublicPluginSetup } from '../../data/public';
import { UiActionsStart } from '../../ui_actions/public';
+import { Capabilities } from '../../../core/public';
export type VisBuilderSetup = TypeServiceSetup;
export interface VisBuilderStart extends TypeServiceStart {
@@ -54,6 +55,7 @@ export interface VisBuilderServices extends CoreStart {
osdUrlStateStorage: IOsdUrlStateStorage;
dashboard: DashboardStart;
uiActions: UiActionsStart;
+ capabilities: Capabilities;
}
export interface ISavedVis {
diff --git a/src/plugins/vis_builder/server/capabilities_provider.ts b/src/plugins/vis_builder/server/capabilities_provider.ts
index c810efabdfe5..54493073e708 100644
--- a/src/plugins/vis_builder/server/capabilities_provider.ts
+++ b/src/plugins/vis_builder/server/capabilities_provider.ts
@@ -12,6 +12,6 @@ export const capabilitiesProvider = () => ({
show: true,
// showWriteControls: true,
// save: true,
- // saveQuery: true,
+ saveQuery: true,
},
});