@perses-dev/dashboards 0.54.0-beta.1 → 0.54.0-beta.2

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 (115) hide show
  1. package/dist/cjs/components/Panel/Panel.js +4 -1
  2. package/dist/cjs/components/Variables/VariableEditor.js +51 -17
  3. package/dist/cjs/context/DatasourceStoreProvider.js +4 -1
  4. package/dist/cjs/context/VariableProvider/VariableProvider.js +10 -6
  5. package/dist/components/AddGroupButton/AddGroupButton.js +1 -1
  6. package/dist/components/AddGroupButton/AddGroupButton.js.map +1 -1
  7. package/dist/components/AddPanelButton/AddPanelButton.js +1 -1
  8. package/dist/components/AddPanelButton/AddPanelButton.js.map +1 -1
  9. package/dist/components/Dashboard/Dashboard.js +1 -1
  10. package/dist/components/Dashboard/Dashboard.js.map +1 -1
  11. package/dist/components/DashboardLinks/DashboardLinksEditor.js +1 -1
  12. package/dist/components/DashboardLinks/DashboardLinksEditor.js.map +1 -1
  13. package/dist/components/DashboardLinks/EditDashboardLinksButton.js +1 -1
  14. package/dist/components/DashboardLinks/EditDashboardLinksButton.js.map +1 -1
  15. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js +1 -1
  16. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js.map +1 -1
  17. package/dist/components/DashboardToolbar/DashboardToolbar.js +1 -1
  18. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  19. package/dist/components/Datasources/DatasourceEditor.d.ts.map +1 -1
  20. package/dist/components/Datasources/DatasourceEditor.js +1 -1
  21. package/dist/components/Datasources/DatasourceEditor.js.map +1 -1
  22. package/dist/components/Datasources/EditDatasourcesButton.js +1 -1
  23. package/dist/components/Datasources/EditDatasourcesButton.js.map +1 -1
  24. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +1 -1
  25. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js.map +1 -1
  26. package/dist/components/DownloadButton/DownloadButton.js +1 -1
  27. package/dist/components/DownloadButton/DownloadButton.js.map +1 -1
  28. package/dist/components/EditButton/EditButton.js +1 -1
  29. package/dist/components/EditButton/EditButton.js.map +1 -1
  30. package/dist/components/EditJsonButton/EditJsonButton.js +1 -1
  31. package/dist/components/EditJsonButton/EditJsonButton.js.map +1 -1
  32. package/dist/components/EditJsonDialog/EditJsonDialog.js +1 -1
  33. package/dist/components/EditJsonDialog/EditJsonDialog.js.map +1 -1
  34. package/dist/components/EmptyDashboard/EmptyDashboard.js +1 -1
  35. package/dist/components/EmptyDashboard/EmptyDashboard.js.map +1 -1
  36. package/dist/components/GridLayout/GridContainer.js +1 -1
  37. package/dist/components/GridLayout/GridContainer.js.map +1 -1
  38. package/dist/components/GridLayout/GridItemContent.js +1 -1
  39. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  40. package/dist/components/GridLayout/GridLayout.js +1 -1
  41. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  42. package/dist/components/GridLayout/GridTitle.js +1 -1
  43. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  44. package/dist/components/GridLayout/Row.js +1 -1
  45. package/dist/components/GridLayout/Row.js.map +1 -1
  46. package/dist/components/LeaveDialog/LeaveDialog.js +1 -1
  47. package/dist/components/LeaveDialog/LeaveDialog.js.map +1 -1
  48. package/dist/components/LinksDisplay/LinksDisplay.js +1 -1
  49. package/dist/components/LinksDisplay/LinksDisplay.js.map +1 -1
  50. package/dist/components/Panel/Panel.js +5 -2
  51. package/dist/components/Panel/Panel.js.map +1 -1
  52. package/dist/components/Panel/PanelActions.js +1 -1
  53. package/dist/components/Panel/PanelActions.js.map +1 -1
  54. package/dist/components/Panel/PanelContent.js +1 -1
  55. package/dist/components/Panel/PanelContent.js.map +1 -1
  56. package/dist/components/Panel/PanelHeader.js +1 -1
  57. package/dist/components/Panel/PanelHeader.js.map +1 -1
  58. package/dist/components/Panel/PanelPluginLoader.js +1 -1
  59. package/dist/components/Panel/PanelPluginLoader.js.map +1 -1
  60. package/dist/components/Panel/useSelectionItemActions.js +1 -1
  61. package/dist/components/Panel/useSelectionItemActions.js.map +1 -1
  62. package/dist/components/PanelDrawer/PanelDrawer.js +1 -1
  63. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  64. package/dist/components/PanelDrawer/PanelEditorForm.js +1 -1
  65. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  66. package/dist/components/PanelDrawer/PanelPreview.js +1 -1
  67. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
  68. package/dist/components/PanelDrawer/PanelQueriesSharedControls.js +1 -1
  69. package/dist/components/PanelDrawer/PanelQueriesSharedControls.js.map +1 -1
  70. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +1 -1
  71. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
  72. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js +1 -1
  73. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js.map +1 -1
  74. package/dist/components/QuerySummaryTable/QuerySummaryTable.js +1 -1
  75. package/dist/components/QuerySummaryTable/QuerySummaryTable.js.map +1 -1
  76. package/dist/components/QueryViewerDialog/QueryViewerDialog.js +1 -1
  77. package/dist/components/QueryViewerDialog/QueryViewerDialog.js.map +1 -1
  78. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +1 -1
  79. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -1
  80. package/dist/components/Variables/EditVariablesButton.js +1 -1
  81. package/dist/components/Variables/EditVariablesButton.js.map +1 -1
  82. package/dist/components/Variables/ListVariableListBox.js +1 -1
  83. package/dist/components/Variables/ListVariableListBox.js.map +1 -1
  84. package/dist/components/Variables/Variable.js +2 -2
  85. package/dist/components/Variables/Variable.js.map +1 -1
  86. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  87. package/dist/components/Variables/VariableEditor.js +56 -22
  88. package/dist/components/Variables/VariableEditor.js.map +1 -1
  89. package/dist/components/Variables/VariableList.js +1 -1
  90. package/dist/components/Variables/VariableList.js.map +1 -1
  91. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  92. package/dist/context/DashboardProvider/DashboardProvider.js +1 -1
  93. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  94. package/dist/context/DatasourceStoreProvider.d.ts +1 -1
  95. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  96. package/dist/context/DatasourceStoreProvider.js +5 -2
  97. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  98. package/dist/context/PanelEditorProvider/PanelEditorProvider.js +1 -1
  99. package/dist/context/PanelEditorProvider/PanelEditorProvider.js.map +1 -1
  100. package/dist/context/VariableProvider/VariableProvider.d.ts +2 -1
  101. package/dist/context/VariableProvider/VariableProvider.d.ts.map +1 -1
  102. package/dist/context/VariableProvider/VariableProvider.js +12 -8
  103. package/dist/context/VariableProvider/VariableProvider.js.map +1 -1
  104. package/dist/keyboard-shortcuts/PanelFocusProvider.js +1 -1
  105. package/dist/keyboard-shortcuts/PanelFocusProvider.js.map +1 -1
  106. package/dist/test/datasource-provider.d.ts +1 -1
  107. package/dist/test/datasource-provider.d.ts.map +1 -1
  108. package/dist/test/datasource-provider.js.map +1 -1
  109. package/dist/test/render.js +1 -1
  110. package/dist/test/render.js.map +1 -1
  111. package/dist/views/ViewDashboard/DashboardApp.js +1 -1
  112. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  113. package/dist/views/ViewDashboard/ViewDashboard.js +1 -1
  114. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  115. package/package.json +6 -9
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,7 +11,6 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import React, { useMemo } from 'react';
15
15
  import { Dialog } from '@perses-dev/components';
16
16
  import { Button, Divider } from '@mui/material';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/QueryViewerDialog/QueryViewerDialog.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 React, { ReactElement, useMemo } from 'react';\nimport { Dialog } from '@perses-dev/components';\nimport { Button, Divider } from '@mui/material';\nimport { PluginSpecEditor } from '@perses-dev/plugin-system';\nimport { QueryDefinition } from '@perses-dev/spec';\n\nexport interface QueryViewerDialogProps {\n open: boolean;\n queryDefinitions: QueryDefinition[];\n onClose: () => void;\n}\n\nexport function QueryViewerDialog({ open, queryDefinitions, onClose }: QueryViewerDialogProps): ReactElement {\n const queryRows = useMemo(() => {\n if (!queryDefinitions?.length) return null;\n\n const queryItems: ReactElement[] = [];\n queryDefinitions.forEach((query, index) => {\n if (query?.spec?.plugin?.kind && query?.kind) {\n queryItems.push(\n <React.Fragment key={`query-${index}`}>\n <PluginSpecEditor\n value={query.spec.plugin.spec}\n pluginSelection={{ kind: query.spec.plugin.kind, type: query.kind }}\n onChange={(): void => {}}\n isReadonly\n />\n {index < queryDefinitions.length - 1 && <Divider sx={{ my: 2 }} />}\n </React.Fragment>\n );\n }\n });\n\n return queryItems;\n }, [queryDefinitions]);\n\n return (\n <Dialog open={open} onClose={onClose} maxWidth=\"lg\" fullWidth={true}>\n <Dialog.Header>Query Viewer</Dialog.Header>\n <Dialog.Content>{queryRows}</Dialog.Content>\n <Dialog.Actions>\n <Button variant=\"outlined\" color=\"secondary\" onClick={onClose}>\n Close\n </Button>\n </Dialog.Actions>\n </Dialog>\n );\n}\n"],"names":["React","useMemo","Dialog","Button","Divider","PluginSpecEditor","QueryViewerDialog","open","queryDefinitions","onClose","queryRows","length","queryItems","forEach","query","index","spec","plugin","kind","push","Fragment","value","pluginSelection","type","onChange","isReadonly","sx","my","maxWidth","fullWidth","Header","Content","Actions","variant","color","onClick"],"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,OAAOA,SAAuBC,OAAO,QAAQ,QAAQ;AACrD,SAASC,MAAM,QAAQ,yBAAyB;AAChD,SAASC,MAAM,EAAEC,OAAO,QAAQ,gBAAgB;AAChD,SAASC,gBAAgB,QAAQ,4BAA4B;AAS7D,OAAO,SAASC,kBAAkB,EAAEC,IAAI,EAAEC,gBAAgB,EAAEC,OAAO,EAA0B;IAC3F,MAAMC,YAAYT,QAAQ;QACxB,IAAI,CAACO,kBAAkBG,QAAQ,OAAO;QAEtC,MAAMC,aAA6B,EAAE;QACrCJ,iBAAiBK,OAAO,CAAC,CAACC,OAAOC;YAC/B,IAAID,OAAOE,MAAMC,QAAQC,QAAQJ,OAAOI,MAAM;gBAC5CN,WAAWO,IAAI,eACb,MAACnB,MAAMoB,QAAQ;;sCACb,KAACf;4BACCgB,OAAOP,MAAME,IAAI,CAACC,MAAM,CAACD,IAAI;4BAC7BM,iBAAiB;gCAAEJ,MAAMJ,MAAME,IAAI,CAACC,MAAM,CAACC,IAAI;gCAAEK,MAAMT,MAAMI,IAAI;4BAAC;4BAClEM,UAAU,KAAa;4BACvBC,UAAU;;wBAEXV,QAAQP,iBAAiBG,MAAM,GAAG,mBAAK,KAACP;4BAAQsB,IAAI;gCAAEC,IAAI;4BAAE;;;mBAP1C,CAAC,MAAM,EAAEZ,OAAO;YAUzC;QACF;QAEA,OAAOH;IACT,GAAG;QAACJ;KAAiB;IAErB,qBACE,MAACN;QAAOK,MAAMA;QAAME,SAASA;QAASmB,UAAS;QAAKC,WAAW;;0BAC7D,KAAC3B,OAAO4B,MAAM;0BAAC;;0BACf,KAAC5B,OAAO6B,OAAO;0BAAErB;;0BACjB,KAACR,OAAO8B,OAAO;0BACb,cAAA,KAAC7B;oBAAO8B,SAAQ;oBAAWC,OAAM;oBAAYC,SAAS1B;8BAAS;;;;;AAMvE"}
