@perses-dev/dashboards 0.41.1 → 0.42.1

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 (89) hide show
  1. package/dist/cjs/components/DashboardStickyToolbar/DashboardStickyToolbar.js +2 -2
  2. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +11 -9
  3. package/dist/cjs/components/Datasources/DatasourceEditor.js +236 -0
  4. package/dist/cjs/components/Datasources/EditDatasourcesButton.js +109 -0
  5. package/dist/cjs/components/Datasources/index.js +31 -0
  6. package/dist/cjs/components/EditJsonDialog/EditJsonDialog.js +12 -1
  7. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +3 -41
  8. package/dist/cjs/components/PanelDrawer/index.js +1 -0
  9. package/dist/cjs/components/QuerySummaryTable/QuerySummaryTable.js +2 -2
  10. package/dist/cjs/components/Variables/TemplateVariable.js +139 -51
  11. package/dist/cjs/components/Variables/VariableList.js +1 -1
  12. package/dist/cjs/components/index.js +1 -0
  13. package/dist/cjs/constants/user-interface-text.js +1 -0
  14. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +4 -2
  15. package/dist/cjs/context/DatasourceStoreProvider.js +58 -6
  16. package/dist/cjs/context/TemplateVariableProvider/TemplateVariableProvider.js +16 -0
  17. package/dist/cjs/context/useDashboard.js +5 -3
  18. package/dist/cjs/views/ViewDashboard/DashboardApp.js +4 -0
  19. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +2 -3
  20. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js +2 -2
  21. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js.map +1 -1
  22. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  23. package/dist/components/DashboardToolbar/DashboardToolbar.js +11 -9
  24. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  25. package/dist/components/Datasources/DatasourceEditor.d.ts +8 -0
  26. package/dist/components/Datasources/DatasourceEditor.d.ts.map +1 -0
  27. package/dist/components/Datasources/DatasourceEditor.js +223 -0
  28. package/dist/components/Datasources/DatasourceEditor.js.map +1 -0
  29. package/dist/components/Datasources/EditDatasourcesButton.d.ts +3 -0
  30. package/dist/components/Datasources/EditDatasourcesButton.d.ts.map +1 -0
  31. package/dist/components/Datasources/EditDatasourcesButton.js +96 -0
  32. package/dist/components/Datasources/EditDatasourcesButton.js.map +1 -0
  33. package/dist/components/Datasources/index.d.ts +3 -0
  34. package/dist/components/Datasources/index.d.ts.map +1 -0
  35. package/dist/components/Datasources/index.js +16 -0
  36. package/dist/components/Datasources/index.js.map +1 -0
  37. package/dist/components/EditJsonDialog/EditJsonDialog.js +13 -2
  38. package/dist/components/EditJsonDialog/EditJsonDialog.js.map +1 -1
  39. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +1 -1
  40. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  41. package/dist/components/PanelDrawer/PanelEditorForm.js +3 -2
  42. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  43. package/dist/components/PanelDrawer/index.d.ts +1 -0
  44. package/dist/components/PanelDrawer/index.d.ts.map +1 -1
  45. package/dist/components/PanelDrawer/index.js +1 -0
  46. package/dist/components/PanelDrawer/index.js.map +1 -1
  47. package/dist/components/QuerySummaryTable/QuerySummaryTable.js +2 -2
  48. package/dist/components/QuerySummaryTable/QuerySummaryTable.js.map +1 -1
  49. package/dist/components/Variables/TemplateVariable.d.ts +1 -1
  50. package/dist/components/Variables/TemplateVariable.d.ts.map +1 -1
  51. package/dist/components/Variables/TemplateVariable.js +141 -53
  52. package/dist/components/Variables/TemplateVariable.js.map +1 -1
  53. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  54. package/dist/components/Variables/VariableEditor.js.map +1 -1
  55. package/dist/components/Variables/VariableList.js +1 -1
  56. package/dist/components/Variables/VariableList.js.map +1 -1
  57. package/dist/components/index.d.ts +1 -0
  58. package/dist/components/index.d.ts.map +1 -1
  59. package/dist/components/index.js +1 -0
  60. package/dist/components/index.js.map +1 -1
  61. package/dist/constants/user-interface-text.d.ts +1 -0
  62. package/dist/constants/user-interface-text.d.ts.map +1 -1
  63. package/dist/constants/user-interface-text.js +1 -0
  64. package/dist/constants/user-interface-text.js.map +1 -1
  65. package/dist/context/DashboardProvider/DashboardProvider.d.ts +2 -1
  66. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  67. package/dist/context/DashboardProvider/DashboardProvider.js +4 -2
  68. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  69. package/dist/context/DashboardProvider/panel-editor-slice.d.ts +1 -2
  70. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  71. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  72. package/dist/context/DatasourceStoreProvider.d.ts +2 -1
  73. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  74. package/dist/context/DatasourceStoreProvider.js +59 -7
  75. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  76. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts +1 -0
  77. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +1 -1
  78. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js +13 -0
  79. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +1 -1
  80. package/dist/context/useDashboard.d.ts.map +1 -1
  81. package/dist/context/useDashboard.js +5 -3
  82. package/dist/context/useDashboard.js.map +1 -1
  83. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  84. package/dist/views/ViewDashboard/DashboardApp.js +4 -0
  85. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  86. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  87. package/dist/views/ViewDashboard/ViewDashboard.js +4 -5
  88. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  89. package/package.json +6 -6
@@ -19,6 +19,7 @@ import { AddGroupButton } from '../AddGroupButton';
19
19
  import { DownloadButton } from '../DownloadButton';
20
20
  import { TimeRangeControls } from '../TimeRangeControls';
21
21
  import { EditVariablesButton } from '../Variables';
22
+ import { EditDatasourcesButton } from '../Datasources';
22
23
  import { EditButton } from '../EditButton';
23
24
  import { EditJsonButton } from '../EditJsonButton';
24
25
  import { SaveDashboardButton } from '../SaveDashboardButton';
