@perses-dev/dashboards 0.30.0 → 0.31.0

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.
Files changed (93) hide show
  1. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +5 -22
  2. package/dist/cjs/components/EditJsonButton/EditJsonButton.js +1 -0
  3. package/dist/cjs/components/GridLayout/GridTitle.js +30 -9
  4. package/dist/cjs/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +88 -0
  5. package/dist/cjs/components/SaveChangesConfirmationDialog/index.js +28 -0
  6. package/dist/cjs/components/SaveDashboardButton/SaveDashboardButton.js +78 -0
  7. package/dist/cjs/components/SaveDashboardButton/index.js +28 -0
  8. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +123 -197
  9. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +178 -0
  10. package/dist/cjs/components/Variables/VariableEditorForm/index.js +1 -0
  11. package/dist/cjs/components/Variables/index.js +1 -0
  12. package/dist/cjs/components/index.js +1 -0
  13. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +2 -0
  14. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +9 -0
  15. package/dist/cjs/context/DashboardProvider/save-changes-dialog-slice.js +33 -0
  16. package/dist/cjs/context/TemplateVariableProvider/TemplateVariableProvider.js +56 -7
  17. package/dist/cjs/context/TemplateVariableProvider/hydrationUtils.js +2 -0
  18. package/dist/cjs/context/TemplateVariableProvider/utils.js +37 -0
  19. package/dist/cjs/views/ViewDashboard/DashboardApp.js +2 -1
  20. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  21. package/dist/components/DashboardToolbar/DashboardToolbar.js +6 -23
  22. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  23. package/dist/components/EditJsonButton/EditJsonButton.js +1 -0
  24. package/dist/components/EditJsonButton/EditJsonButton.js.map +1 -1
  25. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  26. package/dist/components/GridLayout/GridTitle.js +30 -9
  27. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  28. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts +3 -0
  29. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts.map +1 -0
  30. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +82 -0
  31. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -0
  32. package/dist/components/SaveChangesConfirmationDialog/index.d.ts +2 -0
  33. package/dist/components/SaveChangesConfirmationDialog/index.d.ts.map +1 -0
  34. package/dist/components/SaveChangesConfirmationDialog/index.js +15 -0
  35. package/dist/components/SaveChangesConfirmationDialog/index.js.map +1 -0
  36. package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts +10 -0
  37. package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts.map +1 -0
  38. package/dist/components/SaveDashboardButton/SaveDashboardButton.js +72 -0
  39. package/dist/components/SaveDashboardButton/SaveDashboardButton.js.map +1 -0
  40. package/dist/components/SaveDashboardButton/index.d.ts +2 -0
  41. package/dist/components/SaveDashboardButton/index.d.ts.map +1 -0
  42. package/dist/components/SaveDashboardButton/index.js +15 -0
  43. package/dist/components/SaveDashboardButton/index.js.map +1 -0
  44. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +4 -2
  45. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  46. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +126 -195
  47. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  48. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +16 -0
  49. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -0
  50. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +122 -0
  51. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -0
  52. package/dist/components/Variables/VariableEditorForm/index.d.ts +1 -0
  53. package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -1
  54. package/dist/components/Variables/VariableEditorForm/index.js +1 -0
  55. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -1
  56. package/dist/components/Variables/index.d.ts +1 -0
  57. package/dist/components/Variables/index.d.ts.map +1 -1
  58. package/dist/components/Variables/index.js +1 -0
  59. package/dist/components/Variables/index.js.map +1 -1
  60. package/dist/components/index.d.ts +1 -0
  61. package/dist/components/index.d.ts.map +1 -1
  62. package/dist/components/index.js +1 -0
  63. package/dist/components/index.js.map +1 -1
  64. package/dist/context/DashboardProvider/DashboardProvider.d.ts +2 -1
  65. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  66. package/dist/context/DashboardProvider/DashboardProvider.js +2 -0
  67. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  68. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +5 -0
  69. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  70. package/dist/context/DashboardProvider/dashboard-provider-api.js +8 -0
  71. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  72. package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts +15 -0
  73. package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts.map +1 -0
  74. package/dist/context/DashboardProvider/save-changes-dialog-slice.js +27 -0
  75. package/dist/context/DashboardProvider/save-changes-dialog-slice.js.map +1 -0
  76. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts +4 -0
  77. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +1 -1
  78. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js +51 -7
  79. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +1 -1
  80. package/dist/context/TemplateVariableProvider/hydrationUtils.d.ts.map +1 -1
  81. package/dist/context/TemplateVariableProvider/hydrationUtils.js +2 -0
  82. package/dist/context/TemplateVariableProvider/hydrationUtils.js.map +1 -1
  83. package/dist/context/TemplateVariableProvider/utils.d.ts +4 -0
  84. package/dist/context/TemplateVariableProvider/utils.d.ts.map +1 -0
  85. package/dist/context/TemplateVariableProvider/utils.js +33 -0
  86. package/dist/context/TemplateVariableProvider/utils.js.map +1 -0
  87. package/dist/stories/decorators/WithDashboard.js.map +1 -1
  88. package/dist/stories/decorators/WithDatasourceStore.js.map +1 -1
  89. package/dist/stories/decorators/WithTemplateVariables.js.map +1 -1
  90. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  91. package/dist/views/ViewDashboard/DashboardApp.js +3 -2
  92. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  93. package/package.json +6 -6