1
+ {"version":3,"sources":["../../../src/components/QueryViewerDialog/QueryViewerDialog.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 React, { ReactElement, useMemo } from 'react';\nimport { Dialog } from '@perses-dev/components';\nimport { Button, Divider } from '@mui/material';\nimport { PluginSpecEditor } from '@perses-dev/plugin-system';\nimport { QueryDefinition } from '@perses-dev/spec';\n\nexport interface QueryViewerDialogProps {\n open: boolean;\n queryDefinitions: QueryDefinition[];\n onClose: () => void;\n}\n\nexport function QueryViewerDialog({ open, queryDefinitions, onClose }: QueryViewerDialogProps): ReactElement {\n const queryRows = useMemo(() => {\n if (!queryDefinitions?.length) return null;\n\n const queryItems: ReactElement[] = [];\n queryDefinitions.forEach((query, index) => {\n if (query?.spec?.plugin?.kind && query?.kind) {\n queryItems.push(\n <React.Fragment key={`query-${index}`}>\n <PluginSpecEditor\n value={query.spec.plugin.spec}\n pluginSelection={{ kind: query.spec.plugin.kind, type: query.kind }}\n onChange={(): void => {}}\n isReadonly\n />\n {index < queryDefinitions.length - 1 && <Divider sx={{ my: 2 }} />}\n </React.Fragment>\n );\n }\n });\n\n return queryItems;\n }, [queryDefinitions]);\n\n return (\n <Dialog open={open} onClose={onClose} maxWidth=\"lg\" fullWidth={true}>\n <Dialog.Header>Query Viewer</Dialog.Header>\n <Dialog.Content>{queryRows}</Dialog.Content>\n <Dialog.Actions>\n <Button variant=\"outlined\" color=\"secondary\" onClick={onClose}>\n Close\n </Button>\n </Dialog.Actions>\n </Dialog>\n );\n}\n"],"names":["React","useMemo","Dialog","Button","Divider","PluginSpecEditor","QueryViewerDialog","open","queryDefinitions","onClose","queryRows","length","queryItems","forEach","query","index","spec","plugin","kind","push","Fragment","value","pluginSelection","type","onChange","isReadonly","sx","my","maxWidth","fullWidth","Header","Content","Actions","variant","color","onClick"],"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,OAAOA,SAAuBC,OAAO,QAAQ,QAAQ;AACrD,SAASC,MAAM,QAAQ,yBAAyB;AAChD,SAASC,MAAM,EAAEC,OAAO,QAAQ,gBAAgB;AAChD,SAASC,gBAAgB,QAAQ,4BAA4B;AAS7D,OAAO,SAASC,kBAAkB,EAAEC,IAAI,EAAEC,gBAAgB,EAAEC,OAAO,EAA0B;IAC3F,MAAMC,YAAYT,QAAQ;QACxB,IAAI,CAACO,kBAAkBG,QAAQ,OAAO;QAEtC,MAAMC,aAA6B,EAAE;QACrCJ,iBAAiBK,OAAO,CAAC,CAACC,OAAOC;YAC/B,IAAID,OAAOE,MAAMC,QAAQC,QAAQJ,OAAOI,MAAM;gBAC5CN,WAAWO,IAAI,eACb,MAACnB,MAAMoB,QAAQ;;sCACb,KAACf;4BACCgB,OAAOP,MAAME,IAAI,CAACC,MAAM,CAACD,IAAI;4BAC7BM,iBAAiB;gCAAEJ,MAAMJ,MAAME,IAAI,CAACC,MAAM,CAACC,IAAI;gCAAEK,MAAMT,MAAMI,IAAI;4BAAC;4BAClEM,UAAU,KAAa;4BACvBC,UAAU;;wBAEXV,QAAQP,iBAAiBG,MAAM,GAAG,mBAAK,KAACP;4BAAQsB,IAAI;gCAAEC,IAAI;4BAAE;;;mBAP1C,CAAC,MAAM,EAAEZ,OAAO;YAUzC;QACF;QAEA,OAAOH;IACT,GAAG;QAACJ;KAAiB;IAErB,qBACE,MAACN;QAAOK,MAAMA;QAAME,SAASA;QAASmB,UAAS;QAAKC,WAAW;;0BAC7D,KAAC3B,OAAO4B,MAAM;0BAAC;;0BACf,KAAC5B,OAAO6B,OAAO;0BAAErB;;0BACjB,KAACR,OAAO8B,OAAO;0BACb,cAAA,KAAC7B;oBAAO8B,SAAQ;oBAAWC,OAAM;oBAAYC,SAAS1B;8BAAS;;;;;AAMvE"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,7 +11,6 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
14
  import { useState } from 'react';
15
15
  import { Checkbox, FormGroup, FormControlLabel, Typography } from '@mui/material';
16
16
  import { DEFAULT_REFRESH_INTERVAL_OPTIONS, useTimeRange } from '@perses-dev/plugin-system';
@@ -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,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;oCACC+C,uBACE,KAACjD;wCACCkD,UAAU,CAACpC,2BAA2B,CAACR,oBAAoBqB;wCAC3DwB,SAASlC,wBAAwBH,2BAA2BR,oBAAoBqB;wCAChFyB,UAAU,CAACC,IAA2CnC,wBAAwBmC,EAAEC,MAAM,CAACH,OAAO;;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 } 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,wBAAwB,GAAGrB,SAASgB;IACjE,MAAM,CAACM,4BAA4BC,0BAA0B,GAAGvB,SAASiB;IAEzE,MAAM,EAAEO,uBAAuB,EAAE,GAAGd;IACpC,MAAM,EAAEe,qBAAqB,EAAE,GAA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C,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,3 +1,4 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,7 +11,6 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
14
  import { useState } from 'react';
15
15
  import { Button } from '@mui/material';
16
16
  import PencilIcon from 'mdi-material-ui/PencilOutline';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Variables/EditVariablesButton.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 { Button, ButtonProps } from '@mui/material';\nimport PencilIcon from 'mdi-material-ui/PencilOutline';\nimport { Drawer, InfoTooltip } from '@perses-dev/components';\nimport { BuiltinVariableDefinition, VariableDefinition } from '@perses-dev/spec';\nimport { useBuiltinVariableDefinitions } from '@perses-dev/plugin-system';\nimport { ExternalVariableDefinition } from '../../model/VariableDefinition';\nimport { TOOLTIP_TEXT, editButtonStyle } from '../../constants';\nimport { useExternalVariableDefinitions, useVariableDefinitionActions, useVariableDefinitions } from '../../context';\nimport { VariableEditor } from './VariableEditor';\n\nexport interface EditVariablesButtonProps extends Pick<ButtonProps, 'fullWidth'> {\n /**\n * The variant to use to display the button.\n */\n variant?: 'text' | 'outlined';\n\n /**\n * The color to use to display the button.\n */\n color?: 'primary' | 'secondary';\n\n /**\n * The label used inside the button.\n */\n label?: string;\n}\n\nexport function EditVariablesButton({\n variant = 'text',\n label = 'Variables',\n color = 'primary',\n fullWidth,\n}: EditVariablesButtonProps): ReactElement {\n const [isVariableEditorOpen, setIsVariableEditorOpen] = useState(false);\n const variableDefinitions: VariableDefinition[] = useVariableDefinitions();\n const externalVariableDefinitions: ExternalVariableDefinition[] = useExternalVariableDefinitions();\n const builtinVariableDefinitions: BuiltinVariableDefinition[] = useBuiltinVariableDefinitions();\n const { setVariableDefinitions } = useVariableDefinitionActions();\n\n const openVariableEditor = (): void => {\n setIsVariableEditorOpen(true);\n };\n\n const closeVariableEditor = (): void => {\n setIsVariableEditorOpen(false);\n };\n\n return (\n <>\n <InfoTooltip description={TOOLTIP_TEXT.editVariables}>\n <Button\n startIcon={<PencilIcon />}\n onClick={openVariableEditor}\n aria-label={TOOLTIP_TEXT.editVariables}\n variant={variant}\n color={color}\n fullWidth={fullWidth}\n sx={editButtonStyle}\n >\n {label}\n </Button>\n </InfoTooltip>\n <Drawer\n isOpen={isVariableEditorOpen}\n onClose={closeVariableEditor}\n PaperProps={{ sx: { width: '50%' } }}\n data-testid=\"variable-editor\"\n >\n <VariableEditor\n variableDefinitions={variableDefinitions}\n externalVariableDefinitions={externalVariableDefinitions}\n builtinVariableDefinitions={builtinVariableDefinitions}\n onCancel={closeVariableEditor}\n onChange={(variables: VariableDefinition[]) => {\n setVariableDefinitions(variables);\n setIsVariableEditorOpen(false);\n }}\n />\n </Drawer>\n </>\n );\n}\n"],"names":["useState","Button","PencilIcon","Drawer","InfoTooltip","useBuiltinVariableDefinitions","TOOLTIP_TEXT","editButtonStyle","useExternalVariableDefinitions","useVariableDefinitionActions","useVariableDefinitions","VariableEditor","EditVariablesButton","variant","label","color","fullWidth","isVariableEditorOpen","setIsVariableEditorOpen","variableDefinitions","externalVariableDefinitions","builtinVariableDefinitions","setVariableDefinitions","openVariableEditor","closeVariableEditor","description","editVariables","startIcon","onClick","aria-label","sx","isOpen","onClose","PaperProps","width","data-testid","onCancel","onChange","variables"],"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,MAAM,QAAqB,gBAAgB;AACpD,OAAOC,gBAAgB,gCAAgC;AACvD,SAASC,MAAM,EAAEC,WAAW,QAAQ,yBAAyB;AAE7D,SAASC,6BAA6B,QAAQ,4BAA4B;AAE1E,SAASC,YAAY,EAAEC,eAAe,QAAQ,kBAAkB;AAChE,SAASC,8BAA8B,EAAEC,4BAA4B,EAAEC,sBAAsB,QAAQ,gBAAgB;AACrH,SAASC,cAAc,QAAQ,mBAAmB;AAmBlD,OAAO,SAASC,oBAAoB,EAClCC,UAAU,MAAM,EAChBC,QAAQ,WAAW,EACnBC,QAAQ,SAAS,EACjBC,SAAS,EACgB;IACzB,MAAM,CAACC,sBAAsBC,wBAAwB,GAAGlB,SAAS;IACjE,MAAMmB,sBAA4CT;IAClD,MAAMU,8BAA4DZ;IAClE,MAAMa,6BAA0DhB;IAChE,MAAM,EAAEiB,sBAAsB,EAAE,GAAGb;IAEnC,MAAMc,qBAAqB;QACzBL,wBAAwB;IAC1B;IAEA,MAAMM,sBAAsB;QAC1BN,wBAAwB;IAC1B;IAEA,qBACE;;0BACE,KAACd;gBAAYqB,aAAanB,aAAaoB,aAAa;0BAClD,cAAA,KAACzB;oBACC0B,yBAAW,KAACzB;oBACZ0B,SAASL;oBACTM,cAAYvB,aAAaoB,aAAa;oBACtCb,SAASA;oBACTE,OAAOA;oBACPC,WAAWA;oBACXc,IAAIvB;8BAEHO;;;0BAGL,KAACX;gBACC4B,QAAQd;gBACRe,SAASR;gBACTS,YAAY;oBAAEH,IAAI;wBAAEI,OAAO;oBAAM;gBAAE;gBACnCC,eAAY;0BAEZ,cAAA,KAACxB;oBACCQ,qBAAqBA;oBACrBC,6BAA6BA;oBAC7BC,4BAA4BA;oBAC5Be,UAAUZ;oBACVa,UAAU,CAACC;wBACThB,uBAAuBgB;wBACvBpB,wBAAwB;oBAC1B;;;;;AAKV"}