@@ -39,7 +40,8 @@ export const DashboardToolbar = (props)=>{
39
40
  "data-testid": testId,
40
41
  children: [
41
42
  /*#__PURE__*/ _jsxs(Box, {
42
- p: 2,
43
+ px: 2,
44
+ py: 1.5,
43
45
  display: "flex",
44
46
  sx: {
45
47
  backgroundColor: (theme)=>theme.palette.primary.main + '30'
@@ -48,8 +50,8 @@ export const DashboardToolbar = (props)=>{
48
50
  dashboardTitle,
49
51
  /*#__PURE__*/ _jsxs(Stack, {
50
52
  direction: "row",
51
- spacing: 1,
52
- marginLeft: "auto",
53
+ gap: 1,
54
+ ml: "auto",
53
55
  children: [
54
56
  isReadonly && /*#__PURE__*/ _jsx(Alert, {
55
57
  severity: 'warning',
@@ -77,7 +79,7 @@ export const DashboardToolbar = (props)=>{
77
79
  display: 'flex',
78
80
  width: '100%',
79
81
  alignItems: 'start',
80
- padding: (theme)=>theme.spacing(1, 2)
82
+ padding: (theme)=>theme.spacing(1, 2, 0, 2)
81
83
  },
82
84
  children: [
83
85
  /*#__PURE__*/ _jsx(ErrorBoundary, {
@@ -99,10 +101,10 @@ export const DashboardToolbar = (props)=>{
99
101
  direction: "row",
100
102
  spacing: 1,
101
103
  ml: 1,
102
- mb: 1,
103
104
  whiteSpace: "nowrap",
104
105
  children: [
105
106
  /*#__PURE__*/ _jsx(EditVariablesButton, {}),
107
+ /*#__PURE__*/ _jsx(EditDatasourcesButton, {}),
106
108
  /*#__PURE__*/ _jsx(AddPanelButton, {}),
107
109
  /*#__PURE__*/ _jsx(AddGroupButton, {})
108
110
  ]
@@ -111,7 +113,6 @@ export const DashboardToolbar = (props)=>{
111
113
  direction: "row",
112
114
  spacing: 1,
113
115
  ml: 1,
114
- mb: 1,
115
116
  children: [
116
117
  /*#__PURE__*/ _jsx(TimeRangeControls, {}),
117
118
  /*#__PURE__*/ _jsx(DownloadButton, {}),
@@ -124,8 +125,9 @@ export const DashboardToolbar = (props)=>{
124
125
  })
125
126
  ]
126
127
  }) : /*#__PURE__*/ _jsxs(Stack, {
127
- spacing: 1,
128
- padding: 2,
128
+ gap: 1,
129
+ mx: 2,
130
+ mt: 1.5,
129
131
  "data-testid": testId,
130
132
  children: [
131
133
  /*#__PURE__*/ _jsxs(Box, {
@@ -150,7 +152,7 @@ export const DashboardToolbar = (props)=>{
150
152
  ]
151
153
  }),
152
154
  /*#__PURE__*/ _jsx(Box, {
153
- paddingY: 2,
155
+ mt: 1,
154
156
  children: /*#__PURE__*/ _jsx(ErrorBoundary, {
155
157
  FallbackComponent: ErrorAlert,
156
158
  children: /*#__PURE__*/ _jsx(DashboardStickyToolbar, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/DashboardToolbar/DashboardToolbar.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 { Typography, Stack, Button, Box, useTheme, useMediaQuery, Alert } from '@mui/material';\nimport { ErrorBoundary, ErrorAlert } from '@perses-dev/components';\nimport { OnSaveDashboard, useEditMode } from '../../context';\nimport { AddPanelButton } from '../AddPanelButton';\nimport { AddGroupButton } from '../AddGroupButton';\nimport { DownloadButton } from '../DownloadButton';\nimport { TimeRangeControls } from '../TimeRangeControls';\nimport { EditVariablesButton } from '../Variables';\nimport { EditButton } from '../EditButton';\nimport { EditJsonButton } from '../EditJsonButton';\nimport { SaveDashboardButton } from '../SaveDashboardButton';\nimport { DashboardStickyToolbar } from '../DashboardStickyToolbar';\n\nexport interface DashboardToolbarProps {\n dashboardName: string;\n dashboardTitleComponent?: JSX.Element;\n initialVariableIsSticky?: boolean;\n isReadonly: boolean;\n onEditButtonClick: () => void;\n onCancelButtonClick: () => void;\n onSave?: OnSaveDashboard;\n}\n\nexport const DashboardToolbar = (props: DashboardToolbarProps) => {\n const {\n dashboardName,\n dashboardTitleComponent,\n initialVariableIsSticky,\n isReadonly,\n onEditButtonClick,\n onCancelButtonClick,\n onSave,\n } = props;\n\n const { isEditMode } = useEditMode();\n\n const isBiggerThanSm = useMediaQuery(useTheme().breakpoints.up('sm'));\n const isBiggerThanLg = useMediaQuery(useTheme().breakpoints.up('lg'));\n\n const dashboardTitle = dashboardTitleComponent ? (\n dashboardTitleComponent\n ) : (\n <Typography variant=\"h2\">{dashboardName}</Typography>\n );\n\n const testId = 'dashboard-toolbar';\n\n return (\n <>\n {isEditMode ? (\n <Stack spacing={1} data-testid={testId}>\n <Box p={2} display=\"flex\" sx={{ backgroundColor: (theme) => theme.palette.primary.main + '30' }}>\n {dashboardTitle}\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n {isReadonly && (\n <Alert severity={'warning'} sx={{ backgroundColor: 'transparent', padding: 0 }}>\n Dashboard managed via code only. Download JSON and commit changes to save.\n </Alert>\n )}\n <SaveDashboardButton onSave={onSave} isDisabled={isReadonly} />\n <Button variant=\"outlined\" onClick={onCancelButtonClick}>\n Cancel\n </Button>\n </Stack>\n </Box>\n <Box\n sx={{\n display: 'flex',\n width: '100%',\n alignItems: 'start',\n padding: (theme) => theme.spacing(1, 2),\n }}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <DashboardStickyToolbar\n initialVariableIsSticky={initialVariableIsSticky}\n sx={{\n backgroundColor: ({ palette }) => palette.background.default,\n }}\n />\n </ErrorBoundary>\n <Stack ml=\"auto\" direction=\"row\" flexWrap={isBiggerThanLg ? 'nowrap' : 'wrap-reverse'} justifyContent=\"end\">\n <Stack direction=\"row\" spacing={1} ml={1} mb={1} whiteSpace=\"nowrap\">\n <EditVariablesButton />\n <AddPanelButton />\n <AddGroupButton />\n </Stack>\n <Stack direction=\"row\" spacing={1} ml={1} mb={1}>\n <TimeRangeControls />\n <DownloadButton />\n <EditJsonButton />\n </Stack>\n </Stack>\n </Box>\n </Stack>\n ) : (\n <Stack spacing={1} padding={2} data-testid={testId}>\n <Box sx={{ display: 'flex', width: '100%' }}>\n {dashboardTitle}\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n <TimeRangeControls />\n <DownloadButton />\n {isBiggerThanSm && <EditButton onClick={onEditButtonClick} />}\n </Stack>\n </Box>\n <Box paddingY={2}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <DashboardStickyToolbar\n initialVariableIsSticky={initialVariableIsSticky}\n sx={{\n backgroundColor: ({ palette }) => palette.background.default,\n }}\n />\n </ErrorBoundary>\n </Box>\n </Stack>\n )}\n </>\n );\n};\n"],"names":["Typography","Stack","Button","Box","useTheme","useMediaQuery","Alert","ErrorBoundary","ErrorAlert","useEditMode","AddPanelButton","AddGroupButton","DownloadButton","TimeRangeControls","EditVariablesButton","EditButton","EditJsonButton","SaveDashboardButton","DashboardStickyToolbar","DashboardToolbar","props","dashboardName","dashboardTitleComponent","initialVariableIsSticky","isReadonly","onEditButtonClick","onCancelButtonClick","onSave","isEditMode","isBiggerThanSm","breakpoints","up","isBiggerThanLg","dashboardTitle","variant","testId","spacing","data-testid","p","display","sx","backgroundColor","theme","palette","primary","main","direction","marginLeft","severity","padding","isDisabled","onClick","width","alignItems","FallbackComponent","background","default","ml","flexWrap","justifyContent","mb","whiteSpace","paddingY"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;A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yBA;4BACzBiB,IAAI;gCACFC,iBAAiB,CAAC,EAAEE,QAAO,EAAE,GAAKA,QAAQY,WAAWC;4BACvD;;;;;;;AAQhB,EAAE"}
1
+ {"version":3,"sources":["../../../src/components/DashboardToolbar/DashboardToolbar.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 { Typography, Stack, Button, Box, useTheme, useMediaQuery, Alert } from '@mui/material';\nimport { ErrorBoundary, ErrorAlert } from '@perses-dev/components';\nimport { OnSaveDashboard, useEditMode } from '../../context';\nimport { AddPanelButton } from '../AddPanelButton';\nimport { AddGroupButton } from '../AddGroupButton';\nimport { DownloadButton } from '../DownloadButton';\nimport { TimeRangeControls } from '../TimeRangeControls';\nimport { EditVariablesButton } from '../Variables';\nimport { EditDatasourcesButton } from '../Datasources';\nimport { EditButton } from '../EditButton';\nimport { EditJsonButton } from '../EditJsonButton';\nimport { SaveDashboardButton } from '../SaveDashboardButton';\nimport { DashboardStickyToolbar } from '../DashboardStickyToolbar';\n\nexport interface DashboardToolbarProps {\n dashboardName: string;\n dashboardTitleComponent?: JSX.Element;\n initialVariableIsSticky?: boolean;\n isReadonly: boolean;\n onEditButtonClick: () => void;\n onCancelButtonClick: () => void;\n onSave?: OnSaveDashboard;\n}\n\nexport const DashboardToolbar = (props: DashboardToolbarProps) => {\n const {\n dashboardName,\n dashboardTitleComponent,\n initialVariableIsSticky,\n isReadonly,\n onEditButtonClick,\n onCancelButtonClick,\n onSave,\n } = props;\n\n const { isEditMode } = useEditMode();\n\n const isBiggerThanSm = useMediaQuery(useTheme().breakpoints.up('sm'));\n const isBiggerThanLg = useMediaQuery(useTheme().breakpoints.up('lg'));\n\n const dashboardTitle = dashboardTitleComponent ? (\n dashboardTitleComponent\n ) : (\n <Typography variant=\"h2\">{dashboardName}</Typography>\n );\n\n const testId = 'dashboard-toolbar';\n\n return (\n <>\n {isEditMode ? (\n <Stack spacing={1} data-testid={testId}>\n <Box px={2} py={1.5} display=\"flex\" sx={{ backgroundColor: (theme) => theme.palette.primary.main + '30' }}>\n {dashboardTitle}\n <Stack direction=\"row\" gap={1} ml=\"auto\">\n {isReadonly && (\n <Alert severity={'warning'} sx={{ backgroundColor: 'transparent', padding: 0 }}>\n Dashboard managed via code only. Download JSON and commit changes to save.\n </Alert>\n )}\n <SaveDashboardButton onSave={onSave} isDisabled={isReadonly} />\n <Button variant=\"outlined\" onClick={onCancelButtonClick}>\n Cancel\n </Button>\n </Stack>\n </Box>\n <Box\n sx={{\n display: 'flex',\n width: '100%',\n alignItems: 'start',\n padding: (theme) => theme.spacing(1, 2, 0, 2),\n }}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <DashboardStickyToolbar\n initialVariableIsSticky={initialVariableIsSticky}\n sx={{\n backgroundColor: ({ palette }) => palette.background.default,\n }}\n />\n </ErrorBoundary>\n <Stack ml=\"auto\" direction=\"row\" flexWrap={isBiggerThanLg ? 'nowrap' : 'wrap-reverse'} justifyContent=\"end\">\n <Stack direction=\"row\" spacing={1} ml={1} whiteSpace=\"nowrap\">\n <EditVariablesButton />\n <EditDatasourcesButton />\n <AddPanelButton />\n <AddGroupButton />\n </Stack>\n <Stack direction=\"row\" spacing={1} ml={1}>\n <TimeRangeControls />\n <DownloadButton />\n <EditJsonButton />\n </Stack>\n </Stack>\n </Box>\n </Stack>\n ) : (\n <Stack gap={1} mx={2} mt={1.5} data-testid={testId}>\n <Box sx={{ display: 'flex', width: '100%' }}>\n {dashboardTitle}\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n <TimeRangeControls />\n <DownloadButton />\n {isBiggerThanSm && <EditButton onClick={onEditButtonClick} />}\n </Stack>\n </Box>\n <Box mt={1}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <DashboardStickyToolbar\n initialVariableIsSticky={initialVariableIsSticky}\n sx={{\n backgroundColor: ({ palette }) => palette.background.default,\n }}\n />\n </ErrorBoundary>\n </Box>\n </Stack>\n )}\n </>\n );\n};\n"],"names":["Typography","Stack","Button","Box","useTheme","useMediaQuery","Alert","ErrorBoundary","ErrorAlert","useEditMode","AddPanelButton","AddGroupButton","DownloadButton","TimeRangeControls","EditVariablesButton","EditDatasourcesButton","EditButton","EditJsonButton","SaveDashboardButton","DashboardStickyToolbar","DashboardToolbar","props","dashboardName","dashboardTitleComponent","initialVariableIsSticky","isReadonly","onEditButtonClick","onCancelButtonClick","onSave","isEditMode","isBiggerThanSm","breakpoints","up","isBiggerThanLg","dashboardTitle","variant","testId","spacing","data-testid","px","py","display","sx","backgroundColor","theme","palette","primary","main","direction","gap","ml","severity","padding","isDisabled","onClick","width","alignItems","FallbackComponent","background","default","flexWrap","justifyContent","whiteSpace","mx","mt","marginLeft"],"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,SAASA,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,EAAEC,aAAa,EAAEC,KAAK,QAAQ,gBAAgB;AAC/F,SAASC,aAAa,EAAEC,UAAU,QAAQ,yBAAyB;AACnE,SAA0BC,WAAW,QAAQ,gBAAgB;AAC7D,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,iBAAiB,QAAQ,uBAAuB;AACzD,SAASC,mBAAmB,QAAQ,eAAe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D,mBAAmBjD;sCAChC,cAAA,KAACW;gCACCK,yBAAyBA;gCACzBkB,IAAI;oCACFC,iBAAiB,CAAC,EAAEE,QAAO,EAAE,GAAKA,QAAQa,WAAWC;gCACvD;;;sCAGJ,MAAC1D;4BAAMiD,IAAG;4BAAOF,WAAU;4BAAMY,UAAU3B,iBAAiB,WAAW;4BAAgB4B,gBAAe;;8CACpG,MAAC5D;oCAAM+C,WAAU;oCAAMX,SAAS;oCAAGa,IAAI;oCAAGY,YAAW;;sDACnD,KAAChD;sDACD,KAACC;sDACD,KAACL;sDACD,KAACC;;;8CAEH,MAACV;oCAAM+C,WAAU;oCAAMX,SAAS;oCAAGa,IAAI;;sDACrC,KAACrC;sDACD,KAACD;sDACD,KAACK;;;;;;;;2BAMT,MAAChB;YAAMgD,KAAK;YAAGc,IAAI;YAAGC,IAAI;YAAK1B,eAAaF;;8BAC1C,MAACjC;oBAAIuC,IAAI;wBAAED,SAAS;wBAAQc,OAAO;oBAAO;;wBACvCrB;sCACD,MAACjC;4BAAM+C,WAAU;4BAAMX,SAAS;4BAAG4B,YAAW;;8CAC5C,KAACpD;8CACD,KAACD;gCACAkB,gCAAkB,KAACd;oCAAWsC,SAAS5B;;;;;;8BAG5C,KAACvB;oBAAI6D,IAAI;8BACP,cAAA,KAACzD;wBAAckD,mBAAmBjD;kCAChC,cAAA,KAACW;4BACCK,yBAAyBA;4BACzBkB,IAAI;gCACFC,iBAAiB,CAAC,EAAEE,QAAO,EAAE,GAAKA,QAAQa,WAAWC;4BACvD;;;;;;;AAQhB,EAAE"}
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { DatasourceSpec } from '@perses-dev/core';
3
+ export declare function DatasourceEditor(props: {
4
+ datasources: Record<string, DatasourceSpec>;
5
+ onChange: (datasources: Record<string, DatasourceSpec>) => void;
6
+ onCancel: () => void;
7
+ }): JSX.Element;
8
+ //# sourceMappingURL=DatasourceEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DatasourceEditor.d.ts","sourceRoot":"","sources":["../../../src/components/Datasources/DatasourceEditor.tsx"],"names":[],"mappings":";AA6BA,OAAO,EAAU,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAM1D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC5C,QAAQ,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,KAAK,IAAI,CAAC;IAChE,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,eAyJA"}
@@ -0,0 +1,223 @@
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 { Box, Button, IconButton, Stack, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Typography } from '@mui/material';
15
+ import AddIcon from 'mdi-material-ui/Plus';
16
+ import PencilIcon from 'mdi-material-ui/Pencil';
17
+ import TrashIcon from 'mdi-material-ui/TrashCan';
18
+ import { DatasourceEditorForm } from '@perses-dev/plugin-system';
19
+ import { useState } from 'react';
20
+ import { useImmer } from 'use-immer';
21
+ import { useDiscardChangesConfirmationDialog } from '../../context';
22
+ export function DatasourceEditor(props) {
23
+ const [datasources, setDatasources] = useImmer(props.datasources);
24
+ const [datasourceFormAction, setDatasourceFormAction] = useState('update');
25
+ const [datasourceEdit, setDatasourceEdit] = useState(null);
26
+ const defaultSpec = {
27
+ default: false,
28
+ plugin: {
29
+ // TODO: find a way to avoid assuming that the PrometheusDatasource plugin is installed
30
+ kind: 'PrometheusDatasource',
31
+ spec: {}
32
+ }
33
+ };
34
+ const { openDiscardChangesConfirmationDialog , closeDiscardChangesConfirmationDialog } = useDiscardChangesConfirmationDialog();
35
+ const handleCancel = ()=>{
36
+ if (JSON.stringify(props.datasources) !== JSON.stringify(datasources)) {
37
+ openDiscardChangesConfirmationDialog({
38
+ onDiscardChanges: ()=>{
39
+ closeDiscardChangesConfirmationDialog();
40
+ props.onCancel();
41
+ },
42
+ onCancel: ()=>{
43
+ closeDiscardChangesConfirmationDialog();
44
+ },
45
+ description: 'You have unapplied changes. Are you sure you want to discard these changes? Changes cannot be recovered.'
46
+ });
47
+ } else {
48
+ props.onCancel();
49
+ }
50
+ };
51
+ const removeDatasource = (name)=>{
52
+ setDatasources((draft)=>{
53
+ delete draft[name];
54
+ });
55
+ };
56
+ const addDatasource = ()=>{
57
+ setDatasourceFormAction('create');
58
+ setDatasourceEdit({
59
+ name: 'NewDatasource',
60
+ spec: defaultSpec
61
+ });
62
+ };
63
+ const editDatasource = (name)=>{
64
+ setDatasourceFormAction('update');
65
+ var _datasources_name;
66
+ setDatasourceEdit({
67
+ name: name,
68
+ spec: (_datasources_name = datasources[name]) !== null && _datasources_name !== void 0 ? _datasources_name : defaultSpec
69
+ });
70
+ };
71
+ return /*#__PURE__*/ _jsx(_Fragment, {
72
+ children: datasourceEdit ? /*#__PURE__*/ _jsx(DatasourceEditorForm, {
73
+ initialName: datasourceEdit.name,
74
+ initialSpec: datasourceEdit.spec,
75
+ initialAction: datasourceFormAction,
76
+ isDraft: true,
77
+ onSave: (name, spec)=>{
78
+ setDatasources((draft)=>{
79
+ draft[name] = spec;
80
+ setDatasourceEdit(null);
81
+ });
82
+ },
83
+ onClose: ()=>{
84
+ setDatasourceEdit(null);
85
+ }
86
+ }) : /*#__PURE__*/ _jsxs(_Fragment, {
87
+ children: [
88
+ /*#__PURE__*/ _jsxs(Box, {
89
+ sx: {
90
+ display: 'flex',
91
+ alignItems: 'center',
92
+ padding: (theme)=>theme.spacing(1, 2),
93
+ borderBottom: (theme)=>`1px solid ${theme.palette.divider}`
94
+ },
95
+ children: [
96
+ /*#__PURE__*/ _jsx(Typography, {
97
+ variant: "h2",
98
+ children: "Edit Dashboard Datasources"
99
+ }),
100
+ /*#__PURE__*/ _jsxs(Stack, {
101
+ direction: "row",
102
+ spacing: 1,
103
+ marginLeft: "auto",
104
+ children: [
105
+ /*#__PURE__*/ _jsx(Button, {
106
+ disabled: props.datasources === datasources,
107
+ variant: "contained",
108
+ onClick: ()=>{
109
+ props.onChange(datasources);
110
+ },
111
+ children: "Apply"
112
+ }),
113
+ /*#__PURE__*/ _jsx(Button, {
114
+ color: "secondary",
115
+ variant: "outlined",
116
+ onClick: handleCancel,
117
+ children: "Cancel"
118
+ })
119
+ ]
120
+ })
121
+ ]
122
+ }),
123
+ /*#__PURE__*/ _jsx(Box, {
124
+ padding: 2,
125
+ sx: {
126
+ overflowY: 'scroll'
127
+ },
128
+ children: /*#__PURE__*/ _jsx(Stack, {
129
+ spacing: 2,
130
+ children: /*#__PURE__*/ _jsxs(Stack, {
131
+ spacing: 2,
132
+ children: [
133
+ /*#__PURE__*/ _jsx(TableContainer, {
134
+ children: /*#__PURE__*/ _jsxs(Table, {
135
+ sx: {
136
+ minWidth: 650
137
+ },
138
+ "aria-label": "table of datasources",
139
+ children: [
140
+ /*#__PURE__*/ _jsx(TableHead, {
141
+ children: /*#__PURE__*/ _jsxs(TableRow, {
142
+ children: [
143
+ /*#__PURE__*/ _jsx(TableCell, {
144
+ children: "Name"
145
+ }),
146
+ /*#__PURE__*/ _jsx(TableCell, {
147
+ children: "Type"
148
+ }),
149
+ /*#__PURE__*/ _jsx(TableCell, {
150
+ children: "Description"
151
+ }),
152
+ /*#__PURE__*/ _jsx(TableCell, {
153
+ align: "right",
154
+ children: "Actions"
155
+ })
156
+ ]
157
+ })
158
+ }),
159
+ /*#__PURE__*/ _jsx(TableBody, {
160
+ children: Object.entries(datasources).map(([name, spec])=>{
161
+ var _spec_display;
162
+ var _spec_display_description;
163
+ return /*#__PURE__*/ _jsxs(TableRow, {
164
+ children: [
165
+ /*#__PURE__*/ _jsx(TableCell, {
166
+ component: "th",
167
+ scope: "row",
168
+ sx: {
169
+ fontWeight: 'bold'
170
+ },
171
+ children: name
172
+ }),
173
+ /*#__PURE__*/ _jsx(TableCell, {
174
+ children: spec.plugin.kind
175
+ }),
176
+ /*#__PURE__*/ _jsx(TableCell, {
177
+ children: (_spec_display_description = (_spec_display = spec.display) === null || _spec_display === void 0 ? void 0 : _spec_display.description) !== null && _spec_display_description !== void 0 ? _spec_display_description : ''
178
+ }),
179
+ /*#__PURE__*/ _jsxs(TableCell, {
180
+ align: "right",
181
+ sx: {
182
+ whiteSpace: 'nowrap'
183
+ },
184
+ children: [
185
+ /*#__PURE__*/ _jsx(IconButton, {
186
+ onClick: ()=>editDatasource(name),
187
+ children: /*#__PURE__*/ _jsx(PencilIcon, {})
188
+ }),
189
+ /*#__PURE__*/ _jsx(IconButton, {
190
+ onClick: ()=>removeDatasource(name),
191
+ children: /*#__PURE__*/ _jsx(TrashIcon, {})
192
+ })
193
+ ]
194
+ })
195
+ ]
196
+ }, name);
197
+ })
198
+ })
199
+ ]
200
+ })
201
+ }),
202
+ /*#__PURE__*/ _jsx(Box, {
203
+ display: "flex",
204
+ children: /*#__PURE__*/ _jsx(Button, {
205
+ variant: "contained",
206
+ startIcon: /*#__PURE__*/ _jsx(AddIcon, {}),
207
+ sx: {
208
+ marginLeft: 'auto'
209
+ },
210
+ onClick: addDatasource,
211
+ children: "Add Datasource"
212
+ })
213
+ })
214
+ ]
215
+ })
216
+ })
217
+ })
218
+ ]
219
+ })
220
+ });
221
+ }
222
+
223
+ //# sourceMappingURL=DatasourceEditor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/Datasources/DatasourceEditor.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 {\n Box,\n Button,\n IconButton,\n Stack,\n Table,\n TableBody,\n TableCell,\n TableContainer,\n TableHead,\n TableRow,\n Typography,\n} from '@mui/material';\nimport AddIcon from 'mdi-material-ui/Plus';\nimport PencilIcon from 'mdi-material-ui/Pencil';\nimport TrashIcon from 'mdi-material-ui/TrashCan';\nimport { Action, DatasourceSpec } from '@perses-dev/core';\nimport { DatasourceEditorForm } from '@perses-dev/plugin-system';\nimport { useState } from 'react';\nimport { useImmer } from 'use-immer';\nimport { useDiscardChangesConfirmationDialog } from '../../context';\n\nexport function DatasourceEditor(props: {\n datasources: Record<string, DatasourceSpec>;\n onChange: (datasources: Record<string, DatasourceSpec>) => void;\n onCancel: () => void;\n}) {\n const [datasources, setDatasources] = useImmer(props.datasources);\n const [datasourceFormAction, setDatasourceFormAction] = useState<Action>('update');\n const [datasourceEdit, setDatasourceEdit] = useState<{ name: string; spec: DatasourceSpec } | null>(null);\n const defaultSpec: DatasourceSpec = {\n default: false,\n plugin: {\n // TODO: find a way to avoid assuming that the PrometheusDatasource plugin is installed\n kind: 'PrometheusDatasource',\n spec: {},\n },\n };\n\n const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } =\n useDiscardChangesConfirmationDialog();\n\n const handleCancel = () => {\n if (JSON.stringify(props.datasources) !== JSON.stringify(datasources)) {\n openDiscardChangesConfirmationDialog({\n onDiscardChanges: () => {\n closeDiscardChangesConfirmationDialog();\n props.onCancel();\n },\n onCancel: () => {\n closeDiscardChangesConfirmationDialog();\n },\n description:\n 'You have unapplied changes. Are you sure you want to discard these changes? Changes cannot be recovered.',\n });\n } else {\n props.onCancel();\n }\n };\n\n const removeDatasource = (name: string) => {\n setDatasources((draft) => {\n delete draft[name];\n });\n };\n\n const addDatasource = () => {\n setDatasourceFormAction('create');\n setDatasourceEdit({\n name: 'NewDatasource',\n spec: defaultSpec,\n });\n };\n\n const editDatasource = (name: string) => {\n setDatasourceFormAction('update');\n setDatasourceEdit({\n name: name,\n spec: datasources[name] ?? defaultSpec,\n });\n };\n\n return (\n <>\n {datasourceEdit ? (\n <DatasourceEditorForm\n initialName={datasourceEdit.name}\n initialSpec={datasourceEdit.spec}\n initialAction={datasourceFormAction}\n isDraft={true}\n onSave={(name: string, spec: DatasourceSpec) => {\n setDatasources((draft) => {\n draft[name] = spec;\n setDatasourceEdit(null);\n });\n }}\n onClose={() => {\n setDatasourceEdit(null);\n }}\n />\n ) : (\n <>\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n padding: (theme) => theme.spacing(1, 2),\n borderBottom: (theme) => `1px solid ${theme.palette.divider}`,\n }}\n >\n <Typography variant=\"h2\">Edit Dashboard Datasources</Typography>\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n <Button\n disabled={props.datasources === datasources}\n variant=\"contained\"\n onClick={() => {\n props.onChange(datasources);\n }}\n >\n Apply\n </Button>\n <Button color=\"secondary\" variant=\"outlined\" onClick={handleCancel}>\n Cancel\n </Button>\n </Stack>\n </Box>\n <Box padding={2} sx={{ overflowY: 'scroll' }}>\n <Stack spacing={2}>\n <Stack spacing={2}>\n <TableContainer>\n <Table sx={{ minWidth: 650 }} aria-label=\"table of datasources\">\n <TableHead>\n <TableRow>\n <TableCell>Name</TableCell>\n <TableCell>Type</TableCell>\n <TableCell>Description</TableCell>\n <TableCell align=\"right\">Actions</TableCell>\n </TableRow>\n </TableHead>\n <TableBody>\n {Object.entries(datasources).map(([name, spec]) => {\n return (\n <TableRow key={name}>\n <TableCell component=\"th\" scope=\"row\" sx={{ fontWeight: 'bold' }}>\n {name}\n </TableCell>\n <TableCell>{spec.plugin.kind}</TableCell>\n <TableCell>{spec.display?.description ?? ''}</TableCell>\n <TableCell align=\"right\" sx={{ whiteSpace: 'nowrap' }}>\n <IconButton onClick={() => editDatasource(name)}>\n <PencilIcon />\n </IconButton>\n <IconButton onClick={() => removeDatasource(name)}>\n <TrashIcon />\n </IconButton>\n </TableCell>\n </TableRow>\n );\n })}\n </TableBody>\n </Table>\n </TableContainer>\n <Box display=\"flex\">\n <Button\n variant=\"contained\"\n startIcon={<AddIcon />}\n sx={{ marginLeft: 'auto' }}\n onClick={addDatasource}\n >\n Add Datasource\n </Button>\n </Box>\n </Stack>\n </Stack>\n </Box>\n </>\n )}\n </>\n );\n}\n"],"names":["Box","Button","IconButton","Stack","Table","TableBody","TableCell","TableContainer","TableHead","TableRow","Typography","AddIcon","PencilIcon","TrashIcon","DatasourceEditorForm","useState","useImmer","useDiscardChangesConfirmationDialog","DatasourceEditor","props","datasources","setDatasources","datasourceFormAction","setDatasourceFormAction","datasourceEdit","setDatasourceEdit","defaultSpec","default","plugin","kind","spec","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","handleCancel","JSON","stringify","onDiscardChanges","onCancel","description","removeDatasource","name","draft","addDatasource","editDatasource","initialName","initialSpec","initialAction","isDraft","onSave","onClose","sx","display","alignItems","padding","theme","spacing","borderBottom","palette","divider","variant","direction","marginLeft","disabled","onClick","onChange","color","overflowY","minWidth","aria-label","align","Object","entries","map","component","scope","fontWeight","whiteSpace","startIcon"],"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,SACEA,GAAG,EACHC,MAAM,EACNC,UAAU,EACVC,KAAK,EACLC,KAAK,EACLC,SAAS,EACTC,SAAS,EACTC,cAAc,EACdC,SAAS,EACT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AAI;oEAAEyB,YAAY;gEAAO;0EAC5DnC;;0EAEH,KAAClC;0EAAWwB,KAAKF,OAAOC;;0EACxB,KAACvB;0EAAWwB,CAAAA,4BAAAA,CAAAA,gBAAAA,KAAKqB,qBAALrB,2BAAAA,KAAAA,IAAAA,cAAcQ,yBAAdR,uCAAAA,4BAA6B;;0EACzC,MAACxB;gEAAU+D,OAAM;gEAAQnB,IAAI;oEAAE0B,YAAY;gEAAS;;kFAClD,KAAC1E;wEAAW6D,SAAS,IAAMpB,eAAeH;kFACxC,cAAA,KAAC5B;;kFAEH,KAACV;wEAAW6D,SAAS,IAAMxB,iBAAiBC;kFAC1C,cAAA,KAAC3B;;;;;uDAXQ2B;gDAgBnB;;;;;8CAIN,KAACxC;oCAAImD,SAAQ;8CACX,cAAA,KAAClD;wCACC0D,SAAQ;wCACRkB,yBAAW,KAAClE;wCACZuC,IAAI;4CAAEW,YAAY;wCAAO;wCACzBE,SAASrB;kDACV;;;;;;;;;;AAWnB"}
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ export declare function EditDatasourcesButton(): JSX.Element;
3
+ //# sourceMappingURL=EditDatasourcesButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EditDatasourcesButton.d.ts","sourceRoot":"","sources":["../../../src/components/Datasources/EditDatasourcesButton.tsx"],"names":[],"mappings":";AAuBA,wBAAgB,qBAAqB,gBA2EpC"}
@@ -0,0 +1,96 @@
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 { Button } from '@mui/material';
16
+ import PencilIcon from 'mdi-material-ui/PencilOutline';
17
+ import { Drawer, InfoTooltip } from '@perses-dev/components';
18
+ import { useDatasourceStore } from '@perses-dev/plugin-system';
19
+ import { TOOLTIP_TEXT } from '../../constants';
20
+ import { useDashboard } from '../../context';
21
+ import { DatasourceEditor } from './DatasourceEditor';
22
+ export function EditDatasourcesButton() {
23
+ const [isDatasourceEditorOpen, setIsDatasourceEditorOpen] = useState(false);
24
+ const { getLocalDatasources , setLocalDatasources , getSavedDatasources , setSavedDatasources } = useDatasourceStore();
25
+ const localDatasources = getLocalDatasources();
26
+ const savedDatasources = getSavedDatasources();
27
+ const { dashboard , setDashboard } = useDashboard();
28
+ const openDatasourceEditor = ()=>{
29
+ setIsDatasourceEditorOpen(true);
30
+ };
31
+ const closeDatasourceEditor = ()=>{
32
+ setIsDatasourceEditorOpen(false);
33
+ };
34
+ const handleChangeDatasources = (datasources)=>{
35
+ // Calculates the new list of datasources that are allowed to be used.
36
+ const newSavedDatasources = Object.keys(datasources).filter((key)=>{
37
+ var _datasources_key, _datasources_key_plugin, _savedDatasources_key, _savedDatasources_key_plugin, _datasources_key1, _datasources_key_plugin1, _datasources_key_plugin_spec, _savedDatasources_key1, _savedDatasources_key_plugin1, _savedDatasources_key_plugin_spec;
38
+ var _datasources_key_plugin_spec1;
39
+ // Datasources are allowed to be used if a) they are direct, or b) they are proxied, and their
40
+ // proxy is the same as what we have saved.
41
+ const isDirect = 'directUrl' in ((_datasources_key_plugin_spec1 = (_datasources_key = datasources[key]) === null || _datasources_key === void 0 ? void 0 : (_datasources_key_plugin = _datasources_key.plugin) === null || _datasources_key_plugin === void 0 ? void 0 : _datasources_key_plugin.spec) !== null && _datasources_key_plugin_spec1 !== void 0 ? _datasources_key_plugin_spec1 : {});
42
+ var _savedDatasources_key_plugin_spec1;
43
+ const isSavedProxy = !isDirect && !('directUrl' in ((_savedDatasources_key_plugin_spec1 = (_savedDatasources_key = savedDatasources[key]) === null || _savedDatasources_key === void 0 ? void 0 : (_savedDatasources_key_plugin = _savedDatasources_key.plugin) === null || _savedDatasources_key_plugin === void 0 ? void 0 : _savedDatasources_key_plugin.spec) !== null && _savedDatasources_key_plugin_spec1 !== void 0 ? _savedDatasources_key_plugin_spec1 : {})) && ((_datasources_key1 = datasources[key]) === null || _datasources_key1 === void 0 ? void 0 : (_datasources_key_plugin1 = _datasources_key1.plugin) === null || _datasources_key_plugin1 === void 0 ? void 0 : (_datasources_key_plugin_spec = _datasources_key_plugin1.spec) === null || _datasources_key_plugin_spec === void 0 ? void 0 : _datasources_key_plugin_spec.proxy) === ((_savedDatasources_key1 = savedDatasources[key]) === null || _savedDatasources_key1 === void 0 ? void 0 : (_savedDatasources_key_plugin1 = _savedDatasources_key1.plugin) === null || _savedDatasources_key_plugin1 === void 0 ? void 0 : (_savedDatasources_key_plugin_spec = _savedDatasources_key_plugin1.spec) === null || _savedDatasources_key_plugin_spec === void 0 ? void 0 : _savedDatasources_key_plugin_spec.proxy);
44
+ return isDirect || isSavedProxy;
45
+ }).reduce((obj, key)=>{
46
+ obj[key] = datasources[key];
47
+ return obj;
48
+ }, {});
49
+ setDashboard({
50
+ ...dashboard,
51
+ spec: {
52
+ ...dashboard.spec,
53
+ datasources: datasources
54
+ }
55
+ });
56
+ setSavedDatasources(newSavedDatasources);
57
+ setLocalDatasources(datasources);
58
+ setIsDatasourceEditorOpen(false);
59
+ };
60
+ return /*#__PURE__*/ _jsxs(_Fragment, {
61
+ children: [
62
+ /*#__PURE__*/ _jsx(InfoTooltip, {
63
+ description: TOOLTIP_TEXT.editDatasources,
64
+ children: /*#__PURE__*/ _jsx(Button, {
65
+ startIcon: /*#__PURE__*/ _jsx(PencilIcon, {}),
66
+ onClick: openDatasourceEditor,
67
+ "aria-label": TOOLTIP_TEXT.editDatasources,
68
+ variant: "text",
69
+ color: "primary",
70
+ sx: {
71
+ whiteSpace: 'nowrap',
72
+ minWidth: 'auto'
73
+ },
74
+ children: "Datasources"
75
+ })
76
+ }),
77
+ /*#__PURE__*/ _jsx(Drawer, {
78
+ isOpen: isDatasourceEditorOpen,
79
+ onClose: closeDatasourceEditor,
80
+ PaperProps: {
81
+ sx: {
82
+ width: '50%'
83
+ }
84
+ },
85
+ "data-testid": "datasource-editor",
86
+ children: /*#__PURE__*/ _jsx(DatasourceEditor, {
87
+ datasources: localDatasources,
88
+ onCancel: closeDatasourceEditor,
89
+ onChange: handleChangeDatasources
90
+ })
91
+ })
92
+ ]
93
+ });
94
+ }
95
+
96
+ //# sourceMappingURL=EditDatasourcesButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/Datasources/EditDatasourcesButton.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 } from '@mui/material';\nimport PencilIcon from 'mdi-material-ui/PencilOutline';\nimport { Drawer, InfoTooltip } from '@perses-dev/components';\nimport { DatasourceSpec } from '@perses-dev/core';\nimport { useDatasourceStore } from '@perses-dev/plugin-system';\nimport { TOOLTIP_TEXT } from '../../constants';\nimport { useDashboard } from '../../context';\nimport { DatasourceEditor } from './DatasourceEditor';\n\nexport function EditDatasourcesButton() {\n const [isDatasourceEditorOpen, setIsDatasourceEditorOpen] = useState(false);\n const { getLocalDatasources, setLocalDatasources, getSavedDatasources, setSavedDatasources } = useDatasourceStore();\n const localDatasources: Record<string, DatasourceSpec> = getLocalDatasources();\n const savedDatasources: Record<string, DatasourceSpec> = getSavedDatasources();\n const { dashboard, setDashboard } = useDashboard();\n\n const openDatasourceEditor = () => {\n setIsDatasourceEditorOpen(true);\n };\n\n const closeDatasourceEditor = () => {\n setIsDatasourceEditorOpen(false);\n };\n\n const handleChangeDatasources = (datasources: Record<string, DatasourceSpec>) => {\n // Calculates the new list of datasources that are allowed to be used.\n const newSavedDatasources: Record<string, DatasourceSpec> = Object.keys(datasources)\n .filter((key) => {\n // Datasources are allowed to be used if a) they are direct, or b) they are proxied, and their\n // proxy is the same as what we have saved.\n const isDirect = 'directUrl' in (datasources[key]?.plugin?.spec ?? {});\n const isSavedProxy =\n !isDirect &&\n !('directUrl' in (savedDatasources[key]?.plugin?.spec ?? {})) &&\n datasources[key]?.plugin?.spec?.proxy === savedDatasources[key]?.plugin?.spec?.proxy;\n\n return isDirect || isSavedProxy;\n })\n .reduce((obj, key) => {\n obj[key] = datasources[key] as DatasourceSpec;\n\n return obj;\n }, {} as Record<string, DatasourceSpec>);\n\n setDashboard({\n ...dashboard,\n spec: {\n ...dashboard.spec,\n datasources: datasources,\n },\n });\n setSavedDatasources(newSavedDatasources);\n setLocalDatasources(datasources);\n setIsDatasourceEditorOpen(false);\n };\n\n return (\n <>\n <InfoTooltip description={TOOLTIP_TEXT.editDatasources}>\n <Button\n startIcon={<PencilIcon />}\n onClick={openDatasourceEditor}\n aria-label={TOOLTIP_TEXT.editDatasources}\n variant=\"text\"\n color=\"primary\"\n sx={{ whiteSpace: 'nowrap', minWidth: 'auto' }}\n >\n Datasources\n </Button>\n </InfoTooltip>\n <Drawer\n isOpen={isDatasourceEditorOpen}\n onClose={closeDatasourceEditor}\n PaperProps={{ sx: { width: '50%' } }}\n data-testid=\"datasource-editor\"\n >\n <DatasourceEditor\n datasources={localDatasources}\n onCancel={closeDatasourceEditor}\n onChange={handleChangeDatasources}\n />\n </Drawer>\n </>\n );\n}\n"],"names":["useState","Button","PencilIcon","Drawer","InfoTooltip","useDatasourceStore","TOOLTIP_TEXT","useDashboard","DatasourceEditor","EditDatasourcesButton","isDatasourceEditorOpen","setIsDatasourceEditorOpen","getLocalDatasources","setLocalDatasources","getSavedDatasources","setSavedDatasources","localDatasources","savedDatasources","dashboard","setDashboard","openDatasourceEditor","closeDatasourceEditor","handleChangeDatasources","datasources","newSavedDatasources","Object","keys","filter","key","isDirect","plugin","spec","isSavedProxy","proxy","reduce","obj","description","editDatasources","startIcon","onClick","aria-label","variant","color","sx","whiteSpace","minWidth","isOpen","onClose","PaperProps","width","data-testid","onCancel","onChange"],"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,SAASA,QAAQ,QAAQ,QAAQ;AACjC,SAASC,MAAM,QAAQ,gBAAgB;AACvC,OAAOC,gBAAgB,gCAAgC;AACvD,SAASC,MAAM,EAAEC,WAAW,QAAQ,yBAAyB;AAE7D,SAASC,kBAAkB,QAAQ,4BAA4B;AAC/D,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SAASC,gBAAgB,QAAQ,qBAAqB;AAEtD,OAAO,SAASC;IACd,MAAM,CAACC,wBAAwBC,0BAA0B,GAAGX,SAAS;IACrE,MAAM,EAAEY,oBAAmB,EAAEC,oBAAmB,EAAEC,oBAAmB,EAAEC,oBAAmB,EAAE,GAAGV;IAC/F,MAAMW,mBAAmDJ;IACzD,MAAMK,mBAAmDH;IACzD,MAAM,EAAEI,UAAS,EAAEC,aAAY,EAAE,GAAGZ;IAEpC,MAAMa,uBAAuB;QAC3BT,0BAA0B;IAC5B;IAEA,MAAMU,wBAAwB;QAC5BV,0BAA0B;IAC5B;IAEA,MAAMW,0BAA0B,CAACC;QAC/B,sEAAsE;QACtE,MAAMC,sBAAsDC,OAAOC,KAAKH,aACrEI,OAAO,CAACC;gBAG0BL,2CAGbN,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nB;oBACToB,cAAYlC,aAAa+B;oBACzBI,SAAQ;oBACRC,OAAM;oBACNC,IAAI;wBAAEC,YAAY;wBAAUC,UAAU;oBAAO;8BAC9C;;;0BAIH,KAAC1C;gBACC2C,QAAQpC;gBACRqC,SAAS1B;gBACT2B,YAAY;oBAAEL,IAAI;wBAAEM,OAAO;oBAAM;gBAAE;gBACnCC,eAAY;0BAEZ,cAAA,KAAC1C;oBACCe,aAAaP;oBACbmC,UAAU9B;oBACV+B,UAAU9B;;;;;AAKpB"}
@@ -0,0 +1,3 @@
1
+ export * from './EditDatasourcesButton';
2
+ export * from './DatasourceEditor';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Datasources/index.ts"],"names":[],"mappings":"AAaA,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,16 @@
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 './EditDatasourcesButton';
14
+ export * from './DatasourceEditor';
15
+
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/Datasources/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 './EditDatasourcesButton';\nexport * from './DatasourceEditor';\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,0BAA0B;AACxC,cAAc,qBAAqB"}
@@ -14,7 +14,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { useState } from 'react';
15
15
  import { Alert, FormControl } from '@mui/material';
16
16
  import { Dialog, JSONEditor } from '@perses-dev/components';
17
- import { useTimeRange } from '@perses-dev/plugin-system';
17
+ import { useDatasourceStore, useTimeRange } from '@perses-dev/plugin-system';
18
18
  import { useEditJsonDialog } from '../../context/DashboardProvider';
19
19
  import { useDashboard } from '../../context/useDashboard';
20
20
  export const EditJsonDialog = (props)=>{
@@ -41,6 +41,7 @@ const EditJsonDialogForm = (props)=>{
41
41
  const { closeEditJsonDialog } = useEditJsonDialog();
42
42
  const { setTimeRange , setRefreshInterval } = useTimeRange();
43
43
  const { dashboard , setDashboard } = useDashboard();
44
+ const { setLocalDatasources } = useDatasourceStore();
44
45
  const [draftDashboard, setDraftDashboard] = useState(dashboard);
45
46
  const handleApply = (e)=>{
46
47
  e.preventDefault();
@@ -50,8 +51,18 @@ const EditJsonDialogForm = (props)=>{
50
51
  });
51
52
  var _draftDashboard_spec_refreshInterval;
52
53
  setRefreshInterval((_draftDashboard_spec_refreshInterval = draftDashboard.spec.refreshInterval) !== null && _draftDashboard_spec_refreshInterval !== void 0 ? _draftDashboard_spec_refreshInterval : '0s');
54
+ var _draftDashboard_spec_datasources;
55
+ setLocalDatasources((_draftDashboard_spec_datasources = draftDashboard.spec.datasources) !== null && _draftDashboard_spec_datasources !== void 0 ? _draftDashboard_spec_datasources : {});
53
56
  closeEditJsonDialog();
54
57
  };
58
+ const completeDraftDashboard = (dashboard)=>{
59
+ try {
60
+ const json = JSON.parse(dashboard !== null && dashboard !== void 0 ? dashboard : '{}');
61
+ setDraftDashboard(json);
62
+ } catch (e) {
63
+ // do nothing
64
+ }
65
+ };
55
66
  return /*#__PURE__*/ _jsxs(Dialog.Form, {
56
67
  onSubmit: handleApply,
57
68
  children: [
@@ -73,7 +84,7 @@ const EditJsonDialogForm = (props)=>{
73
84
  minHeight: "300px",
74
85
  maxHeight: "70vh",
75
86
  value: draftDashboard,
76
- onChange: (value)=>setDraftDashboard(value)
87
+ onChange: (value)=>completeDraftDashboard(value)
77
88
  })
78
89
  })
79
90
  ]