@@ -0,0 +1,82 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
+ import { useState } from 'react';
15
+ import { Checkbox, FormGroup, FormControlLabel, Typography } from '@mui/material';
16
+ import { useTimeRange } from '@perses-dev/plugin-system';
17
+ import { isRelativeTimeRange, SAVE_DEFAULTS_DIALOG_TEXT } from '@perses-dev/core';
18
+ import { Dialog } from '@perses-dev/components';
19
+ import { useSaveChangesConfirmationDialog } from '../../context';
20
+ export const SaveChangesConfirmationDialog = ()=>{
21
+ const [saveDefaultTimeRange, setSaveDefaultTimeRange] = useState(true);
22
+ const [saveDefaultVariables, setSaveDefaultVariables] = useState(true);
23
+ const { saveChangesConfirmationDialog: dialog } = useSaveChangesConfirmationDialog();
24
+ const isOpen = dialog !== undefined;
25
+ const { timeRange } = useTimeRange();
26
+ const currentTimeRangeText = isRelativeTimeRange(timeRange) ? `(Last ${timeRange.pastDuration})` : '(Absolute time ranges can not be saved)';
27
+ const timeRangeInfoText = `Save current time range as new default ${currentTimeRangeText}`;
28
+ return /*#__PURE__*/ _jsx(Dialog, {
29
+ open: isOpen,
30
+ children: dialog !== undefined && /*#__PURE__*/ _jsxs(_Fragment, {
31
+ children: [
32
+ /*#__PURE__*/ _jsx(Dialog.Header, {
33
+ onClose: ()=>dialog.onCancel(),
34
+ children: "Save Dashboard"
35
+ }),
36
+ /*#__PURE__*/ _jsxs(Dialog.Content, {
37
+ children: [
38
+ /*#__PURE__*/ _jsx(Typography, {
39
+ marginBottom: 2,
40
+ children: dialog.description || SAVE_DEFAULTS_DIALOG_TEXT
41
+ }),
42
+ /*#__PURE__*/ _jsxs(FormGroup, {
43
+ children: [
44
+ /*#__PURE__*/ _jsx(FormControlLabel, {
45
+ control: /*#__PURE__*/ _jsx(Checkbox, {
46
+ disabled: !isRelativeTimeRange(timeRange),
47
+ checked: saveDefaultTimeRange && isRelativeTimeRange(timeRange),
48
+ onChange: (e)=>setSaveDefaultTimeRange(e.target.checked)
49
+ }),
50
+ label: timeRangeInfoText
51
+ }),
52
+ /*#__PURE__*/ _jsx(FormControlLabel, {
53
+ control: /*#__PURE__*/ _jsx(Checkbox, {
54
+ checked: saveDefaultVariables,
55
+ onChange: (e)=>setSaveDefaultVariables(e.target.checked)
56
+ }),
57
+ label: "Save current variable values as new default."
58
+ })
59
+ ]
60
+ })
61
+ ]
62
+ }),
63
+ /*#__PURE__*/ _jsxs(Dialog.Actions, {
64
+ children: [
65
+ /*#__PURE__*/ _jsx(Dialog.PrimaryButton, {
66
+ onClick: ()=>{
67
+ return dialog.onSaveChanges(saveDefaultTimeRange, saveDefaultVariables);
68
+ },
69
+ children: "Save Changes"
70
+ }),
71
+ /*#__PURE__*/ _jsx(Dialog.SecondaryButton, {
72
+ onClick: ()=>dialog.onCancel(),
73
+ children: "Cancel"
74
+ })
75
+ ]
76
+ })
77
+ ]
78
+ })
79
+ });
80
+ };
81
+
82
+ //# sourceMappingURL=SaveChangesConfirmationDialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.tsx"],"sourcesContent":["// Copyright 2023 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 { useState } from 'react';\nimport { Checkbox, FormGroup, FormControlLabel, Typography } from '@mui/material';\nimport { useTimeRange } from '@perses-dev/plugin-system';\nimport { isRelativeTimeRange, SAVE_DEFAULTS_DIALOG_TEXT } from '@perses-dev/core';\nimport { Dialog } from '@perses-dev/components';\nimport { useSaveChangesConfirmationDialog } from '../../context';\n\nexport const SaveChangesConfirmationDialog = () => {\n const [saveDefaultTimeRange, setSaveDefaultTimeRange] = useState(true);\n const [saveDefaultVariables, setSaveDefaultVariables] = useState(true);\n\n const { saveChangesConfirmationDialog: dialog } = useSaveChangesConfirmationDialog();\n const isOpen = dialog !== undefined;\n\n const { timeRange } = useTimeRange();\n const currentTimeRangeText = isRelativeTimeRange(timeRange)\n ? `(Last ${timeRange.pastDuration})`\n : '(Absolute time ranges can not be saved)';\n\n const timeRangeInfoText = `Save current time range as new default ${currentTimeRangeText}`;\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={!isRelativeTimeRange(timeRange)}\n checked={saveDefaultTimeRange && isRelativeTimeRange(timeRange)}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => setSaveDefaultTimeRange(e.target.checked)}\n />\n }\n label={timeRangeInfoText}\n />\n <FormControlLabel\n control={\n <Checkbox\n checked={saveDefaultVariables}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => setSaveDefaultVariables(e.target.checked)}\n />\n }\n label=\"Save current variable values as new default.\"\n />\n </FormGroup>\n </Dialog.Content>\n\n <Dialog.Actions>\n <Dialog.PrimaryButton\n onClick={() => {\n return dialog.onSaveChanges(saveDefaultTimeRange, 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","useTimeRange","isRelativeTimeRange","SAVE_DEFAULTS_DIALOG_TEXT","Dialog","useSaveChangesConfirmationDialog","SaveChangesConfirmationDialog","saveDefaultTimeRange","setSaveDefaultTimeRange","saveDefaultVariables","setSaveDefaultVariables","saveChangesConfirmationDialog","dialog","isOpen","undefined","timeRange","currentTimeRangeText","pastDuration","timeRangeInfoText","open","Header","onClose","onCancel","Content","marginBottom","description","control","disabled","checked","onChange","e","target","label","Actions","PrimaryButton","onClick","onSaveChanges","SecondaryButton"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,QAAQ,QAAQ,OAAO,CAAC;AACjC,SAASC,QAAQ,EAAEC,SAAS,EAAEC,gBAAgB,EAAEC,UA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wCACP8B,QAAQ,EAAE,CAACzB,mBAAmB,CAACa,SAAS,CAAC;wCACzCa,OAAO,EAAErB,oBAAoB,IAAIL,mBAAmB,CAACa,SAAS,CAAC;wCAC/Dc,QAAQ,EAAE,CAACC,CAAsC,GAAKtB,uBAAuB,CAACsB,CAAC,CAACC,MAAM,CAACH,OAAO,CAAC;sCAC/F;oCAEJI,KAAK,EAAEd,iBAAiB;kCACxB;8CACF,KAACnB,gBAAgB;oCACf2B,OAAO,gBACL,KAAC7B,QAAQ;wCACP+B,OAAO,EAAEnB,oBAAoB;wCAC7BoB,QAAQ,EAAE,CAACC,CAAsC,GAAKpB,uBAAuB,CAACoB,CAAC,CAACC,MAAM,CAACH,OAAO,CAAC;sCAC/F;oCAEJI,KAAK,EAAC,8CAA8C;kCACpD;;0BACQ;;kBACG;8BAEjB,MAAC5B,MAAM,CAAC6B,OAAO;;sCACb,KAAC7B,MAAM,CAAC8B,aAAa;4BACnBC,OAAO,EAAE,IAAM;gCACb,OAAOvB,MAAM,CAACwB,aAAa,CAAC7B,oBAAoB,EAAEE,oBAAoB,CAAC,CAAC;4BAC1E,CAAC;sCACF,cAED;0BAAuB;sCACvB,KAACL,MAAM,CAACiC,eAAe;4BAACF,OAAO,EAAE,IAAMvB,MAAM,CAACU,QAAQ,EAAE;sCAAE,QAAM;0BAAyB;;kBAC1E;;UAChB,AACJ;MACM,CACT;AACJ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './SaveChangesConfirmationDialog';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SaveChangesConfirmationDialog/index.ts"],"names":[],"mappings":"AAaA,cAAc,iCAAiC,CAAC"}
@@ -0,0 +1,15 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './SaveChangesConfirmationDialog';
14
+
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/SaveChangesConfirmationDialog/index.ts"],"sourcesContent":["// Copyright 2023 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\nexport * from './SaveChangesConfirmationDialog';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,iCAAiC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { ButtonProps } from '@mui/material';
3
+ import { DashboardResource } from '@perses-dev/core';
4
+ export interface SaveDashboardButtonProps extends Pick<ButtonProps, 'fullWidth'> {
5
+ onSave?: (entity: DashboardResource) => Promise<DashboardResource>;
6
+ isDisabled: boolean;
7
+ variant?: 'contained' | 'text' | 'outlined';
8
+ }
9
+ export declare const SaveDashboardButton: ({ onSave, isDisabled, variant }: SaveDashboardButtonProps) => JSX.Element;
10
+ //# sourceMappingURL=SaveDashboardButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SaveDashboardButton.d.ts","sourceRoot":"","sources":["../../../src/components/SaveDashboardButton/SaveDashboardButton.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAU,WAAW,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAuB,MAAM,kBAAkB,CAAC;AAI1E,MAAM,WAAW,wBAAyB,SAAQ,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC;IAC9E,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACnE,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,UAAU,CAAC;CAC7C;AAED,eAAO,MAAM,mBAAmB,oCAAmD,wBAAwB,gBAyD1G,CAAC"}
@@ -0,0 +1,72 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { useState } from 'react';
15
+ import { Button } from '@mui/material';
16
+ import { isRelativeTimeRange } from '@perses-dev/core';
17
+ import { useTimeRange } from '@perses-dev/plugin-system';
18
+ import { useDashboard, useEditMode, useSaveChangesConfirmationDialog, useTemplateVariableActions } from '../../context';
19
+ export const SaveDashboardButton = ({ onSave , isDisabled , variant ='contained' })=>{
20
+ const [isSavingDashboard, setSavingDashboard] = useState(false);
21
+ const { dashboard } = useDashboard();
22
+ const { getSavedVariablesStatus , setVariableDefaultValues } = useTemplateVariableActions();
23
+ const isSavedVariableModified = getSavedVariablesStatus();
24
+ const { timeRange } = useTimeRange();
25
+ const { setEditMode } = useEditMode();
26
+ const { openSaveChangesConfirmationDialog , closeSaveChangesConfirmationDialog } = useSaveChangesConfirmationDialog();
27
+ const onSaveButtonClick = ()=>{
28
+ const isSavedDurationModified = isRelativeTimeRange(timeRange) && dashboard.spec.duration !== timeRange.pastDuration;
29
+ // Save dashboard if active timeRange from plugin-system is relative and different than currently saved
30
+ if (isSavedDurationModified || isSavedVariableModified) {
31
+ openSaveChangesConfirmationDialog({
32
+ onSaveChanges: (saveDefaultTimeRange, saveDefaultVariables)=>{
33
+ if (isRelativeTimeRange(timeRange) && saveDefaultTimeRange === true) {
34
+ dashboard.spec.duration = timeRange.pastDuration;
35
+ }
36
+ if (saveDefaultVariables === true) {
37
+ const variables = setVariableDefaultValues();
38
+ dashboard.spec.variables = variables;
39
+ }
40
+ saveDashboard();
41
+ },
42
+ onCancel: ()=>{
43
+ closeSaveChangesConfirmationDialog();
44
+ }
45
+ });
46
+ } else {
47
+ saveDashboard();
48
+ }
49
+ };
50
+ const saveDashboard = ()=>{
51
+ if (onSave !== undefined) {
52
+ setSavingDashboard(true);
53
+ onSave(dashboard).then(()=>{
54
+ setSavingDashboard(false);
55
+ closeSaveChangesConfirmationDialog();
56
+ setEditMode(false);
57
+ }).catch(()=>{
58
+ setSavingDashboard(false);
59
+ });
60
+ } else {
61
+ setEditMode(false);
62
+ }
63
+ };
64
+ return /*#__PURE__*/ _jsx(Button, {
65
+ variant: variant,
66
+ onClick: onSaveButtonClick,
67
+ disabled: isDisabled || isSavingDashboard,
68
+ children: "Save"
69
+ });
70
+ };
71
+
72
+ //# sourceMappingURL=SaveDashboardButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/SaveDashboardButton/SaveDashboardButton.tsx"],"sourcesContent":["// Copyright 2023 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 { useState } from 'react';\nimport { Button, ButtonProps } from '@mui/material';\nimport { DashboardResource, isRelativeTimeRange } from '@perses-dev/core';\nimport { useTimeRange } from '@perses-dev/plugin-system';\nimport { useDashboard, useEditMode, useSaveChangesConfirmationDialog, useTemplateVariableActions } from '../../context';\n\nexport interface SaveDashboardButtonProps extends Pick<ButtonProps, 'fullWidth'> {\n onSave?: (entity: DashboardResource) => Promise<DashboardResource>;\n isDisabled: boolean;\n variant?: 'contained' | 'text' | 'outlined';\n}\n\nexport const SaveDashboardButton = ({ onSave, isDisabled, variant = 'contained' }: SaveDashboardButtonProps) => {\n const [isSavingDashboard, setSavingDashboard] = useState<boolean>(false);\n const { dashboard } = useDashboard();\n const { getSavedVariablesStatus, setVariableDefaultValues } = useTemplateVariableActions();\n const isSavedVariableModified = getSavedVariablesStatus();\n const { timeRange } = useTimeRange();\n const { setEditMode } = useEditMode();\n const { openSaveChangesConfirmationDialog, closeSaveChangesConfirmationDialog } = useSaveChangesConfirmationDialog();\n\n const onSaveButtonClick = () => {\n const isSavedDurationModified =\n isRelativeTimeRange(timeRange) && dashboard.spec.duration !== timeRange.pastDuration;\n\n // Save dashboard if active timeRange from plugin-system is relative and different than currently saved\n if (isSavedDurationModified || isSavedVariableModified) {\n openSaveChangesConfirmationDialog({\n onSaveChanges: (saveDefaultTimeRange, saveDefaultVariables) => {\n if (isRelativeTimeRange(timeRange) && saveDefaultTimeRange === true) {\n dashboard.spec.duration = timeRange.pastDuration;\n }\n if (saveDefaultVariables === true) {\n const variables = setVariableDefaultValues();\n dashboard.spec.variables = variables;\n }\n saveDashboard();\n },\n onCancel: () => {\n closeSaveChangesConfirmationDialog();\n },\n });\n } else {\n saveDashboard();\n }\n };\n\n const saveDashboard = () => {\n if (onSave !== undefined) {\n setSavingDashboard(true);\n onSave(dashboard)\n .then(() => {\n setSavingDashboard(false);\n closeSaveChangesConfirmationDialog();\n setEditMode(false);\n })\n .catch(() => {\n setSavingDashboard(false);\n });\n } else {\n setEditMode(false);\n }\n };\n\n return (\n <Button variant={variant} onClick={onSaveButtonClick} disabled={isDisabled || isSavingDashboard}>\n Save\n </Button>\n );\n};\n"],"names":["useState","Button","isRelativeTimeRange","useTimeRange","useDashboard","useEditMode","useSaveChangesConfirmationDialog","useTemplateVariableActions","SaveDashboardButton","onSave","isDisabled","variant","isSavingDashboard","setSavingDashboard","dashboard","getSavedVariablesStatus","setVariableDefaultValues","isSavedVariableModified","timeRange","setEditMode","openSaveChangesConfirmationDialog","closeSaveChangesConfirmationDialog","onSaveButtonClick","isSavedDurationModified","spec","duration","pastDuration","onSaveChanges","saveDefaultTimeRange","saveDefaultVariables","variables","saveDashboard","onCancel","undefined","then","catch","onClick","disabled"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,QAAQ,QAAQ,OAAO,CAAC;AACjC,SAASC,MAAM,QAAqB,eAAe,CAAC;AACpD,SAA4BC,mBAAmB,QAAQ,kBAAkB,CAAC;AAC1E,SAASC,YAAY,QAAQ,2BAA2B,CAAC;AACzD,SAASC,YAAY,EAAEC,WAAW,EAAEC,gCAAgC,EAAEC,0BAA0B,QAAQ,eAAe,CAAC;AAQxH,OAAO,MAAMC,mBAAmB,GAAG,CAAC,EAAEC,MAAM,CAAA,EAAEC,UAAU,CAAA,EAAEC,OAAO,EAAG,WAAW,CAAA,EAA4B,GAAK;IAC9G,MAAM,CAACC,iBAAiB,EAAEC,kBAAkB,CAAC,GAAGb,QAAQ,CAAU,KAAK,CAA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AC,AAAC;IAEF,MAAMA,aAAa,GAAG,IAAM;QAC1B,IAAItB,MAAM,KAAKwB,SAAS,EAAE;YACxBpB,kBAAkB,CAAC,IAAI,CAAC,CAAC;YACzBJ,MAAM,CAACK,SAAS,CAAC,CACdoB,IAAI,CAAC,IAAM;gBACVrB,kBAAkB,CAAC,KAAK,CAAC,CAAC;gBAC1BQ,kCAAkC,EAAE,CAAC;gBACrCF,WAAW,CAAC,KAAK,CAAC,CAAC;YACrB,CAAC,CAAC,CACDgB,KAAK,CAAC,IAAM;gBACXtB,kBAAkB,CAAC,KAAK,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;QACP,OAAO;YACLM,WAAW,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;IACH,CAAC,AAAC;IAEF,qBACE,KAAClB,MAAM;QAACU,OAAO,EAAEA,OAAO;QAAEyB,OAAO,EAAEd,iBAAiB;QAAEe,QAAQ,EAAE3B,UAAU,IAAIE,iBAAiB;kBAAE,MAEjG;MAAS,CACT;AACJ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './SaveDashboardButton';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SaveDashboardButton/index.tsx"],"names":[],"mappings":"AAaA,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,15 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './SaveDashboardButton';
14
+
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/SaveDashboardButton/index.tsx"],"sourcesContent":["// Copyright 2023 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\nexport * from './SaveDashboardButton';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,uBAAuB,CAAC"}
@@ -1,8 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import { VariableDefinition } from '@perses-dev/core';
3
- export declare function VariableEditForm({ initialVariableDefinition, onChange, onCancel, }: {
3
+ interface VariableEditFormProps {
4
4
  initialVariableDefinition: VariableDefinition;
5
5
  onChange: (def: VariableDefinition) => void;
6
6
  onCancel: () => void;
7
- }): JSX.Element;
7
+ }
8
+ export declare function VariableEditForm(props: VariableEditFormProps): JSX.Element;
9
+ export {};
8
10
  //# sourceMappingURL=VariableEditorForm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"VariableEditorForm.d.ts","sourceRoot":"","sources":["../../../../src/components/Variables/VariableEditorForm/VariableEditorForm.tsx"],"names":[],"mappings":";AAiCA,OAAO,EAAE,kBAAkB,EAA0B,MAAM,kBAAkB,CAAC;AAsF9E,wBAAgB,gBAAgB,CAAC,EAC/B,yBAAyB,EACzB,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,yBAAyB,EAAE,kBAAkB,CAAC;IAC9C,QAAQ,EAAE,CAAC,GAAG,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC5C,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,eAgNA"}
1
+ {"version":3,"file":"VariableEditorForm.d.ts","sourceRoot":"","sources":["../../../../src/components/Variables/VariableEditorForm/VariableEditorForm.tsx"],"names":[],"mappings":";AAgCA,OAAO,EAAE,kBAAkB,EAA0B,MAAM,kBAAkB,CAAC;AA6B9E,UAAU,qBAAqB;IAC7B,yBAAyB,EAAE,kBAAkB,CAAC;IAC9C,QAAQ,EAAE,CAAC,GAAG,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC5C,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,eA+O5D"}