mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* Move xss and sanitize packages to grafana-data
* Move text, url and location utils to grafana-data
* Move grafana config types to grafana-data
* Move field display value proxy to grafana-data
* Fix
* Move data links built in vars to grafana-data
* Attach links supplier to when applying field overrides
* Prep tests
* Use links suppliers attached via field overrides
* locationUtil dependencies type
* Move sanitize-url declaration to grafana-data
* Revert "Move sanitize-url declaration to grafana-data"
This reverts commit 11db9f5e55
.
* Fix typo
* fix ts vol1
* Remove import from runtime in data.... Make TS happy at the same time ;)
* Lovely TS, please shut up
* Lovely TS, please shut up vol2
* fix tests
* Fixes
* minor refactor
* Attach get links to FieldDisplayValue for seamless usage
* Update packages/grafana-data/src/field/fieldOverrides.ts
* Make storybook build
51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
import { useEffect } from 'react';
|
|
import useAsyncFn from 'react-use/lib/useAsyncFn';
|
|
import { AppEvents, locationUtil } from '@grafana/data';
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
import { SaveDashboardOptions } from './types';
|
|
import { CoreEvents, StoreState } from 'app/types';
|
|
import appEvents from 'app/core/app_events';
|
|
import { updateLocation } from 'app/core/reducers/location';
|
|
import { DashboardModel } from 'app/features/dashboard/state';
|
|
import { getBackendSrv } from 'app/core/services/backend_srv';
|
|
|
|
const saveDashboard = async (saveModel: any, options: SaveDashboardOptions, dashboard: DashboardModel) => {
|
|
const folderId = options.folderId >= 0 ? options.folderId : dashboard.meta.folderId || saveModel.folderId;
|
|
return await getBackendSrv().saveDashboard(saveModel, { ...options, folderId });
|
|
};
|
|
|
|
export const useDashboardSave = (dashboard: DashboardModel) => {
|
|
const location = useSelector((state: StoreState) => state.location);
|
|
const dispatch = useDispatch();
|
|
const [state, onDashboardSave] = useAsyncFn(
|
|
async (clone: any, options: SaveDashboardOptions, dashboard: DashboardModel) =>
|
|
await saveDashboard(clone, options, dashboard),
|
|
[]
|
|
);
|
|
|
|
useEffect(() => {
|
|
if (state.value) {
|
|
dashboard.version = state.value.version;
|
|
|
|
// important that these happen before location redirect below
|
|
appEvents.emit(CoreEvents.dashboardSaved, dashboard);
|
|
appEvents.emit(AppEvents.alertSuccess, ['Dashboard saved']);
|
|
|
|
const newUrl = locationUtil.stripBaseFromUrl(state.value.url);
|
|
const currentPath = location.path;
|
|
|
|
if (newUrl !== currentPath) {
|
|
dispatch(
|
|
updateLocation({
|
|
path: newUrl,
|
|
replace: true,
|
|
query: {},
|
|
})
|
|
);
|
|
}
|
|
}
|
|
}, [state]);
|
|
|
|
return { state, onDashboardSave };
|
|
};
|