@perses-dev/dashboards 0.54.0-beta.7 → 0.54.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +2 -2
- package/dist/cjs/components/GridLayout/GridItemContent.js +2 -9
- package/dist/cjs/components/PanelDrawer/PanelQueriesSharedControls.js +3 -16
- package/dist/cjs/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +20 -3
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +9 -2
- package/dist/cjs/context/DashboardProvider/use-save-dashboard.js +12 -4
- package/dist/cjs/context/useDashboard.js +3 -1
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +8 -1
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +3 -2
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +1 -0
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar/DashboardToolbar.js +2 -2
- package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +2 -9
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/PanelDrawer/PanelQueriesSharedControls.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelQueriesSharedControls.js +4 -17
- package/dist/components/PanelDrawer/PanelQueriesSharedControls.js.map +1 -1
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts.map +1 -1
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +21 -4
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.d.ts +2 -0
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +9 -2
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
- package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts +8 -1
- package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/save-changes-dialog-slice.js.map +1 -1
- package/dist/context/DashboardProvider/use-save-dashboard.d.ts.map +1 -1
- package/dist/context/DashboardProvider/use-save-dashboard.js +13 -5
- package/dist/context/DashboardProvider/use-save-dashboard.js.map +1 -1
- package/dist/context/useDashboard.d.ts.map +1 -1
- package/dist/context/useDashboard.js +3 -1
- package/dist/context/useDashboard.js.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.d.ts +1 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +9 -2
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js +3 -2
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
- package/package.json +5 -5
|
@@ -13,7 +13,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
import { useState } from 'react';
|
|
15
15
|
import { Checkbox, FormGroup, FormControlLabel, Typography } from '@mui/material';
|
|
16
|
-
import { DEFAULT_REFRESH_INTERVAL_OPTIONS, useTimeRange } from '@perses-dev/plugin-system';
|
|
16
|
+
import { DEFAULT_REFRESH_INTERVAL_OPTIONS, useTimeRange, useTimeZoneParams } from '@perses-dev/plugin-system';
|
|
17
17
|
import { isRelativeTimeRange } from '@perses-dev/spec';
|
|
18
18
|
import { Dialog } from '@perses-dev/components';
|
|
19
19
|
import { useSaveChangesConfirmationDialog, useVariableDefinitionActions } from '../../context';
|
|
@@ -23,16 +23,20 @@ export const SaveChangesConfirmationDialog = ()=>{
|
|
|
23
23
|
const isSavedDurationModified = dialog?.isSavedDurationModified ?? true;
|
|
24
24
|
const isSavedVariableModified = dialog?.isSavedVariableModified ?? true;
|
|
25
25
|
const isSavedRefreshIntervalModified = dialog?.isSavedRefreshIntervalModified ?? true;
|
|
26
|
+
const isSavedTimeZoneModified = dialog?.isTimeZoneModified ?? true;
|
|
26
27
|
const [saveDefaultTimeRange, setSaveDefaultTimeRange] = useState(isSavedDurationModified);
|
|
27
28
|
const [saveDefaultVariables, setSaveDefaultVariables] = useState(isSavedVariableModified);
|
|
28
29
|
const [saveDefaultRefreshInterval, setDefaultRefreshInterval] = useState(isSavedRefreshIntervalModified);
|
|
30
|
+
const [saveDefaultTimeZone, setSaveDefaultTimeZone] = useState(isSavedTimeZoneModified);
|
|
29
31
|
const { getSavedVariablesStatus } = useVariableDefinitionActions();
|
|
30
32
|
const { modifiedVariableNames } = getSavedVariablesStatus();
|
|
31
33
|
const isOpen = dialog !== undefined;
|
|
32
34
|
const { timeRange, refreshInterval } = useTimeRange();
|
|
35
|
+
const { timeZone } = useTimeZoneParams();
|
|
33
36
|
const currentTimeRangeText = isRelativeTimeRange(timeRange) ? `(Last ${timeRange.pastDuration})` : '(Absolute time ranges can not be saved)';
|
|
34
|
-
const saveTimeRangeMessage = `Save current time range as new default ${currentTimeRangeText}`;
|
|
35
|
-
const
|
|
37
|
+
const saveTimeRangeMessage = `Save current time range as the new default ${currentTimeRangeText}`;
|
|
38
|
+
const saveTimeZoneMessage = `Save the current timezone as the new default (${timeZone})`;
|
|
39
|
+
const saveVariableMessage = `Save current variable values as the new default (${modifiedVariableNames.length > 0 ? modifiedVariableNames.join(', ') : 'No modified variables'})`;
|
|
36
40
|
const refreshIntervalDisplay = DEFAULT_REFRESH_INTERVAL_OPTIONS.some((i)=>i.display === refreshInterval) ? refreshInterval : DEFAULT_REFRESH_INTERVAL_OPTIONS.find((i)=>i.value.pastDuration === refreshInterval)?.display;
|
|
37
41
|
const saveRefreshIntervalMessage = `Save current refresh interval as new default ${refreshIntervalDisplay ? `(${refreshIntervalDisplay})` : 'refresh interval not modified'}`;
|
|
38
42
|
return /*#__PURE__*/ _jsx(Dialog, {
|
|
@@ -74,6 +78,14 @@ export const SaveChangesConfirmationDialog = ()=>{
|
|
|
74
78
|
onChange: (e)=>setSaveDefaultVariables(e.target.checked)
|
|
75
79
|
}),
|
|
76
80
|
label: saveVariableMessage
|
|
81
|
+
}),
|
|
82
|
+
/*#__PURE__*/ _jsx(FormControlLabel, {
|
|
83
|
+
control: /*#__PURE__*/ _jsx(Checkbox, {
|
|
84
|
+
disabled: !isSavedTimeZoneModified,
|
|
85
|
+
checked: saveDefaultTimeZone && isSavedTimeZoneModified,
|
|
86
|
+
onChange: (e)=>setSaveDefaultTimeZone(e.target.checked)
|
|
87
|
+
}),
|
|
88
|
+
label: saveTimeZoneMessage
|
|
77
89
|
})
|
|
78
90
|
]
|
|
79
91
|
})
|
|
@@ -83,7 +95,12 @@ export const SaveChangesConfirmationDialog = ()=>{
|
|
|
83
95
|
children: [
|
|
84
96
|
/*#__PURE__*/ _jsx(Dialog.PrimaryButton, {
|
|
85
97
|
onClick: ()=>{
|
|
86
|
-
return dialog.onSaveChanges(
|
|
98
|
+
return dialog.onSaveChanges({
|
|
99
|
+
saveDefaultTimeRange,
|
|
100
|
+
saveDefaultRefreshInterval,
|
|
101
|
+
saveDefaultVariables,
|
|
102
|
+
saveDefaultTimeZone
|
|
103
|
+
});
|
|
87
104
|
},
|
|
88
105
|
children: "Save Changes"
|
|
89
106
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ReactElement, useState } from 'react';\nimport { Checkbox, FormGroup, FormControlLabel, Typography } from '@mui/material';\nimport { DEFAULT_REFRESH_INTERVAL_OPTIONS, useTimeRange } from '@perses-dev/plugin-system';\nimport { isRelativeTimeRange } from '@perses-dev/spec';\nimport { Dialog } from '@perses-dev/components';\nimport { useSaveChangesConfirmationDialog, useVariableDefinitionActions } from '../../context';\n\nconst SAVE_DEFAULTS_DIALOG_TEXT =\n 'You have made changes to the time range or the variables values. Would you like to save these as defaults?';\n\nexport const SaveChangesConfirmationDialog = (): ReactElement => {\n const { saveChangesConfirmationDialog: dialog } = useSaveChangesConfirmationDialog();\n const isSavedDurationModified = dialog?.isSavedDurationModified ?? true;\n const isSavedVariableModified = dialog?.isSavedVariableModified ?? true;\n const isSavedRefreshIntervalModified = dialog?.isSavedRefreshIntervalModified ?? true;\n\n const [saveDefaultTimeRange, setSaveDefaultTimeRange] = useState(isSavedDurationModified);\n const [saveDefaultVariables, setSaveDefaultVariables] = useState(isSavedVariableModified);\n const [saveDefaultRefreshInterval, setDefaultRefreshInterval] = useState(isSavedRefreshIntervalModified);\n\n const { getSavedVariablesStatus } = useVariableDefinitionActions();\n const { modifiedVariableNames } = getSavedVariablesStatus();\n\n const isOpen = dialog !== undefined;\n\n const { timeRange, refreshInterval } = useTimeRange();\n\n const currentTimeRangeText = isRelativeTimeRange(timeRange)\n ? `(Last ${timeRange.pastDuration})`\n : '(Absolute time ranges can not be saved)';\n\n const saveTimeRangeMessage = `Save current time range as new default ${currentTimeRangeText}`;\n\n const saveVariableMessage = `Save current variable values as new default (${\n modifiedVariableNames.length > 0 ? modifiedVariableNames.join(', ') : 'No modified variables'\n })`;\n\n const refreshIntervalDisplay = DEFAULT_REFRESH_INTERVAL_OPTIONS.some((i) => i.display === refreshInterval)\n ? refreshInterval\n : DEFAULT_REFRESH_INTERVAL_OPTIONS.find((i) => i.value.pastDuration === refreshInterval)?.display;\n\n const saveRefreshIntervalMessage = `Save current refresh interval as new default ${refreshIntervalDisplay ? `(${refreshIntervalDisplay})` : 'refresh interval not modified'}`;\n\n return (\n <Dialog open={isOpen}>\n {dialog !== undefined && (\n <>\n <Dialog.Header onClose={() => dialog.onCancel()}>Save Dashboard</Dialog.Header>\n\n <Dialog.Content>\n <Typography marginBottom={2}>{dialog.description || SAVE_DEFAULTS_DIALOG_TEXT}</Typography>\n <FormGroup>\n <FormControlLabel\n control={\n <Checkbox\n disabled={!isSavedDurationModified || !isRelativeTimeRange(timeRange)}\n checked={saveDefaultTimeRange && isSavedDurationModified && isRelativeTimeRange(timeRange)}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => setSaveDefaultTimeRange(e.target.checked)}\n />\n }\n label={saveTimeRangeMessage}\n />\n <FormControlLabel\n control={\n <Checkbox\n disabled={!isSavedRefreshIntervalModified}\n checked={saveDefaultRefreshInterval && isSavedRefreshIntervalModified}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => setDefaultRefreshInterval(e.target.checked)}\n />\n }\n label={saveRefreshIntervalMessage}\n />\n <FormControlLabel\n control={\n <Checkbox\n disabled={!isSavedVariableModified}\n checked={saveDefaultVariables && isSavedVariableModified}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => setSaveDefaultVariables(e.target.checked)}\n />\n }\n label={saveVariableMessage}\n />\n </FormGroup>\n </Dialog.Content>\n\n <Dialog.Actions>\n <Dialog.PrimaryButton\n onClick={() => {\n return dialog.onSaveChanges(saveDefaultTimeRange, saveDefaultRefreshInterval, saveDefaultVariables);\n }}\n >\n Save Changes\n </Dialog.PrimaryButton>\n <Dialog.SecondaryButton onClick={() => dialog.onCancel()}>Cancel</Dialog.SecondaryButton>\n </Dialog.Actions>\n </>\n )}\n </Dialog>\n );\n};\n"],"names":["useState","Checkbox","FormGroup","FormControlLabel","Typography","DEFAULT_REFRESH_INTERVAL_OPTIONS","useTimeRange","isRelativeTimeRange","Dialog","useSaveChangesConfirmationDialog","useVariableDefinitionActions","SAVE_DEFAULTS_DIALOG_TEXT","SaveChangesConfirmationDialog","saveChangesConfirmationDialog","dialog","isSavedDurationModified","isSavedVariableModified","isSavedRefreshIntervalModified","saveDefaultTimeRange","setSaveDefaultTimeRange","saveDefaultVariables","setSaveDefaultVariables","saveDefaultRefreshInterval","setDefaultRefreshInterval","getSavedVariablesStatus","modifiedVariableNames","isOpen","undefined","timeRange","refreshInterval","currentTimeRangeText","pastDuration","saveTimeRangeMessage","saveVariableMessage","length","join","refreshIntervalDisplay","some","i","display","find","value","saveRefreshIntervalMessage","open","Header","onClose","onCancel","Content","marginBottom","description","control","disabled","checked","onChange","e","target","label","Actions","PrimaryButton","onClick","onSaveChanges","SecondaryButton"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAuBA,QAAQ,QAAQ,QAAQ;AAC/C,SAASC,QAAQ,EAAEC,SAAS,EAAEC,gBAAgB,EAAEC,UAAU,QAAQ,gBAAgB;AAClF,SAASC,gCAAgC,EAAEC,YAAY,QAAQ,4BAA4B;AAC3F,SAASC,mBAAmB,QAAQ,mBAAmB;AACvD,SAASC,MAAM,QAAQ,yBAAyB;AAChD,SAASC,gCAAgC,EAAEC,4BAA4B,QAAQ,gBAAgB;AAE/F,MAAMC,4BACJ;AAEF,OAAO,MAAMC,gCAAgC;IAC3C,MAAM,EAAEC,+BAA+BC,MAAM,EAAE,GAAGL;IAClD,MAAMM,0BAA0BD,QAAQC,2BAA2B;IACnE,MAAMC,0BAA0BF,QAAQE,2BAA2B;IACnE,MAAMC,iCAAiCH,QAAQG,kCAAkC;IAEjF,MAAM,CAACC,sBAAsBC,wBAAwB,GAAGnB,SAASe;IACjE,MAAM,CAACK,sBAAsBC,wB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;;oCAGlGI,OAAOxB;;8CAET,KAAC7B;oCACC+C,uBACE,KAACjD;wCACCkD,UAAU,CAAClC;wCACXmC,SAAS9B,8BAA8BL;wCACvCoC,UAAU,CAACC,IAA2C/B,0BAA0B+B,EAAEC,MAAM,CAACH,OAAO;;oCAGpGI,OAAOd;;8CAET,KAACvC;oCACC+C,uBACE,KAACjD;wCACCkD,UAAU,CAACnC;wCACXoC,SAAShC,wBAAwBJ;wCACjCqC,UAAU,CAACC,IAA2CjC,wBAAwBiC,EAAEC,MAAM,CAACH,OAAO;;oCAGlGI,OAAOvB;;;;;;8BAKb,MAACzB,OAAOiD,OAAO;;sCACb,KAACjD,OAAOkD,aAAa;4BACnBC,SAAS;gCACP,OAAO7C,OAAO8C,aAAa,CAAC1C,sBAAsBI,4BAA4BF;4BAChF;sCACD;;sCAGD,KAACZ,OAAOqD,eAAe;4BAACF,SAAS,IAAM7C,OAAOgC,QAAQ;sCAAI;;;;;;;AAMtE,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ReactElement, useState } from 'react';\nimport { Checkbox, FormGroup, FormControlLabel, Typography } from '@mui/material';\nimport { DEFAULT_REFRESH_INTERVAL_OPTIONS, useTimeRange, useTimeZoneParams } from '@perses-dev/plugin-system';\nimport { isRelativeTimeRange } from '@perses-dev/spec';\nimport { Dialog } from '@perses-dev/components';\nimport { useSaveChangesConfirmationDialog, useVariableDefinitionActions } from '../../context';\n\nconst SAVE_DEFAULTS_DIALOG_TEXT =\n 'You have made changes to the time range or the variables values. Would you like to save these as defaults?';\n\nexport const SaveChangesConfirmationDialog = (): ReactElement => {\n const { saveChangesConfirmationDialog: dialog } = useSaveChangesConfirmationDialog();\n const isSavedDurationModified = dialog?.isSavedDurationModified ?? true;\n const isSavedVariableModified = dialog?.isSavedVariableModified ?? true;\n const isSavedRefreshIntervalModified = dialog?.isSavedRefreshIntervalModified ?? true;\n const isSavedTimeZoneModified = dialog?.isTimeZoneModified ?? true;\n\n const [saveDefaultTimeRange, setSaveDefaultTimeRange] = useState(isSavedDurationModified);\n const [saveDefaultVariables, setSaveDefaultVariables] = useState(isSavedVariableModified);\n const [saveDefaultRefreshInterval, setDefaultRefreshInterval] = useState(isSavedRefreshIntervalModified);\n const [saveDefaultTimeZone, setSaveDefaultTimeZone] = useState(isSavedTimeZoneModified);\n\n const { getSavedVariablesStatus } = useVariableDefinitionActions();\n const { modifiedVariableNames } = getSavedVariablesStatus();\n\n const isOpen = dialog !== undefined;\n\n const { timeRange, refreshInterval } = useTimeRange();\n const { timeZone } = useTimeZoneParams();\n\n const currentTimeRangeText = isRelativeTimeRange(timeRange)\n ? `(Last ${timeRange.pastDuration})`\n : '(Absolute time ranges can not be saved)';\n\n const saveTimeRangeMessage = `Save current time range as the new default ${currentTimeRangeText}`;\n\n const saveTimeZoneMessage = `Save the current timezone as the new default (${timeZone})`;\n\n const saveVariableMessage = `Save current variable values as the new default (${\n modifiedVariableNames.length > 0 ? modifiedVariableNames.join(', ') : 'No modified variables'\n })`;\n\n const refreshIntervalDisplay = DEFAULT_REFRESH_INTERVAL_OPTIONS.some((i) => i.display === refreshInterval)\n ? refreshInterval\n : DEFAULT_REFRESH_INTERVAL_OPTIONS.find((i) => i.value.pastDuration === refreshInterval)?.display;\n\n const saveRefreshIntervalMessage = `Save current refresh interval as new default ${refreshIntervalDisplay ? `(${refreshIntervalDisplay})` : 'refresh interval not modified'}`;\n\n return (\n <Dialog open={isOpen}>\n {dialog !== undefined && (\n <>\n <Dialog.Header onClose={() => dialog.onCancel()}>Save Dashboard</Dialog.Header>\n\n <Dialog.Content>\n <Typography marginBottom={2}>{dialog.description || SAVE_DEFAULTS_DIALOG_TEXT}</Typography>\n <FormGroup>\n <FormControlLabel\n control={\n <Checkbox\n disabled={!isSavedDurationModified || !isRelativeTimeRange(timeRange)}\n checked={saveDefaultTimeRange && isSavedDurationModified && isRelativeTimeRange(timeRange)}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => setSaveDefaultTimeRange(e.target.checked)}\n />\n }\n label={saveTimeRangeMessage}\n />\n <FormControlLabel\n control={\n <Checkbox\n disabled={!isSavedRefreshIntervalModified}\n checked={saveDefaultRefreshInterval && isSavedRefreshIntervalModified}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => setDefaultRefreshInterval(e.target.checked)}\n />\n }\n label={saveRefreshIntervalMessage}\n />\n <FormControlLabel\n control={\n <Checkbox\n disabled={!isSavedVariableModified}\n checked={saveDefaultVariables && isSavedVariableModified}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => setSaveDefaultVariables(e.target.checked)}\n />\n }\n label={saveVariableMessage}\n />\n <FormControlLabel\n control={\n <Checkbox\n disabled={!isSavedTimeZoneModified}\n checked={saveDefaultTimeZone && isSavedTimeZoneModified}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => setSaveDefaultTimeZone(e.target.checked)}\n />\n }\n label={saveTimeZoneMessage}\n />\n </FormGroup>\n </Dialog.Content>\n\n <Dialog.Actions>\n <Dialog.PrimaryButton\n onClick={() => {\n return dialog.onSaveChanges({\n saveDefaultTimeRange,\n saveDefaultRefreshInterval,\n saveDefaultVariables,\n saveDefaultTimeZone,\n });\n }}\n >\n Save Changes\n </Dialog.PrimaryButton>\n <Dialog.SecondaryButton onClick={() => dialog.onCancel()}>Cancel</Dialog.SecondaryButton>\n </Dialog.Actions>\n </>\n )}\n </Dialog>\n );\n};\n"],"names":["useState","Checkbox","FormGroup","FormControlLabel","Typography","DEFAULT_REFRESH_INTERVAL_OPTIONS","useTimeRange","useTimeZoneParams","isRelativeTimeRange","Dialog","useSaveChangesConfirmationDialog","useVariableDefinitionActions","SAVE_DEFAULTS_DIALOG_TEXT","SaveChangesConfirmationDialog","saveChangesConfirmationDialog","dialog","isSavedDurationModified","isSavedVariableModified","isSavedRefreshIntervalModified","isSavedTimeZoneModified","isTimeZoneModified","saveDefaultTimeRange","setSaveDefaultTimeRange","saveDefaultVariables","setSaveDefaultVariables","saveDefaultRefreshInterval","setDefaultRefreshInterval","saveDefaultTimeZone","setSaveDefaultTimeZone","getSavedVariablesStatus","modifiedVariableNames","isOpen","undefined","timeRange","refreshInterval","timeZone","currentTimeRangeText","pastDuration","saveTimeRangeMessage","saveTimeZoneMessage","saveVariableMessage","length","join","refreshIntervalDisplay","some","i","display","find","value","saveRefreshIntervalMessage","open","Header","onClose","onCancel","Content","marginBottom","description","control","disabled","checked","onChange","e","target","label","Actions","PrimaryButton","onClick","onSaveChanges","SecondaryButton"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAuBA,QAAQ,QAAQ,QAAQ;AAC/C,SAASC,QAAQ,EAAEC,SAAS,EAAEC,gBAAgB,EAAEC,UAAU,QAAQ,gBAAgB;AAClF,SAASC,gCAAgC,EAAEC,YAAY,EAAEC,iBAAiB,QAAQ,4BAA4B;AAC9G,SAASC,mBAAmB,QAAQ,mBAAmB;AACvD,SAASC,MAAM,QAAQ,yBAAyB;AAChD,SAASC,gCAAgC,EAAEC,4BAA4B,QAAQ,gBAAgB;AAE/F,MAAMC,4BACJ;AAEF,OAAO,MAAMC,gCAAgC;IAC3C,MAAM,EAAEC,+BAA+BC,MAAM,EAAE,GAAGL;IAClD,MAAMM,0BAA0BD,QAAQC,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KAACvB,OAAO0C,MAAM;oBAACC,SAAS,IAAMrC,OAAOsC,QAAQ;8BAAI;;8BAEjD,MAAC5C,OAAO6C,OAAO;;sCACb,KAAClD;4BAAWmD,cAAc;sCAAIxC,OAAOyC,WAAW,IAAI5C;;sCACpD,MAACV;;8CACC,KAACC;oCACCsD,uBACE,KAACxD;wCACCyD,UAAU,CAAC1C,2BAA2B,CAACR,oBAAoByB;wCAC3D0B,SAAStC,wBAAwBL,2BAA2BR,oBAAoByB;wCAChF2B,UAAU,CAACC,IAA2CvC,wBAAwBuC,EAAEC,MAAM,CAACH,OAAO;;oCAGlGI,OAAOzB;;8CAET,KAACnC;oCACCsD,uBACE,KAACxD;wCACCyD,UAAU,CAACxC;wCACXyC,SAASlC,8BAA8BP;wCACvC0C,UAAU,CAACC,IAA2CnC,0BAA0BmC,EAAEC,MAAM,CAACH,OAAO;;oCAGpGI,OAAOd;;8CAET,KAAC9C;oCACCsD,uBACE,KAACxD;wCACCyD,UAAU,CAACzC;wCACX0C,SAASpC,wBAAwBN;wCACjC2C,UAAU,CAACC,IAA2CrC,wBAAwBqC,EAAEC,MAAM,CAACH,OAAO;;oCAGlGI,OAAOvB;;8CAET,KAACrC;oCACCsD,uBACE,KAACxD;wCACCyD,UAAU,CAACvC;wCACXwC,SAAShC,uBAAuBR;wCAChCyC,UAAU,CAACC,IAA2CjC,uBAAuBiC,EAAEC,MAAM,CAACH,OAAO;;oCAGjGI,OAAOxB;;;;;;8BAKb,MAAC9B,OAAOuD,OAAO;;sCACb,KAACvD,OAAOwD,aAAa;4BACnBC,SAAS;gCACP,OAAOnD,OAAOoD,aAAa,CAAC;oCAC1B9C;oCACAI;oCACAF;oCACAI;gCACF;4BACF;sCACD;;sCAGD,KAAClB,OAAO2D,eAAe;4BAACF,SAAS,IAAMnD,OAAOsC,QAAQ;sCAAI;;;;;;;AAMtE,EAAE"}
|
|
@@ -18,9 +18,11 @@ export interface DashboardStoreState extends PanelGroupSlice, PanelSlice, PanelG
|
|
|
18
18
|
isEditMode: boolean;
|
|
19
19
|
setEditMode: (isEditMode: boolean) => void;
|
|
20
20
|
setDashboard: (dashboard: DashboardResource) => void;
|
|
21
|
+
setMetadata: (metadata: ProjectMetadata | ((prev: ProjectMetadata) => ProjectMetadata)) => void;
|
|
21
22
|
kind: DashboardKind;
|
|
22
23
|
metadata: ProjectMetadata;
|
|
23
24
|
duration: DurationString;
|
|
25
|
+
timezone?: string;
|
|
24
26
|
refreshInterval: DurationString;
|
|
25
27
|
display?: Display;
|
|
26
28
|
datasources?: Record<string, DatasourceSpec>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DashboardProvider.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/DashboardProvider.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAIxC,OAAO,EAAiB,YAAY,EAAE,SAAS,EAAgD,MAAM,OAAO,CAAC;AAC7G,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAE3E,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEvF,OAAO,EAA+B,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAChG,OAAO,EAAsD,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC1G,OAAO,EAA0B,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAoB,UAAU,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAA+B,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAChG,OAAO,EAA0B,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAmC,qCAAqC,EAAE,MAAM,gCAAgC,CAAC;AACxH,OAAO,EAAgC,kCAAkC,EAAE,MAAM,6BAA6B,CAAC;AAC/G,OAAO,EAA6B,mBAAmB,EAAE,MAAM,yBAAyB,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) {
|
|
|
71
71
|
}
|
|
72
72
|
function initStore(props) {
|
|
73
73
|
const { initialState: { dashboardResource, isEditMode, viewPanelRef, setViewPanelRef } } = props;
|
|
74
|
-
const { kind, metadata, spec: { display, duration, refreshInterval = DEFAULT_REFRESH_INTERVAL, datasources, layouts = [], panels = {} } } = dashboardResource;
|
|
74
|
+
const { kind, metadata, spec: { display, timezone, duration, refreshInterval = DEFAULT_REFRESH_INTERVAL, datasources, layouts = [], panels = {} } } = dashboardResource;
|
|
75
75
|
const links = dashboardResource.spec.links ?? [];
|
|
76
76
|
const ttl = 'ttl' in dashboardResource.spec ? dashboardResource.spec.ttl : undefined;
|
|
77
77
|
const store = createStore()(immer(devtools((...args)=>{
|
|
@@ -92,6 +92,7 @@ function initStore(props) {
|
|
|
92
92
|
kind,
|
|
93
93
|
metadata,
|
|
94
94
|
display,
|
|
95
|
+
timezone,
|
|
95
96
|
duration,
|
|
96
97
|
refreshInterval,
|
|
97
98
|
datasources,
|
|
@@ -102,11 +103,12 @@ function initStore(props) {
|
|
|
102
103
|
isEditMode
|
|
103
104
|
});
|
|
104
105
|
},
|
|
105
|
-
setDashboard: ({ kind, metadata, spec: { display, panels = {}, layouts = [], duration, refreshInterval, datasources = {}, links = [] } })=>{
|
|
106
|
+
setDashboard: ({ kind, metadata, spec: { display, panels = {}, layouts = [], duration, refreshInterval, datasources = {}, links = [], timezone } })=>{
|
|
106
107
|
set((state)=>{
|
|
107
108
|
state.kind = kind;
|
|
108
109
|
state.metadata = metadata;
|
|
109
110
|
state.display = display;
|
|
111
|
+
state.timezone = timezone;
|
|
110
112
|
state.panels = panels;
|
|
111
113
|
const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);
|
|
112
114
|
state.panelGroups = panelGroups;
|
|
@@ -117,6 +119,11 @@ function initStore(props) {
|
|
|
117
119
|
state.links = links;
|
|
118
120
|
// TODO: add ttl here to e.g allow edition from JSON view, but probably requires quite some refactoring
|
|
119
121
|
});
|
|
122
|
+
},
|
|
123
|
+
setMetadata: (metadata)=>{
|
|
124
|
+
set((state)=>{
|
|
125
|
+
state.metadata = typeof metadata === 'function' ? metadata(state.metadata) : metadata;
|
|
126
|
+
});
|
|
120
127
|
}
|
|
121
128
|
};
|
|
122
129
|
})));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/DashboardProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createStore } from 'zustand';\nimport { useStoreWithEqualityFn } from 'zustand/traditional';\nimport type { StoreApi } from 'zustand';\nimport { devtools } from 'zustand/middleware';\nimport { immer } from 'zustand/middleware/immer';\nimport { shallow } from 'zustand/shallow';\nimport { createContext, ReactElement, ReactNode, useCallback, useContext, useEffect, useState } from 'react';\nimport { Display, DurationString, DatasourceSpec } from '@perses-dev/spec';\nimport { usePlugin, usePluginRegistry } from '@perses-dev/plugin-system';\nimport { DashboardKind, DashboardResource, ProjectMetadata } from '@perses-dev/client';\nimport { DEFAULT_REFRESH_INTERVAL } from '../../constants';\nimport { createPanelGroupEditorSlice, PanelGroupEditorSlice } from './panel-group-editor-slice';\nimport { convertLayoutsToPanelGroups, createPanelGroupSlice, PanelGroupSlice } from './panel-group-slice';\nimport { createPanelEditorSlice, PanelEditorSlice } from './panel-editor-slice';\nimport { createPanelSlice, PanelSlice } from './panel-slice';\nimport { createDeletePanelGroupSlice, DeletePanelGroupSlice } from './delete-panel-group-slice';\nimport { createDeletePanelSlice, DeletePanelSlice } from './delete-panel-slice';\nimport { createDiscardChangesDialogSlice, DiscardChangesConfirmationDialogSlice } from './discard-changes-dialog-slice';\nimport { createSaveChangesDialogSlice, SaveChangesConfirmationDialogSlice } from './save-changes-dialog-slice';\nimport { createDuplicatePanelSlice, DuplicatePanelSlice } from './duplicate-panel-slice';\nimport { createEditJsonDialogSlice, EditJsonDialogSlice } from './edit-json-dialog-slice';\nimport { createPanelDefinition } from './common';\nimport { createViewPanelSlice, ViewPanelSlice, VirtualPanelRef } from './view-panel-slice';\nimport { createLinksSlice, LinksSlice } from './links-slice';\n\nexport interface DashboardStoreState\n extends\n PanelGroupSlice,\n PanelSlice,\n PanelGroupEditorSlice,\n DeletePanelGroupSlice,\n PanelEditorSlice,\n DeletePanelSlice,\n DiscardChangesConfirmationDialogSlice,\n DuplicatePanelSlice,\n EditJsonDialogSlice,\n SaveChangesConfirmationDialogSlice,\n ViewPanelSlice,\n LinksSlice {\n isEditMode: boolean;\n setEditMode: (isEditMode: boolean) => void;\n setDashboard: (dashboard: DashboardResource) => void;\n kind: DashboardKind;\n metadata: ProjectMetadata;\n duration: DurationString;\n refreshInterval: DurationString;\n display?: Display;\n datasources?: Record<string, DatasourceSpec>;\n ttl?: DurationString;\n}\n\nexport const DashboardContext = createContext<StoreApi<DashboardStoreState> | undefined>(undefined);\n\nexport function useDashboardStore<T>(selector: (state: DashboardStoreState) => T): T {\n const store = useContext(DashboardContext);\n if (store === undefined) {\n throw new Error('No DashboardContext found. Did you forget a Provider?');\n }\n return useStoreWithEqualityFn(store, selector, shallow);\n}\n\nexport interface DashboardStoreProps {\n dashboardResource: DashboardResource;\n isEditMode?: boolean;\n viewPanelRef?: VirtualPanelRef;\n setViewPanelRef?: (viewPanelRef: VirtualPanelRef | undefined) => void;\n}\n\nexport interface DashboardProviderProps {\n initialState: DashboardStoreProps;\n children?: ReactNode;\n}\n\nexport function DashboardProvider(props: DashboardProviderProps): ReactElement {\n // Prevent calling createDashboardStore every time it rerenders\n const createDashboardStore = useCallback(initStore, [props]);\n const [store] = useState(createDashboardStore(props));\n\n // load plugin to retrieve initial spec if default panel kind is defined\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultPanelKind = defaultPluginKinds?.['Panel'] ?? '';\n const { data: plugin } = usePlugin('Panel', defaultPanelKind);\n\n useEffect(() => {\n if (plugin === undefined) return;\n const defaultPanelSpec = plugin.createInitialOptions ? plugin.createInitialOptions() : {};\n // set default panel kind, spec, and queries for add panel editor\n store.setState({\n initialValues: {\n panelDefinition: createPanelDefinition(defaultPanelKind, defaultPanelSpec),\n },\n });\n }, [plugin, store, defaultPanelKind]);\n\n return (\n <DashboardContext.Provider value={store as StoreApi<DashboardStoreState>}>\n {props.children}\n </DashboardContext.Provider>\n );\n}\n\nfunction initStore(props: DashboardProviderProps): StoreApi<DashboardStoreState> {\n const {\n initialState: { dashboardResource, isEditMode, viewPanelRef, setViewPanelRef },\n } = props;\n\n const {\n kind,\n metadata,\n spec: { display, duration, refreshInterval = DEFAULT_REFRESH_INTERVAL, datasources, layouts = [], panels = {} },\n } = dashboardResource;\n\n const links = dashboardResource.spec.links ?? [];\n\n const ttl = 'ttl' in dashboardResource.spec ? (dashboardResource.spec.ttl as DurationString) : undefined;\n\n const store = createStore<DashboardStoreState>()(\n immer(\n devtools((...args) => {\n const [set] = args;\n return {\n /* Groups */\n ...createPanelGroupSlice(layouts)(...args),\n ...createPanelGroupEditorSlice(...args),\n ...createDeletePanelGroupSlice(...args),\n /* Panels */\n ...createPanelSlice(panels)(...args),\n ...createPanelEditorSlice()(...args),\n ...createDeletePanelSlice()(...args),\n ...createDuplicatePanelSlice()(...args),\n ...createViewPanelSlice(viewPanelRef, setViewPanelRef)(...args),\n /* Links */\n ...createLinksSlice(links)(...args),\n /* General */\n ...createDiscardChangesDialogSlice(...args),\n ...createEditJsonDialogSlice(...args),\n ...createSaveChangesDialogSlice(...args),\n kind,\n metadata,\n display,\n duration,\n refreshInterval,\n datasources,\n ttl,\n isEditMode: !!isEditMode,\n setEditMode: (isEditMode: boolean): void => {\n set({ isEditMode });\n },\n setDashboard: ({\n kind,\n metadata,\n spec: { display, panels = {}, layouts = [], duration, refreshInterval, datasources = {}, links = [] },\n }): void => {\n set((state) => {\n state.kind = kind;\n state.metadata = metadata;\n state.display = display;\n state.panels = panels;\n const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);\n state.panelGroups = panelGroups;\n state.panelGroupOrder = panelGroupOrder;\n state.duration = duration;\n state.refreshInterval = refreshInterval ?? DEFAULT_REFRESH_INTERVAL;\n state.datasources = datasources;\n state.links = links;\n // TODO: add ttl here to e.g allow edition from JSON view, but probably requires quite some refactoring\n });\n },\n };\n })\n )\n );\n\n return store;\n}\n"],"names":["createStore","useStoreWithEqualityFn","devtools","immer","shallow","createContext","useCallback","useContext","useEffect","useState","usePlugin","usePluginRegistry","DEFAULT_REFRESH_INTERVAL","createPanelGroupEditorSlice","convertLayoutsToPanelGroups","createPanelGroupSlice","createPanelEditorSlice","createPanelSlice","createDeletePanelGroupSlice","createDeletePanelSlice","createDiscardChangesDialogSlice","createSaveChangesDialogSlice","createDuplicatePanelSlice","createEditJsonDialogSlice","createPanelDefinition","createViewPanelSlice","createLinksSlice","DashboardContext","undefined","useDashboardStore","selector","store","Error","DashboardProvider","props","createDashboardStore","initStore","defaultPluginKinds","defaultPanelKind","data","plugin","defaultPanelSpec","createInitialOptions","setState","initialValues","panelDefinition","Provider","value","children","initialState","dashboardResource","isEditMode","viewPanelRef","setViewPanelRef","kind","metadata","spec","display","duration","refreshInterval","datasources","layouts","panels","links","ttl","args","set","setEditMode","setDashboard","state","panelGroups","panelGroupOrder"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,WAAW,QAAQ,UAAU;AACtC,SAASC,sBAAsB,QAAQ,sBAAsB;AAE7D,SAASC,QAAQ,QAA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xC,qBAAqB2B,cAAcC,oBAAoBY,KAAK;YAC/D,SAAS,GACT,GAAGvC,iBAAiBqC,UAAUE,KAAK;YACnC,WAAW,GACX,GAAG7C,mCAAmC6C,KAAK;YAC3C,GAAG1C,6BAA6B0C,KAAK;YACrC,GAAG5C,gCAAgC4C,KAAK;YACxCX;YACAC;YACAE;YACAC;YACAC;YACAC;YACAI;YACAb,YAAY,CAAC,CAACA;YACdgB,aAAa,CAAChB;gBACZe,IAAI;oBAAEf;gBAAW;YACnB;YACAiB,cAAc,CAAC,EACbd,IAAI,EACJC,QAAQ,EACRC,MAAM,EAAEC,OAAO,EAAEK,SAAS,CAAC,CAAC,EAAED,UAAU,EAAE,EAAEH,QAAQ,EAAEC,eAAe,EAAEC,cAAc,CAAC,CAAC,EAAEG,QAAQ,EAAE,EAAE,EACtG;gBACCG,IAAI,CAACG;oBACHA,MAAMf,IAAI,GAAGA;oBACbe,MAAMd,QAAQ,GAAGA;oBACjBc,MAAMZ,OAAO,GAAGA;oBAChBY,MAAMP,MAAM,GAAGA;oBACf,MAAM,EAAEQ,WAAW,EAAEC,eAAe,EAAE,GAAGzD,4BAA4B+C;oBACrEQ,MAAMC,WAAW,GAAGA;oBACpBD,MAAME,eAAe,GAAGA;oBACxBF,MAAMX,QAAQ,GAAGA;oBACjBW,MAAMV,eAAe,GAAGA,mBAAmB/C;oBAC3CyD,MAAMT,WAAW,GAAGA;oBACpBS,MAAMN,KAAK,GAAGA;gBACd,uGAAuG;gBACzG;YACF;QACF;IACF;IAIJ,OAAOhC;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/DashboardProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createStore } from 'zustand';\nimport { useStoreWithEqualityFn } from 'zustand/traditional';\nimport type { StoreApi } from 'zustand';\nimport { devtools } from 'zustand/middleware';\nimport { immer } from 'zustand/middleware/immer';\nimport { shallow } from 'zustand/shallow';\nimport { createContext, ReactElement, ReactNode, useCallback, useContext, useEffect, useState } from 'react';\nimport { Display, DurationString, DatasourceSpec } from '@perses-dev/spec';\nimport { usePlugin, usePluginRegistry } from '@perses-dev/plugin-system';\nimport { DashboardKind, DashboardResource, ProjectMetadata } from '@perses-dev/client';\nimport { DEFAULT_REFRESH_INTERVAL } from '../../constants';\nimport { createPanelGroupEditorSlice, PanelGroupEditorSlice } from './panel-group-editor-slice';\nimport { convertLayoutsToPanelGroups, createPanelGroupSlice, PanelGroupSlice } from './panel-group-slice';\nimport { createPanelEditorSlice, PanelEditorSlice } from './panel-editor-slice';\nimport { createPanelSlice, PanelSlice } from './panel-slice';\nimport { createDeletePanelGroupSlice, DeletePanelGroupSlice } from './delete-panel-group-slice';\nimport { createDeletePanelSlice, DeletePanelSlice } from './delete-panel-slice';\nimport { createDiscardChangesDialogSlice, DiscardChangesConfirmationDialogSlice } from './discard-changes-dialog-slice';\nimport { createSaveChangesDialogSlice, SaveChangesConfirmationDialogSlice } from './save-changes-dialog-slice';\nimport { createDuplicatePanelSlice, DuplicatePanelSlice } from './duplicate-panel-slice';\nimport { createEditJsonDialogSlice, EditJsonDialogSlice } from './edit-json-dialog-slice';\nimport { createPanelDefinition } from './common';\nimport { createViewPanelSlice, ViewPanelSlice, VirtualPanelRef } from './view-panel-slice';\nimport { createLinksSlice, LinksSlice } from './links-slice';\n\nexport interface DashboardStoreState\n extends\n PanelGroupSlice,\n PanelSlice,\n PanelGroupEditorSlice,\n DeletePanelGroupSlice,\n PanelEditorSlice,\n DeletePanelSlice,\n DiscardChangesConfirmationDialogSlice,\n DuplicatePanelSlice,\n EditJsonDialogSlice,\n SaveChangesConfirmationDialogSlice,\n ViewPanelSlice,\n LinksSlice {\n isEditMode: boolean;\n setEditMode: (isEditMode: boolean) => void;\n setDashboard: (dashboard: DashboardResource) => void;\n setMetadata: (metadata: ProjectMetadata | ((prev: ProjectMetadata) => ProjectMetadata)) => void;\n kind: DashboardKind;\n metadata: ProjectMetadata;\n duration: DurationString;\n timezone?: string;\n refreshInterval: DurationString;\n display?: Display;\n datasources?: Record<string, DatasourceSpec>;\n ttl?: DurationString;\n}\n\nexport const DashboardContext = createContext<StoreApi<DashboardStoreState> | undefined>(undefined);\n\nexport function useDashboardStore<T>(selector: (state: DashboardStoreState) => T): T {\n const store = useContext(DashboardContext);\n if (store === undefined) {\n throw new Error('No DashboardContext found. Did you forget a Provider?');\n }\n return useStoreWithEqualityFn(store, selector, shallow);\n}\n\nexport interface DashboardStoreProps {\n dashboardResource: DashboardResource;\n isEditMode?: boolean;\n viewPanelRef?: VirtualPanelRef;\n setViewPanelRef?: (viewPanelRef: VirtualPanelRef | undefined) => void;\n}\n\nexport interface DashboardProviderProps {\n initialState: DashboardStoreProps;\n children?: ReactNode;\n}\n\nexport function DashboardProvider(props: DashboardProviderProps): ReactElement {\n // Prevent calling createDashboardStore every time it rerenders\n const createDashboardStore = useCallback(initStore, [props]);\n const [store] = useState(createDashboardStore(props));\n\n // load plugin to retrieve initial spec if default panel kind is defined\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultPanelKind = defaultPluginKinds?.['Panel'] ?? '';\n const { data: plugin } = usePlugin('Panel', defaultPanelKind);\n\n useEffect(() => {\n if (plugin === undefined) return;\n const defaultPanelSpec = plugin.createInitialOptions ? plugin.createInitialOptions() : {};\n // set default panel kind, spec, and queries for add panel editor\n store.setState({\n initialValues: {\n panelDefinition: createPanelDefinition(defaultPanelKind, defaultPanelSpec),\n },\n });\n }, [plugin, store, defaultPanelKind]);\n\n return (\n <DashboardContext.Provider value={store as StoreApi<DashboardStoreState>}>\n {props.children}\n </DashboardContext.Provider>\n );\n}\n\nfunction initStore(props: DashboardProviderProps): StoreApi<DashboardStoreState> {\n const {\n initialState: { dashboardResource, isEditMode, viewPanelRef, setViewPanelRef },\n } = props;\n\n const {\n kind,\n metadata,\n spec: {\n display,\n timezone,\n duration,\n refreshInterval = DEFAULT_REFRESH_INTERVAL,\n datasources,\n layouts = [],\n panels = {},\n },\n } = dashboardResource;\n\n const links = dashboardResource.spec.links ?? [];\n\n const ttl = 'ttl' in dashboardResource.spec ? (dashboardResource.spec.ttl as DurationString) : undefined;\n\n const store = createStore<DashboardStoreState>()(\n immer(\n devtools((...args) => {\n const [set] = args;\n return {\n /* Groups */\n ...createPanelGroupSlice(layouts)(...args),\n ...createPanelGroupEditorSlice(...args),\n ...createDeletePanelGroupSlice(...args),\n /* Panels */\n ...createPanelSlice(panels)(...args),\n ...createPanelEditorSlice()(...args),\n ...createDeletePanelSlice()(...args),\n ...createDuplicatePanelSlice()(...args),\n ...createViewPanelSlice(viewPanelRef, setViewPanelRef)(...args),\n /* Links */\n ...createLinksSlice(links)(...args),\n /* General */\n ...createDiscardChangesDialogSlice(...args),\n ...createEditJsonDialogSlice(...args),\n ...createSaveChangesDialogSlice(...args),\n kind,\n metadata,\n display,\n timezone,\n duration,\n refreshInterval,\n datasources,\n ttl,\n isEditMode: !!isEditMode,\n setEditMode: (isEditMode: boolean): void => {\n set({ isEditMode });\n },\n setDashboard: ({\n kind,\n metadata,\n spec: {\n display,\n panels = {},\n layouts = [],\n duration,\n refreshInterval,\n datasources = {},\n links = [],\n timezone,\n },\n }): void => {\n set((state) => {\n state.kind = kind;\n state.metadata = metadata;\n state.display = display;\n state.timezone = timezone;\n state.panels = panels;\n const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);\n state.panelGroups = panelGroups;\n state.panelGroupOrder = panelGroupOrder;\n state.duration = duration;\n state.refreshInterval = refreshInterval ?? DEFAULT_REFRESH_INTERVAL;\n state.datasources = datasources;\n state.links = links;\n // TODO: add ttl here to e.g allow edition from JSON view, but probably requires quite some refactoring\n });\n },\n setMetadata: (metadata): void => {\n set((state) => {\n state.metadata = typeof metadata === 'function' ? metadata(state.metadata) : metadata;\n });\n },\n };\n })\n )\n );\n\n return store;\n}\n"],"names":["createStore","useStoreWithEqualityFn","devtools","immer","shallow","createContext","useCallback","useContext","useEffect","useState","usePlugin","usePluginRegistry","DEFAULT_REFRESH_INTERVAL","createPanelGroupEditorSlice","convertLayoutsToPanelGroups","createPanelGroupSlice","createPanelEditorSlice","createPanelSlice","createDeletePanelGroupSlice","createDeletePanelSlice","createDiscardChangesDialogSlice","createSaveChangesDialogSlice","createDuplicatePanelSlice","createEditJsonDialogSlice","createPanelDefinition","createViewPanelSlice","createLinksSlice","DashboardContext","undefined","useDashboardStore","selector","store","Error","DashboardProvider","props","createDashboardStore","initStore","defaultPluginKinds","defaultPanelKind","data","plugin","defaultPanelSpec","createInitialOptions","setState","initialValues","panelDefinition","Provider","value","children","initialState","dashboardResource","isEditMode","viewPanelRef","setViewPanelRef","kind","metadata","spec","display","timezone","duration","refreshInterval","datasources","layouts","panels","links","ttl","args","set","setEditMode","setDashboard","state","panelGroups","panelGroupOrder","setMetadata"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,WAAW,QAAQ,UAAU;AACtC,SAASC,sBAAsB,QAAQ,sBAAsB;AAE7D,SAASC,QAAQ,QAAQ,qBAAqB;AAC9C,SAASC,KAAK,QAAQ,2BAA2B;AACjD,SAASC,OAAO,QAAQ,kBAAkB;AAC1C,SAASC,aAAa,EAA2BC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAE7G,SAASC,SAAS,EAAEC,iBAAiB,QAAQ,4BAA4B;AAEzE,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ACAC;YACAC;YACAC;YACAI;YACAd,YAAY,CAAC,CAACA;YACdiB,aAAa,CAACjB;gBACZgB,IAAI;oBAAEhB;gBAAW;YACnB;YACAkB,cAAc,CAAC,EACbf,IAAI,EACJC,QAAQ,EACRC,MAAM,EACJC,OAAO,EACPM,SAAS,CAAC,CAAC,EACXD,UAAU,EAAE,EACZH,QAAQ,EACRC,eAAe,EACfC,cAAc,CAAC,CAAC,EAChBG,QAAQ,EAAE,EACVN,QAAQ,EACT,EACF;gBACCS,IAAI,CAACG;oBACHA,MAAMhB,IAAI,GAAGA;oBACbgB,MAAMf,QAAQ,GAAGA;oBACjBe,MAAMb,OAAO,GAAGA;oBAChBa,MAAMZ,QAAQ,GAAGA;oBACjBY,MAAMP,MAAM,GAAGA;oBACf,MAAM,EAAEQ,WAAW,EAAEC,eAAe,EAAE,GAAG1D,4BAA4BgD;oBACrEQ,MAAMC,WAAW,GAAGA;oBACpBD,MAAME,eAAe,GAAGA;oBACxBF,MAAMX,QAAQ,GAAGA;oBACjBW,MAAMV,eAAe,GAAGA,mBAAmBhD;oBAC3C0D,MAAMT,WAAW,GAAGA;oBACpBS,MAAMN,KAAK,GAAGA;gBACd,uGAAuG;gBACzG;YACF;YACAS,aAAa,CAAClB;gBACZY,IAAI,CAACG;oBACHA,MAAMf,QAAQ,GAAG,OAAOA,aAAa,aAAaA,SAASe,MAAMf,QAAQ,IAAIA;gBAC/E;YACF;QACF;IACF;IAIJ,OAAOxB;AACT"}
|
|
@@ -5,12 +5,19 @@ export interface SaveChangesConfirmationDialogSlice {
|
|
|
5
5
|
openSaveChangesConfirmationDialog: (saveChangesConfirmationDialog: SaveChangesConfirmationDialogState) => void;
|
|
6
6
|
closeSaveChangesConfirmationDialog: () => void;
|
|
7
7
|
}
|
|
8
|
+
export type SaveChangesConfirmationDialogOptions = {
|
|
9
|
+
saveDefaultTimeRange: boolean;
|
|
10
|
+
saveDefaultRefreshInterval: boolean;
|
|
11
|
+
saveDefaultVariables: boolean;
|
|
12
|
+
saveDefaultTimeZone: boolean;
|
|
13
|
+
};
|
|
8
14
|
export interface SaveChangesConfirmationDialogState {
|
|
9
|
-
onSaveChanges: (
|
|
15
|
+
onSaveChanges: (options: SaveChangesConfirmationDialogOptions) => void;
|
|
10
16
|
onCancel: () => void;
|
|
11
17
|
isSavedDurationModified: boolean;
|
|
12
18
|
isSavedRefreshIntervalModified: boolean;
|
|
13
19
|
isSavedVariableModified: boolean;
|
|
20
|
+
isTimeZoneModified: boolean;
|
|
14
21
|
description?: string;
|
|
15
22
|
}
|
|
16
23
|
export declare const createSaveChangesDialogSlice: StateCreator<SaveChangesConfirmationDialogSlice, Middleware, [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save-changes-dialog-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/save-changes-dialog-slice.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,WAAW,kCAAkC;IACjD,6BAA6B,CAAC,EAAE,kCAAkC,CAAC;IACnE,iCAAiC,EAAE,CAAC,6BAA6B,EAAE,kCAAkC,KAAK,IAAI,CAAC;IAC/G,kCAAkC,EAAE,MAAM,IAAI,CAAC;CAChD;AAED,MAAM,
|
|
1
|
+
{"version":3,"file":"save-changes-dialog-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/save-changes-dialog-slice.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,WAAW,kCAAkC;IACjD,6BAA6B,CAAC,EAAE,kCAAkC,CAAC;IACnE,iCAAiC,EAAE,CAAC,6BAA6B,EAAE,kCAAkC,KAAK,IAAI,CAAC;IAC/G,kCAAkC,EAAE,MAAM,IAAI,CAAC;CAChD;AAED,MAAM,MAAM,oCAAoC,GAAG;IACjD,oBAAoB,EAAE,OAAO,CAAC;IAC9B,0BAA0B,EAAE,OAAO,CAAC;IACpC,oBAAoB,EAAE,OAAO,CAAC;IAC9B,mBAAmB,EAAE,OAAO,CAAC;CAC9B,CAAC;AACF,MAAM,WAAW,kCAAkC;IACjD,aAAa,EAAE,CAAC,OAAO,EAAE,oCAAoC,KAAK,IAAI,CAAC;IACvE,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,uBAAuB,EAAE,OAAO,CAAC;IACjC,8BAA8B,EAAE,OAAO,CAAC;IACxC,uBAAuB,EAAE,OAAO,CAAC;IACjC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,4BAA4B,EAAE,YAAY,CACrD,kCAAkC,EAClC,UAAU,EACV;CAAE,EACF,kCAAkC,CAuBlC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/save-changes-dialog-slice.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\n\nexport interface SaveChangesConfirmationDialogSlice {\n saveChangesConfirmationDialog?: SaveChangesConfirmationDialogState;\n openSaveChangesConfirmationDialog: (saveChangesConfirmationDialog: SaveChangesConfirmationDialogState) => void;\n closeSaveChangesConfirmationDialog: () => void;\n}\n\nexport
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/save-changes-dialog-slice.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\n\nexport interface SaveChangesConfirmationDialogSlice {\n saveChangesConfirmationDialog?: SaveChangesConfirmationDialogState;\n openSaveChangesConfirmationDialog: (saveChangesConfirmationDialog: SaveChangesConfirmationDialogState) => void;\n closeSaveChangesConfirmationDialog: () => void;\n}\n\nexport type SaveChangesConfirmationDialogOptions = {\n saveDefaultTimeRange: boolean;\n saveDefaultRefreshInterval: boolean;\n saveDefaultVariables: boolean;\n saveDefaultTimeZone: boolean;\n};\nexport interface SaveChangesConfirmationDialogState {\n onSaveChanges: (options: SaveChangesConfirmationDialogOptions) => void;\n onCancel: () => void;\n isSavedDurationModified: boolean;\n isSavedRefreshIntervalModified: boolean;\n isSavedVariableModified: boolean;\n isTimeZoneModified: boolean;\n description?: string;\n}\n\nexport const createSaveChangesDialogSlice: StateCreator<\n SaveChangesConfirmationDialogSlice,\n Middleware,\n [],\n SaveChangesConfirmationDialogSlice\n> = (set) => ({\n isOpen: false,\n\n openSaveChangesConfirmationDialog(dialog): void {\n set(\n (state) => {\n state.saveChangesConfirmationDialog = dialog;\n },\n false,\n 'openSaveChangesConfirmationDialog'\n );\n },\n\n closeSaveChangesConfirmationDialog(): void {\n set(\n (state) => {\n state.saveChangesConfirmationDialog = undefined;\n },\n false,\n 'closeSaveChangesConfirmationDialog'\n );\n },\n});\n"],"names":["createSaveChangesDialogSlice","set","isOpen","openSaveChangesConfirmationDialog","dialog","state","saveChangesConfirmationDialog","closeSaveChangesConfirmationDialog","undefined"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AA2BjC,OAAO,MAAMA,+BAKT,CAACC,MAAS,CAAA;QACZC,QAAQ;QAERC,mCAAkCC,MAAM;YACtCH,IACE,CAACI;gBACCA,MAAMC,6BAA6B,GAAGF;YACxC,GACA,OACA;QAEJ;QAEAG;YACEN,IACE,CAACI;gBACCA,MAAMC,6BAA6B,GAAGE;YACxC,GACA,OACA;QAEJ;IACF,CAAA,EAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-save-dashboard.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/use-save-dashboard.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"use-save-dashboard.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/use-save-dashboard.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAI3C,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,aAAa,EAAE,MAAM,IAAI,CAAC;IAE1B;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,mBAAmB,CAmF9E"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { useCallback, useState } from 'react';
|
|
14
14
|
import { isRelativeTimeRange } from '@perses-dev/spec';
|
|
15
|
-
import { useTimeRange } from '@perses-dev/plugin-system';
|
|
15
|
+
import { useTimeRange, useTimeZoneParams } from '@perses-dev/plugin-system';
|
|
16
16
|
import { useVariableDefinitionActions } from '../VariableProvider/VariableProvider';
|
|
17
17
|
import { useDashboard } from '../useDashboard';
|
|
18
18
|
import { useEditMode, useSaveChangesConfirmationDialog } from './dashboard-provider-api';
|
|
@@ -30,6 +30,7 @@ import { useEditMode, useSaveChangesConfirmationDialog } from './dashboard-provi
|
|
|
30
30
|
const { dashboard, setDashboard } = useDashboard();
|
|
31
31
|
const { setEditMode } = useEditMode();
|
|
32
32
|
const { timeRange, refreshInterval } = useTimeRange();
|
|
33
|
+
const { timeZone } = useTimeZoneParams();
|
|
33
34
|
const { getSavedVariablesStatus, setVariableDefaultValues } = useVariableDefinitionActions();
|
|
34
35
|
const { openSaveChangesConfirmationDialog, closeSaveChangesConfirmationDialog } = useSaveChangesConfirmationDialog();
|
|
35
36
|
const performSave = useCallback(async ()=>{
|
|
@@ -58,12 +59,17 @@ import { useEditMode, useSaveChangesConfirmationDialog } from './dashboard-provi
|
|
|
58
59
|
const { isSavedVariableModified } = getSavedVariablesStatus();
|
|
59
60
|
const isSavedDurationModified = isRelativeTimeRange(timeRange) && dashboard.spec.duration !== timeRange.pastDuration;
|
|
60
61
|
const isSavedRefreshIntervalModified = dashboard.spec.refreshInterval !== refreshInterval;
|
|
61
|
-
|
|
62
|
+
const isTimeZoneModified = timeZone === 'local' && !dashboard.spec.timezone ? false : dashboard.spec.timezone !== timeZone;
|
|
63
|
+
if (isSavedDurationModified || isSavedVariableModified || isSavedRefreshIntervalModified || isTimeZoneModified) {
|
|
62
64
|
openSaveChangesConfirmationDialog({
|
|
63
|
-
onSaveChanges: (
|
|
65
|
+
onSaveChanges: (options)=>{
|
|
66
|
+
const { saveDefaultRefreshInterval, saveDefaultTimeRange, saveDefaultTimeZone, saveDefaultVariables } = options;
|
|
64
67
|
if (isRelativeTimeRange(timeRange) && saveDefaultTimeRange) {
|
|
65
68
|
dashboard.spec.duration = timeRange.pastDuration;
|
|
66
69
|
}
|
|
70
|
+
if (saveDefaultTimeZone) {
|
|
71
|
+
dashboard.spec.timezone = timeZone;
|
|
72
|
+
}
|
|
67
73
|
if (saveDefaultVariables) {
|
|
68
74
|
const variables = setVariableDefaultValues();
|
|
69
75
|
dashboard.spec.variables = variables;
|
|
@@ -79,17 +85,19 @@ import { useEditMode, useSaveChangesConfirmationDialog } from './dashboard-provi
|
|
|
79
85
|
},
|
|
80
86
|
isSavedDurationModified,
|
|
81
87
|
isSavedVariableModified,
|
|
82
|
-
isSavedRefreshIntervalModified
|
|
88
|
+
isSavedRefreshIntervalModified,
|
|
89
|
+
isTimeZoneModified
|
|
83
90
|
});
|
|
84
91
|
} else {
|
|
85
92
|
performSave();
|
|
86
93
|
}
|
|
87
94
|
}, [
|
|
88
95
|
isSaving,
|
|
89
|
-
getSavedVariablesStatus,
|
|
90
96
|
timeRange,
|
|
91
97
|
dashboard,
|
|
92
98
|
refreshInterval,
|
|
99
|
+
timeZone,
|
|
100
|
+
getSavedVariablesStatus,
|
|
93
101
|
openSaveChangesConfirmationDialog,
|
|
94
102
|
setVariableDefaultValues,
|
|
95
103
|
setDashboard,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/use-save-dashboard.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useCallback, useState } from 'react';\nimport { isRelativeTimeRange } from '@perses-dev/spec';\nimport { useTimeRange } from '@perses-dev/plugin-system';\nimport { useVariableDefinitionActions } from '../VariableProvider/VariableProvider';\nimport { useDashboard } from '../useDashboard';\nimport { OnSaveDashboard } from './common';\nimport { useEditMode, useSaveChangesConfirmationDialog } from './dashboard-provider-api';\n\nexport interface SaveDashboardResult {\n /**\n * Triggers the save flow. If time range, refresh interval, or variable defaults have been\n * modified, opens the SaveChangesConfirmationDialog before saving. Otherwise saves directly.\n * Includes a concurrent-save guard to prevent duplicate saves.\n */\n saveDashboard: () => void;\n\n /**\n * Whether a save operation is currently in progress.\n */\n isSaving: boolean;\n}\n\n/**\n * Hook that encapsulates the full save-dashboard flow, including:\n * - Checking for modified defaults (time range, refresh interval, variables)\n * - Opening the SaveChangesConfirmationDialog when defaults have changed\n * - Saving directly when no confirmation is needed\n * - Preventing concurrent saves via an `isSaving` guard\n * - Exiting edit mode after a successful save\n *\n * Used by both SaveDashboardButton and DashboardShortcuts to ensure consistent save behavior.\n */\nexport function useSaveDashboard(onSave?: OnSaveDashboard): SaveDashboardResult {\n const [isSaving, setSaving] = useState(false);\n const { dashboard, setDashboard } = useDashboard();\n const { setEditMode } = useEditMode();\n const { timeRange, refreshInterval } = useTimeRange();\n const { getSavedVariablesStatus, setVariableDefaultValues } = useVariableDefinitionActions();\n const { openSaveChangesConfirmationDialog, closeSaveChangesConfirmationDialog } = useSaveChangesConfirmationDialog();\n
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/use-save-dashboard.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useCallback, useState } from 'react';\nimport { isRelativeTimeRange } from '@perses-dev/spec';\nimport { useTimeRange, useTimeZoneParams } from '@perses-dev/plugin-system';\nimport { useVariableDefinitionActions } from '../VariableProvider/VariableProvider';\nimport { useDashboard } from '../useDashboard';\nimport { OnSaveDashboard } from './common';\nimport { useEditMode, useSaveChangesConfirmationDialog } from './dashboard-provider-api';\nimport { SaveChangesConfirmationDialogOptions } from './save-changes-dialog-slice';\n\nexport interface SaveDashboardResult {\n /**\n * Triggers the save flow. If time range, refresh interval, or variable defaults have been\n * modified, opens the SaveChangesConfirmationDialog before saving. Otherwise saves directly.\n * Includes a concurrent-save guard to prevent duplicate saves.\n */\n saveDashboard: () => void;\n\n /**\n * Whether a save operation is currently in progress.\n */\n isSaving: boolean;\n}\n\n/**\n * Hook that encapsulates the full save-dashboard flow, including:\n * - Checking for modified defaults (time range, refresh interval, variables)\n * - Opening the SaveChangesConfirmationDialog when defaults have changed\n * - Saving directly when no confirmation is needed\n * - Preventing concurrent saves via an `isSaving` guard\n * - Exiting edit mode after a successful save\n *\n * Used by both SaveDashboardButton and DashboardShortcuts to ensure consistent save behavior.\n */\nexport function useSaveDashboard(onSave?: OnSaveDashboard): SaveDashboardResult {\n const [isSaving, setSaving] = useState(false);\n const { dashboard, setDashboard } = useDashboard();\n const { setEditMode } = useEditMode();\n const { timeRange, refreshInterval } = useTimeRange();\n const { timeZone } = useTimeZoneParams();\n const { getSavedVariablesStatus, setVariableDefaultValues } = useVariableDefinitionActions();\n const { openSaveChangesConfirmationDialog, closeSaveChangesConfirmationDialog } = useSaveChangesConfirmationDialog();\n const performSave = useCallback(async (): Promise<void> => {\n if (!onSave) {\n setEditMode(false);\n return;\n }\n\n try {\n setSaving(true);\n await onSave(dashboard);\n closeSaveChangesConfirmationDialog();\n setEditMode(false);\n } finally {\n setSaving(false);\n }\n }, [closeSaveChangesConfirmationDialog, dashboard, onSave, setEditMode]);\n\n const saveDashboard = useCallback((): void => {\n if (isSaving) {\n return;\n }\n\n const { isSavedVariableModified } = getSavedVariablesStatus();\n const isSavedDurationModified =\n isRelativeTimeRange(timeRange) && dashboard.spec.duration !== timeRange.pastDuration;\n const isSavedRefreshIntervalModified = dashboard.spec.refreshInterval !== refreshInterval;\n const isTimeZoneModified =\n timeZone === 'local' && !dashboard.spec.timezone ? false : dashboard.spec.timezone !== timeZone;\n\n if (isSavedDurationModified || isSavedVariableModified || isSavedRefreshIntervalModified || isTimeZoneModified) {\n openSaveChangesConfirmationDialog({\n onSaveChanges: (options: SaveChangesConfirmationDialogOptions) => {\n const { saveDefaultRefreshInterval, saveDefaultTimeRange, saveDefaultTimeZone, saveDefaultVariables } =\n options;\n if (isRelativeTimeRange(timeRange) && saveDefaultTimeRange) {\n dashboard.spec.duration = timeRange.pastDuration;\n }\n if (saveDefaultTimeZone) {\n dashboard.spec.timezone = timeZone;\n }\n if (saveDefaultVariables) {\n const variables = setVariableDefaultValues();\n dashboard.spec.variables = variables;\n }\n if (saveDefaultRefreshInterval && isSavedRefreshIntervalModified) {\n dashboard.spec.refreshInterval = refreshInterval;\n }\n setDashboard(dashboard);\n performSave();\n },\n onCancel: () => {\n closeSaveChangesConfirmationDialog();\n },\n isSavedDurationModified,\n isSavedVariableModified,\n isSavedRefreshIntervalModified,\n isTimeZoneModified,\n });\n } else {\n performSave();\n }\n }, [\n isSaving,\n timeRange,\n dashboard,\n refreshInterval,\n timeZone,\n getSavedVariablesStatus,\n openSaveChangesConfirmationDialog,\n setVariableDefaultValues,\n setDashboard,\n performSave,\n closeSaveChangesConfirmationDialog,\n ]);\n\n return { saveDashboard, isSaving };\n}\n"],"names":["useCallback","useState","isRelativeTimeRange","useTimeRange","useTimeZoneParams","useVariableDefinitionActions","useDashboard","useEditMode","useSaveChangesConfirmationDialog","useSaveDashboard","onSave","isSaving","setSaving","dashboard","setDashboard","setEditMode","timeRange","refreshInterval","timeZone","getSavedVariablesStatus","setVariableDefaultValues","openSaveChangesConfirmationDialog","closeSaveChangesConfirmationDialog","performSave","saveDashboard","isSavedVariableModified","isSavedDurationModified","spec","duration","pastDuration","isSavedRefreshIntervalModified","isTimeZoneModified","timezone","onSaveChanges","options","saveDefaultRefreshInterval","saveDefaultTimeRange","saveDefaultTimeZone","saveDefaultVariables","variables","onCancel"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC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,qBACJb,aAAa,WAAW,CAACL,UAAUc,IAAI,CAACK,QAAQ,GAAG,QAAQnB,UAAUc,IAAI,CAACK,QAAQ,KAAKd;QAEzF,IAAIQ,2BAA2BD,2BAA2BK,kCAAkCC,oBAAoB;YAC9GV,kCAAkC;gBAChCY,eAAe,CAACC;oBACd,MAAM,EAAEC,0BAA0B,EAAEC,oBAAoB,EAAEC,mBAAmB,EAAEC,oBAAoB,EAAE,GACnGJ;oBACF,IAAIhC,oBAAoBc,cAAcoB,sBAAsB;wBAC1DvB,UAAUc,IAAI,CAACC,QAAQ,GAAGZ,UAAUa,YAAY;oBAClD;oBACA,IAAIQ,qBAAqB;wBACvBxB,UAAUc,IAAI,CAACK,QAAQ,GAAGd;oBAC5B;oBACA,IAAIoB,sBAAsB;wBACxB,MAAMC,YAAYnB;wBAClBP,UAAUc,IAAI,CAACY,SAAS,GAAGA;oBAC7B;oBACA,IAAIJ,8BAA8BL,gCAAgC;wBAChEjB,UAAUc,IAAI,CAACV,eAAe,GAAGA;oBACnC;oBACAH,aAAaD;oBACbU;gBACF;gBACAiB,UAAU;oBACRlB;gBACF;gBACAI;gBACAD;gBACAK;gBACAC;YACF;QACF,OAAO;YACLR;QACF;IACF,GAAG;QACDZ;QACAK;QACAH;QACAI;QACAC;QACAC;QACAE;QACAD;QACAN;QACAS;QACAD;KACD;IAED,OAAO;QAAEE;QAAeb;IAAS;AACnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDashboard.d.ts","sourceRoot":"","sources":["../../src/context/useDashboard.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAkB,aAAa,EAAE,cAAc,EAAgC,MAAM,kBAAkB,CAAC;AAC/G,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAOvD,KAAK,aAAa,GAAG,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,aAAa,GAAG;QAAE,GAAG,CAAC,EAAE,cAAc,CAAA;KAAE,CAAA;CAAE,CAAC;AAC1G,wBAAgB,YAAY,IAAI;IAC9B,SAAS,EAAE,aAAa,CAAC;IACzB,YAAY,EAAE,CAAC,iBAAiB,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAC9D,
|
|
1
|
+
{"version":3,"file":"useDashboard.d.ts","sourceRoot":"","sources":["../../src/context/useDashboard.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAkB,aAAa,EAAE,cAAc,EAAgC,MAAM,kBAAkB,CAAC;AAC/G,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAOvD,KAAK,aAAa,GAAG,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,aAAa,GAAG;QAAE,GAAG,CAAC,EAAE,cAAc,CAAA;KAAE,CAAA;CAAE,CAAC;AAC1G,wBAAgB,YAAY,IAAI;IAC9B,SAAS,EAAE,aAAa,CAAC;IACzB,YAAY,EAAE,CAAC,iBAAiB,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAC9D,CAmGA"}
|
|
@@ -15,13 +15,14 @@ import { useDashboardStore } from './DashboardProvider';
|
|
|
15
15
|
import { useVariableDefinitionActions, useVariableDefinitions } from './VariableProvider';
|
|
16
16
|
import { useAnnotationActions, useAnnotationSpecs } from './AnnotationProvider';
|
|
17
17
|
export function useDashboard() {
|
|
18
|
-
const { panels, panelGroups, panelGroupOrder, setDashboard: setDashboardResource, kind, metadata, display, duration, refreshInterval, datasources, links, ttl } = useDashboardStore(({ panels, panelGroups, panelGroupOrder, setDashboard, kind, metadata, display, duration, refreshInterval, datasources, links, ttl })=>({
|
|
18
|
+
const { panels, panelGroups, panelGroupOrder, setDashboard: setDashboardResource, kind, metadata, display, timezone, duration, refreshInterval, datasources, links, ttl } = useDashboardStore(({ panels, panelGroups, panelGroupOrder, setDashboard, kind, metadata, timezone, display, duration, refreshInterval, datasources, links, ttl })=>({
|
|
19
19
|
panels,
|
|
20
20
|
panelGroups,
|
|
21
21
|
panelGroupOrder,
|
|
22
22
|
setDashboard,
|
|
23
23
|
kind,
|
|
24
24
|
metadata,
|
|
25
|
+
timezone,
|
|
25
26
|
display,
|
|
26
27
|
duration,
|
|
27
28
|
refreshInterval,
|
|
@@ -44,6 +45,7 @@ export function useDashboard() {
|
|
|
44
45
|
variables,
|
|
45
46
|
annotations,
|
|
46
47
|
duration,
|
|
48
|
+
timezone,
|
|
47
49
|
refreshInterval,
|
|
48
50
|
datasources,
|
|
49
51
|
links
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/useDashboard.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createPanelRef, DashboardSpec, DurationString, GridDefinition, PanelGroupId } from '@perses-dev/spec';\nimport { DashboardResource } from '@perses-dev/client';\nimport { PanelGroupDefinition } from '../model';\n\nimport { useDashboardStore } from './DashboardProvider';\nimport { useVariableDefinitionActions, useVariableDefinitions } from './VariableProvider';\nimport { useAnnotationActions, useAnnotationSpecs } from './AnnotationProvider';\n\ntype DashboardType = Omit<DashboardResource, 'spec'> & { spec: DashboardSpec & { ttl?: DurationString } };\nexport function useDashboard(): {\n dashboard: DashboardType;\n setDashboard: (dashboardResource: DashboardResource) => void;\n} {\n const {\n panels,\n panelGroups,\n panelGroupOrder,\n setDashboard: setDashboardResource,\n kind,\n metadata,\n display,\n duration,\n refreshInterval,\n datasources,\n links,\n ttl,\n } = useDashboardStore(\n ({\n panels,\n panelGroups,\n panelGroupOrder,\n setDashboard,\n kind,\n metadata,\n display,\n duration,\n refreshInterval,\n datasources,\n links,\n ttl,\n }) => ({\n panels,\n panelGroups,\n panelGroupOrder,\n setDashboard,\n kind,\n metadata,\n display,\n duration,\n refreshInterval,\n datasources,\n links,\n ttl,\n })\n );\n const { setVariableDefinitions } = useVariableDefinitionActions();\n const { setAnnotationSpecs } = useAnnotationActions();\n const variables = useVariableDefinitions();\n const annotations = useAnnotationSpecs();\n const layouts = convertPanelGroupsToLayouts(panelGroups, panelGroupOrder);\n\n const dashboard: DashboardType =\n kind === 'Dashboard'\n ? {\n kind,\n metadata,\n spec: {\n display,\n panels,\n layouts,\n variables,\n annotations,\n duration,\n refreshInterval,\n datasources,\n links,\n },\n }\n : {\n kind,\n metadata,\n spec: {\n display,\n panels,\n layouts,\n variables,\n annotations,\n duration,\n refreshInterval,\n datasources,\n links,\n ttl,\n },\n };\n\n const setDashboard = (dashboardResource: DashboardResource): void => {\n setVariableDefinitions(dashboardResource.spec.variables);\n if (dashboardResource.spec.annotations) {\n setAnnotationSpecs(dashboardResource.spec.annotations);\n }\n setDashboardResource(dashboardResource);\n };\n\n return {\n dashboard,\n setDashboard,\n };\n}\n\nfunction convertPanelGroupsToLayouts(\n panelGroups: Record<number, PanelGroupDefinition>,\n panelGroupOrder: PanelGroupId[]\n): GridDefinition[] {\n const layouts: GridDefinition[] = [];\n panelGroupOrder.map((groupOrderId) => {\n const group = panelGroups[groupOrderId];\n if (group === undefined) {\n throw new Error('panel group not found');\n }\n const { title, isCollapsed, repeatVariable, itemLayouts, itemPanelKeys } = group;\n let display = undefined;\n if (title || isCollapsed !== undefined) {\n display = {\n title: title ?? '',\n collapse: {\n open: !isCollapsed,\n },\n };\n }\n const layout: GridDefinition = {\n kind: 'Grid',\n spec: {\n display,\n items: itemLayouts.map((layout) => {\n const panelKey = itemPanelKeys[layout.i];\n if (panelKey === undefined) {\n throw new Error(`Missing panel key of layout ${layout.i}`);\n }\n return {\n x: layout.x,\n y: layout.y,\n width: layout.w,\n height: layout.h,\n content: createPanelRef(panelKey),\n };\n }),\n repeatVariable: repeatVariable,\n },\n };\n layouts.push(layout);\n });\n\n return layouts;\n}\n"],"names":["createPanelRef","useDashboardStore","useVariableDefinitionActions","useVariableDefinitions","useAnnotationActions","useAnnotationSpecs","useDashboard","panels","panelGroups","panelGroupOrder","setDashboard","setDashboardResource","kind","metadata","display","duration","refreshInterval","datasources","links","ttl","setVariableDefinitions","setAnnotationSpecs","variables","annotations","layouts","convertPanelGroupsToLayouts","dashboard","spec","dashboardResource","map","groupOrderId","group","undefined","Error","title","isCollapsed","repeatVariable","itemLayouts","itemPanelKeys","collapse","open","layout","items","panelKey","i","x","y","width","w","height","h","content","push"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,cAAc,QAAqE,mBAAmB;AAI/G,SAASC,iBAAiB,QAAQ,sBAAsB;AACxD,SAASC,4BAA4B,EAAEC,sBAAsB,QAAQ,qBAAqB;AAC1F,SAASC,oBAAoB,EAAEC,kBAAkB,QAAQ,uBAAuB;AAGhF,OAAO,SAASC;IAId,MAAM,EACJC,MAAM,EACNC,WAAW,EACXC,eAAe,EACfC,cAAcC,oBAAoB,EAClCC,IAAI,EACJC,QAAQ,EACRC,OAAO,EACPC,QAAQ,EACRC,eAAe,EACfC,WAAW,EACXC,KAAK,EACLC,GAAG,EACJ,
|
|
1
|
+
{"version":3,"sources":["../../src/context/useDashboard.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createPanelRef, DashboardSpec, DurationString, GridDefinition, PanelGroupId } from '@perses-dev/spec';\nimport { DashboardResource } from '@perses-dev/client';\nimport { PanelGroupDefinition } from '../model';\n\nimport { useDashboardStore } from './DashboardProvider';\nimport { useVariableDefinitionActions, useVariableDefinitions } from './VariableProvider';\nimport { useAnnotationActions, useAnnotationSpecs } from './AnnotationProvider';\n\ntype DashboardType = Omit<DashboardResource, 'spec'> & { spec: DashboardSpec & { ttl?: DurationString } };\nexport function useDashboard(): {\n dashboard: DashboardType;\n setDashboard: (dashboardResource: DashboardResource) => void;\n} {\n const {\n panels,\n panelGroups,\n panelGroupOrder,\n setDashboard: setDashboardResource,\n kind,\n metadata,\n display,\n timezone,\n duration,\n refreshInterval,\n datasources,\n links,\n ttl,\n } = useDashboardStore(\n ({\n panels,\n panelGroups,\n panelGroupOrder,\n setDashboard,\n kind,\n metadata,\n timezone,\n display,\n duration,\n refreshInterval,\n datasources,\n links,\n ttl,\n }) => ({\n panels,\n panelGroups,\n panelGroupOrder,\n setDashboard,\n kind,\n metadata,\n timezone,\n display,\n duration,\n refreshInterval,\n datasources,\n links,\n ttl,\n })\n );\n const { setVariableDefinitions } = useVariableDefinitionActions();\n const { setAnnotationSpecs } = useAnnotationActions();\n const variables = useVariableDefinitions();\n const annotations = useAnnotationSpecs();\n const layouts = convertPanelGroupsToLayouts(panelGroups, panelGroupOrder);\n\n const dashboard: DashboardType =\n kind === 'Dashboard'\n ? {\n kind,\n metadata,\n spec: {\n display,\n panels,\n layouts,\n variables,\n annotations,\n duration,\n timezone,\n refreshInterval,\n datasources,\n links,\n },\n }\n : {\n kind,\n metadata,\n spec: {\n display,\n panels,\n layouts,\n variables,\n annotations,\n duration,\n refreshInterval,\n datasources,\n links,\n ttl,\n },\n };\n\n const setDashboard = (dashboardResource: DashboardResource): void => {\n setVariableDefinitions(dashboardResource.spec.variables);\n if (dashboardResource.spec.annotations) {\n setAnnotationSpecs(dashboardResource.spec.annotations);\n }\n setDashboardResource(dashboardResource);\n };\n\n return {\n dashboard,\n setDashboard,\n };\n}\n\nfunction convertPanelGroupsToLayouts(\n panelGroups: Record<number, PanelGroupDefinition>,\n panelGroupOrder: PanelGroupId[]\n): GridDefinition[] {\n const layouts: GridDefinition[] = [];\n panelGroupOrder.map((groupOrderId) => {\n const group = panelGroups[groupOrderId];\n if (group === undefined) {\n throw new Error('panel group not found');\n }\n const { title, isCollapsed, repeatVariable, itemLayouts, itemPanelKeys } = group;\n let display = undefined;\n if (title || isCollapsed !== undefined) {\n display = {\n title: title ?? '',\n collapse: {\n open: !isCollapsed,\n },\n };\n }\n const layout: GridDefinition = {\n kind: 'Grid',\n spec: {\n display,\n items: itemLayouts.map((layout) => {\n const panelKey = itemPanelKeys[layout.i];\n if (panelKey === undefined) {\n throw new Error(`Missing panel key of layout ${layout.i}`);\n }\n return {\n x: layout.x,\n y: layout.y,\n width: layout.w,\n height: layout.h,\n content: createPanelRef(panelKey),\n };\n }),\n repeatVariable: repeatVariable,\n },\n };\n layouts.push(layout);\n });\n\n return layouts;\n}\n"],"names":["createPanelRef","useDashboardStore","useVariableDefinitionActions","useVariableDefinitions","useAnnotationActions","useAnnotationSpecs","useDashboard","panels","panelGroups","panelGroupOrder","setDashboard","setDashboardResource","kind","metadata","display","timezone","duration","refreshInterval","datasources","links","ttl","setVariableDefinitions","setAnnotationSpecs","variables","annotations","layouts","convertPanelGroupsToLayouts","dashboard","spec","dashboardResource","map","groupOrderId","group","undefined","Error","title","isCollapsed","repeatVariable","itemLayouts","itemPanelKeys","collapse","open","layout","items","panelKey","i","x","y","width","w","height","h","content","push"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,cAAc,QAAqE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B;IACvB;IAEA,OAAO;QACLF;QACAjB;IACF;AACF;AAEA,SAASgB,4BACPlB,WAAiD,EACjDC,eAA+B;IAE/B,MAAMgB,UAA4B,EAAE;IACpChB,gBAAgBqB,GAAG,CAAC,CAACC;QACnB,MAAMC,QAAQxB,WAAW,CAACuB,aAAa;QACvC,IAAIC,UAAUC,WAAW;YACvB,MAAM,IAAIC,MAAM;QAClB;QACA,MAAM,EAAEC,KAAK,EAAEC,WAAW,EAAEC,cAAc,EAAEC,WAAW,EAAEC,aAAa,EAAE,GAAGP;QAC3E,IAAIlB,UAAUmB;QACd,IAAIE,SAASC,gBAAgBH,WAAW;YACtCnB,UAAU;gBACRqB,OAAOA,SAAS;gBAChBK,UAAU;oBACRC,MAAM,CAACL;gBACT;YACF;QACF;QACA,MAAMM,SAAyB;YAC7B9B,MAAM;YACNgB,MAAM;gBACJd;gBACA6B,OAAOL,YAAYR,GAAG,CAAC,CAACY;oBACtB,MAAME,WAAWL,aAAa,CAACG,OAAOG,CAAC,CAAC;oBACxC,IAAID,aAAaX,WAAW;wBAC1B,MAAM,IAAIC,MAAM,CAAC,4BAA4B,EAAEQ,OAAOG,CAAC,EAAE;oBAC3D;oBACA,OAAO;wBACLC,GAAGJ,OAAOI,CAAC;wBACXC,GAAGL,OAAOK,CAAC;wBACXC,OAAON,OAAOO,CAAC;wBACfC,QAAQR,OAAOS,CAAC;wBAChBC,SAASpD,eAAe4C;oBAC1B;gBACF;gBACAP,gBAAgBA;YAClB;QACF;QACAZ,QAAQ4B,IAAI,CAACX;IACf;IAEA,OAAOjB;AACT"}
|
|
@@ -15,6 +15,7 @@ export interface DashboardAppProps {
|
|
|
15
15
|
isInitialVariableSticky?: boolean;
|
|
16
16
|
isLeavingConfirmDialogEnabled?: boolean;
|
|
17
17
|
dashboardTitleComponent?: ReactNode;
|
|
18
|
+
userPreferenceTimezone?: DashboardSpec['timezone'];
|
|
18
19
|
onSave?: OnSaveDashboard;
|
|
19
20
|
onDiscard?: (name: string, spec: DashboardSpec) => void;
|
|
20
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DashboardApp.d.ts","sourceRoot":"","sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"DashboardApp.d.ts","sourceRoot":"","sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAqB,MAAM,OAAO,CAAC;AAInE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EASL,mBAAmB,EAIpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAkE,MAAM,eAAe,CAAC;AAGhH,MAAM,WAAW,iBAAiB;IAChC,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,mBAAmB,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACnD,UAAU,EAAE,OAAO,CAAC;IACpB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC,6BAA6B,CAAC,EAAE,OAAO,CAAC;IACxC,uBAAuB,CAAC,EAAE,SAAS,CAAC;IACpC,sBAAsB,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IACnD,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;CACzD;AAED,eAAO,MAAM,YAAY,UAAW,iBAAiB,KAAG,YAMvD,CAAC"}
|
|
@@ -11,7 +11,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
import { useState } from 'react';
|
|
14
|
+
import { useMemo, useState } from 'react';
|
|
15
15
|
import { Box } from '@mui/material';
|
|
16
16
|
import { ChartsProvider, ErrorAlert, ErrorBoundary, useChartsTheme } from '@perses-dev/components';
|
|
17
17
|
import { useDatasourceStore } from '@perses-dev/plugin-system';
|
|
@@ -26,7 +26,7 @@ export const DashboardApp = (props)=>{
|
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
28
|
const DashboardAppContent = (props)=>{
|
|
29
|
-
const { dashboardResource, emptyDashboardProps, isReadonly, isVariableEnabled, isAnnotationEnabled, isDatasourceEnabled, disableShortcuts, isCreating, isInitialVariableSticky, isLeavingConfirmDialogEnabled, dashboardTitleComponent, onSave, onDiscard } = props;
|
|
29
|
+
const { dashboardResource, emptyDashboardProps, isReadonly, isVariableEnabled, isAnnotationEnabled, isDatasourceEnabled, disableShortcuts, isCreating, isInitialVariableSticky, isLeavingConfirmDialogEnabled, dashboardTitleComponent, userPreferenceTimezone, onSave, onDiscard } = props;
|
|
30
30
|
const chartsTheme = useChartsTheme();
|
|
31
31
|
const { isEditMode, setEditMode } = useEditMode();
|
|
32
32
|
const { dashboard, setDashboard } = useDashboard();
|
|
@@ -71,6 +71,12 @@ const DashboardAppContent = (props)=>{
|
|
|
71
71
|
onCancelButtonClick,
|
|
72
72
|
disabled: disableShortcuts
|
|
73
73
|
});
|
|
74
|
+
const toolBarTimezone = useMemo(()=>{
|
|
75
|
+
return dashboardResource.spec.timezone || userPreferenceTimezone || 'local';
|
|
76
|
+
}, [
|
|
77
|
+
dashboardResource.spec,
|
|
78
|
+
userPreferenceTimezone
|
|
79
|
+
]);
|
|
74
80
|
return /*#__PURE__*/ _jsxs(Box, {
|
|
75
81
|
sx: {
|
|
76
82
|
flexGrow: 1,
|
|
@@ -82,6 +88,7 @@ const DashboardAppContent = (props)=>{
|
|
|
82
88
|
children: [
|
|
83
89
|
/*#__PURE__*/ _jsx(DashboardToolbar, {
|
|
84
90
|
dashboardName: dashboardResource.metadata.name,
|
|
91
|
+
timezone: toolBarTimezone,
|
|
85
92
|
dashboardTitleComponent: dashboardTitleComponent,
|
|
86
93
|
initialVariableIsSticky: isInitialVariableSticky,
|
|
87
94
|
onSave: onSave,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ReactElement, ReactNode, useState } from 'react';\nimport { Box } from '@mui/material';\nimport { ChartsProvider, ErrorAlert, ErrorBoundary, useChartsTheme } from '@perses-dev/components';\nimport { useDatasourceStore } from '@perses-dev/plugin-system';\nimport { DashboardSpec } from '@perses-dev/spec';\nimport { DashboardResource } from '@perses-dev/client';\nimport {\n PanelDrawer,\n Dashboard,\n useDashboardShortcuts,\n PanelGroupDialog,\n DeletePanelGroupDialog,\n DashboardDiscardChangesConfirmationDialog,\n DashboardToolbar,\n DeletePanelDialog,\n EmptyDashboardProps,\n EditJsonDialog,\n SaveChangesConfirmationDialog,\n LeaveDialog,\n} from '../../components';\nimport { OnSaveDashboard, useDashboard, useDiscardChangesConfirmationDialog, useEditMode } from '../../context';\nimport { PanelFocusProvider } from '../../keyboard-shortcuts';\n\nexport interface DashboardAppProps {\n dashboardResource: DashboardResource;\n emptyDashboardProps?: Partial<EmptyDashboardProps>;\n isReadonly: boolean;\n isVariableEnabled: boolean;\n isAnnotationEnabled: boolean;\n isDatasourceEnabled: boolean;\n disableShortcuts?: boolean;\n isCreating?: boolean;\n isInitialVariableSticky?: boolean;\n // If true, browser confirmation dialog will be shown when navigating away with unsaved changes (closing tab, ...).\n isLeavingConfirmDialogEnabled?: boolean;\n dashboardTitleComponent?: ReactNode;\n onSave?: OnSaveDashboard;\n onDiscard?: (name: string, spec: DashboardSpec) => void;\n}\n\nexport const DashboardApp = (props: DashboardAppProps): ReactElement => {\n return (\n <PanelFocusProvider>\n <DashboardAppContent {...props} />\n </PanelFocusProvider>\n );\n};\n\nconst DashboardAppContent = (props: DashboardAppProps): ReactElement => {\n const {\n dashboardResource,\n emptyDashboardProps,\n isReadonly,\n isVariableEnabled,\n isAnnotationEnabled,\n isDatasourceEnabled,\n disableShortcuts,\n isCreating,\n isInitialVariableSticky,\n isLeavingConfirmDialogEnabled,\n dashboardTitleComponent,\n onSave,\n onDiscard,\n } = props;\n\n const chartsTheme = useChartsTheme();\n\n const { isEditMode, setEditMode } = useEditMode();\n\n const { dashboard, setDashboard } = useDashboard();\n const [originalDashboard, setOriginalDashboard] = useState<DashboardResource | undefined>(undefined);\n\n const { setSavedDatasources } = useDatasourceStore();\n\n const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } =\n useDiscardChangesConfirmationDialog();\n\n const handleDiscardChanges = (): void => {\n // Reset to the original spec and exit edit mode\n if (originalDashboard) {\n setDashboard(originalDashboard);\n }\n setEditMode(false);\n closeDiscardChangesConfirmationDialog();\n if (onDiscard) {\n onDiscard(dashboard.metadata.name, dashboard.spec);\n }\n };\n\n const onEditButtonClick = (): void => {\n setEditMode(true);\n setOriginalDashboard(dashboard);\n setSavedDatasources(dashboard.spec.datasources ?? {});\n };\n\n const onCancelButtonClick = (): void => {\n // check if dashboard has been modified\n if (JSON.stringify(dashboard) === JSON.stringify(originalDashboard)) {\n setEditMode(false);\n } else {\n openDiscardChangesConfirmationDialog({\n onDiscardChanges: () => {\n handleDiscardChanges();\n },\n onCancel: () => {\n closeDiscardChangesConfirmationDialog();\n },\n });\n }\n };\n\n useDashboardShortcuts({\n onSave,\n isReadonly,\n onEditButtonClick,\n onCancelButtonClick,\n disabled: disableShortcuts,\n });\n\n return (\n <Box\n sx={{\n flexGrow: 1,\n overflowX: 'hidden',\n overflowY: 'auto',\n display: 'flex',\n flexDirection: 'column',\n }}\n >\n <DashboardToolbar\n dashboardName={dashboardResource.metadata.name}\n dashboardTitleComponent={dashboardTitleComponent}\n initialVariableIsSticky={isInitialVariableSticky}\n onSave={onSave}\n isReadonly={isReadonly}\n isVariableEnabled={isVariableEnabled}\n isAnnotationEnabled={isAnnotationEnabled}\n isDatasourceEnabled={isDatasourceEnabled}\n onEditButtonClick={onEditButtonClick}\n onCancelButtonClick={onCancelButtonClick}\n />\n <Box sx={{ paddingTop: 2, paddingX: 2, height: '100%' }}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <Dashboard\n emptyDashboardProps={{\n onEditButtonClick,\n ...emptyDashboardProps,\n }}\n />\n </ErrorBoundary>\n <ChartsProvider chartsTheme={chartsTheme} enablePinning={false} enableSyncGrouping={false}>\n <PanelDrawer />\n </ChartsProvider>\n <PanelGroupDialog />\n <DeletePanelGroupDialog />\n <DeletePanelDialog />\n <DashboardDiscardChangesConfirmationDialog />\n <EditJsonDialog isReadonly={!isEditMode} disableMetadataEdition={!isCreating} />\n <SaveChangesConfirmationDialog />\n {isLeavingConfirmDialogEnabled && isEditMode && (\n <LeaveDialog original={originalDashboard} current={dashboard} />\n )}\n </Box>\n </Box>\n );\n};\n"],"names":["useState","Box","ChartsProvider","ErrorAlert","ErrorBoundary","useChartsTheme","useDatasourceStore","PanelDrawer","Dashboard","useDashboardShortcuts","PanelGroupDialog","DeletePanelGroupDialog","DashboardDiscardChangesConfirmationDialog","DashboardToolbar","DeletePanelDialog","EditJsonDialog","SaveChangesConfirmationDialog","LeaveDialog","useDashboard","useDiscardChangesConfirmationDialog","useEditMode","PanelFocusProvider","DashboardApp","props","DashboardAppContent","dashboardResource","emptyDashboardProps","isReadonly","isVariableEnabled","isAnnotationEnabled","isDatasourceEnabled","disableShortcuts","isCreating","isInitialVariableSticky","isLeavingConfirmDialogEnabled","dashboardTitleComponent","onSave","onDiscard","chartsTheme","isEditMode","setEditMode","dashboard","setDashboard","originalDashboard","setOriginalDashboard","undefined","setSavedDatasources","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","handleDiscardChanges","metadata","name","spec","onEditButtonClick","datasources","onCancelButtonClick","JSON","stringify","onDiscardChanges","onCancel","disabled","sx","flexGrow","overflowX","overflowY","display","flexDirection","dashboardName","initialVariableIsSticky","paddingTop","paddingX","height","FallbackComponent","enablePinning","enableSyncGrouping","disableMetadataEdition","original","current"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAkCA,QAAQ,QAAQ,QAAQ;AAC1D,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAASC,cAAc,EAAEC,UAAU,EAAEC,aAAa,EAAEC,cAAc,QAAQ,yBAAyB;AACnG,SAASC,kBAAkB,QAAQ,4BAA4B;AAG/D,SACEC,WAAW,EACXC,SAAS,EACTC,qBAAqB,EACrBC,gBAAgB,EAChBC,sBAAsB,EACtBC,yCAAyC,EACzCC,gBAAgB,EAChBC,iBAAiB,EAEjBC,cAAc,EACdC,6BAA6B,EAC7BC,WAAW,QACN,mBAAmB;AAC1B,SAA0BC,YAAY,EAAEC,mCAAmC,EAAEC,WAAW,QAAQ,gBAAgB;AAChH,SAASC,kBAAkB,QAAQ,2BAA2B;AAmB9D,OAAO,MAAMC,eAAe,CAACC;I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YACVC,WAAW;YACXC,WAAW;YACXC,SAAS;YACTC,eAAe;QACjB;;0BAEA,KAACrD;gBACCsD,eAAe1C,kBAAkByB,QAAQ,CAACC,IAAI;gBAC9ChB,yBAAyBA;gBACzBiC,yBAAyBnC;gBACzBG,QAAQA;gBACRT,YAAYA;gBACZC,mBAAmBA;gBACnBC,qBAAqBA;gBACrBC,qBAAqBA;gBACrBuB,mBAAmBA;gBACnBE,qBAAqBA;;0BAEvB,MAACtD;gBAAI4D,IAAI;oBAAEQ,YAAY;oBAAGC,UAAU;oBAAGC,QAAQ;gBAAO;;kCACpD,KAACnE;wBAAcoE,mBAAmBrE;kCAChC,cAAA,KAACK;4BACCkB,qBAAqB;gCACnB2B;gCACA,GAAG3B,mBAAmB;4BACxB;;;kCAGJ,KAACxB;wBAAeoC,aAAaA;wBAAamC,eAAe;wBAAOC,oBAAoB;kCAClF,cAAA,KAACnE;;kCAEH,KAACG;kCACD,KAACC;kCACD,KAACG;kCACD,KAACF;kCACD,KAACG;wBAAeY,YAAY,CAACY;wBAAYoC,wBAAwB,CAAC3C;;kCAClE,KAAChB;oBACAkB,iCAAiCK,4BAChC,KAACtB;wBAAY2D,UAAUjC;wBAAmBkC,SAASpC;;;;;;AAK7D"}
|
|
1
|
+
{"version":3,"sources":["../../../src/views/ViewDashboard/DashboardApp.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ReactElement, ReactNode, useMemo, useState } from 'react';\nimport { Box } from '@mui/material';\nimport { ChartsProvider, ErrorAlert, ErrorBoundary, useChartsTheme } from '@perses-dev/components';\nimport { useDatasourceStore } from '@perses-dev/plugin-system';\nimport { DashboardSpec } from '@perses-dev/spec';\nimport { DashboardResource } from '@perses-dev/client';\nimport {\n PanelDrawer,\n Dashboard,\n useDashboardShortcuts,\n PanelGroupDialog,\n DeletePanelGroupDialog,\n DashboardDiscardChangesConfirmationDialog,\n DashboardToolbar,\n DeletePanelDialog,\n EmptyDashboardProps,\n EditJsonDialog,\n SaveChangesConfirmationDialog,\n LeaveDialog,\n} from '../../components';\nimport { OnSaveDashboard, useDashboard, useDiscardChangesConfirmationDialog, useEditMode } from '../../context';\nimport { PanelFocusProvider } from '../../keyboard-shortcuts';\n\nexport interface DashboardAppProps {\n dashboardResource: DashboardResource;\n emptyDashboardProps?: Partial<EmptyDashboardProps>;\n isReadonly: boolean;\n isVariableEnabled: boolean;\n isAnnotationEnabled: boolean;\n isDatasourceEnabled: boolean;\n disableShortcuts?: boolean;\n isCreating?: boolean;\n isInitialVariableSticky?: boolean;\n // If true, browser confirmation dialog will be shown when navigating away with unsaved changes (closing tab, ...).\n isLeavingConfirmDialogEnabled?: boolean;\n dashboardTitleComponent?: ReactNode;\n userPreferenceTimezone?: DashboardSpec['timezone'];\n onSave?: OnSaveDashboard;\n onDiscard?: (name: string, spec: DashboardSpec) => void;\n}\n\nexport const DashboardApp = (props: DashboardAppProps): ReactElement => {\n return (\n <PanelFocusProvider>\n <DashboardAppContent {...props} />\n </PanelFocusProvider>\n );\n};\n\nconst DashboardAppContent = (props: DashboardAppProps): ReactElement => {\n const {\n dashboardResource,\n emptyDashboardProps,\n isReadonly,\n isVariableEnabled,\n isAnnotationEnabled,\n isDatasourceEnabled,\n disableShortcuts,\n isCreating,\n isInitialVariableSticky,\n isLeavingConfirmDialogEnabled,\n dashboardTitleComponent,\n userPreferenceTimezone,\n onSave,\n onDiscard,\n } = props;\n\n const chartsTheme = useChartsTheme();\n\n const { isEditMode, setEditMode } = useEditMode();\n\n const { dashboard, setDashboard } = useDashboard();\n const [originalDashboard, setOriginalDashboard] = useState<DashboardResource | undefined>(undefined);\n\n const { setSavedDatasources } = useDatasourceStore();\n\n const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } =\n useDiscardChangesConfirmationDialog();\n\n const handleDiscardChanges = (): void => {\n // Reset to the original spec and exit edit mode\n if (originalDashboard) {\n setDashboard(originalDashboard);\n }\n setEditMode(false);\n closeDiscardChangesConfirmationDialog();\n if (onDiscard) {\n onDiscard(dashboard.metadata.name, dashboard.spec);\n }\n };\n\n const onEditButtonClick = (): void => {\n setEditMode(true);\n setOriginalDashboard(dashboard);\n setSavedDatasources(dashboard.spec.datasources ?? {});\n };\n\n const onCancelButtonClick = (): void => {\n // check if dashboard has been modified\n if (JSON.stringify(dashboard) === JSON.stringify(originalDashboard)) {\n setEditMode(false);\n } else {\n openDiscardChangesConfirmationDialog({\n onDiscardChanges: () => {\n handleDiscardChanges();\n },\n onCancel: () => {\n closeDiscardChangesConfirmationDialog();\n },\n });\n }\n };\n\n useDashboardShortcuts({\n onSave,\n isReadonly,\n onEditButtonClick,\n onCancelButtonClick,\n disabled: disableShortcuts,\n });\n\n const toolBarTimezone = useMemo((): string => {\n return dashboardResource.spec.timezone || userPreferenceTimezone || 'local';\n }, [dashboardResource.spec, userPreferenceTimezone]);\n\n return (\n <Box\n sx={{\n flexGrow: 1,\n overflowX: 'hidden',\n overflowY: 'auto',\n display: 'flex',\n flexDirection: 'column',\n }}\n >\n <DashboardToolbar\n dashboardName={dashboardResource.metadata.name}\n timezone={toolBarTimezone}\n dashboardTitleComponent={dashboardTitleComponent}\n initialVariableIsSticky={isInitialVariableSticky}\n onSave={onSave}\n isReadonly={isReadonly}\n isVariableEnabled={isVariableEnabled}\n isAnnotationEnabled={isAnnotationEnabled}\n isDatasourceEnabled={isDatasourceEnabled}\n onEditButtonClick={onEditButtonClick}\n onCancelButtonClick={onCancelButtonClick}\n />\n <Box sx={{ paddingTop: 2, paddingX: 2, height: '100%' }}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <Dashboard\n emptyDashboardProps={{\n onEditButtonClick,\n ...emptyDashboardProps,\n }}\n />\n </ErrorBoundary>\n <ChartsProvider chartsTheme={chartsTheme} enablePinning={false} enableSyncGrouping={false}>\n <PanelDrawer />\n </ChartsProvider>\n <PanelGroupDialog />\n <DeletePanelGroupDialog />\n <DeletePanelDialog />\n <DashboardDiscardChangesConfirmationDialog />\n <EditJsonDialog isReadonly={!isEditMode} disableMetadataEdition={!isCreating} />\n <SaveChangesConfirmationDialog />\n {isLeavingConfirmDialogEnabled && isEditMode && (\n <LeaveDialog original={originalDashboard} current={dashboard} />\n )}\n </Box>\n </Box>\n );\n};\n"],"names":["useMemo","useState","Box","ChartsProvider","ErrorAlert","ErrorBoundary","useChartsTheme","useDatasourceStore","PanelDrawer","Dashboard","useDashboardShortcuts","PanelGroupDialog","DeletePanelGroupDialog","DashboardDiscardChangesConfirmationDialog","DashboardToolbar","DeletePanelDialog","EditJsonDialog","SaveChangesConfirmationDialog","LeaveDialog","useDashboard","useDiscardChangesConfirmationDialog","useEditMode","PanelFocusProvider","DashboardApp","props","DashboardAppContent","dashboardResource","emptyDashboardProps","isReadonly","isVariableEnabled","isAnnotationEnabled","isDatasourceEnabled","disableShortcuts","isCreating","isInitialVariableSticky","isLeavingConfirmDialogEnabled","dashboardTitleComponent","userPreferenceTimezone","onSave","onDiscard","chartsTheme","isEditMode","setEditMode","dashboard","setDashboard","originalDashboard","setOriginalDashboard","undefined","setSavedDatasources","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","handleDiscardChanges","metadata","name","spec","onEditButtonClick","datasources","onCancelButtonClick","JSON","stringify","onDiscardChanges","onCancel","disabled","toolBarTimezone","timezone","sx","flexGrow","overflowX","overflowY","display","flexDirection","dashboardName","initialVariableIsSticky","paddingTop","paddingX","height","FallbackComponent","enablePinning","enableSyncGrouping","disableMetadataEdition","original","current"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,E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