1
+ {"version":3,"sources":["../../../src/components/Variables/EditVariablesButton.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 { Button, ButtonProps } from '@mui/material';\nimport PencilIcon from 'mdi-material-ui/PencilOutline';\nimport { Drawer, InfoTooltip } from '@perses-dev/components';\nimport { BuiltinVariableDefinition, VariableDefinition } from '@perses-dev/spec';\nimport { useBuiltinVariableDefinitions } from '@perses-dev/plugin-system';\nimport { ExternalVariableDefinition } from '../../model/VariableDefinition';\nimport { TOOLTIP_TEXT, editButtonStyle } from '../../constants';\nimport { useExternalVariableDefinitions, useVariableDefinitionActions, useVariableDefinitions } from '../../context';\nimport { VariableEditor } from './VariableEditor';\n\nexport interface EditVariablesButtonProps extends Pick<ButtonProps, 'fullWidth'> {\n /**\n * The variant to use to display the button.\n */\n variant?: 'text' | 'outlined';\n\n /**\n * The color to use to display the button.\n */\n color?: 'primary' | 'secondary';\n\n /**\n * The label used inside the button.\n */\n label?: string;\n}\n\nexport function EditVariablesButton({\n variant = 'text',\n label = 'Variables',\n color = 'primary',\n fullWidth,\n}: EditVariablesButtonProps): ReactElement {\n const [isVariableEditorOpen, setIsVariableEditorOpen] = useState(false);\n const variableDefinitions: VariableDefinition[] = useVariableDefinitions();\n const externalVariableDefinitions: ExternalVariableDefinition[] = useExternalVariableDefinitions();\n const builtinVariableDefinitions: BuiltinVariableDefinition[] = useBuiltinVariableDefinitions();\n const { setVariableDefinitions } = useVariableDefinitionActions();\n\n const openVariableEditor = (): void => {\n setIsVariableEditorOpen(true);\n };\n\n const closeVariableEditor = (): void => {\n setIsVariableEditorOpen(false);\n };\n\n return (\n <>\n <InfoTooltip description={TOOLTIP_TEXT.editVariables}>\n <Button\n startIcon={<PencilIcon />}\n onClick={openVariableEditor}\n aria-label={TOOLTIP_TEXT.editVariables}\n variant={variant}\n color={color}\n fullWidth={fullWidth}\n sx={editButtonStyle}\n >\n {label}\n </Button>\n </InfoTooltip>\n <Drawer\n isOpen={isVariableEditorOpen}\n onClose={closeVariableEditor}\n PaperProps={{ sx: { width: '50%' } }}\n data-testid=\"variable-editor\"\n >\n <VariableEditor\n variableDefinitions={variableDefinitions}\n externalVariableDefinitions={externalVariableDefinitions}\n builtinVariableDefinitions={builtinVariableDefinitions}\n onCancel={closeVariableEditor}\n onChange={(variables: VariableDefinition[]) => {\n setVariableDefinitions(variables);\n setIsVariableEditorOpen(false);\n }}\n />\n </Drawer>\n </>\n );\n}\n"],"names":["useState","Button","PencilIcon","Drawer","InfoTooltip","useBuiltinVariableDefinitions","TOOLTIP_TEXT","editButtonStyle","useExternalVariableDefinitions","useVariableDefinitionActions","useVariableDefinitions","VariableEditor","EditVariablesButton","variant","label","color","fullWidth","isVariableEditorOpen","setIsVariableEditorOpen","variableDefinitions","externalVariableDefinitions","builtinVariableDefinitions","setVariableDefinitions","openVariableEditor","closeVariableEditor","description","editVariables","startIcon","onClick","aria-label","sx","isOpen","onClose","PaperProps","width","data-testid","onCancel","onChange","variables"],"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,MAAM,QAAqB,gBAAgB;AACpD,OAAOC,gBAAgB,gCAAgC;AACvD,SAASC,MAAM,EAAEC,WAAW,QAAQ,yBAAyB;AAE7D,SAASC,6BAA6B,QAAQ,4BAA4B;AAE1E,SAASC,YAAY,EAAEC,eAAe,QAAQ,kBAAkB;AAChE,SAASC,8BAA8B,EAAEC,4BAA4B,EAAEC,sBAAsB,QAAQ,gBAAgB;AACrH,SAASC,cAAc,QAAQ,mBAAmB;AAmBlD,OAAO,SAASC,oBAAoB,EAClCC,UAAU,MAAM,EAChBC,QAAQ,WAAW,EACnBC,QAAQ,SAAS,EACjBC,SAAS,EACgB;IACzB,MAAM,CAACC,sBAAsBC,wBAAwB,GAAGlB,SAAS;IACjE,MAAMmB,sBAA4CT;IAClD,MAAMU,8BAA4DZ;IAClE,MAAMa,6BAA0DhB;IAChE,MAAM,EAAEiB,sBAAsB,EAAE,GAAGb;IAEnC,MAAMc,qBAAqB;QACzBL,wBAAwB;IAC1B;IAEA,MAAMM,sBAAsB;QAC1BN,wBAAwB;IAC1B;IAEA,qBACE;;0BACE,KAACd;gBAAYqB,aAAanB,aAAaoB,aAAa;0BAClD,cAAA,KAACzB;oBACC0B,yBAAW,KAACzB;oBACZ0B,SAASL;oBACTM,cAAYvB,aAAaoB,aAAa;oBACtCb,SAASA;oBACTE,OAAOA;oBACPC,WAAWA;oBACXc,IAAIvB;8BAEHO;;;0BAGL,KAACX;gBACC4B,QAAQd;gBACRe,SAASR;gBACTS,YAAY;oBAAEH,IAAI;wBAAEI,OAAO;oBAAM;gBAAE;gBACnCC,eAAY;0BAEZ,cAAA,KAACxB;oBACCQ,qBAAqBA;oBACrBC,6BAA6BA;oBAC7BC,4BAA4BA;oBAC5Be,UAAUZ;oBACVa,UAAU,CAACC;wBACThB,uBAAuBgB;wBACvBpB,wBAAwB;oBAC1B;;;;;AAKV"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,7 +11,6 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import React, { forwardRef, useContext, useMemo } from 'react';
15
15
  import { Checkbox, Divider } from '@mui/material';
16
16
  import { DEFAULT_ALL_VALUE } from '@perses-dev/spec';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Variables/ListVariableListBox.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 React, { ForwardedRef, HTMLAttributes, ReactNode, forwardRef, useContext, useMemo } from 'react';\nimport { Checkbox, Divider } from '@mui/material';\nimport { VariableOption } from '@perses-dev/plugin-system';\nimport { DEFAULT_ALL_VALUE } from '@perses-dev/spec';\n\nexport interface ListVariableListBoxContextValue {\n options: VariableOption[];\n selectedOptions: VariableOption[];\n filteredOptions: VariableOption[];\n allowAllValue: boolean;\n onChange: (selectedOptions: VariableOption[]) => void;\n}\n\nconst ListVariableListBoxContext = React.createContext<ListVariableListBoxContextValue | undefined>(undefined);\n\nexport function useListVariableListBoxContext(): ListVariableListBoxContextValue {\n const ctx = useContext(ListVariableListBoxContext);\n if (!ctx) throw new Error('ListVariableListBoxContext not found');\n return ctx;\n}\n\n/*\n * Handles the logic for toggling the global select checkbox in the ListBox header.\n *\n * If all options are selected, it will deselect all options.\n * Except if filteredOptions is a subset of options, then it will only deselect the filtered options.\n *\n * If some options are selected, it will select all filtered options.\n *\n * If no options are selected, it will select all filtered options.\n * Should be not possible since a ListVariable has always at least one value.\n *\n * If allowAllValue is true, it will handle the special \"All\" option logic.\n * Main difference is if some options are selected and there is no filter, it will select the \"All\" option\n */\nfunction handleGlobalSelectToggle(\n options: VariableOption[],\n selectedOptions: VariableOption[],\n filteredOptions: VariableOption[],\n isIndeterminate: boolean,\n isAllSelected: boolean,\n allowAllValue: boolean,\n onChange: (selectedOptions: VariableOption[]) => void\n): void {\n if (isAllSelected) {\n if (filteredOptions.length !== options.length) {\n onChange(selectedOptions.filter((o) => !filteredOptions.includes(o)));\n } else {\n onChange([]);\n }\n return;\n }\n\n if (isIndeterminate) {\n if (allowAllValue) {\n if (filteredOptions.length === options.length) {\n if (selectedOptions[0]?.value === DEFAULT_ALL_VALUE) {\n onChange(options.filter((o) => o.value !== DEFAULT_ALL_VALUE));\n } else {\n onChange([{ label: DEFAULT_ALL_VALUE, value: DEFAULT_ALL_VALUE }]);\n }\n } else {\n if (filteredOptions.every((o) => selectedOptions.includes(o))) {\n onChange(selectedOptions.filter((o) => !filteredOptions.includes(o)));\n } else {\n onChange([...selectedOptions, ...filteredOptions.filter((o) => o.value !== DEFAULT_ALL_VALUE)]);\n }\n }\n } else {\n if (filteredOptions.length === options.length) {\n onChange(options);\n } else {\n if (filteredOptions.every((o) => selectedOptions.includes(o))) {\n onChange(selectedOptions.filter((o) => !filteredOptions.includes(o)));\n } else {\n onChange([...selectedOptions, ...filteredOptions]);\n }\n }\n }\n return;\n }\n\n // Nothing selected, so select filtered options\n onChange(filteredOptions);\n}\n\nexport function ListVariableListBoxProvider({\n value,\n children,\n}: {\n value: ListVariableListBoxContextValue;\n children: ReactNode;\n}): React.ReactElement {\n return <ListVariableListBoxContext.Provider value={value}>{children}</ListVariableListBoxContext.Provider>;\n}\n\nexport const ListVariableListBox = forwardRef(function ListVariableListBox(\n props: HTMLAttributes<HTMLUListElement>,\n ref: ForwardedRef<HTMLUListElement>\n) {\n const { children, ...rest } = props;\n const { options, selectedOptions, filteredOptions, allowAllValue, onChange } = useListVariableListBoxContext();\n\n // Derived selection metadata for context listbox header\n const selectedCount = useMemo(() => selectedOptions.length, [selectedOptions]);\n const isIndeterminate = useMemo(\n () => options.length > 0 && selectedCount > 0 && selectedCount !== options.length,\n [selectedCount, options]\n );\n const isAllSelected = useMemo(() => options.length > 0 && selectedCount === options.length, [selectedCount, options]);\n\n return (\n <ul {...rest} ref={ref} role=\"listbox\">\n <li style={{ display: 'flex', alignItems: 'center' }}>\n <Checkbox\n indeterminate={isIndeterminate}\n checked={isAllSelected}\n // intentionally not passing event to underlying handler to mimic previous behavior\n onChange={() =>\n handleGlobalSelectToggle(\n options,\n selectedOptions,\n filteredOptions,\n isIndeterminate,\n isAllSelected,\n allowAllValue,\n onChange\n )\n }\n />\n <span>\n <strong>{selectedCount}</strong> Selected\n </span>\n </li>\n <Divider />\n {children}\n </ul>\n );\n});\n"],"names":["React","forwardRef","useContext","useMemo","Checkbox","Divider","DEFAULT_ALL_VALUE","ListVariableListBoxContext","createContext","undefined","useListVariableListBoxContext","ctx","Error","handleGlobalSelectToggle","options","selectedOptions","filteredOptions","isIndeterminate","isAllSelected","allowAllValue","onChange","length","filter","o","includes","value","label","every","ListVariableListBoxProvider","children","Provider","ListVariableListBox","props","ref","rest","selectedCount","ul","role","li","style","display","alignItems","indeterminate","checked","span","strong"],"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,OAAOA,SAAkDC,UAAU,EAAEC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AACxG,SAASC,QAAQ,EAAEC,OAAO,QAAQ,gBAAgB;AAElD,SAASC,iBAAiB,QAAQ,mBAAmB;AAUrD,MAAMC,2CAA6BP,MAAMQ,aAAa,CAA8CC;AAEpG,OAAO,SAASC;IACd,MAAMC,MAAMT,WAAWK;IACvB,IAAI,CAACI,KAAK,MAAM,IAAIC,MAAM;IAC1B,OAAOD;AACT;AAEA;;;;;;;;;;;;;CAaC,GACD,SAASE,yBACPC,OAAyB,EACzBC,eAAiC,EACjCC,eAAiC,EACjCC,eAAwB,EACxBC,aAAsB,EACtBC,aAAsB,EACtBC,QAAqD;IAErD,IAAIF,eAAe;QACjB,IAAIF,gBAAgBK,MAAM,KAAKP,QAAQO,MAAM,EAAE;YAC7CD,SAASL,gBAAgBO,MAAM,CAAC,CAACC,IAAM,CAACP,gBAAgBQ,QAAQ,CAACD;QACnE,OAAO;YACLH,SAAS,EAAE;QACb;QACA;IACF;IAEA,IAAIH,iBAAiB;QACnB,IAAIE,eAAe;YACjB,IAAIH,gBAAgBK,MAAM,KAAKP,QAAQO,MAAM,EAAE;gBAC7C,IAAIN,eAAe,CAAC,EAAE,EAAEU,UAAUnB,mBAAmB;oBACnDc,SAASN,QAAQQ,MAAM,CAAC,CAACC,IAAMA,EAAEE,KAAK,KA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AQO,MAAM,GAAG,KAAKc,gBAAgB,KAAKA,kBAAkBrB,QAAQO,MAAM,EACjF;QAACc;QAAerB;KAAQ;IAE1B,MAAMI,gBAAgBf,QAAQ,IAAMW,QAAQO,MAAM,GAAG,KAAKc,kBAAkBrB,QAAQO,MAAM,EAAE;QAACc;QAAerB;KAAQ;IAEpH,qBACE,MAACsB;QAAI,GAAGF,IAAI;QAAED,KAAKA;QAAKI,MAAK;;0BAC3B,MAACC;gBAAGC,OAAO;oBAAEC,SAAS;oBAAQC,YAAY;gBAAS;;kCACjD,KAACrC;wBACCsC,eAAezB;wBACf0B,SAASzB;wBACT,mFAAmF;wBACnFE,UAAU,IACRP,yBACEC,SACAC,iBACAC,iBACAC,iBACAC,eACAC,eACAC;;kCAIN,MAACwB;;0CACC,KAACC;0CAAQV;;4BAAuB;;;;;0BAGpC,KAAC9B;YACAwB;;;AAGP,GAAG"}
1
+ {"version":3,"sources":["../../../src/components/Variables/ListVariableListBox.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 React, { ForwardedRef, HTMLAttributes, ReactNode, forwardRef, useContext, useMemo } from 'react';\nimport { Checkbox, Divider } from '@mui/material';\nimport { VariableOption } from '@perses-dev/plugin-system';\nimport { DEFAULT_ALL_VALUE } from '@perses-dev/spec';\n\nexport interface ListVariableListBoxContextValue {\n options: VariableOption[];\n selectedOptions: VariableOption[];\n filteredOptions: VariableOption[];\n allowAllValue: boolean;\n onChange: (selectedOptions: VariableOption[]) => void;\n}\n\nconst ListVariableListBoxContext = React.createContext<ListVariableListBoxContextValue | undefined>(undefined);\n\nexport function useListVariableListBoxContext(): ListVariableListBoxContextValue {\n const ctx = useContext(ListVariableListBoxContext);\n if (!ctx) throw new Error('ListVariableListBoxContext not found');\n return ctx;\n}\n\n/*\n * Handles the logic for toggling the global select checkbox in the ListBox header.\n *\n * If all options are selected, it will deselect all options.\n * Except if filteredOptions is a subset of options, then it will only deselect the filtered options.\n *\n * If some options are selected, it will select all filtered options.\n *\n * If no options are selected, it will select all filtered options.\n * Should be not possible since a ListVariable has always at least one value.\n *\n * If allowAllValue is true, it will handle the special \"All\" option logic.\n * Main difference is if some options are selected and there is no filter, it will select the \"All\" option\n */\nfunction handleGlobalSelectToggle(\n options: VariableOption[],\n selectedOptions: VariableOption[],\n filteredOptions: VariableOption[],\n isIndeterminate: boolean,\n isAllSelected: boolean,\n allowAllValue: boolean,\n onChange: (selectedOptions: VariableOption[]) => void\n): void {\n if (isAllSelected) {\n if (filteredOptions.length !== options.length) {\n onChange(selectedOptions.filter((o) => !filteredOptions.includes(o)));\n } else {\n onChange([]);\n }\n return;\n }\n\n if (isIndeterminate) {\n if (allowAllValue) {\n if (filteredOptions.length === options.length) {\n if (selectedOptions[0]?.value === DEFAULT_ALL_VALUE) {\n onChange(options.filter((o) => o.value !== DEFAULT_ALL_VALUE));\n } else {\n onChange([{ label: DEFAULT_ALL_VALUE, value: DEFAULT_ALL_VALUE }]);\n }\n } else {\n if (filteredOptions.every((o) => selectedOptions.includes(o))) {\n onChange(selectedOptions.filter((o) => !filteredOptions.includes(o)));\n } else {\n onChange([...selectedOptions, ...filteredOptions.filter((o) => o.value !== DEFAULT_ALL_VALUE)]);\n }\n }\n } else {\n if (filteredOptions.length === options.length) {\n onChange(options);\n } else {\n if (filteredOptions.every((o) => selectedOptions.includes(o))) {\n onChange(selectedOptions.filter((o) => !filteredOptions.includes(o)));\n } else {\n onChange([...selectedOptions, ...filteredOptions]);\n }\n }\n }\n return;\n }\n\n // Nothing selected, so select filtered options\n onChange(filteredOptions);\n}\n\nexport function ListVariableListBoxProvider({\n value,\n children,\n}: {\n value: ListVariableListBoxContextValue;\n children: ReactNode;\n}): React.ReactElement {\n return <ListVariableListBoxContext.Provider value={value}>{children}</ListVariableListBoxContext.Provider>;\n}\n\nexport const ListVariableListBox = forwardRef(function ListVariableListBox(\n props: HTMLAttributes<HTMLUListElement>,\n ref: ForwardedRef<HTMLUListElement>\n) {\n const { children, ...rest } = props;\n const { options, selectedOptions, filteredOptions, allowAllValue, onChange } = useListVariableListBoxContext();\n\n // Derived selection metadata for context listbox header\n const selectedCount = useMemo(() => selectedOptions.length, [selectedOptions]);\n const isIndeterminate = useMemo(\n () => options.length > 0 && selectedCount > 0 && selectedCount !== options.length,\n [selectedCount, options]\n );\n const isAllSelected = useMemo(() => options.length > 0 && selectedCount === options.length, [selectedCount, options]);\n\n return (\n <ul {...rest} ref={ref} role=\"listbox\">\n <li style={{ display: 'flex', alignItems: 'center' }}>\n <Checkbox\n indeterminate={isIndeterminate}\n checked={isAllSelected}\n // intentionally not passing event to underlying handler to mimic previous behavior\n onChange={() =>\n handleGlobalSelectToggle(\n options,\n selectedOptions,\n filteredOptions,\n isIndeterminate,\n isAllSelected,\n allowAllValue,\n onChange\n )\n }\n />\n <span>\n <strong>{selectedCount}</strong> Selected\n </span>\n </li>\n <Divider />\n {children}\n </ul>\n );\n});\n"],"names":["React","forwardRef","useContext","useMemo","Checkbox","Divider","DEFAULT_ALL_VALUE","ListVariableListBoxContext","createContext","undefined","useListVariableListBoxContext","ctx","Error","handleGlobalSelectToggle","options","selectedOptions","filteredOptions","isIndeterminate","isAllSelected","allowAllValue","onChange","length","filter","o","includes","value","label","every","ListVariableListBoxProvider","children","Provider","ListVariableListBox","props","ref","rest","selectedCount","ul","role","li","style","display","alignItems","indeterminate","checked","span","strong"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EA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AS;;kCACjD,KAACrC;wBACCsC,eAAezB;wBACf0B,SAASzB;wBACT,mFAAmF;wBACnFE,UAAU,IACRP,yBACEC,SACAC,iBACAC,iBACAC,iBACAC,eACAC,eACAC;;kCAIN,MAACwB;;0CACC,KAACC;0CAAQV;;4BAAuB;;;;;0BAGpC,KAAC9B;YACAwB;;;AAGP,GAAG"}
@@ -1,3 +1,5 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { createElement as _createElement } from "react";
1
3
  // Copyright The Perses Authors
2
4
  // Licensed under the Apache License, Version 2.0 (the "License");
3
5
  // you may not use this file except in compliance with the License.
@@ -10,8 +12,6 @@
10
12
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
13
  // See the License for the specific language governing permissions and
12
14
  // limitations under the License.
13
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
- import { createElement as _createElement } from "react";
15
15
  import { useCallback, useEffect, useMemo, useState } from 'react';
16
16
  import { TextField, Popper, Checkbox, Autocomplete, createFilterOptions, Chip, Box } from '@mui/material';
17
17
  import { DEFAULT_ALL_VALUE } from '@perses-dev/spec';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Variables/Variable.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, useCallback, useEffect, useMemo, useState } from 'react';\nimport { TextField, Popper, PopperProps, Checkbox, Autocomplete, createFilterOptions, Chip, Box } from '@mui/material';\nimport {\n DEFAULT_ALL_VALUE,\n ListVariableDefinition,\n ListVariableSpec,\n TextVariableDefinition,\n VariableName,\n VariableValue,\n} from '@perses-dev/spec';\nimport {\n SORT_METHODS,\n SortMethodName,\n useListVariablePluginValues,\n VariableOption,\n VariableState,\n} from '@perses-dev/plugin-system';\nimport { UseQueryResult } from '@tanstack/react-query';\nimport { useVariableDefinitionAndState, useVariableDefinitionActions } from '../../context';\nimport { MAX_VARIABLE_WIDTH, MIN_VARIABLE_WIDTH } from '../../constants';\nimport { ListVariableListBoxProvider, ListVariableListBox } from './ListVariableListBox';\n\ntype VariableProps = {\n name: VariableName;\n source?: string;\n};\n\nfunction variableOptionToVariableValue(options: VariableOption | VariableOption[] | null): VariableValue {\n if (options === null) {\n return null;\n }\n if (Array.isArray(options)) {\n return options.map((v) => {\n return v.value;\n });\n }\n return options.value;\n}\n\nexport function Variable({ name, source }: VariableProps): ReactElement {\n const ctx = useVariableDefinitionAndState(name, source);\n const kind = ctx.definition?.kind;\n switch (kind) {\n case 'TextVariable':\n return <TextVariable name={name} source={source} />;\n case 'ListVariable':\n return <ListVariable name={name} source={source} />;\n }\n\n return <div>Unsupported Variable Kind: ${kind}</div>;\n}\n\nexport function useListVariableState(\n spec: ListVariableSpec | undefined,\n state: VariableState | undefined,\n variablesOptionsQuery: Partial<UseQueryResult<VariableOption[]>>\n): {\n // Value, Loading, Options are modified only when we want to save the changes made\n value: VariableValue | undefined;\n loading: boolean;\n options: VariableOption[] | undefined;\n // selectedOptions is/are the option(s) selected in the view\n selectedOptions: VariableOption | VariableOption[];\n // viewOptions are the options used in the view only (= options + All if allowed)\n viewOptions: VariableOption[];\n} {\n const allowMultiple = spec?.allowMultiple === true;\n const allowAllValue = spec?.allowAllValue === true;\n const sort = spec?.sort;\n const loading = useMemo(() => variablesOptionsQuery.isFetching ?? false, [variablesOptionsQuery.isFetching]);\n const options = useMemo(() => variablesOptionsQuery.data ?? [], [variablesOptionsQuery.data]);\n\n let value = state?.value;\n\n // Make sure value is an array if allowMultiple is true\n if (allowMultiple && !Array.isArray(value)) {\n value = typeof value === 'string' ? [value] : [];\n }\n\n // Sort the provided list of options according to the method defined\n const sortedOptions = useMemo((): VariableOption[] => {\n const opts = options ? [...options] : [];\n\n if (!sort || sort === 'none') return opts;\n const sortMethod = SORT_METHODS[sort as SortMethodName];\n return !sortMethod ? opts : sortMethod.sort(opts);\n }, [options, sort]);\n\n const viewOptions = useMemo(() => {\n let computedOptions = sortedOptions;\n\n // Add the all value if it's allowed\n if (allowAllValue) {\n computedOptions = [{ value: DEFAULT_ALL_VALUE, label: 'All' }, ...computedOptions];\n }\n return computedOptions;\n }, [allowAllValue, sortedOptions]);\n\n const valueIsInOptions = useMemo(\n () =>\n Boolean(\n viewOptions.find((v) => {\n if (allowMultiple) {\n return (value as string[]).includes(v.value);\n }\n return value === v.value;\n })\n ),\n [viewOptions, value, allowMultiple]\n );\n\n value = useMemo(() => {\n const firstOptionValue = viewOptions?.[allowAllValue ? 1 : 0]?.value;\n\n // If there is no value but there are options, or the value is not in options, we set the value to the first option.\n if (firstOptionValue) {\n if (!valueIsInOptions || !value || value.length === 0) {\n return allowMultiple ? [firstOptionValue] : firstOptionValue;\n }\n }\n\n return value;\n }, [viewOptions, value, valueIsInOptions, allowMultiple, allowAllValue]);\n\n const selectedOptions = useMemo(() => {\n // In the case Autocomplete.multiple equals false, Autocomplete.value expects a single object, not\n // an array, hence this conditional\n if (Array.isArray(value)) {\n return viewOptions.filter((o) => {\n return value?.includes(o.value);\n });\n } else {\n return (\n viewOptions.find((o) => {\n return value === o.value;\n }) ?? { value: '', label: '' }\n );\n }\n }, [value, viewOptions]);\n\n return { value, loading, options, selectedOptions, viewOptions };\n}\n\nconst StyledPopper = (props: PopperProps): ReactElement => (\n <Popper {...props} sx={{ minWidth: 'fit-content' }} placement=\"bottom-start\" />\n);\n\nconst LETTER_HSIZE = 8; // approximation\nconst ARROW_OFFSET = 40; // right offset for list variables (= take into account the dropdown toggle size)\nconst getWidthPx = (inputValue: string, kind: 'list' | 'text'): number => {\n const width = (inputValue.length + 1) * LETTER_HSIZE + (kind === 'list' ? ARROW_OFFSET : 0);\n if (width < MIN_VARIABLE_WIDTH) {\n return MIN_VARIABLE_WIDTH;\n } else if (width > MAX_VARIABLE_WIDTH) {\n return MAX_VARIABLE_WIDTH;\n } else {\n return width;\n }\n};\n\nfunction ListVariable({ name, source }: VariableProps): ReactElement {\n const ctx = useVariableDefinitionAndState(name, source);\n const definition = ctx.definition as ListVariableDefinition;\n const variablesOptionsQuery = useListVariablePluginValues(definition);\n const { setVariableValue, setVariableLoading, setVariableOptions } = useVariableDefinitionActions();\n const { selectedOptions, value, loading, options, viewOptions } = useListVariableState(\n definition?.spec,\n ctx.state,\n variablesOptionsQuery\n );\n const [inputWidth, setInputWidth] = useState(MIN_VARIABLE_WIDTH);\n // Used for multiple value variables, it will not clear variable input when selecting an option\n const [inputValue, setInputValue] = useState('');\n\n const title = definition?.spec.display?.name ?? name;\n const allowMultiple = definition?.spec.allowMultiple === true;\n const allowAllValue = definition?.spec.allowAllValue === true;\n\n const filterOptions = createFilterOptions<VariableOption>({});\n\n const filteredOptions = useMemo(\n () => filterOptions(viewOptions, { inputValue, getOptionLabel: (o) => o.label }),\n [inputValue, viewOptions, filterOptions]\n );\n\n // Update value when changed\n useEffect(() => {\n if (value) {\n setVariableValue(name, value, source);\n }\n }, [setVariableValue, name, value, source]);\n\n // Update loading when changed\n useEffect(() => {\n setVariableLoading(name, loading, source);\n }, [setVariableLoading, name, loading, source]);\n\n // Update options when changed\n useEffect(() => {\n if (options) {\n setVariableOptions(name, options, source);\n }\n }, [setVariableOptions, name, options, source]);\n\n const handleGlobalSelect = useCallback(\n (options: VariableOption[]): void => {\n setVariableValue(name, variableOptionToVariableValue(options), source);\n },\n [name, setVariableValue, source]\n );\n\n const listBoxProviderValue = useMemo(\n () => ({\n options: viewOptions,\n selectedOptions: selectedOptions as VariableOption[], // Only used when allowMultiple is true => selectedOptions is always an array\n filteredOptions: filteredOptions,\n allowAllValue,\n onChange: handleGlobalSelect,\n }),\n [allowAllValue, filteredOptions, handleGlobalSelect, selectedOptions, viewOptions]\n );\n\n const autocompleteComponent = useMemo(() => {\n return (\n <Autocomplete\n disablePortal\n loading={loading}\n disableCloseOnSelect={allowMultiple}\n multiple={allowMultiple}\n fullWidth\n limitTags={3}\n size=\"small\"\n disableClearable\n slotProps={{ listbox: { component: allowMultiple ? ListVariableListBox : undefined } }}\n slots={{ popper: StyledPopper }}\n sx={{\n '& .MuiInputBase-root': {\n minHeight: '38px',\n },\n '& .MuiAutocomplete-tag': {\n margin: '1px 2px', // Default margin of 2px (Y axis) make min height of the autocomplete 40px\n },\n }}\n filterOptions={filterOptions}\n options={viewOptions}\n value={selectedOptions}\n onChange={(_, value) => {\n if ((value === null || (Array.isArray(value) && value.length === 0)) && allowAllValue) {\n setVariableValue(name, DEFAULT_ALL_VALUE, source);\n } else {\n setVariableValue(name, variableOptionToVariableValue(value as VariableOption), source);\n }\n }}\n inputValue={allowMultiple ? inputValue : undefined}\n onInputChange={(_, newInputValue) => {\n if (!allowMultiple) {\n setInputWidth(getWidthPx(newInputValue, 'list'));\n }\n }}\n onBlur={() => {\n if (allowMultiple) {\n setInputValue('');\n }\n }}\n renderInput={(params) => {\n return allowMultiple ? (\n <TextField {...params} label={title} onChange={(e) => setInputValue(e.target.value)} />\n ) : (\n <TextField {...params} label={title} style={{ width: `${inputWidth}px` }} />\n );\n }}\n renderOption={(props, option, { selected }) => {\n const { key, ...optionProps } = props;\n return (\n <li key={key} {...optionProps} style={{ padding: 0 }}>\n <Checkbox style={{ marginRight: 8 }} checked={selected} />\n {option.label}\n </li>\n );\n }}\n renderTags={(value, getTagProps, ownerState) => {\n // When focused, if there are too much value selected, it will use all screen place. Putting limit to 200px (~6 lines of chips)\n if (ownerState.focused) {\n return (\n <Box sx={{ maxHeight: 200, overflowY: 'auto' }}>\n {value.map((option, index) => (\n <Chip {...getTagProps({ index })} key={index} label={option.label} size=\"small\" />\n ))}\n </Box>\n );\n }\n\n const limitTags: number | undefined = ownerState.limitTags;\n const numTags: number = value.length;\n\n return (\n <>\n {value.slice(0, limitTags).map((option, index) => (\n <Chip {...getTagProps({ index })} key={index} label={option.label} size=\"small\" />\n ))}\n\n {limitTags && numTags > limitTags && ` +${numTags - limitTags}`}\n </>\n );\n }}\n />\n );\n }, [\n allowAllValue,\n allowMultiple,\n filterOptions,\n inputValue,\n inputWidth,\n loading,\n name,\n selectedOptions,\n setVariableValue,\n source,\n title,\n viewOptions,\n ]);\n\n if (allowMultiple) {\n return (\n <ListVariableListBoxProvider value={listBoxProviderValue}>{autocompleteComponent}</ListVariableListBoxProvider>\n );\n }\n\n return autocompleteComponent;\n}\n\nfunction TextVariable({ name, source }: VariableProps): ReactElement {\n const ctx = useVariableDefinitionAndState(name, source);\n const state = ctx.state;\n const definition = ctx.definition as TextVariableDefinition;\n const [tempValue, setTempValue] = useState(state?.value ?? '');\n const [inputWidth, setInputWidth] = useState(getWidthPx(tempValue as string, 'text'));\n const { setVariableValue } = useVariableDefinitionActions();\n\n useEffect(() => {\n setTempValue(state?.value ?? '');\n }, [state?.value]);\n\n return (\n <TextField\n title={tempValue as string}\n value={tempValue}\n onChange={(e) => {\n setTempValue(e.target.value);\n setInputWidth(getWidthPx(e.target.value, 'text'));\n }}\n onBlur={() => setVariableValue(name, tempValue, source)}\n placeholder={name}\n label={definition?.spec.display?.name ?? name}\n slotProps={{\n input: {\n readOnly: definition?.spec.constant ?? false,\n },\n }}\n sx={{\n width: `${inputWidth}px`,\n '& .MuiInputBase-root': {\n minHeight: '38px',\n },\n '& .MuiInputBase-input': {\n textOverflow: 'ellipsis',\n },\n }}\n />\n );\n}\n"],"names":["useCallback","useEffect","useMemo","useState","TextField","Popper","Checkbox","Autocomplete","createFilterOptions","Chip","Box","DEFAULT_ALL_VALUE","SORT_METHODS","useListVariablePluginValues","useVariableDefinitionAndState","useVariableDefinitionActions","MAX_VARIABLE_WIDTH","MIN_VARIABLE_WIDTH","ListVariableListBoxProvider","ListVariableListBox","variableOptionToVariableValue","options","Array","isArray","map","v","value","Variable","name","source","ctx","kind","definition","TextVariable","ListVariable","div","useListVariableState","spec","state","variablesOptionsQuery","allowMultiple","allowAllValue","sort","loading","isFetching","data","sortedOptions","opts","sortMethod","viewOptions","computedOptions","label","valueIsInOptions","Boolean","find","includes","firstOptionValue","length","selectedOptions","filter","o","StyledPopper","props","sx","minWidth","placement","LETTER_HSIZE","ARROW_OFFSET","getWidthPx","inputValue","width","setVariableValue","setVariableLoading","setVariableOptions","inputWidth","setInputWidth","setInputValue","title","display","filterOptions","filteredOptions","getOptionLabel","handleGlobalSelect","listBoxProviderValue","onChange","autocompleteComponent","disablePortal","disableCloseOnSelect","multiple","fullWidth","limitTags","size","disableClearable","slotProps","listbox","component","undefined","slots","popper","minHeight","margin","_","onInputChange","newInputValue","onBlur","renderInput","params","e","target","style","renderOption","option","selected","key","optionProps","li","padding","marginRight","checked","renderTags","getTagProps","ownerState","focused","maxHeight","overflowY","index","numTags","slice","tempValue","setTempValue","placeholder","input","readOnly","constant","textOverflow"],"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,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAChF,SAASC,SAAS,EAAEC,MAAM,EAAeC,QAAQ,EAAEC,YAAY,EAAEC,mBAAmB,EAAEC,IAAI,EAAEC,GAAG,QAAQ,gBAAgB;AACvH,SACEC,iBAAiB,QAMZ,mBAAmB;AAC1B,SACEC,YAAY,EAEZC,2BAA2B,QAGtB,4BAA4B;AAEnC,SAASC,6BAA6B,EAAEC,4BAA4B,QAAQ,gBAAgB;AAC5F,SAASC,kBAAkB,EAAEC,kBAAkB,QAAQ,kBAAkB;AACzE,SAASC,2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TsB,aAAatB,EAAEC,MAAM,CAAClF,KAAK;YAC3BiD,cAAcP,WAAWuC,EAAEC,MAAM,CAAClF,KAAK,EAAE;QAC3C;QACA8E,QAAQ,IAAMjC,iBAAiB3C,MAAMoG,WAAWnG;QAChDqG,aAAatG;QACbuB,OAAOnB,YAAYK,KAAKyC,SAASlD,QAAQA;QACzCiE,WAAW;YACTsC,OAAO;gBACLC,UAAUpG,YAAYK,KAAKgG,YAAY;YACzC;QACF;QACAtE,IAAI;YACFO,OAAO,GAAGI,WAAW,EAAE,CAAC;YACxB,wBAAwB;gBACtByB,WAAW;YACb;YACA,yBAAyB;gBACvBmC,cAAc;YAChB;QACF;;AAGN"}
1
+ {"version":3,"sources":["../../../src/components/Variables/Variable.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, useCallback, useEffect, useMemo, useState } from 'react';\nimport { TextField, Popper, PopperProps, Checkbox, Autocomplete, createFilterOptions, Chip, Box } from '@mui/material';\nimport {\n DEFAULT_ALL_VALUE,\n ListVariableDefinition,\n ListVariableSpec,\n TextVariableDefinition,\n VariableName,\n VariableValue,\n} from '@perses-dev/spec';\nimport {\n SORT_METHODS,\n SortMethodName,\n useListVariablePluginValues,\n VariableOption,\n VariableState,\n} from '@perses-dev/plugin-system';\nimport { UseQueryResult } from '@tanstack/react-query';\nimport { useVariableDefinitionAndState, useVariableDefinitionActions } from '../../context';\nimport { MAX_VARIABLE_WIDTH, MIN_VARIABLE_WIDTH } from '../../constants';\nimport { ListVariableListBoxProvider, ListVariableListBox } from './ListVariableListBox';\n\ntype VariableProps = {\n name: VariableName;\n source?: string;\n};\n\nfunction variableOptionToVariableValue(options: VariableOption | VariableOption[] | null): VariableValue {\n if (options === null) {\n return null;\n }\n if (Array.isArray(options)) {\n return options.map((v) => {\n return v.value;\n });\n }\n return options.value;\n}\n\nexport function Variable({ name, source }: VariableProps): ReactElement {\n const ctx = useVariableDefinitionAndState(name, source);\n const kind = ctx.definition?.kind;\n switch (kind) {\n case 'TextVariable':\n return <TextVariable name={name} source={source} />;\n case 'ListVariable':\n return <ListVariable name={name} source={source} />;\n }\n\n return <div>Unsupported Variable Kind: ${kind}</div>;\n}\n\nexport function useListVariableState(\n spec: ListVariableSpec | undefined,\n state: VariableState | undefined,\n variablesOptionsQuery: Partial<UseQueryResult<VariableOption[]>>\n): {\n // Value, Loading, Options are modified only when we want to save the changes made\n value: VariableValue | undefined;\n loading: boolean;\n options: VariableOption[] | undefined;\n // selectedOptions is/are the option(s) selected in the view\n selectedOptions: VariableOption | VariableOption[];\n // viewOptions are the options used in the view only (= options + All if allowed)\n viewOptions: VariableOption[];\n} {\n const allowMultiple = spec?.allowMultiple === true;\n const allowAllValue = spec?.allowAllValue === true;\n const sort = spec?.sort;\n const loading = useMemo(() => variablesOptionsQuery.isFetching ?? false, [variablesOptionsQuery.isFetching]);\n const options = useMemo(() => variablesOptionsQuery.data ?? [], [variablesOptionsQuery.data]);\n\n let value = state?.value;\n\n // Make sure value is an array if allowMultiple is true\n if (allowMultiple && !Array.isArray(value)) {\n value = typeof value === 'string' ? [value] : [];\n }\n\n // Sort the provided list of options according to the method defined\n const sortedOptions = useMemo((): VariableOption[] => {\n const opts = options ? [...options] : [];\n\n if (!sort || sort === 'none') return opts;\n const sortMethod = SORT_METHODS[sort as SortMethodName];\n return !sortMethod ? opts : sortMethod.sort(opts);\n }, [options, sort]);\n\n const viewOptions = useMemo(() => {\n let computedOptions = sortedOptions;\n\n // Add the all value if it's allowed\n if (allowAllValue) {\n computedOptions = [{ value: DEFAULT_ALL_VALUE, label: 'All' }, ...computedOptions];\n }\n return computedOptions;\n }, [allowAllValue, sortedOptions]);\n\n const valueIsInOptions = useMemo(\n () =>\n Boolean(\n viewOptions.find((v) => {\n if (allowMultiple) {\n return (value as string[]).includes(v.value);\n }\n return value === v.value;\n })\n ),\n [viewOptions, value, allowMultiple]\n );\n\n value = useMemo(() => {\n const firstOptionValue = viewOptions?.[allowAllValue ? 1 : 0]?.value;\n\n // If there is no value but there are options, or the value is not in options, we set the value to the first option.\n if (firstOptionValue) {\n if (!valueIsInOptions || !value || value.length === 0) {\n return allowMultiple ? [firstOptionValue] : firstOptionValue;\n }\n }\n\n return value;\n }, [viewOptions, value, valueIsInOptions, allowMultiple, allowAllValue]);\n\n const selectedOptions = useMemo(() => {\n // In the case Autocomplete.multiple equals false, Autocomplete.value expects a single object, not\n // an array, hence this conditional\n if (Array.isArray(value)) {\n return viewOptions.filter((o) => {\n return value?.includes(o.value);\n });\n } else {\n return (\n viewOptions.find((o) => {\n return value === o.value;\n }) ?? { value: '', label: '' }\n );\n }\n }, [value, viewOptions]);\n\n return { value, loading, options, selectedOptions, viewOptions };\n}\n\nconst StyledPopper = (props: PopperProps): ReactElement => (\n <Popper {...props} sx={{ minWidth: 'fit-content' }} placement=\"bottom-start\" />\n);\n\nconst LETTER_HSIZE = 8; // approximation\nconst ARROW_OFFSET = 40; // right offset for list variables (= take into account the dropdown toggle size)\nconst getWidthPx = (inputValue: string, kind: 'list' | 'text'): number => {\n const width = (inputValue.length + 1) * LETTER_HSIZE + (kind === 'list' ? ARROW_OFFSET : 0);\n if (width < MIN_VARIABLE_WIDTH) {\n return MIN_VARIABLE_WIDTH;\n } else if (width > MAX_VARIABLE_WIDTH) {\n return MAX_VARIABLE_WIDTH;\n } else {\n return width;\n }\n};\n\nfunction ListVariable({ name, source }: VariableProps): ReactElement {\n const ctx = useVariableDefinitionAndState(name, source);\n const definition = ctx.definition as ListVariableDefinition;\n const variablesOptionsQuery = useListVariablePluginValues(definition);\n const { setVariableValue, setVariableLoading, setVariableOptions } = useVariableDefinitionActions();\n const { selectedOptions, value, loading, options, viewOptions } = useListVariableState(\n definition?.spec,\n ctx.state,\n variablesOptionsQuery\n );\n const [inputWidth, setInputWidth] = useState(MIN_VARIABLE_WIDTH);\n // Used for multiple value variables, it will not clear variable input when selecting an option\n const [inputValue, setInputValue] = useState('');\n\n const title = definition?.spec.display?.name ?? name;\n const allowMultiple = definition?.spec.allowMultiple === true;\n const allowAllValue = definition?.spec.allowAllValue === true;\n\n const filterOptions = createFilterOptions<VariableOption>({});\n\n const filteredOptions = useMemo(\n () => filterOptions(viewOptions, { inputValue, getOptionLabel: (o) => o.label }),\n [inputValue, viewOptions, filterOptions]\n );\n\n // Update value when changed\n useEffect(() => {\n if (value) {\n setVariableValue(name, value, source);\n }\n }, [setVariableValue, name, value, source]);\n\n // Update loading when changed\n useEffect(() => {\n setVariableLoading(name, loading, source);\n }, [setVariableLoading, name, loading, source]);\n\n // Update options when changed\n useEffect(() => {\n if (options) {\n setVariableOptions(name, options, source);\n }\n }, [setVariableOptions, name, options, source]);\n\n const handleGlobalSelect = useCallback(\n (options: VariableOption[]): void => {\n setVariableValue(name, variableOptionToVariableValue(options), source);\n },\n [name, setVariableValue, source]\n );\n\n const listBoxProviderValue = useMemo(\n () => ({\n options: viewOptions,\n selectedOptions: selectedOptions as VariableOption[], // Only used when allowMultiple is true => selectedOptions is always an array\n filteredOptions: filteredOptions,\n allowAllValue,\n onChange: handleGlobalSelect,\n }),\n [allowAllValue, filteredOptions, handleGlobalSelect, selectedOptions, viewOptions]\n );\n\n const autocompleteComponent = useMemo(() => {\n return (\n <Autocomplete\n disablePortal\n loading={loading}\n disableCloseOnSelect={allowMultiple}\n multiple={allowMultiple}\n fullWidth\n limitTags={3}\n size=\"small\"\n disableClearable\n slotProps={{ listbox: { component: allowMultiple ? ListVariableListBox : undefined } }}\n slots={{ popper: StyledPopper }}\n sx={{\n '& .MuiInputBase-root': {\n minHeight: '38px',\n },\n '& .MuiAutocomplete-tag': {\n margin: '1px 2px', // Default margin of 2px (Y axis) make min height of the autocomplete 40px\n },\n }}\n filterOptions={filterOptions}\n options={viewOptions}\n value={selectedOptions}\n onChange={(_, value) => {\n if ((value === null || (Array.isArray(value) && value.length === 0)) && allowAllValue) {\n setVariableValue(name, DEFAULT_ALL_VALUE, source);\n } else {\n setVariableValue(name, variableOptionToVariableValue(value as VariableOption), source);\n }\n }}\n inputValue={allowMultiple ? inputValue : undefined}\n onInputChange={(_, newInputValue) => {\n if (!allowMultiple) {\n setInputWidth(getWidthPx(newInputValue, 'list'));\n }\n }}\n onBlur={() => {\n if (allowMultiple) {\n setInputValue('');\n }\n }}\n renderInput={(params) => {\n return allowMultiple ? (\n <TextField {...params} label={title} onChange={(e) => setInputValue(e.target.value)} />\n ) : (\n <TextField {...params} label={title} style={{ width: `${inputWidth}px` }} />\n );\n }}\n renderOption={(props, option, { selected }) => {\n const { key, ...optionProps } = props;\n return (\n <li key={key} {...optionProps} style={{ padding: 0 }}>\n <Checkbox style={{ marginRight: 8 }} checked={selected} />\n {option.label}\n </li>\n );\n }}\n renderTags={(value, getTagProps, ownerState) => {\n // When focused, if there are too much value selected, it will use all screen place. Putting limit to 200px (~6 lines of chips)\n if (ownerState.focused) {\n return (\n <Box sx={{ maxHeight: 200, overflowY: 'auto' }}>\n {value.map((option, index) => (\n <Chip {...getTagProps({ index })} key={index} label={option.label} size=\"small\" />\n ))}\n </Box>\n );\n }\n\n const limitTags: number | undefined = ownerState.limitTags;\n const numTags: number = value.length;\n\n return (\n <>\n {value.slice(0, limitTags).map((option, index) => (\n <Chip {...getTagProps({ index })} key={index} label={option.label} size=\"small\" />\n ))}\n\n {limitTags && numTags > limitTags && ` +${numTags - limitTags}`}\n </>\n );\n }}\n />\n );\n }, [\n allowAllValue,\n allowMultiple,\n filterOptions,\n inputValue,\n inputWidth,\n loading,\n name,\n selectedOptions,\n setVariableValue,\n source,\n title,\n viewOptions,\n ]);\n\n if (allowMultiple) {\n return (\n <ListVariableListBoxProvider value={listBoxProviderValue}>{autocompleteComponent}</ListVariableListBoxProvider>\n );\n }\n\n return autocompleteComponent;\n}\n\nfunction TextVariable({ name, source }: VariableProps): ReactElement {\n const ctx = useVariableDefinitionAndState(name, source);\n const state = ctx.state;\n const definition = ctx.definition as TextVariableDefinition;\n const [tempValue, setTempValue] = useState(state?.value ?? '');\n const [inputWidth, setInputWidth] = useState(getWidthPx(tempValue as string, 'text'));\n const { setVariableValue } = useVariableDefinitionActions();\n\n useEffect(() => {\n setTempValue(state?.value ?? '');\n }, [state?.value]);\n\n return (\n <TextField\n title={tempValue as string}\n value={tempValue}\n onChange={(e) => {\n setTempValue(e.target.value);\n setInputWidth(getWidthPx(e.target.value, 'text'));\n }}\n onBlur={() => setVariableValue(name, tempValue, source)}\n placeholder={name}\n label={definition?.spec.display?.name ?? name}\n slotProps={{\n input: {\n readOnly: definition?.spec.constant ?? false,\n },\n }}\n sx={{\n width: `${inputWidth}px`,\n '& .MuiInputBase-root': {\n minHeight: '38px',\n },\n '& .MuiInputBase-input': {\n textOverflow: 'ellipsis',\n },\n }}\n />\n );\n}\n"],"names":["useCallback","useEffect","useMemo","useState","TextField","Popper","Checkbox","Autocomplete","createFilterOptions","Chip","Box","DEFAULT_ALL_VALUE","SORT_METHODS","useListVariablePluginValues","useVariableDefinitionAndState","useVariableDefinitionActions","MAX_VARIABLE_WIDTH","MIN_VARIABLE_WIDTH","ListVariableListBoxProvider","ListVariableListBox","variableOptionToVariableValue","options","Array","isArray","map","v","value","Variable","name","source","ctx","kind","definition","TextVariable","ListVariable","div","useListVariableState","spec","state","variablesOptionsQuery","allowMultiple","allowAllValue","sort","loading","isFetching","data","sortedOptions","opts","sortMethod","viewOptions","computedOptions","label","valueIsInOptions","Boolean","find","includes","firstOptionValue","length","selectedOptions","filter","o","StyledPopper","props","sx","minWidth","placement","LETTER_HSIZE","ARROW_OFFSET","getWidthPx","inputValue","width","setVariableValue","setVariableLoading","setVariableOptions","inputWidth","setInputWidth","setInputValue","title","display","filterOptions","filteredOptions","getOptionLabel","handleGlobalSelect","listBoxProviderValue","onChange","autocompleteComponent","disablePortal","disableCloseOnSelect","multiple","fullWidth","limitTags","size","disableClearable","slotProps","listbox","component","undefined","slots","popper","minHeight","margin","_","onInputChange","newInputValue","onBlur","renderInput","params","e","target","style","renderOption","option","selected","key","optionProps","li","padding","marginRight","checked","renderTags","getTagProps","ownerState","focused","maxHeight","overflowY","index","numTags","slice","tempValue","setTempValue","placeholder","input","readOnly","constant","textOverflow"],"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,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAChF,SAASC,SAAS,EAAEC,MAAM,EAAeC,QAAQ,EAAEC,YAAY,EAAEC,mBAAmB,EAAEC,IAAI,EAAEC,GAAG,QAAQ,gBAAgB;AACvH,SACEC,iBAAiB,QAMZ,mBAAmB;AAC1B,SACEC,YAAY,EAEZC,2BAA2B,QAGtB,4BAA4B;AAEnC,SAASC,6BAA6B,EAAEC,4BAA4B,QAAQ,gBAAgB;AAC5F,SAASC,kBAAkB,EAAEC,kBAAkB,QAAQ,kBAAkB;AACzE,SAASC,2BAA2B,EAAEC,mBAAmB,QAAQ,wBAAwB;AAOzF,SAASC,8BAA8BC,OAAiD;IACtF,IAAIA,YAAY,MAAM;QACpB,OAAO;IACT;IACA,IAAIC,MAAMC,OAAO,CAACF,UAAU;QAC1B,OAAOA,QAAQG,GAAG,CAAC,CAACC;YAClB,OAAOA,EAAEC,KAAK;QAChB;IACF;IACA,OAAOL,QAAQK,KAAK;AACtB;AAEA,OAAO,SAASC,SAAS,EAAEC,IAAI,EAAEC,MAAM,EAAiB;IACtD,MAAMC,MAAMhB,8BAA8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YACxB,wBAAwB;gBACtByB,WAAW;YACb;YACA,yBAAyB;gBACvBmC,cAAc;YAChB;QACF;;AAGN"}
@@ -1 +1 @@
1
- {"version":3,"file":"VariableEditor.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/VariableEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAqB,YAAY,EAAE,MAAM,OAAO,CAAC;AAuBxD,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAWjF,OAAO,EAA0C,aAAa,EAAkB,MAAM,2BAA2B,CAAC;AAElH,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAwB5E,wBAAgB,cAAc,CAAC,KAAK,EAAE;IACpC,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C,2BAA2B,EAAE,0BAA0B,EAAE,CAAC;IAC1D,0BAA0B,EAAE,yBAAyB,EAAE,CAAC;IACxD,QAAQ,EAAE,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,KAAK,IAAI,CAAC;IAC9D,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,GAAG,YAAY,CAsVf;AAMD,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,aAAa,GAAG,SAAS,CAAA;CAAE,GAAG,YAAY,CAoBpG"}
1
+ {"version":3,"file":"VariableEditor.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/VariableEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAqB,MAAM,OAAO,CAAC;AAwBxD,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAWjF,OAAO,EAIL,aAAa,EAEd,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAwB5E,wBAAgB,cAAc,CAAC,KAAK,EAAE;IACpC,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C,2BAA2B,EAAE,0BAA0B,EAAE,CAAC;IAC1D,0BAA0B,EAAE,yBAAyB,EAAE,CAAC;IACxD,QAAQ,EAAE,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,KAAK,IAAI,CAAC;IAC9D,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,GAAG,YAAY,CAsVf;AAmED,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,aAAa,GAAG,SAAS,CAAA;CAAE,GAAG,YAAY,CAoBpG"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
2
  // Copyright The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,9 +11,8 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
- import { useState, useMemo } from 'react';
15
- import { Button, Stack, Box, TableContainer, TableBody, TableRow, TableCell as MuiTableCell, Table, TableHead, Switch, Typography, IconButton, Alert, styled, capitalize, Tooltip, Accordion, AccordionSummary, AccordionDetails } from '@mui/material';
14
+ import { useMemo, useState } from 'react';
15
+ import { Accordion, AccordionDetails, AccordionSummary, Alert, Box, Button, capitalize, CircularProgress, IconButton, Stack, styled, Switch, Table, TableBody, TableCell as MuiTableCell, TableContainer, TableHead, TableRow, Tooltip, Typography } from '@mui/material';
16
16
  import AddIcon from 'mdi-material-ui/Plus';
17
17
  import { useImmer } from 'use-immer';
18
18
  import PencilIcon from 'mdi-material-ui/Pencil';
@@ -23,9 +23,9 @@ import ArrowDown from 'mdi-material-ui/ArrowDown';
23
23
  import ContentDuplicate from 'mdi-material-ui/ContentDuplicate';
24
24
  import OpenInNewIcon from 'mdi-material-ui/OpenInNew';
25
25
  import ExpandMoreIcon from 'mdi-material-ui/ChevronUp';
26
- import { ValidationProvider, VariableEditorForm, VARIABLE_TYPES } from '@perses-dev/plugin-system';
26
+ import { ValidationProvider, VARIABLE_TYPES, VariableEditorForm, useResolveListVariableValues } from '@perses-dev/plugin-system';
27
27
  import { InfoTooltip } from '@perses-dev/components';
28
- import { useDiscardChangesConfirmationDialog } from '../../context';
28
+ import { useDiscardChangesConfirmationDialog, VariableProvider } from '../../context';
29
29
  import { hydrateVariableDefinitionStates } from '../../context/VariableProvider/hydrationUtils';
30
30
  import { BuiltinVariableAccordions } from './BuiltinVariableAccordions';
31
31
  function getVariableLabelByKind(kind) {
@@ -143,25 +143,25 @@ export function VariableEditor(props) {
143
143
  };
144
144
  return /*#__PURE__*/ _jsxs(_Fragment, {
145
145
  children: [
146
- currentEditingVariableDefinition && /*#__PURE__*/ _jsx(ValidationProvider, {
147
- children: /*#__PURE__*/ _jsx(VariableEditorForm, {
148
- initialVariableDefinition: currentEditingVariableDefinition,
149
- action: variableFormAction,
150
- isDraft: true,
151
- onActionChange: setVariableFormAction,
152
- onSave: (definition)=>{
153
- setVariableDefinitions((draft)=>{
154
- draft[variableEditIdx] = definition;
155
- setVariableEditIdx(null);
156
- });
157
- },
158
- onClose: ()=>{
159
- if (variableFormAction === 'create') {
160
- removeVariable(variableEditIdx);
161
- }
146
+ currentEditingVariableDefinition && /*#__PURE__*/ _jsx(VariableEditorFormWithContext, {
147
+ variableDefinitions: variableDefinitions,
148
+ externalVariableDefinitions: externalVariableDefinitions,
149
+ builtinVariableDefinitions: builtinVariableDefinitions,
150
+ currentEditingVariableDefinition: currentEditingVariableDefinition,
151
+ variableFormAction: variableFormAction,
152
+ onActionChange: setVariableFormAction,
153
+ onSave: (definition)=>{
154
+ setVariableDefinitions((draft)=>{
155
+ draft[variableEditIdx] = definition;
162
156
  setVariableEditIdx(null);
157
+ });
158
+ },
159
+ onClose: ()=>{
160
+ if (variableFormAction === 'create') {
161
+ removeVariable(variableEditIdx);
163
162
  }
164
- })
163
+ setVariableEditIdx(null);
164
+ }
165
165
  }),
166
166
  !currentEditingVariableDefinition && /*#__PURE__*/ _jsxs(_Fragment, {
167
167
  children: [
@@ -512,6 +512,40 @@ export function VariableEditor(props) {
512
512
  const TableCell = styled(MuiTableCell)(({ theme })=>({
513
513
  borderBottom: `solid 1px ${theme.palette.divider}`
514
514
  }));
515
+ function VariableEditorFormWithContext({ variableDefinitions, externalVariableDefinitions, builtinVariableDefinitions, currentEditingVariableDefinition, variableFormAction, onActionChange, onSave, onClose }) {
516
+ const { initialVariableValues, isLoading } = useResolveListVariableValues(variableDefinitions);
517
+ if (isLoading) {
518
+ return /*#__PURE__*/ _jsx(Stack, {
519
+ sx: {
520
+ display: 'flex',
521
+ alignItems: 'center',
522
+ justifyContent: 'center',
523
+ height: '100%',
524
+ width: '100%',
525
+ overflow: 'hidden'
526
+ },
527
+ children: /*#__PURE__*/ _jsx(CircularProgress, {
528
+ "aria-label": "loading"
529
+ })
530
+ });
531
+ }
532
+ return /*#__PURE__*/ _jsx(VariableProvider, {
533
+ initialVariableDefinitions: variableDefinitions,
534
+ externalVariableDefinitions: externalVariableDefinitions,
535
+ builtinVariableDefinitions: builtinVariableDefinitions,
536
+ initialVariableValues: initialVariableValues,
537
+ children: /*#__PURE__*/ _jsx(ValidationProvider, {
538
+ children: /*#__PURE__*/ _jsx(VariableEditorForm, {
539
+ initialVariableDefinition: currentEditingVariableDefinition,
540
+ action: variableFormAction,
541
+ isDraft: true,
542
+ onActionChange: onActionChange,
543
+ onSave: onSave,
544
+ onClose: onClose
545
+ })
546
+ })
547
+ });
548
+ }
515
549
  export function VariableName(props) {
516
550
  const { name, state } = props;
517
551
  return /*#__PURE__*/ _jsxs(_Fragment, {