mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 12:49:06 +08:00
fix: removed selectedValue & uuid from exported and copied dashboard json (#6145)
* fix: removed selectedValue from exported and copied dashboard json * fix: added uuid validation to not expect empty uuid * fix: removed uuid from export and copied dashboard json * fix: resolved comment and removed uuid when empty * fix: renamed function
This commit is contained in:
parent
503ed45a99
commit
e5be431f18
@ -82,6 +82,12 @@ function ImportJSON({
|
|||||||
|
|
||||||
const dashboardData = JSON.parse(editorValue) as DashboardData;
|
const dashboardData = JSON.parse(editorValue) as DashboardData;
|
||||||
|
|
||||||
|
// Add validation for uuid
|
||||||
|
if (dashboardData.uuid !== undefined && dashboardData.uuid.trim() === '') {
|
||||||
|
// silently remove uuid if it is empty
|
||||||
|
delete dashboardData.uuid;
|
||||||
|
}
|
||||||
|
|
||||||
if (dashboardData?.layout) {
|
if (dashboardData?.layout) {
|
||||||
dashboardData.layout = getUpdatedLayout(dashboardData.layout);
|
dashboardData.layout = getUpdatedLayout(dashboardData.layout);
|
||||||
} else {
|
} else {
|
||||||
@ -123,11 +129,14 @@ function ImportJSON({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
setDashboardCreating(false);
|
setDashboardCreating(false);
|
||||||
} catch {
|
} catch (error) {
|
||||||
setDashboardCreating(false);
|
setDashboardCreating(false);
|
||||||
setIsFeatureAlert(false);
|
setIsFeatureAlert(false);
|
||||||
|
|
||||||
setIsCreateDashboardError(true);
|
setIsCreateDashboardError(true);
|
||||||
|
notifications.error({
|
||||||
|
message: error instanceof Error ? error.message : t('error_loading_json'),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,7 +47,11 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
import { useCopyToClipboard } from 'react-use';
|
import { useCopyToClipboard } from 'react-use';
|
||||||
import { AppState } from 'store/reducers';
|
import { AppState } from 'store/reducers';
|
||||||
import { Dashboard, DashboardData } from 'types/api/dashboard/getAll';
|
import {
|
||||||
|
Dashboard,
|
||||||
|
DashboardData,
|
||||||
|
IDashboardVariable,
|
||||||
|
} from 'types/api/dashboard/getAll';
|
||||||
import AppReducer from 'types/reducer/app';
|
import AppReducer from 'types/reducer/app';
|
||||||
import { ROLES, USER_ROLES } from 'types/roles';
|
import { ROLES, USER_ROLES } from 'types/roles';
|
||||||
import { ComponentTypes } from 'utils/permission';
|
import { ComponentTypes } from 'utils/permission';
|
||||||
@ -63,6 +67,30 @@ interface DashboardDescriptionProps {
|
|||||||
handle: FullScreenHandle;
|
handle: FullScreenHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sanitizeDashboardData(
|
||||||
|
selectedData: DashboardData,
|
||||||
|
): Omit<DashboardData, 'uuid'> {
|
||||||
|
if (!selectedData?.variables) {
|
||||||
|
const { uuid, ...rest } = selectedData;
|
||||||
|
return rest;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedVariables = Object.entries(selectedData.variables).reduce(
|
||||||
|
(acc, [key, value]) => {
|
||||||
|
const { selectedValue, ...rest } = value;
|
||||||
|
acc[key] = rest;
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{} as Record<string, IDashboardVariable>,
|
||||||
|
);
|
||||||
|
|
||||||
|
const { uuid, ...restData } = selectedData;
|
||||||
|
return {
|
||||||
|
...restData,
|
||||||
|
variables: updatedVariables,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line sonarjs/cognitive-complexity
|
// eslint-disable-next-line sonarjs/cognitive-complexity
|
||||||
function DashboardDescription(props: DashboardDescriptionProps): JSX.Element {
|
function DashboardDescription(props: DashboardDescriptionProps): JSX.Element {
|
||||||
const { handle } = props;
|
const { handle } = props;
|
||||||
@ -407,7 +435,10 @@ function DashboardDescription(props: DashboardDescriptionProps): JSX.Element {
|
|||||||
type="text"
|
type="text"
|
||||||
icon={<FileJson size={14} />}
|
icon={<FileJson size={14} />}
|
||||||
onClick={(): void => {
|
onClick={(): void => {
|
||||||
downloadObjectAsJson(selectedData, selectedData.title);
|
downloadObjectAsJson(
|
||||||
|
sanitizeDashboardData(selectedData),
|
||||||
|
selectedData.title,
|
||||||
|
);
|
||||||
setIsDashbordSettingsOpen(false);
|
setIsDashbordSettingsOpen(false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@ -417,7 +448,9 @@ function DashboardDescription(props: DashboardDescriptionProps): JSX.Element {
|
|||||||
type="text"
|
type="text"
|
||||||
icon={<ClipboardCopy size={14} />}
|
icon={<ClipboardCopy size={14} />}
|
||||||
onClick={(): void => {
|
onClick={(): void => {
|
||||||
setCopy(JSON.stringify(selectedData, null, 2));
|
setCopy(
|
||||||
|
JSON.stringify(sanitizeDashboardData(selectedData), null, 2),
|
||||||
|
);
|
||||||
setIsDashbordSettingsOpen(false);
|
setIsDashbordSettingsOpen(false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user