From fee291c3c81540f45cba657e70277ec494786835 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Thu, 28 Apr 2022 07:02:33 -0700 Subject: [PATCH] Save Drawer: reduce the number of diff elements we show (#48309) --- .../SaveDashboard/SaveDashboardDiff.tsx | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/public/app/features/dashboard/components/SaveDashboard/SaveDashboardDiff.tsx b/public/app/features/dashboard/components/SaveDashboard/SaveDashboardDiff.tsx index 6deb43117f4..16e20289dc0 100644 --- a/public/app/features/dashboard/components/SaveDashboard/SaveDashboardDiff.tsx +++ b/public/app/features/dashboard/components/SaveDashboard/SaveDashboardDiff.tsx @@ -1,5 +1,5 @@ import { css } from '@emotion/css'; -import React from 'react'; +import React, { ReactElement } from 'react'; import { useAsync } from 'react-use'; import { GrafanaTheme2 } from '@grafana/data'; @@ -22,12 +22,30 @@ export const SaveDashboardDiff = ({ diff, oldValue, newValue }: SaveDashboardDif const loader = useAsync(async () => { const oldJSON = JSON.stringify(oldValue ?? {}, null, 2); const newJSON = JSON.stringify(newValue ?? {}, null, 2); + + // Schema changes will have MANY changes that the user will not understand + let schemaChange: ReactElement | undefined = undefined; + const diffs: ReactElement[] = []; + let count = 0; + if (diff) { + for (const [key, changes] of Object.entries(diff)) { + // this takes a long time for large diffs (so this is async) + const g = ; + if (key === 'schemaVersion') { + schemaChange = g; + } else { + diffs.push(g); + } + count += changes.length; + } + } return { oldJSON, newJSON, - diffs: Object.entries(diff ?? []).map(([key, diffs]) => ( - // this takes a long time for large diffs - )), + schemaChange, + diffs, + count, + showDiffs: count < 15, // overwhelming if too many changes }; }, [diff, oldValue, newValue]); @@ -36,15 +54,17 @@ export const SaveDashboardDiff = ({ diff, oldValue, newValue }: SaveDashboardDif return ; } - if (!value.diffs.length) { + if (value.count < 1) { return
No changes in this dashboard
; } return (
-
{value.diffs}
+ {value.schemaChange &&
{value.schemaChange}
} -

JSON Diff

+ {value.showDiffs &&
{value.diffs}
} + +

JSON Model

);