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.
[D&D] Enable basic saving and loading
- Add `/edit` route - Sync state for saving and loading - Add setter for vizualization slice - Switch from BrowserRouter to Router - Add version to saved objects - Add savedWizardLoader to services partially addresses opensearch-project#1620 Signed-off-by: Josh Romero <[email protected]>
- Loading branch information
1 parent
e1f1c49
commit 8e26a4b
Showing
16 changed files
with
212 additions
and
38 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
16 changes: 16 additions & 0 deletions
16
src/plugins/wizard/public/application/utils/get_saved_wizard_vis.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,16 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { WizardServices } from '../..'; | ||
|
||
export const getSavedWizardVis = async (services: WizardServices, wizardVisId?: string) => { | ||
const { savedWizardLoader } = services; | ||
if (!savedWizardLoader) { | ||
return {}; | ||
} | ||
const savedWizardVis = await savedWizardLoader.get(wizardVisId); | ||
|
||
return savedWizardVis; | ||
}; |
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
84 changes: 84 additions & 0 deletions
84
src/plugins/wizard/public/application/utils/use/use_saved_wizard_vis.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,84 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// import { i18n } from '@osd/i18n'; | ||
import { useEffect, useState } from 'react'; | ||
import { SavedObject } from '../../../../../saved_objects/public'; | ||
// import { redirectWhenMissing } from '../../../../../opensearch_dashboards_utils/public'; | ||
// import { EDIT_PATH } from '../../../../common'; | ||
import { WizardServices } from '../../../types'; | ||
import { MetricOptionsDefaults } from '../../../visualizations/metric/metric_viz_type'; | ||
import { getSavedWizardVis } from '../get_saved_wizard_vis'; | ||
import { useTypedDispatch, setStyleState, setVisualizationState } from '../state_management'; | ||
|
||
export const useSavedWizardVisInstance = ( | ||
services: WizardServices, | ||
visualizationIdFromUrl: string | undefined | ||
) => { | ||
const [state, setState] = useState<{ | ||
savedWizardVis?: SavedObject; | ||
}>({}); | ||
const dispatch = useTypedDispatch(); | ||
|
||
useEffect(() => { | ||
const { | ||
// application: { navigateToApp }, | ||
chrome, | ||
// history, | ||
// http: { basePath }, | ||
// setActiveUrl, | ||
// toastNotifications, | ||
} = services; | ||
// TODO: remove "instance" from naming | ||
const getSavedWizardVisInstance = async () => { | ||
try { | ||
const savedWizardVis = await getSavedWizardVis(services, visualizationIdFromUrl); | ||
|
||
if (savedWizardVis.id) { | ||
// TODO: update breadcrumbs | ||
// chrome.setBreadcrumbs(getEditBreadcrumbs(savedWizardVis.title)); | ||
chrome.docTitle.change(savedWizardVis.title); | ||
} else { | ||
// chrome.setBreadcrumbs(getCreateBreadcrumbs()); | ||
} | ||
|
||
dispatch(setStyleState<MetricOptionsDefaults>(JSON.parse(savedWizardVis.state).style)); | ||
dispatch(setVisualizationState(JSON.parse(savedWizardVis.state).visualization)); | ||
setState({ savedWizardVis }); | ||
} catch (error) { | ||
// TODO: implement error handling | ||
// const managementRedirectTarget = { | ||
// app: 'management', | ||
// path: `opensearch-dashboards/objects/savedVisualizations/${visualizationIdFromUrl}`, | ||
// }; | ||
// | ||
// try { | ||
// redirectWhenMissing({ | ||
// history, | ||
// navigateToApp, | ||
// toastNotifications, | ||
// basePath, | ||
// mapping: managementRedirectTarget, | ||
// onBeforeRedirect() { | ||
// setActiveUrl(EDIT_PATH); | ||
// }, | ||
// })(error); | ||
// } catch (e) { | ||
// toastNotifications.addWarning({ | ||
// title: i18n.translate('visualize.createVisualization.failedToLoadErrorMessage', { | ||
// defaultMessage: 'Failed to load the visualization', | ||
// }), | ||
// text: e.message, | ||
// }); | ||
// history.replace(EDIT_PATH); | ||
// } | ||
} | ||
}; | ||
|
||
getSavedWizardVisInstance(); | ||
}, [dispatch, services, visualizationIdFromUrl]); | ||
|
||
return state; | ||
}; |
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.