mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-10-14 09:01:34 +08:00

Co-authored-by: gitstart <gitstart@users.noreply.github.com> Co-authored-by: Nitesh Singh <nitesh.singh@gitstart.dev> Co-authored-by: gitstart-app[bot] <57568882+gitstart-app[bot]@users.noreply.github.com> Co-authored-by: Rubens Rafael <70234898+RubensRafael@users.noreply.github.com> Co-authored-by: RubensRafael <rubensrafael2@live.com> Co-authored-by: niteshsingh1357 <niteshsingh1357@gmail.com> Co-authored-by: gitstart_bot <gitstart_bot@users.noreply.github.com> Co-authored-by: Palash Gupta <palashgdev@gmail.com>
111 lines
2.4 KiB
TypeScript
111 lines
2.4 KiB
TypeScript
import { NotificationInstance } from 'antd/es/notification/interface';
|
|
import updateDashboardApi from 'api/dashboard/update';
|
|
import {
|
|
ClickHouseQueryTemplate,
|
|
PromQLQueryTemplate,
|
|
QueryBuilderQueryTemplate,
|
|
} from 'constants/dashboard';
|
|
import { GRAPH_TYPES } from 'container/NewDashboard/ComponentsSlider';
|
|
import GetQueryName from 'lib/query/GetQueryName';
|
|
import { Layout } from 'react-grid-layout';
|
|
import store from 'store';
|
|
import { Dashboard } from 'types/api/dashboard/getAll';
|
|
import { EQueryType } from 'types/common/dashboard';
|
|
|
|
export const UpdateDashboard = async (
|
|
{
|
|
data,
|
|
graphType,
|
|
generateWidgetId,
|
|
layout,
|
|
selectedDashboard,
|
|
isRedirected,
|
|
}: UpdateDashboardProps,
|
|
notify: NotificationInstance,
|
|
): Promise<Dashboard | undefined> => {
|
|
const updatedSelectedDashboard: Dashboard = {
|
|
...selectedDashboard,
|
|
data: {
|
|
title: data.title,
|
|
description: data.description,
|
|
name: data.name,
|
|
tags: data.tags,
|
|
variables: data.variables,
|
|
widgets: [
|
|
...(data.widgets || []),
|
|
{
|
|
description: '',
|
|
id: generateWidgetId,
|
|
isStacked: false,
|
|
nullZeroValues: '',
|
|
opacity: '',
|
|
panelTypes: graphType,
|
|
query: {
|
|
queryType: EQueryType.QUERY_BUILDER,
|
|
promQL: [
|
|
{
|
|
name: GetQueryName([]) || '',
|
|
...PromQLQueryTemplate,
|
|
},
|
|
],
|
|
clickHouse: [
|
|
{
|
|
name: GetQueryName([]) || '',
|
|
...ClickHouseQueryTemplate,
|
|
},
|
|
],
|
|
metricsBuilder: {
|
|
formulas: [],
|
|
queryBuilder: [
|
|
{
|
|
name: GetQueryName([]) || '',
|
|
...QueryBuilderQueryTemplate,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
queryData: {
|
|
data: { queryData: [] },
|
|
error: false,
|
|
errorMessage: '',
|
|
loading: false,
|
|
},
|
|
timePreferance: 'GLOBAL_TIME',
|
|
title: '',
|
|
},
|
|
],
|
|
layout,
|
|
},
|
|
uuid: selectedDashboard.uuid,
|
|
};
|
|
|
|
const response = await updateDashboardApi(updatedSelectedDashboard);
|
|
|
|
if (response.payload) {
|
|
store.dispatch({
|
|
type: 'UPDATE_DASHBOARD',
|
|
payload: response.payload,
|
|
});
|
|
}
|
|
|
|
if (isRedirected) {
|
|
if (response.statusCode === 200) {
|
|
return response.payload;
|
|
}
|
|
notify.error({
|
|
message: response.error || 'Something went wrong',
|
|
});
|
|
return undefined;
|
|
}
|
|
return undefined;
|
|
};
|
|
|
|
interface UpdateDashboardProps {
|
|
data: Dashboard['data'];
|
|
graphType: GRAPH_TYPES;
|
|
generateWidgetId: string;
|
|
layout: Layout[];
|
|
selectedDashboard: Dashboard;
|
|
isRedirected: boolean;
|
|
}
|