@perses-dev/dashboards 0.51.0-beta.0 → 0.51.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +21 -9
  2. package/dist/cjs/context/VariableProvider/VariableProvider.js +16 -20
  3. package/dist/cjs/test/datasource-provider.js +1 -1
  4. package/dist/components/Datasources/DatasourceEditor.js.map +1 -1
  5. package/dist/components/DownloadButton/DownloadButton.js.map +1 -1
  6. package/dist/components/GridLayout/GridContainer.js.map +1 -1
  7. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  8. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  9. package/dist/components/Panel/HeaderIconButton.d.ts +1 -1
  10. package/dist/components/Panel/HeaderIconButton.d.ts.map +1 -1
  11. package/dist/components/Panel/Panel.js.map +1 -1
  12. package/dist/components/Panel/PanelHeader.js.map +1 -1
  13. package/dist/components/Panel/PanelLinks.js.map +1 -1
  14. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  15. package/dist/components/PanelDrawer/PanelEditorForm.js +21 -9
  16. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  17. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -1
  18. package/dist/components/SaveDashboardButton/SaveDashboardButton.js.map +1 -1
  19. package/dist/components/Variables/BuiltinVariableAccordions.js.map +1 -1
  20. package/dist/components/Variables/Variable.js.map +1 -1
  21. package/dist/components/Variables/VariableEditor.js.map +1 -1
  22. package/dist/components/Variables/VariableList.js.map +1 -1
  23. package/dist/constants/user-interface-text.js.map +1 -1
  24. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  25. package/dist/context/DashboardProvider/delete-panel-slice.js.map +1 -1
  26. package/dist/context/DashboardProvider/duplicate-panel-slice.js.map +1 -1
  27. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  28. package/dist/context/DashboardProvider/panel-group-slice.d.ts +1 -1
  29. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  30. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  31. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  32. package/dist/context/VariableProvider/VariableProvider.d.ts.map +1 -1
  33. package/dist/context/VariableProvider/VariableProvider.js +13 -12
  34. package/dist/context/VariableProvider/VariableProvider.js.map +1 -1
  35. package/dist/context/VariableProvider/query-params.js.map +1 -1
  36. package/dist/context/useDashboard.js.map +1 -1
  37. package/dist/test/datasource-provider.d.ts +1 -1
  38. package/dist/test/datasource-provider.d.ts.map +1 -1
  39. package/dist/test/datasource-provider.js +1 -1
  40. package/dist/test/datasource-provider.js.map +1 -1
  41. package/dist/utils/panelUtils.js.map +1 -1
  42. package/package.json +8 -9
  43. package/dist/cjs/stories/decorators/WithDashboard.js +0 -41
  44. package/dist/cjs/stories/decorators/WithDatasourceStore.js +0 -39
  45. package/dist/cjs/stories/decorators/WithVariables.js +0 -37
  46. package/dist/cjs/stories/decorators/constants.js +0 -39
  47. package/dist/cjs/stories/decorators/index.js +0 -33
  48. package/dist/stories/decorators/WithDashboard.js +0 -33
  49. package/dist/stories/decorators/WithDashboard.js.map +0 -1
  50. package/dist/stories/decorators/WithDatasourceStore.js +0 -31
  51. package/dist/stories/decorators/WithDatasourceStore.js.map +0 -1
  52. package/dist/stories/decorators/WithVariables.js +0 -29
  53. package/dist/stories/decorators/WithVariables.js.map +0 -1
  54. package/dist/stories/decorators/constants.js +0 -31
  55. package/dist/stories/decorators/constants.js.map +0 -1
  56. package/dist/stories/decorators/index.js +0 -18
  57. package/dist/stories/decorators/index.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Variables/VariableList.tsx"],"sourcesContent":["// Copyright 2024 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 { Box } from '@mui/material';\nimport { VariableDefinition, VariableSpec } from '@perses-dev/core';\nimport { ReactElement } from 'react';\nimport {\n ExternalVariableDefinition,\n useExternalVariableDefinitions,\n useVariableDefinitionAndState,\n useVariableDefinitions,\n} from '../../context';\nimport { MAX_VARIABLE_WIDTH, MIN_VARIABLE_WIDTH } from '../../constants';\nimport { Variable } from './Variable';\n\nexport function VariableList(): ReactElement {\n const variableDefinitions: VariableDefinition[] = useVariableDefinitions();\n const externalVariableDefinitions: ExternalVariableDefinition[] = useExternalVariableDefinitions();\n\n return (\n <>\n {externalVariableDefinitions\n .slice()\n .reverse() // We reverse to have the most prioritized on top\n .map((def) =>\n def.definitions.map((v) => (\n <VariableListItem key={v.spec.name + def.source} spec={v.spec} source={def.source} />\n ))\n )}\n {variableDefinitions.map((v) => (\n <VariableListItem key={v.spec.name} spec={v.spec} />\n ))}\n </>\n );\n}\n\nexport function VariableListItem({ spec, source }: { spec: VariableSpec; source?: string }): ReactElement | null {\n const ctx = useVariableDefinitionAndState(spec.name, source);\n if (ctx.state?.overridden) {\n return null;\n }\n return (\n <Box\n key={spec.name + source ?? ''}\n display={spec.display?.hidden ? 'none' : undefined}\n minWidth={`${MIN_VARIABLE_WIDTH}px`}\n maxWidth={`${MAX_VARIABLE_WIDTH}px`}\n flexShrink={0}\n data-testid={'variable-' + spec.name}\n >\n <Variable key={spec.name + source ?? ''} name={spec.name} source={source} />\n </Box>\n );\n}\n"],"names":["Box","useExternalVariableDefinitions","useVariableDefinitionAndState","useVariableDefinitions","MAX_VARIABLE_WIDTH","MIN_VARIABLE_WIDTH","Variable","VariableList","variableDefinitions","externalVariableDefinitions","slice","reverse","map","def","definitions","v","VariableListItem","spec","source","name","ctx","state","overridden","display","hidden","undefined","minWidth","maxWidth","flexShrink","data-testid"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,GAAG,QAAQ,gBAAgB;AAGpC,SAEEC,8BAA8B,EAC9BC,6BAA6B,EAC7BC,sBAAsB,QACjB,gBAAgB;AACvB,SAASC,kBAAkB,EAAEC,kBAAkB,QAAQ,kBAAkB;AACzE,SAASC,QAAQ,QAAQ,aAAa;AAEtC,OAAO,SAASC;IACd,MAAMC,sBAA4CL;IAClD,MAAMM,8BAA4DR;IAElE,qBACE;;YACGQ,4BACEC,KAAK,GACLC,OAAO,GAAG,iDAAiD;aAC3DC,GAAG,CAAC,CAACC,MACJA,IAAIC,WAAW,CAACF,GAAG,CAAC,CAACG,kBACnB,KAACC;wBAAgDC,MAAMF,EAAEE,IAAI;wBAAEC,QAAQL,IAAIK,MAAM;uBAA1DH,EAAEE,IAAI,CAACE,IAAI,GAAGN,IAAIK,MAAM;YAGpDV,oBAAoBI,GAAG,CAAC,CAACG,kBACxB,KAACC;oBAAmCC,MAAMF,EAAEE,IAAI;mBAAzBF,EAAEE,IAAI,CAACE,IAAI;;;AAI1C;AAEA,OAAO,SAASH,iBAAiB,EAAEC,IAAI,EAAEC,MAAM,EAA2C;IACxF,MAAME,MAAMlB,8BAA8Be,KAAKE,IAAI,EAAED;IACrD,IAAIE,IAAIC,KAAK,EAAEC,YAAY;QACzB,OAAO;IACT;IACA,qBACE,KAACtB;QAECuB,SAASN,KAAKM,OAAO,EAAEC,SAAS,SAASC;QACzCC,UAAU,CAAC,EAAErB,mBAAmB,EAAE,CAAC;QACnCsB,UAAU,CAAC,EAAEvB,mBAAmB,EAAE,CAAC;QACnCwB,YAAY;QACZC,eAAa,cAAcZ,KAAKE,IAAI;kBAEpC,cAAA,KAACb;YAAwCa,MAAMF,KAAKE,IAAI;YAAED,QAAQA;WAAnDD,CAAAA,KAAKE,IAAI,GAAGD,MAAK,KAAK;OAPhCD,CAAAA,KAAKE,IAAI,GAAGD,MAAK,KAAK;AAUjC"}
1
+ {"version":3,"sources":["../../../src/components/Variables/VariableList.tsx"],"sourcesContent":["// Copyright 2024 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 { Box } from '@mui/material';\nimport { VariableDefinition, VariableSpec } from '@perses-dev/core';\nimport { ReactElement } from 'react';\nimport {\n ExternalVariableDefinition,\n useExternalVariableDefinitions,\n useVariableDefinitionAndState,\n useVariableDefinitions,\n} from '../../context';\nimport { MAX_VARIABLE_WIDTH, MIN_VARIABLE_WIDTH } from '../../constants';\nimport { Variable } from './Variable';\n\nexport function VariableList(): ReactElement {\n const variableDefinitions: VariableDefinition[] = useVariableDefinitions();\n const externalVariableDefinitions: ExternalVariableDefinition[] = useExternalVariableDefinitions();\n\n return (\n <>\n {externalVariableDefinitions\n .slice()\n .reverse() // We reverse to have the most prioritized on top\n .map((def) =>\n def.definitions.map((v) => (\n <VariableListItem key={v.spec.name + def.source} spec={v.spec} source={def.source} />\n ))\n )}\n {variableDefinitions.map((v) => (\n <VariableListItem key={v.spec.name} spec={v.spec} />\n ))}\n </>\n );\n}\n\nexport function VariableListItem({ spec, source }: { spec: VariableSpec; source?: string }): ReactElement | null {\n const ctx = useVariableDefinitionAndState(spec.name, source);\n if (ctx.state?.overridden) {\n return null;\n }\n return (\n <Box\n key={spec.name + source ?? ''}\n display={spec.display?.hidden ? 'none' : undefined}\n minWidth={`${MIN_VARIABLE_WIDTH}px`}\n maxWidth={`${MAX_VARIABLE_WIDTH}px`}\n flexShrink={0}\n data-testid={'variable-' + spec.name}\n >\n <Variable key={spec.name + source ?? ''} name={spec.name} source={source} />\n </Box>\n );\n}\n"],"names":["Box","useExternalVariableDefinitions","useVariableDefinitionAndState","useVariableDefinitions","MAX_VARIABLE_WIDTH","MIN_VARIABLE_WIDTH","Variable","VariableList","variableDefinitions","externalVariableDefinitions","slice","reverse","map","def","definitions","v","VariableListItem","spec","source","name","ctx","state","overridden","display","hidden","undefined","minWidth","maxWidth","flexShrink","data-testid"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,GAAG,QAAQ,gBAAgB;AAGpC,SAEEC,8BAA8B,EAC9BC,6BAA6B,EAC7BC,sBAAsB,QACjB,gBAAgB;AACvB,SAASC,kBAAkB,EAAEC,kBAAkB,QAAQ,kBAAkB;AACzE,SAASC,QAAQ,QAAQ,aAAa;AAEtC,OAAO,SAASC;IACd,MAAMC,sBAA4CL;IAClD,MAAMM,8BAA4DR;IAElE,qBACE;;YACGQ,4BACEC,KAAK,GACLC,OAAO,GAAG,iDAAiD;aAC3DC,GAAG,CAAC,CAACC,MACJA,IAAIC,WAAW,CAACF,GAAG,CAAC,CAACG,kBACnB,KAACC;wBAAgDC,MAAMF,EAAEE,IAAI;wBAAEC,QAAQL,IAAIK,MAAM;uBAA1DH,EAAEE,IAAI,CAACE,IAAI,GAAGN,IAAIK,MAAM;YAGpDV,oBAAoBI,GAAG,CAAC,CAACG,kBACxB,KAACC;oBAAmCC,MAAMF,EAAEE,IAAI;mBAAzBF,EAAEE,IAAI,CAACE,IAAI;;;AAI1C;AAEA,OAAO,SAASH,iBAAiB,EAAEC,IAAI,EAAEC,MAAM,EAA2C;IACxF,MAAME,MAAMlB,8BAA8Be,KAAKE,IAAI,EAAED;IACrD,IAAIE,IAAIC,KAAK,EAAEC,YAAY;QACzB,OAAO;IACT;IACA,qBACE,KAACtB;QAECuB,SAASN,KAAKM,OAAO,EAAEC,SAAS,SAASC;QACzCC,UAAU,GAAGrB,mBAAmB,EAAE,CAAC;QACnCsB,UAAU,GAAGvB,mBAAmB,EAAE,CAAC;QACnCwB,YAAY;QACZC,eAAa,cAAcZ,KAAKE,IAAI;kBAEpC,cAAA,KAACb;YAAwCa,MAAMF,KAAKE,IAAI;YAAED,QAAQA;WAAnDD,CAAAA,KAAKE,IAAI,GAAGD,MAAK,KAAK;OAPhCD,CAAAA,KAAKE,IAAI,GAAGD,MAAK,KAAK;AAUjC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/constants/user-interface-text.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport const TOOLTIP_TEXT = {\n // Toolbar buttons\n addPanel: 'Add panel',\n addGroup: 'Add panel group',\n editDatasources: 'Edit datasources',\n editJson: 'Edit JSON',\n editVariables: 'Edit variables',\n viewJson: 'View JSON',\n // Group buttons\n addPanelToGroup: 'Add panel to group',\n deleteGroup: 'Delete group',\n editGroup: 'Edit group',\n moveGroupDown: 'Move group down',\n moveGroupUp: 'Move group up',\n // Panel buttons\n viewPanel: 'Toggle View Mode',\n editPanel: 'Edit',\n duplicatePanel: 'Duplicate',\n deletePanel: 'Delete',\n movePanel: 'Move',\n // Variable editor buttons\n refreshVariableValues: 'Refresh values',\n copyVariableValues: 'Copy values to clipboard',\n};\n\nexport const ARIA_LABEL_TEXT = {\n // Group buttons\n addPanelToGroup: (groupName: string): string => `add panel to group ${groupName}`,\n deleteGroup: (groupName: string): string => `delete group ${groupName}`,\n editGroup: (groupName: string): string => `edit group ${groupName}`,\n moveGroupDown: (groupName: string): string => `move group ${groupName} down`,\n moveGroupUp: (groupName: string): string => `move group ${groupName} up`,\n // Panel buttons\n viewPanel: (panelName: string): string => `toggle panel ${panelName} view mode`,\n editPanel: (panelName: string): string => `edit panel ${panelName}`,\n duplicatePanel: (panelName: string): string => `duplicate panel ${panelName}`,\n deletePanel: (panelName: string): string => `delete panel ${panelName}`,\n showPanelActions: (panelName: string): string => `show panel actions for ${panelName}`,\n movePanel: (panelName: string): string => `move panel ${panelName}`,\n};\n"],"names":["TOOLTIP_TEXT","addPanel","addGroup","editDatasources","editJson","editVariables","viewJson","addPanelToGroup","deleteGroup","editGroup","moveGroupDown","moveGroupUp","viewPanel","editPanel","duplicatePanel","deletePanel","movePanel","refreshVariableValues","copyVariableValues","ARIA_LABEL_TEXT","groupName","panelName","showPanelActions"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAO,MAAMA,eAAe;IAC1B,kBAAkB;IAClBC,UAAU;IACVC,UAAU;IACVC,iBAAiB;IACjBC,UAAU;IACVC,eAAe;IACfC,UAAU;IACV,gBAAgB;IAChBC,iBAAiB;IACjBC,aAAa;IACbC,WAAW;IACXC,eAAe;IACfC,aAAa;IACb,gBAAgB;IAChBC,WAAW;IACXC,WAAW;IACXC,gBAAgB;IAChBC,aAAa;IACbC,WAAW;IACX,0BAA0B;IAC1BC,uBAAuB;IACvBC,oBAAoB;AACtB,EAAE;AAEF,OAAO,MAAMC,kBAAkB;IAC7B,gBAAgB;IAChBZ,iBAAiB,CAACa,YAA8B,CAAC,mBAAmB,EAAEA,UAAU,CAAC;IACjFZ,aAAa,CAACY,YAA8B,CAAC,aAAa,EAAEA,UAAU,CAAC;IACvEX,WAAW,CAACW,YAA8B,CAAC,WAAW,EAAEA,UAAU,CAAC;IACnEV,eAAe,CAACU,YAA8B,CAAC,WAAW,EAAEA,UAAU,KAAK,CAAC;IAC5ET,aAAa,CAACS,YAA8B,CAAC,WAAW,EAAEA,UAAU,GAAG,CAAC;IACxE,gBAAgB;IAChBR,WAAW,CAACS,YAA8B,CAAC,aAAa,EAAEA,UAAU,UAAU,CAAC;IAC/ER,WAAW,CAACQ,YAA8B,CAAC,WAAW,EAAEA,UAAU,CAAC;IACnEP,gBAAgB,CAACO,YAA8B,CAAC,gBAAgB,EAAEA,UAAU,CAAC;IAC7EN,aAAa,CAACM,YAA8B,CAAC,aAAa,EAAEA,UAAU,CAAC;IACvEC,kBAAkB,CAACD,YAA8B,CAAC,uBAAuB,EAAEA,UAAU,CAAC;IACtFL,WAAW,CAACK,YAA8B,CAAC,WAAW,EAAEA,UAAU,CAAC;AACrE,EAAE"}
1
+ {"version":3,"sources":["../../src/constants/user-interface-text.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport const TOOLTIP_TEXT = {\n // Toolbar buttons\n addPanel: 'Add panel',\n addGroup: 'Add panel group',\n editDatasources: 'Edit datasources',\n editJson: 'Edit JSON',\n editVariables: 'Edit variables',\n viewJson: 'View JSON',\n // Group buttons\n addPanelToGroup: 'Add panel to group',\n deleteGroup: 'Delete group',\n editGroup: 'Edit group',\n moveGroupDown: 'Move group down',\n moveGroupUp: 'Move group up',\n // Panel buttons\n viewPanel: 'Toggle View Mode',\n editPanel: 'Edit',\n duplicatePanel: 'Duplicate',\n deletePanel: 'Delete',\n movePanel: 'Move',\n // Variable editor buttons\n refreshVariableValues: 'Refresh values',\n copyVariableValues: 'Copy values to clipboard',\n};\n\nexport const ARIA_LABEL_TEXT = {\n // Group buttons\n addPanelToGroup: (groupName: string): string => `add panel to group ${groupName}`,\n deleteGroup: (groupName: string): string => `delete group ${groupName}`,\n editGroup: (groupName: string): string => `edit group ${groupName}`,\n moveGroupDown: (groupName: string): string => `move group ${groupName} down`,\n moveGroupUp: (groupName: string): string => `move group ${groupName} up`,\n // Panel buttons\n viewPanel: (panelName: string): string => `toggle panel ${panelName} view mode`,\n editPanel: (panelName: string): string => `edit panel ${panelName}`,\n duplicatePanel: (panelName: string): string => `duplicate panel ${panelName}`,\n deletePanel: (panelName: string): string => `delete panel ${panelName}`,\n showPanelActions: (panelName: string): string => `show panel actions for ${panelName}`,\n movePanel: (panelName: string): string => `move panel ${panelName}`,\n};\n"],"names":["TOOLTIP_TEXT","addPanel","addGroup","editDatasources","editJson","editVariables","viewJson","addPanelToGroup","deleteGroup","editGroup","moveGroupDown","moveGroupUp","viewPanel","editPanel","duplicatePanel","deletePanel","movePanel","refreshVariableValues","copyVariableValues","ARIA_LABEL_TEXT","groupName","panelName","showPanelActions"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAO,MAAMA,eAAe;IAC1B,kBAAkB;IAClBC,UAAU;IACVC,UAAU;IACVC,iBAAiB;IACjBC,UAAU;IACVC,eAAe;IACfC,UAAU;IACV,gBAAgB;IAChBC,iBAAiB;IACjBC,aAAa;IACbC,WAAW;IACXC,eAAe;IACfC,aAAa;IACb,gBAAgB;IAChBC,WAAW;IACXC,WAAW;IACXC,gBAAgB;IAChBC,aAAa;IACbC,WAAW;IACX,0BAA0B;IAC1BC,uBAAuB;IACvBC,oBAAoB;AACtB,EAAE;AAEF,OAAO,MAAMC,kBAAkB;IAC7B,gBAAgB;IAChBZ,iBAAiB,CAACa,YAA8B,CAAC,mBAAmB,EAAEA,WAAW;IACjFZ,aAAa,CAACY,YAA8B,CAAC,aAAa,EAAEA,WAAW;IACvEX,WAAW,CAACW,YAA8B,CAAC,WAAW,EAAEA,WAAW;IACnEV,eAAe,CAACU,YAA8B,CAAC,WAAW,EAAEA,UAAU,KAAK,CAAC;IAC5ET,aAAa,CAACS,YAA8B,CAAC,WAAW,EAAEA,UAAU,GAAG,CAAC;IACxE,gBAAgB;IAChBR,WAAW,CAACS,YAA8B,CAAC,aAAa,EAAEA,UAAU,UAAU,CAAC;IAC/ER,WAAW,CAACQ,YAA8B,CAAC,WAAW,EAAEA,WAAW;IACnEP,gBAAgB,CAACO,YAA8B,CAAC,gBAAgB,EAAEA,WAAW;IAC7EN,aAAa,CAACM,YAA8B,CAAC,aAAa,EAAEA,WAAW;IACvEC,kBAAkB,CAACD,YAA8B,CAAC,uBAAuB,EAAEA,WAAW;IACtFL,WAAW,CAACK,YAA8B,CAAC,WAAW,EAAEA,WAAW;AACrE,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/dashboard-provider-api.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useCallback, useMemo } from 'react';\nimport {\n DashboardResource,\n DurationString,\n EphemeralDashboardResource,\n PanelDefinition,\n PanelGroupId,\n} from '@perses-dev/core';\nimport { DashboardStoreState, useDashboardStore } from './DashboardProvider';\nimport { PanelGroupDefinition, PanelGroupItemId, PanelGroupItemLayout } from './panel-group-slice';\nimport { DeletePanelGroupDialogState } from './delete-panel-group-slice';\nimport { PanelGroupEditor } from './panel-group-editor-slice';\nimport { PanelEditorState } from './panel-editor-slice';\nimport { DeletePanelDialogState } from './delete-panel-slice';\nimport { SaveChangesConfirmationDialogState } from './save-changes-dialog-slice';\nimport { DiscardChangesConfirmationDialogState } from './discard-changes-dialog-slice';\nimport { EditJsonDialogState } from './edit-json-dialog-slice';\nimport { ViewPanelSlice } from './view-panel-slice';\n\nconst selectEditMode: ({ isEditMode, setEditMode }: DashboardStoreState) => {\n setEditMode: (isEditMode: boolean) => void;\n isEditMode: boolean;\n} = ({ isEditMode, setEditMode }: DashboardStoreState) => ({ isEditMode, setEditMode });\nexport function useEditMode(): { setEditMode: (isEditMode: boolean) => void; isEditMode: boolean } {\n return useDashboardStore(selectEditMode);\n}\n\nconst selectDashboardActions: ({ setDashboard, openAddPanelGroup, openAddPanel }: DashboardStoreState) => {\n openAddPanelGroup: () => void;\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n setDashboard: (dashboard: DashboardResource | EphemeralDashboardResource) => void;\n} = ({ setDashboard, openAddPanelGroup, openAddPanel }: DashboardStoreState) => ({\n setDashboard,\n openAddPanelGroup,\n openAddPanel,\n});\n/**\n * Returns actions that can be performed on the current dashboard.\n */\nexport function useDashboardActions(): {\n openAddPanelGroup: () => void;\n openAddPanel: () => void;\n setDashboard: (dashboard: DashboardResource | EphemeralDashboardResource) => void;\n} {\n const { setDashboard, openAddPanelGroup, openAddPanel } = useDashboardStore(selectDashboardActions);\n return {\n setDashboard,\n openAddPanelGroup: () => openAddPanelGroup(),\n openAddPanel: () => openAddPanel(),\n };\n}\n\nconst selectPanelGroupOrder = (state: DashboardStoreState): number[] => state.panelGroupOrder;\n/**\n * Returns an array of PanelGroupIds in the order they appear in the dashboard.\n */\nexport function usePanelGroupIds(): number[] {\n return useDashboardStore(selectPanelGroupOrder);\n}\n\nconst selectPanelGroups: (state: DashboardStoreState) => Record<number, PanelGroupDefinition> = (\n state: DashboardStoreState\n) => state.panelGroups;\n/**\n * Returns an array of PanelGroupDefinitions in the order they appear in the dashboard.\n */\nexport function useListPanelGroups(): PanelGroupDefinition[] {\n const panelGroupIds = usePanelGroupIds();\n const panelGroups = useDashboardStore(selectPanelGroups);\n return useMemo(() => {\n return panelGroupIds.map((id) => {\n const group = panelGroups[id];\n if (group === undefined) {\n throw new Error(`Invalid panel group Id found ${id}`);\n }\n return group;\n });\n }, [panelGroupIds, panelGroups]);\n}\n\n/**\n * Gets a specific panel group by its id. Throws if the panel group does not exist.\n */\nexport function usePanelGroup(panelGroupId: PanelGroupId): PanelGroupDefinition {\n const panelGroup = useDashboardStore(useCallback((state) => state.panelGroups[panelGroupId], [panelGroupId]));\n if (panelGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} was not found`);\n }\n return panelGroup;\n}\n\nconst selectPanelGroupActions: ({\n openEditPanelGroup,\n deletePanelGroup,\n openAddPanel,\n updatePanelGroupLayouts,\n}: DashboardStoreState) => {\n updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;\n openEditPanelGroup: (panelGroupId: PanelGroupId) => void;\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n deletePanelGroup: (panelGroupId: PanelGroupId) => void;\n} = ({ openEditPanelGroup, deletePanelGroup, openAddPanel, updatePanelGroupLayouts }: DashboardStoreState) => ({\n openEditPanelGroup,\n deletePanelGroup,\n openAddPanel,\n updatePanelGroupLayouts,\n});\n/**\n * Returns actions that can be performed on the given panel group.\n */\nexport function usePanelGroupActions(panelGroupId: PanelGroupId): {\n updatePanelGroupLayouts: (itemLayouts: PanelGroupItemLayout[]) => void;\n openEditPanelGroup: () => void;\n openAddPanel: () => void;\n moveDown: (() => void) | undefined;\n deletePanelGroup: () => void;\n moveUp: (() => void) | undefined;\n} {\n const { moveUp, moveDown } = useMovePanelGroup(panelGroupId);\n const { openEditPanelGroup, deletePanelGroup, openAddPanel, updatePanelGroupLayouts } =\n useDashboardStore(selectPanelGroupActions);\n\n return {\n openEditPanelGroup: () => openEditPanelGroup(panelGroupId),\n deletePanelGroup: () => deletePanelGroup(panelGroupId),\n openAddPanel: () => openAddPanel(panelGroupId),\n moveUp,\n moveDown,\n updatePanelGroupLayouts: (itemLayouts: PanelGroupItemLayout[]) =>\n updatePanelGroupLayouts(panelGroupId, itemLayouts),\n };\n}\n\nconst selectSwapPanelGroups: (state: DashboardStoreState) => (xIndex: number, yIndex: number) => void = (\n state: DashboardStoreState\n) => state.swapPanelGroups;\nconst selectPanelGroupsLength: (state: DashboardStoreState) => number = (state: DashboardStoreState) =>\n state.panelGroupOrder.length;\n/**\n * Returns functions for moving a panel group up or down. A function will be undefined if the panel group can't be\n * moved in that direction.\n */\nfunction useMovePanelGroup(panelGroupId: PanelGroupId): {\n moveDown: (() => void) | undefined;\n moveUp: (() => void) | undefined;\n} {\n const currentIndex = useDashboardStore(\n useCallback((store) => store.panelGroupOrder.findIndex((id) => id === panelGroupId), [panelGroupId])\n );\n const panelGroupsLength = useDashboardStore(selectPanelGroupsLength);\n const swapPanelGroups = useDashboardStore(selectSwapPanelGroups);\n\n if (currentIndex < 0) {\n throw new Error(`Could not find panel group with Id ${panelGroupId} in order array`);\n }\n\n const moveUp: () => void = () => swapPanelGroups(currentIndex, currentIndex - 1);\n const moveDown: () => void = () => swapPanelGroups(currentIndex, currentIndex + 1);\n return {\n moveUp: currentIndex > 0 ? moveUp : undefined,\n moveDown: currentIndex < panelGroupsLength - 1 ? moveDown : undefined,\n };\n}\n\nconst selectPanelGroupEditor: (state: DashboardStoreState) => PanelGroupEditor | undefined = (\n state: DashboardStoreState\n) => state.panelGroupEditor;\n/**\n * Gets the Panel Group editor state.\n */\nexport function usePanelGroupEditor(): PanelGroupEditor | undefined {\n return useDashboardStore(selectPanelGroupEditor);\n}\n\nconst selectDeletePanelGroupDialog: ({\n deletePanelGroupDialog,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog,\n deletePanelGroup,\n}: DashboardStoreState) => {\n deletePanelGroupDialog: DeletePanelGroupDialogState | undefined;\n closeDeletePanelGroupDialog: () => void;\n openDeletePanelGroupDialog: (panelGroupId: PanelGroupId) => void;\n deletePanelGroup: (panelGroupId: PanelGroupId) => void;\n} = ({\n deletePanelGroupDialog,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog,\n deletePanelGroup,\n}: DashboardStoreState) => ({\n deletePanelGroupDialog,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog,\n deletePanelGroup,\n});\n/**\n * Gets the Delete Panel Group dialog state.\n */\nexport function useDeletePanelGroupDialog(): {\n deletePanelGroupDialog: DeletePanelGroupDialogState | undefined;\n closeDeletePanelGroupDialog: () => void;\n openDeletePanelGroupDialog: (panelGroupId: PanelGroupId) => void;\n deletePanelGroup: (panelGroupId: PanelGroupId) => void;\n} {\n const { deletePanelGroupDialog, openDeletePanelGroupDialog, closeDeletePanelGroupDialog, deletePanelGroup } =\n useDashboardStore(selectDeletePanelGroupDialog);\n return {\n deletePanelGroupDialog,\n deletePanelGroup,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog: () => closeDeletePanelGroupDialog(),\n };\n}\n\n/**\n * Gets an individual panel in the store. Throws if the panel can't be found.\n */\nexport function usePanel(panelGroupItemId: PanelGroupItemId): PanelDefinition {\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const panel = useDashboardStore(\n useCallback(\n (store) => {\n const panelKey = store.panelGroups[panelGroupId]?.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) return;\n return store.panels[panelKey];\n },\n [panelGroupId, panelGroupLayoutId]\n )\n );\n\n if (panel === undefined) {\n throw new Error(`Could not find panel for Id ${panelGroupItemId}`);\n }\n return panel;\n}\n\nconst selectPanelActions: ({\n openEditPanel,\n openDeletePanelDialog,\n duplicatePanel,\n setViewPanel,\n}: DashboardStoreState) => {\n openDeletePanelDialog: (panelGroupItemId: PanelGroupItemId) => void;\n duplicatePanel: (panelGroupItemId: PanelGroupItemId) => void;\n openEditPanel: (panelGroupItemId: PanelGroupItemId) => void;\n setViewPanel: (panelGroupItemId?: PanelGroupItemId) => void;\n} = ({ openEditPanel, openDeletePanelDialog, duplicatePanel, setViewPanel }: DashboardStoreState) => ({\n openEditPanel,\n openDeletePanelDialog,\n duplicatePanel,\n setViewPanel,\n});\n\n/**\n * Returns actions that can be performed on the given Panel.\n */\nexport function usePanelActions(panelGroupItemId: PanelGroupItemId): {\n openDeletePanelDialog: () => void;\n duplicatePanel: () => void;\n openEditPanel: () => void;\n viewPanel: (panelGroupItemId?: PanelGroupItemId) => void;\n} {\n const { openEditPanel, openDeletePanelDialog, duplicatePanel, setViewPanel } = useDashboardStore(selectPanelActions);\n return {\n openEditPanel: () => openEditPanel(panelGroupItemId),\n openDeletePanelDialog: () => openDeletePanelDialog(panelGroupItemId),\n duplicatePanel: () => duplicatePanel(panelGroupItemId),\n viewPanel: (panelGroupItemId?: PanelGroupItemId) => setViewPanel(panelGroupItemId),\n };\n}\n\nconst selectPanelEditor: (state: DashboardStoreState) => PanelEditorState | undefined = (state: DashboardStoreState) =>\n state.panelEditor;\n/**\n * Gets the state for the Panel Editor.\n */\nexport function usePanelEditor(): PanelEditorState | undefined {\n return useDashboardStore(selectPanelEditor);\n}\n\nconst selectDeletePanelDialog: ({ deletePanelDialog, deletePanel, closeDeletePanelDialog }: DashboardStoreState) => {\n deletePanelDialog: DeletePanelDialogState | undefined;\n closeDeletePanelDialog: () => void;\n deletePanel: (panelGroupItemId: PanelGroupItemId) => void;\n} = ({ deletePanelDialog, deletePanel, closeDeletePanelDialog }: DashboardStoreState) => ({\n deletePanelDialog,\n deletePanel,\n closeDeletePanelDialog,\n});\n\n/**\n * Gets the state for the Delete Panel dialog.\n */\nexport function useDeletePanelDialog(): {\n deletePanelDialog: DeletePanelDialogState | undefined;\n closeDeletePanelDialog: () => void;\n deletePanel: (panelGroupItemId: PanelGroupItemId) => void;\n} {\n // TODO: Refactor similar to other dialogs/editors so these are on the editor state itself\n return useDashboardStore(selectDeletePanelDialog);\n}\n\nconst selectDashboardDuration: (state: DashboardStoreState) => DurationString = (state: DashboardStoreState) =>\n state.duration;\nexport function useDashboardDuration(): DurationString {\n return useDashboardStore(selectDashboardDuration);\n}\n\nconst selectViewPanel: (state: DashboardStoreState) => {\n setViewPanel: DashboardStoreState['setViewPanel'];\n getViewPanel: DashboardStoreState['getViewPanel'];\n viewPanelId: DashboardStoreState['viewPanel']['panelGroupItemId'];\n} = (state: DashboardStoreState) => ({\n setViewPanel: state.setViewPanel,\n getViewPanel: state.getViewPanel,\n viewPanelId: state.getViewPanel(),\n});\n/**\n * Returns actions related to the ViewPanel.\n */\nexport function useViewPanel(): {\n setViewPanel: ViewPanelSlice['setViewPanel'];\n getViewPanel: ViewPanelSlice['getViewPanel'];\n viewPanelId: ViewPanelSlice['viewPanel']['panelGroupItemId'];\n} {\n return useDashboardStore(selectViewPanel);\n}\n\nconst selectViewPanelGroup: (state: DashboardStoreState) => PanelGroupItemId | undefined = (\n state: DashboardStoreState\n) => state.getViewPanel();\n/**\n * Gets the Panel Group for the view panel.\n */\nexport function useViewPanelGroup(): PanelGroupItemId | undefined {\n return useDashboardStore(selectViewPanelGroup);\n}\n\nconst selectSaveChangesConfirmationDialog: ({\n saveChangesConfirmationDialog,\n openSaveChangesConfirmationDialog,\n closeSaveChangesConfirmationDialog,\n}: DashboardStoreState) => {\n closeSaveChangesConfirmationDialog: () => void;\n openSaveChangesConfirmationDialog: (saveChangesConfirmationDialog: SaveChangesConfirmationDialogState) => void;\n saveChangesConfirmationDialog: SaveChangesConfirmationDialogState | undefined;\n} = ({\n saveChangesConfirmationDialog,\n openSaveChangesConfirmationDialog,\n closeSaveChangesConfirmationDialog,\n}: DashboardStoreState) => ({\n saveChangesConfirmationDialog,\n openSaveChangesConfirmationDialog,\n closeSaveChangesConfirmationDialog,\n});\nexport function useSaveChangesConfirmationDialog(): {\n closeSaveChangesConfirmationDialog: () => void;\n openSaveChangesConfirmationDialog: (saveChangesConfirmationDialog: SaveChangesConfirmationDialogState) => void;\n saveChangesConfirmationDialog: SaveChangesConfirmationDialogState | undefined;\n} {\n return useDashboardStore(selectSaveChangesConfirmationDialog);\n}\n\nconst selectDiscardChangesConfirmationDialog: ({\n discardChangesConfirmationDialog,\n openDiscardChangesConfirmationDialog,\n closeDiscardChangesConfirmationDialog,\n}: DashboardStoreState) => {\n discardChangesConfirmationDialog: DiscardChangesConfirmationDialogState | undefined;\n closeDiscardChangesConfirmationDialog: () => void;\n openDiscardChangesConfirmationDialog: (\n discardChangesConfirmationDialog: DiscardChangesConfirmationDialogState\n ) => void;\n} = ({\n discardChangesConfirmationDialog,\n openDiscardChangesConfirmationDialog,\n closeDiscardChangesConfirmationDialog,\n}: DashboardStoreState) => ({\n discardChangesConfirmationDialog,\n openDiscardChangesConfirmationDialog,\n closeDiscardChangesConfirmationDialog,\n});\nexport function useDiscardChangesConfirmationDialog(): {\n discardChangesConfirmationDialog: DiscardChangesConfirmationDialogState | undefined;\n closeDiscardChangesConfirmationDialog: () => void;\n openDiscardChangesConfirmationDialog: (\n discardChangesConfirmationDialog: DiscardChangesConfirmationDialogState\n ) => void;\n} {\n return useDashboardStore(selectDiscardChangesConfirmationDialog);\n}\n\nconst selectEditJsonDialog: ({ editJsonDialog, openEditJsonDialog, closeEditJsonDialog }: DashboardStoreState) => {\n openEditJsonDialog: () => void;\n closeEditJsonDialog: () => void;\n editJsonDialog: EditJsonDialogState | undefined;\n} = ({ editJsonDialog, openEditJsonDialog, closeEditJsonDialog }: DashboardStoreState) => ({\n editJsonDialog,\n openEditJsonDialog,\n closeEditJsonDialog,\n});\n/**\n * Gets the state for the edit JSON dialog.\n */\nexport function useEditJsonDialog(): {\n openEditJsonDialog: () => void;\n closeEditJsonDialog: () => void;\n editJsonDialog: EditJsonDialogState | undefined;\n} {\n return useDashboardStore(selectEditJsonDialog);\n}\n"],"names":["useCallback","useMemo","useDashboardStore","selectEditMode","isEditMode","setEditMode","useEditMode","selectDashboardActions","setDashboard","openAddPanelGroup","openAddPanel","useDashboardActions","selectPanelGroupOrder","state","panelGroupOrder","usePanelGroupIds","selectPanelGroups","panelGroups","useListPanelGroups","panelGroupIds","map","id","group","undefined","Error","usePanelGroup","panelGroupId","panelGroup","selectPanelGroupActions","openEditPanelGroup","deletePanelGroup","updatePanelGroupLayouts","usePanelGroupActions","moveUp","moveDown","useMovePanelGroup","itemLayouts","selectSwapPanelGroups","swapPanelGroups","selectPanelGroupsLength","length","currentIndex","store","findIndex","panelGroupsLength","selectPanelGroupEditor","panelGroupEditor","usePanelGroupEditor","selectDeletePanelGroupDialog","deletePanelGroupDialog","openDeletePanelGroupDialog","closeDeletePanelGroupDialog","useDeletePanelGroupDialog","usePanel","panelGroupItemId","panelGroupItemLayoutId","panelGroupLayoutId","panel","panelKey","itemPanelKeys","panels","selectPanelActions","openEditPanel","openDeletePanelDialog","duplicatePanel","setViewPanel","usePanelActions","viewPanel","selectPanelEditor","panelEditor","usePanelEditor","selectDeletePanelDialog","deletePanelDialog","deletePanel","closeDeletePanelDialog","useDeletePanelDialog","selectDashboardDuration","duration","useDashboardDuration","selectViewPanel","getViewPanel","viewPanelId","useViewPanel","selectViewPanelGroup","useViewPanelGroup","selectSaveChangesConfirmationDialog","saveChangesConfirmationDialog","openSaveChangesConfirmationDialog","closeSaveChangesConfirmationDialog","useSaveChangesConfirmationDialog","selectDiscardChangesConfirmationDialog","discardChangesConfirmationDialog","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","useDiscardChangesConfirmationDialog","selectEditJsonDialog","editJsonDialog","openEditJsonDialog","closeEditJsonD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gCAAgC,EAChCC,oCAAoC,EACpCC,qCAAqC,EACjB,GAAM,CAAA;QAC1BF;QACAC;QACAC;IACF,CAAA;AACA,OAAO,SAASC;IAOd,OAAO5F,kBAAkBwF;AAC3B;AAEA,MAAMK,uBAIF,CAAC,EAAEC,cAAc,EAAEC,kBAAkB,EAAEC,mBAAmB,EAAuB,GAAM,CAAA;QACzFF;QACAC;QACAC;IACF,CAAA;AACA;;CAEC,GACD,OAAO,SAASC;IAKd,OAAOjG,kBAAkB6F;AAC3B"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/dashboard-provider-api.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useCallback, useMemo } from 'react';\nimport {\n DashboardResource,\n DurationString,\n EphemeralDashboardResource,\n PanelDefinition,\n PanelGroupId,\n} from '@perses-dev/core';\nimport { DashboardStoreState, useDashboardStore } from './DashboardProvider';\nimport { PanelGroupDefinition, PanelGroupItemId, PanelGroupItemLayout } from './panel-group-slice';\nimport { DeletePanelGroupDialogState } from './delete-panel-group-slice';\nimport { PanelGroupEditor } from './panel-group-editor-slice';\nimport { PanelEditorState } from './panel-editor-slice';\nimport { DeletePanelDialogState } from './delete-panel-slice';\nimport { SaveChangesConfirmationDialogState } from './save-changes-dialog-slice';\nimport { DiscardChangesConfirmationDialogState } from './discard-changes-dialog-slice';\nimport { EditJsonDialogState } from './edit-json-dialog-slice';\nimport { ViewPanelSlice } from './view-panel-slice';\n\nconst selectEditMode: ({ isEditMode, setEditMode }: DashboardStoreState) => {\n setEditMode: (isEditMode: boolean) => void;\n isEditMode: boolean;\n} = ({ isEditMode, setEditMode }: DashboardStoreState) => ({ isEditMode, setEditMode });\nexport function useEditMode(): { setEditMode: (isEditMode: boolean) => void; isEditMode: boolean } {\n return useDashboardStore(selectEditMode);\n}\n\nconst selectDashboardActions: ({ setDashboard, openAddPanelGroup, openAddPanel }: DashboardStoreState) => {\n openAddPanelGroup: () => void;\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n setDashboard: (dashboard: DashboardResource | EphemeralDashboardResource) => void;\n} = ({ setDashboard, openAddPanelGroup, openAddPanel }: DashboardStoreState) => ({\n setDashboard,\n openAddPanelGroup,\n openAddPanel,\n});\n/**\n * Returns actions that can be performed on the current dashboard.\n */\nexport function useDashboardActions(): {\n openAddPanelGroup: () => void;\n openAddPanel: () => void;\n setDashboard: (dashboard: DashboardResource | EphemeralDashboardResource) => void;\n} {\n const { setDashboard, openAddPanelGroup, openAddPanel } = useDashboardStore(selectDashboardActions);\n return {\n setDashboard,\n openAddPanelGroup: () => openAddPanelGroup(),\n openAddPanel: () => openAddPanel(),\n };\n}\n\nconst selectPanelGroupOrder = (state: DashboardStoreState): number[] => state.panelGroupOrder;\n/**\n * Returns an array of PanelGroupIds in the order they appear in the dashboard.\n */\nexport function usePanelGroupIds(): number[] {\n return useDashboardStore(selectPanelGroupOrder);\n}\n\nconst selectPanelGroups: (state: DashboardStoreState) => Record<number, PanelGroupDefinition> = (\n state: DashboardStoreState\n) => state.panelGroups;\n/**\n * Returns an array of PanelGroupDefinitions in the order they appear in the dashboard.\n */\nexport function useListPanelGroups(): PanelGroupDefinition[] {\n const panelGroupIds = usePanelGroupIds();\n const panelGroups = useDashboardStore(selectPanelGroups);\n return useMemo(() => {\n return panelGroupIds.map((id) => {\n const group = panelGroups[id];\n if (group === undefined) {\n throw new Error(`Invalid panel group Id found ${id}`);\n }\n return group;\n });\n }, [panelGroupIds, panelGroups]);\n}\n\n/**\n * Gets a specific panel group by its id. Throws if the panel group does not exist.\n */\nexport function usePanelGroup(panelGroupId: PanelGroupId): PanelGroupDefinition {\n const panelGroup = useDashboardStore(useCallback((state) => state.panelGroups[panelGroupId], [panelGroupId]));\n if (panelGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} was not found`);\n }\n return panelGroup;\n}\n\nconst selectPanelGroupActions: ({\n openEditPanelGroup,\n deletePanelGroup,\n openAddPanel,\n updatePanelGroupLayouts,\n}: DashboardStoreState) => {\n updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;\n openEditPanelGroup: (panelGroupId: PanelGroupId) => void;\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n deletePanelGroup: (panelGroupId: PanelGroupId) => void;\n} = ({ openEditPanelGroup, deletePanelGroup, openAddPanel, updatePanelGroupLayouts }: DashboardStoreState) => ({\n openEditPanelGroup,\n deletePanelGroup,\n openAddPanel,\n updatePanelGroupLayouts,\n});\n/**\n * Returns actions that can be performed on the given panel group.\n */\nexport function usePanelGroupActions(panelGroupId: PanelGroupId): {\n updatePanelGroupLayouts: (itemLayouts: PanelGroupItemLayout[]) => void;\n openEditPanelGroup: () => void;\n openAddPanel: () => void;\n moveDown: (() => void) | undefined;\n deletePanelGroup: () => void;\n moveUp: (() => void) | undefined;\n} {\n const { moveUp, moveDown } = useMovePanelGroup(panelGroupId);\n const { openEditPanelGroup, deletePanelGroup, openAddPanel, updatePanelGroupLayouts } =\n useDashboardStore(selectPanelGroupActions);\n\n return {\n openEditPanelGroup: () => openEditPanelGroup(panelGroupId),\n deletePanelGroup: () => deletePanelGroup(panelGroupId),\n openAddPanel: () => openAddPanel(panelGroupId),\n moveUp,\n moveDown,\n updatePanelGroupLayouts: (itemLayouts: PanelGroupItemLayout[]) =>\n updatePanelGroupLayouts(panelGroupId, itemLayouts),\n };\n}\n\nconst selectSwapPanelGroups: (state: DashboardStoreState) => (xIndex: number, yIndex: number) => void = (\n state: DashboardStoreState\n) => state.swapPanelGroups;\nconst selectPanelGroupsLength: (state: DashboardStoreState) => number = (state: DashboardStoreState) =>\n state.panelGroupOrder.length;\n/**\n * Returns functions for moving a panel group up or down. A function will be undefined if the panel group can't be\n * moved in that direction.\n */\nfunction useMovePanelGroup(panelGroupId: PanelGroupId): {\n moveDown: (() => void) | undefined;\n moveUp: (() => void) | undefined;\n} {\n const currentIndex = useDashboardStore(\n useCallback((store) => store.panelGroupOrder.findIndex((id) => id === panelGroupId), [panelGroupId])\n );\n const panelGroupsLength = useDashboardStore(selectPanelGroupsLength);\n const swapPanelGroups = useDashboardStore(selectSwapPanelGroups);\n\n if (currentIndex < 0) {\n throw new Error(`Could not find panel group with Id ${panelGroupId} in order array`);\n }\n\n const moveUp: () => void = () => swapPanelGroups(currentIndex, currentIndex - 1);\n const moveDown: () => void = () => swapPanelGroups(currentIndex, currentIndex + 1);\n return {\n moveUp: currentIndex > 0 ? moveUp : undefined,\n moveDown: currentIndex < panelGroupsLength - 1 ? moveDown : undefined,\n };\n}\n\nconst selectPanelGroupEditor: (state: DashboardStoreState) => PanelGroupEditor | undefined = (\n state: DashboardStoreState\n) => state.panelGroupEditor;\n/**\n * Gets the Panel Group editor state.\n */\nexport function usePanelGroupEditor(): PanelGroupEditor | undefined {\n return useDashboardStore(selectPanelGroupEditor);\n}\n\nconst selectDeletePanelGroupDialog: ({\n deletePanelGroupDialog,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog,\n deletePanelGroup,\n}: DashboardStoreState) => {\n deletePanelGroupDialog: DeletePanelGroupDialogState | undefined;\n closeDeletePanelGroupDialog: () => void;\n openDeletePanelGroupDialog: (panelGroupId: PanelGroupId) => void;\n deletePanelGroup: (panelGroupId: PanelGroupId) => void;\n} = ({\n deletePanelGroupDialog,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog,\n deletePanelGroup,\n}: DashboardStoreState) => ({\n deletePanelGroupDialog,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog,\n deletePanelGroup,\n});\n/**\n * Gets the Delete Panel Group dialog state.\n */\nexport function useDeletePanelGroupDialog(): {\n deletePanelGroupDialog: DeletePanelGroupDialogState | undefined;\n closeDeletePanelGroupDialog: () => void;\n openDeletePanelGroupDialog: (panelGroupId: PanelGroupId) => void;\n deletePanelGroup: (panelGroupId: PanelGroupId) => void;\n} {\n const { deletePanelGroupDialog, openDeletePanelGroupDialog, closeDeletePanelGroupDialog, deletePanelGroup } =\n useDashboardStore(selectDeletePanelGroupDialog);\n return {\n deletePanelGroupDialog,\n deletePanelGroup,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog: () => closeDeletePanelGroupDialog(),\n };\n}\n\n/**\n * Gets an individual panel in the store. Throws if the panel can't be found.\n */\nexport function usePanel(panelGroupItemId: PanelGroupItemId): PanelDefinition {\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const panel = useDashboardStore(\n useCallback(\n (store) => {\n const panelKey = store.panelGroups[panelGroupId]?.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) return;\n return store.panels[panelKey];\n },\n [panelGroupId, panelGroupLayoutId]\n )\n );\n\n if (panel === undefined) {\n throw new Error(`Could not find panel for Id ${panelGroupItemId}`);\n }\n return panel;\n}\n\nconst selectPanelActions: ({\n openEditPanel,\n openDeletePanelDialog,\n duplicatePanel,\n setViewPanel,\n}: DashboardStoreState) => {\n openDeletePanelDialog: (panelGroupItemId: PanelGroupItemId) => void;\n duplicatePanel: (panelGroupItemId: PanelGroupItemId) => void;\n openEditPanel: (panelGroupItemId: PanelGroupItemId) => void;\n setViewPanel: (panelGroupItemId?: PanelGroupItemId) => void;\n} = ({ openEditPanel, openDeletePanelDialog, duplicatePanel, setViewPanel }: DashboardStoreState) => ({\n openEditPanel,\n openDeletePanelDialog,\n duplicatePanel,\n setViewPanel,\n});\n\n/**\n * Returns actions that can be performed on the given Panel.\n */\nexport function usePanelActions(panelGroupItemId: PanelGroupItemId): {\n openDeletePanelDialog: () => void;\n duplicatePanel: () => void;\n openEditPanel: () => void;\n viewPanel: (panelGroupItemId?: PanelGroupItemId) => void;\n} {\n const { openEditPanel, openDeletePanelDialog, duplicatePanel, setViewPanel } = useDashboardStore(selectPanelActions);\n return {\n openEditPanel: () => openEditPanel(panelGroupItemId),\n openDeletePanelDialog: () => openDeletePanelDialog(panelGroupItemId),\n duplicatePanel: () => duplicatePanel(panelGroupItemId),\n viewPanel: (panelGroupItemId?: PanelGroupItemId) => setViewPanel(panelGroupItemId),\n };\n}\n\nconst selectPanelEditor: (state: DashboardStoreState) => PanelEditorState | undefined = (state: DashboardStoreState) =>\n state.panelEditor;\n/**\n * Gets the state for the Panel Editor.\n */\nexport function usePanelEditor(): PanelEditorState | undefined {\n return useDashboardStore(selectPanelEditor);\n}\n\nconst selectDeletePanelDialog: ({ deletePanelDialog, deletePanel, closeDeletePanelDialog }: DashboardStoreState) => {\n deletePanelDialog: DeletePanelDialogState | undefined;\n closeDeletePanelDialog: () => void;\n deletePanel: (panelGroupItemId: PanelGroupItemId) => void;\n} = ({ deletePanelDialog, deletePanel, closeDeletePanelDialog }: DashboardStoreState) => ({\n deletePanelDialog,\n deletePanel,\n closeDeletePanelDialog,\n});\n\n/**\n * Gets the state for the Delete Panel dialog.\n */\nexport function useDeletePanelDialog(): {\n deletePanelDialog: DeletePanelDialogState | undefined;\n closeDeletePanelDialog: () => void;\n deletePanel: (panelGroupItemId: PanelGroupItemId) => void;\n} {\n // TODO: Refactor similar to other dialogs/editors so these are on the editor state itself\n return useDashboardStore(selectDeletePanelDialog);\n}\n\nconst selectDashboardDuration: (state: DashboardStoreState) => DurationString = (state: DashboardStoreState) =>\n state.duration;\nexport function useDashboardDuration(): DurationString {\n return useDashboardStore(selectDashboardDuration);\n}\n\nconst selectViewPanel: (state: DashboardStoreState) => {\n setViewPanel: DashboardStoreState['setViewPanel'];\n getViewPanel: DashboardStoreState['getViewPanel'];\n viewPanelId: DashboardStoreState['viewPanel']['panelGroupItemId'];\n} = (state: DashboardStoreState) => ({\n setViewPanel: state.setViewPanel,\n getViewPanel: state.getViewPanel,\n viewPanelId: state.getViewPanel(),\n});\n/**\n * Returns actions related to the ViewPanel.\n */\nexport function useViewPanel(): {\n setViewPanel: ViewPanelSlice['setViewPanel'];\n getViewPanel: ViewPanelSlice['getViewPanel'];\n viewPanelId: ViewPanelSlice['viewPanel']['panelGroupItemId'];\n} {\n return useDashboardStore(selectViewPanel);\n}\n\nconst selectViewPanelGroup: (state: DashboardStoreState) => PanelGroupItemId | undefined = (\n state: DashboardStoreState\n) => state.getViewPanel();\n/**\n * Gets the Panel Group for the view panel.\n */\nexport function useViewPanelGroup(): PanelGroupItemId | undefined {\n return useDashboardStore(selectViewPanelGroup);\n}\n\nconst selectSaveChangesConfirmationDialog: ({\n saveChangesConfirmationDialog,\n openSaveChangesConfirmationDialog,\n closeSaveChangesConfirmationDialog,\n}: DashboardStoreState) => {\n closeSaveChangesConfirmationDialog: () => void;\n openSaveChangesConfirmationDialog: (saveChangesConfirmationDialog: SaveChangesConfirmationDialogState) => void;\n saveChangesConfirmationDialog: SaveChangesConfirmationDialogState | undefined;\n} = ({\n saveChangesConfirmationDialog,\n openSaveChangesConfirmationDialog,\n closeSaveChangesConfirmationDialog,\n}: DashboardStoreState) => ({\n saveChangesConfirmationDialog,\n openSaveChangesConfirmationDialog,\n closeSaveChangesConfirmationDialog,\n});\nexport function useSaveChangesConfirmationDialog(): {\n closeSaveChangesConfirmationDialog: () => void;\n openSaveChangesConfirmationDialog: (saveChangesConfirmationDialog: SaveChangesConfirmationDialogState) => void;\n saveChangesConfirmationDialog: SaveChangesConfirmationDialogState | undefined;\n} {\n return useDashboardStore(selectSaveChangesConfirmationDialog);\n}\n\nconst selectDiscardChangesConfirmationDialog: ({\n discardChangesConfirmationDialog,\n openDiscardChangesConfirmationDialog,\n closeDiscardChangesConfirmationDialog,\n}: DashboardStoreState) => {\n discardChangesConfirmationDialog: DiscardChangesConfirmationDialogState | undefined;\n closeDiscardChangesConfirmationDialog: () => void;\n openDiscardChangesConfirmationDialog: (\n discardChangesConfirmationDialog: DiscardChangesConfirmationDialogState\n ) => void;\n} = ({\n discardChangesConfirmationDialog,\n openDiscardChangesConfirmationDialog,\n closeDiscardChangesConfirmationDialog,\n}: DashboardStoreState) => ({\n discardChangesConfirmationDialog,\n openDiscardChangesConfirmationDialog,\n closeDiscardChangesConfirmationDialog,\n});\nexport function useDiscardChangesConfirmationDialog(): {\n discardChangesConfirmationDialog: DiscardChangesConfirmationDialogState | undefined;\n closeDiscardChangesConfirmationDialog: () => void;\n openDiscardChangesConfirmationDialog: (\n discardChangesConfirmationDialog: DiscardChangesConfirmationDialogState\n ) => void;\n} {\n return useDashboardStore(selectDiscardChangesConfirmationDialog);\n}\n\nconst selectEditJsonDialog: ({ editJsonDialog, openEditJsonDialog, closeEditJsonDialog }: DashboardStoreState) => {\n openEditJsonDialog: () => void;\n closeEditJsonDialog: () => void;\n editJsonDialog: EditJsonDialogState | undefined;\n} = ({ editJsonDialog, openEditJsonDialog, closeEditJsonDialog }: DashboardStoreState) => ({\n editJsonDialog,\n openEditJsonDialog,\n closeEditJsonDialog,\n});\n/**\n * Gets the state for the edit JSON dialog.\n */\nexport function useEditJsonDialog(): {\n openEditJsonDialog: () => void;\n closeEditJsonDialog: () => void;\n editJsonDialog: EditJsonDialogState | undefined;\n} {\n return useDashboardStore(selectEditJsonDialog);\n}\n"],"names":["useCallback","useMemo","useDashboardStore","selectEditMode","isEditMode","setEditMode","useEditMode","selectDashboardActions","setDashboard","openAddPanelGroup","openAddPanel","useDashboardActions","selectPanelGroupOrder","state","panelGroupOrder","usePanelGroupIds","selectPanelGroups","panelGroups","useListPanelGroups","panelGroupIds","map","id","group","undefined","Error","usePanelGroup","panelGroupId","panelGroup","selectPanelGroupActions","openEditPanelGroup","deletePanelGroup","updatePanelGroupLayouts","usePanelGroupActions","moveUp","moveDown","useMovePanelGroup","itemLayouts","selectSwapPanelGroups","swapPanelGroups","selectPanelGroupsLength","length","currentIndex","store","findIndex","panelGroupsLength","selectPanelGroupEditor","panelGroupEditor","usePanelGroupEditor","selectDeletePanelGroupDialog","deletePanelGroupDialog","openDeletePanelGroupDialog","closeDeletePanelGroupDialog","useDeletePanelGroupDialog","usePanel","panelGroupItemId","panelGroupItemLayoutId","panelGroupLayoutId","panel","panelKey","itemPanelKeys","panels","selectPanelActions","openEditPanel","openDeletePanelDialog","duplicatePanel","setViewPanel","usePanelActions","viewPanel","selectPanelEditor","panelEditor","usePanelEditor","selectDeletePanelDialog","deletePanelDialog","deletePanel","closeDeletePanelDialog","useDeletePanelDialog","selectDashboardDuration","duration","useDashboardDuration","selectViewPanel","getViewPanel","viewPanelId","useViewPanel","selectViewPanelGroup","useViewPanelGroup","selectSaveChangesConfirmationDialog","saveChangesConfirmationDialog","openSaveChangesConfirmationDialog","closeSaveChangesConfirmationDialog","useSaveChangesConfirmationDialog","selectDiscardChangesConfirmationDialog","discardChangesConfirmationDialog","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","useDiscardChangesConfirmationDialog","selectEditJsonDialog","editJsonDialog","openEditJsonDialog","closeEditJsonDialog","useEditJsonDialog"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,WAAW,EAAEC,OAAO,QAAQ,QAAQ;AAQ7C,SAA8BC,iBAAiB,QAAQ,sBAAsB;AAW7E,MAAMC,iBAGF,CAAC,EAAEC,UAAU,EAAEC,WAAW,EAAuB,GAAM,CAAA;QAAED;QAAYC;IAAY,CAAA;AACrF,OAAO,SAASC;IACd,OAAOJ,kBAAkBC;AAC3B;AAEA,MAAMI,yBAIF,CAAC,EAAEC,YAAY,EAAEC,iBAAiB,EAAEC,YAAY,EAAuB,GAAM,CAAA;QAC/EF;QACAC;QACAC;IACF,CAAA;AACA;;CAEC,GACD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;IAC1F,OAAOzE,kBAAkBqE;AAC3B;AAEA,MAAMK,0BAA0E,CAAC/D,QAC/EA,MAAMgE,QAAQ;AAChB,OAAO,SAASC;IACd,OAAO5E,kBAAkB0E;AAC3B;AAEA,MAAMG,kBAIF,CAAClE,QAAgC,CAAA;QACnCoD,cAAcpD,MAAMoD,YAAY;QAChCe,cAAcnE,MAAMmE,YAAY;QAChCC,aAAapE,MAAMmE,YAAY;IACjC,CAAA;AACA;;CAEC,GACD,OAAO,SAASE;IAKd,OAAOhF,kBAAkB6E;AAC3B;AAEA,MAAMI,uBAAqF,CACzFtE,QACGA,MAAMmE,YAAY;AACvB;;CAEC,GACD,OAAO,SAASI;IACd,OAAOlF,kBAAkBiF;AAC3B;AAEA,MAAME,sCAQF,CAAC,EACHC,6BAA6B,EAC7BC,iCAAiC,EACjCC,kCAAkC,EACd,GAAM,CAAA;QAC1BF;QACAC;QACAC;IACF,CAAA;AACA,OAAO,SAASC;IAKd,OAAOvF,kBAAkBmF;AAC3B;AAEA,MAAMK,yCAUF,CAAC,EACHC,gCAAgC,EAChCC,oCAAoC,EACpCC,qCAAqC,EACjB,GAAM,CAAA;QAC1BF;QACAC;QACAC;IACF,CAAA;AACA,OAAO,SAASC;IAOd,OAAO5F,kBAAkBwF;AAC3B;AAEA,MAAMK,uBAIF,CAAC,EAAEC,cAAc,EAAEC,kBAAkB,EAAEC,mBAAmB,EAAuB,GAAM,CAAA;QACzFF;QACAC;QACAC;IACF,CAAA;AACA;;CAEC,GACD,OAAO,SAASC;IAKd,OAAOjG,kBAAkB6F;AAC3B"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/delete-panel-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupItemId } from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and actions for deleting Panels.\n */\nexport interface DeletePanelSlice {\n /**\n * Delete panels\n */\n deletePanel: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * State for the delete panel dialog when it's open, otherwise undefined when it's closed.\n */\n deletePanelDialog?: DeletePanelDialogState;\n\n /**\n * Open delete panel dialog\n */\n openDeletePanelDialog: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * Close delete panel dialog\n */\n closeDeletePanelDialog: () => void;\n}\n\nexport interface DeletePanelDialogState {\n panelGroupItemId: PanelGroupItemId;\n panelName: string;\n panelGroupName: string;\n}\n\n/**\n * Curried function for creating the PanelDeleteSlice.\n */\nexport function createDeletePanelSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n DeletePanelSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n DeletePanelSlice\n> {\n // Return the state creator function for Zustand that uses the panels provided as intitial state\n return (set, get) => ({\n deletePanel(panelGroupItemId: PanelGroupItemId): void {\n set((draft) => {\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const existingGroup = draft.panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout) => layout.i === panelGroupLayoutId);\n const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];\n if (existingLayoutIdx === -1 || existingPanelKey === undefined) {\n throw new Error(`Missing panel group item ${panelGroupLayoutId}`);\n }\n\n // remove panel from panel group\n existingGroup.itemLayouts.splice(existingLayoutIdx, 1);\n delete existingGroup.itemPanelKeys[panelGroupLayoutId];\n\n // See if panel key is still used and if not, delete it\n if (isPanelKeyStillUsed(draft.panelGroups, existingPanelKey) === false) {\n delete draft.panels[existingPanelKey];\n }\n });\n },\n\n openDeletePanelDialog(panelGroupItemId: PanelGroupItemId): void {\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n\n const { panels, panelGroups } = get();\n const panelGroup = panelGroups[panelGroupId];\n if (panelGroup === undefined) {\n throw new Error(`Panel group not found ${panelGroupId}`);\n }\n\n const panelKey = panelGroup.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupLayoutId}`);\n }\n\n const panel = panels[panelKey];\n if (panel === undefined) {\n throw new Error(`Could not find panel ${panelKey}`);\n }\n\n set((state) => {\n state.deletePanelDialog = {\n panelGroupItemId: panelGroupItemId,\n panelName: panel.spec.display.name,\n panelGroupName: panelGroup.title ?? '',\n };\n });\n },\n\n closeDeletePanelDialog(): void {\n set((state) => {\n state.deletePanelDialog = undefined;\n });\n },\n });\n}\n\n// Helper function to determine if a panel key is still being used somewhere in Panel Groups\nfunction isPanelKeyStillUsed(panelGroups: PanelGroupSlice['panelGroups'], panelKey: string): boolean {\n for (const group of Object.values(panelGroups)) {\n const found = Object.values(group.itemPanelKeys).find((key) => key === panelKey);\n if (found !== undefined) {\n return true;\n }\n }\n return false;\n}\n"],"names":["createDeletePanelSlice","set","get","deletePanel","panelGroupItemId","draft","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","existingGroup","panelGroups","undefined","Error","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingPanelKey","itemPanelKeys","splice","isPanelKeyStillUsed","panels","openDeletePanelDialog","panelGroup","panelKey","panel","state","deletePanelDialog","panelName","spec","display","name","panelGroupName","title","closeDeletePanelDialog","group","Object","values","found","find","key"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AAC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;gBACzD;gBAEA,MAAMmB,WAAWD,WAAWL,aAAa,CAACX,mBAAmB;gBAC7D,IAAIiB,aAAad,WAAW;oBAC1B,MAAM,IAAIC,MAAM,CAAC,gCAAgC,EAAEJ,mBAAmB,CAAC;gBACzE;gBAEA,MAAMkB,QAAQJ,MAAM,CAACG,SAAS;gBAC9B,IAAIC,UAAUf,WAAW;oBACvB,MAAM,IAAIC,MAAM,CAAC,qBAAqB,EAAEa,SAAS,CAAC;gBACpD;gBAEAxB,IAAI,CAAC0B;oBACHA,MAAMC,iBAAiB,GAAG;wBACxBxB,kBAAkBA;wBAClByB,WAAWH,MAAMI,IAAI,CAACC,OAAO,CAACC,IAAI;wBAClCC,gBAAgBT,WAAWU,KAAK,IAAI;oBACtC;gBACF;YACF;YAEAC;gBACElC,IAAI,CAAC0B;oBACHA,MAAMC,iBAAiB,GAAGjB;gBAC5B;YACF;QACF,CAAA;AACF;AAEA,4FAA4F;AAC5F,SAASU,oBAAoBX,WAA2C,EAAEe,QAAgB;IACxF,KAAK,MAAMW,SAASC,OAAOC,MAAM,CAAC5B,aAAc;QAC9C,MAAM6B,QAAQF,OAAOC,MAAM,CAACF,MAAMjB,aAAa,EAAEqB,IAAI,CAAC,CAACC,MAAQA,QAAQhB;QACvE,IAAIc,UAAU5B,WAAW;YACvB,OAAO;QACT;IACF;IACA,OAAO;AACT"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/delete-panel-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupItemId } from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and actions for deleting Panels.\n */\nexport interface DeletePanelSlice {\n /**\n * Delete panels\n */\n deletePanel: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * State for the delete panel dialog when it's open, otherwise undefined when it's closed.\n */\n deletePanelDialog?: DeletePanelDialogState;\n\n /**\n * Open delete panel dialog\n */\n openDeletePanelDialog: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * Close delete panel dialog\n */\n closeDeletePanelDialog: () => void;\n}\n\nexport interface DeletePanelDialogState {\n panelGroupItemId: PanelGroupItemId;\n panelName: string;\n panelGroupName: string;\n}\n\n/**\n * Curried function for creating the PanelDeleteSlice.\n */\nexport function createDeletePanelSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n DeletePanelSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n DeletePanelSlice\n> {\n // Return the state creator function for Zustand that uses the panels provided as intitial state\n return (set, get) => ({\n deletePanel(panelGroupItemId: PanelGroupItemId): void {\n set((draft) => {\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const existingGroup = draft.panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout) => layout.i === panelGroupLayoutId);\n const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];\n if (existingLayoutIdx === -1 || existingPanelKey === undefined) {\n throw new Error(`Missing panel group item ${panelGroupLayoutId}`);\n }\n\n // remove panel from panel group\n existingGroup.itemLayouts.splice(existingLayoutIdx, 1);\n delete existingGroup.itemPanelKeys[panelGroupLayoutId];\n\n // See if panel key is still used and if not, delete it\n if (isPanelKeyStillUsed(draft.panelGroups, existingPanelKey) === false) {\n delete draft.panels[existingPanelKey];\n }\n });\n },\n\n openDeletePanelDialog(panelGroupItemId: PanelGroupItemId): void {\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n\n const { panels, panelGroups } = get();\n const panelGroup = panelGroups[panelGroupId];\n if (panelGroup === undefined) {\n throw new Error(`Panel group not found ${panelGroupId}`);\n }\n\n const panelKey = panelGroup.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupLayoutId}`);\n }\n\n const panel = panels[panelKey];\n if (panel === undefined) {\n throw new Error(`Could not find panel ${panelKey}`);\n }\n\n set((state) => {\n state.deletePanelDialog = {\n panelGroupItemId: panelGroupItemId,\n panelName: panel.spec.display.name,\n panelGroupName: panelGroup.title ?? '',\n };\n });\n },\n\n closeDeletePanelDialog(): void {\n set((state) => {\n state.deletePanelDialog = undefined;\n });\n },\n });\n}\n\n// Helper function to determine if a panel key is still being used somewhere in Panel Groups\nfunction isPanelKeyStillUsed(panelGroups: PanelGroupSlice['panelGroups'], panelKey: string): boolean {\n for (const group of Object.values(panelGroups)) {\n const found = Object.values(group.itemPanelKeys).find((key) => key === panelKey);\n if (found !== undefined) {\n return true;\n }\n }\n return false;\n}\n"],"names":["createDeletePanelSlice","set","get","deletePanel","panelGroupItemId","draft","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","existingGroup","panelGroups","undefined","Error","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingPanelKey","itemPanelKeys","splice","isPanelKeyStillUsed","panels","openDeletePanelDialog","panelGroup","panelKey","panel","state","deletePanelDialog","panelName","spec","display","name","panelGroupName","title","closeDeletePanelDialog","group","Object","values","found","find","key"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAsCjC;;CAEC,GACD,OAAO,SAASA;IAOd,gGAAgG;IACh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MkB,QAAQJ,MAAM,CAACG,SAAS;gBAC9B,IAAIC,UAAUf,WAAW;oBACvB,MAAM,IAAIC,MAAM,CAAC,qBAAqB,EAAEa,UAAU;gBACpD;gBAEAxB,IAAI,CAAC0B;oBACHA,MAAMC,iBAAiB,GAAG;wBACxBxB,kBAAkBA;wBAClByB,WAAWH,MAAMI,IAAI,CAACC,OAAO,CAACC,IAAI;wBAClCC,gBAAgBT,WAAWU,KAAK,IAAI;oBACtC;gBACF;YACF;YAEAC;gBACElC,IAAI,CAAC0B;oBACHA,MAAMC,iBAAiB,GAAGjB;gBAC5B;YACF;QACF,CAAA;AACF;AAEA,4FAA4F;AAC5F,SAASU,oBAAoBX,WAA2C,EAAEe,QAAgB;IACxF,KAAK,MAAMW,SAASC,OAAOC,MAAM,CAAC5B,aAAc;QAC9C,MAAM6B,QAAQF,OAAOC,MAAM,CAACF,MAAMjB,aAAa,EAAEqB,IAAI,CAAC,CAACC,MAAQA,QAAQhB;QACvE,IAAIc,UAAU5B,WAAW;YACvB,OAAO;QACT;IACF;IACA,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/duplicate-panel-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { getValidPanelKey, insertPanelInLayout, UnpositionedPanelGroupItemLayout } from '../../utils/panelUtils';\nimport { generateId, Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupItemId } from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles duplicating Panels.\n */\nexport interface DuplicatePanelSlice {\n /**\n * Duplicate panel.\n */\n duplicatePanel: (panelGroupItemId: PanelGroupItemId) => void;\n}\n\n/**\n * Curried function for duplicating a panel.\n */\nexport function createDuplicatePanelSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n DuplicatePanelSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n DuplicatePanelSlice\n> {\n return (set) => ({\n duplicatePanel(panelGroupItemId: PanelGroupItemId): void {\n set((state) => {\n const panels = state.panels;\n\n // Figure out the panel key at that location\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n const panelKey = group.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);\n }\n\n // Find the panel to edit\n const panelToDupe = panels[panelKey];\n if (panelToDupe === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n // Find the layout for the item being duped\n const matchingLayout = group.itemLayouts.find((itemLayout) => {\n return itemLayout.i === panelGroupLayoutId;\n });\n\n if (matchingLayout === undefined) {\n throw new Error(`Cannot find layout for Panel with key '${panelKey}'`);\n }\n\n const dupePanelKey = getValidPanelKey(panelKey, panels);\n\n state.panels[dupePanelKey] = panelToDupe;\n\n const duplicateLayout: UnpositionedPanelGroupItemLayout = {\n i: generateId().toString(),\n w: matchingLayout.w,\n h: matchingLayout.h,\n };\n\n group.itemLayouts = insertPanelInLayout(duplicateLayout, matchingLayout, group.itemLayouts);\n\n group.itemPanelKeys[duplicateLayout.i] = dupePanelKey;\n });\n },\n });\n}\n"],"names":["getValidPanelKey","insertPanelInLayout","generateId","createDuplicatePanelSlice","set","duplicatePanel","panelGroupItemId","state","panels","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","group","panelGroups","undefined","Error","panelKey","itemPanelKeys","panelToDupe","matchingLayout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eAAexB,iBAAiBgB,UAAUR;oBAEhDD,MAAMC,MAAM,CAACgB,aAAa,GAAGN;oBAE7B,MAAMO,kBAAoD;wBACxDF,GAAGrB,aAAawB,QAAQ;wBACxBC,GAAGR,eAAeQ,CAAC;wBACnBC,GAAGT,eAAeS,CAAC;oBACrB;oBAEAhB,MAAMQ,WAAW,GAAGnB,oBAAoBwB,iBAAiBN,gBAAgBP,MAAMQ,WAAW;oBAE1FR,MAAMK,aAAa,CAACQ,gBAAgBF,CAAC,CAAC,GAAGC;gBAC3C;YACF;QACF,CAAA;AACF"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/duplicate-panel-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { getValidPanelKey, insertPanelInLayout, UnpositionedPanelGroupItemLayout } from '../../utils/panelUtils';\nimport { generateId, Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupItemId } from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles duplicating Panels.\n */\nexport interface DuplicatePanelSlice {\n /**\n * Duplicate panel.\n */\n duplicatePanel: (panelGroupItemId: PanelGroupItemId) => void;\n}\n\n/**\n * Curried function for duplicating a panel.\n */\nexport function createDuplicatePanelSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n DuplicatePanelSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n DuplicatePanelSlice\n> {\n return (set) => ({\n duplicatePanel(panelGroupItemId: PanelGroupItemId): void {\n set((state) => {\n const panels = state.panels;\n\n // Figure out the panel key at that location\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n const panelKey = group.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);\n }\n\n // Find the panel to edit\n const panelToDupe = panels[panelKey];\n if (panelToDupe === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n // Find the layout for the item being duped\n const matchingLayout = group.itemLayouts.find((itemLayout) => {\n return itemLayout.i === panelGroupLayoutId;\n });\n\n if (matchingLayout === undefined) {\n throw new Error(`Cannot find layout for Panel with key '${panelKey}'`);\n }\n\n const dupePanelKey = getValidPanelKey(panelKey, panels);\n\n state.panels[dupePanelKey] = panelToDupe;\n\n const duplicateLayout: UnpositionedPanelGroupItemLayout = {\n i: generateId().toString(),\n w: matchingLayout.w,\n h: matchingLayout.h,\n };\n\n group.itemLayouts = insertPanelInLayout(duplicateLayout, matchingLayout, group.itemLayouts);\n\n group.itemPanelKeys[duplicateLayout.i] = dupePanelKey;\n });\n },\n });\n}\n"],"names":["getValidPanelKey","insertPanelInLayout","generateId","createDuplicatePanelSlice","set","duplicatePanel","panelGroupItemId","state","panels","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","group","panelGroups","undefined","Error","panelKey","itemPanelKeys","panelToDupe","matchingLayout","itemLayouts","find","itemLayout","i","dupePanelKey","duplicateLayout","toString","w","h"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,gBAAgB,EAAEC,mBAAmB,QAA0C,yBAAyB;AACjH,SAASC,UAAU,QAAoB,WAAW;AAclD;;CAEC,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F;QACF,CAAA;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Action, PanelEditorValues, PanelGroupId } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { getYForNewRow, getValidPanelKey } from '../../utils';\nimport { generateId, Middleware, createPanelDefinition } from './common';\nimport {\n PanelGroupSlice,\n PanelGroupItemId,\n PanelGroupDefinition,\n PanelGroupItemLayout,\n addPanelGroup,\n createEmptyPanelGroup,\n} from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and actions for adding or editing Panels.\n */\nexport interface PanelEditorSlice {\n /**\n * Initial values for add panel if default panel kind is defined\n */\n initialValues?: Pick<PanelEditorValues, 'panelDefinition'>;\n\n /**\n * State for the panel editor when its open, otherwise undefined when it's closed.\n */\n panelEditor?: PanelEditorState;\n\n /**\n * Opens the editor for editing an existing panel by providing its layout coordinates.\n */\n openEditPanel: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * Opens the editor for adding a new Panel to a panel group.\n */\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n}\n\nexport interface PanelEditorState {\n /**\n * Whether we're adding a new panel, or editing an existing panel.\n */\n mode: Action;\n\n /**\n * Initial values for the things that can be edited about a panel.\n */\n initialValues: PanelEditorValues;\n\n /**\n * Applies changes, but doesn't close the editor.\n */\n applyChanges: (next: PanelEditorValues) => void;\n\n /**\n * Close the editor.\n */\n close: () => void;\n}\n\n/**\n * Curried function for creating the PanelEditorSlice.\n */\nexport function createPanelEditorSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n PanelEditorSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelEditorSlice\n> {\n // Return the state creator function for Zustand that uses the panels provided as intitial state\n return (set, get) => ({\n panelEditor: undefined,\n\n openEditPanel(panelGroupItemId): void {\n const { panels, panelGroups } = get();\n\n // Figure out the panel key at that location\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const panelKey = panelGroups[panelGroupId]?.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);\n }\n\n // Find the panel to edit\n const panelToEdit = panels[panelKey];\n if (panelToEdit === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n const editorState: PanelEditorState = {\n mode: 'update',\n initialValues: {\n groupId: panelGroupItemId.panelGroupId,\n panelDefinition: panelToEdit,\n },\n applyChanges: (next) => {\n set((state) => {\n state.panels[panelKey] = next.panelDefinition;\n\n // If the panel didn't change groups, nothing else to do\n if (next.groupId === panelGroupId) {\n return;\n }\n\n // Move panel to the new group\n const existingGroup = state.panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n\n const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout) => layout.i === panelGroupLayoutId);\n const existingLayout = existingGroup.itemLayouts[existingLayoutIdx];\n const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];\n if (existingLayoutIdx === -1 || existingLayout === undefined || existingPanelKey === undefined) {\n throw new Error(`Missing panel group item ${panelGroupLayoutId}`);\n }\n\n // Remove item from the old group\n existingGroup.itemLayouts.splice(existingLayoutIdx, 1);\n delete existingGroup.itemPanelKeys[panelGroupLayoutId];\n\n // Add item to the end of the new group\n const newGroup = state.panelGroups[next.groupId];\n if (newGroup === undefined) {\n throw new Error(`Could not find new group ${next.groupId}`);\n }\n\n newGroup.itemLayouts.push({\n i: existingLayout.i,\n x: 0,\n y: getYForNewRow(newGroup),\n w: existingLayout.w,\n h: existingLayout.h,\n });\n newGroup.itemPanelKeys[existingLayout.i] = existingPanelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n openAddPanel(panelGroupId): void {\n // If a panel group isn't supplied, add to the first group or create a group if there aren't any\n let newGroup: PanelGroupDefinition | undefined = undefined;\n panelGroupId ??= get().panelGroupOrder[0];\n if (panelGroupId === undefined) {\n newGroup = createEmptyPanelGroup();\n newGroup.title = 'Panel Group';\n panelGroupId = newGroup.id;\n }\n\n const editorState: PanelEditorState = {\n mode: 'create',\n initialValues: {\n groupId: panelGroupId,\n panelDefinition: get().initialValues?.panelDefinition ?? createPanelDefinition(),\n },\n applyChanges: (next) => {\n const name = next.panelDefinition.spec.display.name;\n const panelKey = getValidPanelKey(name, get().panels);\n\n set((state) => {\n // Add a panel\n state.panels[panelKey] = next.panelDefinition;\n\n // Also add a panel group item referencing the panel\n const group = state.panelGroups[next.groupId];\n if (group === undefined) {\n throw new Error(`Missing panel group ${next.groupId}`);\n }\n const layout: PanelGroupItemLayout = {\n i: generateId().toString(),\n x: 0,\n y: getYForNewRow(group),\n w: 12,\n h: 6,\n };\n group.itemLayouts.push(layout);\n group.itemPanelKeys[layout.i] = panelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n set((state) => {\n // Add the new panel group if one was created for the panel\n if (newGroup !== undefined) {\n addPanelGroup(state, newGroup);\n }\n\n // Open the editor with the new state\n state.panelEditor = editorState;\n });\n },\n });\n}\n"],"names":["getYForNewRow","getValidPanelKey","generateId","createPanelDefinition","addPanelGroup","createEmptyPanelGroup","createPanelEditorSlice","set","get","panelEditor","undefined","openEditPanel","panelGroupItemId","panels","panelGroups","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","panelKey","itemPanelKeys","Error","panelToEdit","editorState","mode","initialValues","groupId","panelDefinition","applyChanges","next","state","existingGroup","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingLayout","existingPanelKey","splice","newGroup","push","x","y","w","h","close","openAddPanel","panelGroupOrder","title","id","name","spec","display","group","toString"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,aAAa,EAAEC,gBAAgB,QAAQ,cAAc;AAC9D,SAASC,UAAU,EAAcC,qBAAqB,QAAQ,WAAW;AACzE,SAKEC,aAAa,EACbC,qBAAqB,QAChB,sBAAsB;AAkD7B;;CAEC,GACD,OAAO,SAASC;IAOd,gGAAgG;IAChG,OAAO,CAACC,KAAKC,MAAS,CAAA;YACpBC,aAAaC;YAEbC,eAAcC,gBAAgB;gBAC5B,MAAM,EAAEC,MAAM,EAAEC,WAAW,EAAE,GAAGN;gBAEhC,4CAA4C;gBAC5C,MAAM,EAAEO,YAAY,EAAEC,wBAAwBC,kBAAkB,EAAE,GAAGL;gBACrE,MAAMM,WAAWJ,WAAW,CAACC,aAAa,EAAEI,aAAa,CAACF,mBAAmB;gBAC7E,IAAIC,aAAaR,WAAW;oBAC1B,MAAM,IAAIU,MAAM,CAAC,gCAAgC,EAAER,iBAAiB,CAAC;gBACvE;gBAEA,yBAAyB;gBACzB,MAAMS,cAAcR,MAAM,CAACK,SAAS;gBACpC,IAAIG,gBAAgBX,WAAW;oBAC7B,MAAM,IAAIU,MAAM,CAAC,4BAA4B,EAAEF,SAAS,CAAC,CAAC;gBAC5D;gBAEA,MAAMI,cAAgC;oBACpCC,MAAM;oBACNC,eAAe;wBACbC,SAASb,iBAAiBG,YAAY;wBACtCW,iBAAiBL;oBACnB;oBACAM,cAAc,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H,IAAI,CAACsB;oBACH,2DAA2D;oBAC3D,IAAIU,aAAa7B,WAAW;wBAC1BN,cAAcyB,OAAOU;oBACvB;oBAEA,qCAAqC;oBACrCV,MAAMpB,WAAW,GAAGa;gBACtB;YACF;QACF,CAAA;AACF"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Action, PanelEditorValues, PanelGroupId } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { getYForNewRow, getValidPanelKey } from '../../utils';\nimport { generateId, Middleware, createPanelDefinition } from './common';\nimport {\n PanelGroupSlice,\n PanelGroupItemId,\n PanelGroupDefinition,\n PanelGroupItemLayout,\n addPanelGroup,\n createEmptyPanelGroup,\n} from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and actions for adding or editing Panels.\n */\nexport interface PanelEditorSlice {\n /**\n * Initial values for add panel if default panel kind is defined\n */\n initialValues?: Pick<PanelEditorValues, 'panelDefinition'>;\n\n /**\n * State for the panel editor when its open, otherwise undefined when it's closed.\n */\n panelEditor?: PanelEditorState;\n\n /**\n * Opens the editor for editing an existing panel by providing its layout coordinates.\n */\n openEditPanel: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * Opens the editor for adding a new Panel to a panel group.\n */\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n}\n\nexport interface PanelEditorState {\n /**\n * Whether we're adding a new panel, or editing an existing panel.\n */\n mode: Action;\n\n /**\n * Initial values for the things that can be edited about a panel.\n */\n initialValues: PanelEditorValues;\n\n /**\n * Applies changes, but doesn't close the editor.\n */\n applyChanges: (next: PanelEditorValues) => void;\n\n /**\n * Close the editor.\n */\n close: () => void;\n}\n\n/**\n * Curried function for creating the PanelEditorSlice.\n */\nexport function createPanelEditorSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n PanelEditorSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelEditorSlice\n> {\n // Return the state creator function for Zustand that uses the panels provided as intitial state\n return (set, get) => ({\n panelEditor: undefined,\n\n openEditPanel(panelGroupItemId): void {\n const { panels, panelGroups } = get();\n\n // Figure out the panel key at that location\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const panelKey = panelGroups[panelGroupId]?.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);\n }\n\n // Find the panel to edit\n const panelToEdit = panels[panelKey];\n if (panelToEdit === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n const editorState: PanelEditorState = {\n mode: 'update',\n initialValues: {\n groupId: panelGroupItemId.panelGroupId,\n panelDefinition: panelToEdit,\n },\n applyChanges: (next) => {\n set((state) => {\n state.panels[panelKey] = next.panelDefinition;\n\n // If the panel didn't change groups, nothing else to do\n if (next.groupId === panelGroupId) {\n return;\n }\n\n // Move panel to the new group\n const existingGroup = state.panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n\n const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout) => layout.i === panelGroupLayoutId);\n const existingLayout = existingGroup.itemLayouts[existingLayoutIdx];\n const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];\n if (existingLayoutIdx === -1 || existingLayout === undefined || existingPanelKey === undefined) {\n throw new Error(`Missing panel group item ${panelGroupLayoutId}`);\n }\n\n // Remove item from the old group\n existingGroup.itemLayouts.splice(existingLayoutIdx, 1);\n delete existingGroup.itemPanelKeys[panelGroupLayoutId];\n\n // Add item to the end of the new group\n const newGroup = state.panelGroups[next.groupId];\n if (newGroup === undefined) {\n throw new Error(`Could not find new group ${next.groupId}`);\n }\n\n newGroup.itemLayouts.push({\n i: existingLayout.i,\n x: 0,\n y: getYForNewRow(newGroup),\n w: existingLayout.w,\n h: existingLayout.h,\n });\n newGroup.itemPanelKeys[existingLayout.i] = existingPanelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n openAddPanel(panelGroupId): void {\n // If a panel group isn't supplied, add to the first group or create a group if there aren't any\n let newGroup: PanelGroupDefinition | undefined = undefined;\n panelGroupId ??= get().panelGroupOrder[0];\n if (panelGroupId === undefined) {\n newGroup = createEmptyPanelGroup();\n newGroup.title = 'Panel Group';\n panelGroupId = newGroup.id;\n }\n\n const editorState: PanelEditorState = {\n mode: 'create',\n initialValues: {\n groupId: panelGroupId,\n panelDefinition: get().initialValues?.panelDefinition ?? createPanelDefinition(),\n },\n applyChanges: (next) => {\n const name = next.panelDefinition.spec.display.name;\n const panelKey = getValidPanelKey(name, get().panels);\n\n set((state) => {\n // Add a panel\n state.panels[panelKey] = next.panelDefinition;\n\n // Also add a panel group item referencing the panel\n const group = state.panelGroups[next.groupId];\n if (group === undefined) {\n throw new Error(`Missing panel group ${next.groupId}`);\n }\n const layout: PanelGroupItemLayout = {\n i: generateId().toString(),\n x: 0,\n y: getYForNewRow(group),\n w: 12,\n h: 6,\n };\n group.itemLayouts.push(layout);\n group.itemPanelKeys[layout.i] = panelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n set((state) => {\n // Add the new panel group if one was created for the panel\n if (newGroup !== undefined) {\n addPanelGroup(state, newGroup);\n }\n\n // Open the editor with the new state\n state.panelEditor = editorState;\n });\n },\n });\n}\n"],"names":["getYForNewRow","getValidPanelKey","generateId","createPanelDefinition","addPanelGroup","createEmptyPanelGroup","createPanelEditorSlice","set","get","panelEditor","undefined","openEditPanel","panelGroupItemId","panels","panelGroups","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","panelKey","itemPanelKeys","Error","panelToEdit","editorState","mode","initialValues","groupId","panelDefinition","applyChanges","next","state","existingGroup","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingLayout","existingPanelKey","splice","newGroup","push","x","y","w","h","close","openAddPanel","panelGroupOrder","title","id","name","spec","display","group","toString"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,aAAa,EAAEC,gBAAgB,QAAQ,cAAc;AAC9D,SAASC,UAAU,EAAcC,qBAAqB,QAAQ,WAAW;AACzE,SAKEC,aAAa,EACbC,qBAAqB,QAChB,sBAAsB;AAkD7B;;CAEC,GACD,OAAO,SAASC;IAOd,gGAAgG;IAChG,OAAO,CAACC,KAAKC,MAAS,CAAA;YACpBC,aAAaC;YAEbC,eAAcC,gBAAgB;gBAC5B,MAAM,EAAEC,MAAM,EAAEC,WAAW,EAAE,GAAGN;gBAEhC,4CAA4C;gBAC5C,MAAM,EAAEO,YAAY,EAAEC,wBAAwBC,kBAAkB,EAAE,GAAGL;gBACrE,MAAMM,WAAWJ,WAAW,CAACC,aAAa,EAAEI,aAAa,CAACF,mBAAmB;gBAC7E,IAAIC,aAAaR,WAAW;oBAC1B,MAAM,IAAIU,MAAM,CAAC,gCAAgC,EAAER,kBAAkB;gBACvE;gBAEA,yBAAyB;gBACzB,MAAMS,cAAcR,MAAM,CAACK,SAAS;gBACpC,IAAIG,gBAAgBX,WAAW;oBAC7B,MAAM,IAAIU,MAAM,CAAC,4BAA4B,EAAEF,SAAS,CAAC,CA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;wBAClC;oBACF;oBACA2B,OAAO;wBACLtC,IAAI,CAACsB;4BACHA,MAAMpB,WAAW,GAAGC;wBACtB;oBACF;gBACF;gBAEAH,IAAI,CAACsB;oBACH,2DAA2D;oBAC3D,IAAIU,aAAa7B,WAAW;wBAC1BN,cAAcyB,OAAOU;oBACvB;oBAEA,qCAAqC;oBACrCV,MAAMpB,WAAW,GAAGa;gBACtB;YACF;QACF,CAAA;AACF"}
@@ -1,7 +1,7 @@
1
1
  import { LayoutDefinition, PanelGroupId } from '@perses-dev/core';
2
- import { WritableDraft } from 'immer/dist/internal';
3
2
  import { Layout } from 'react-grid-layout';
4
3
  import { StateCreator } from 'zustand';
4
+ import { WritableDraft } from 'immer';
5
5
  import { Middleware } from './common';
6
6
  /**
7
7
  * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.
@@ -1 +1 @@
1
- {"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAsB,gBAAgB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC;IAExD;;OAEG;IACH,eAAe,EAAE,YAAY,EAAE,CAAC;IAEhC;;OAEG;IACH,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAE1D;;OAEG;IACH,uBAAuB,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC;CACjH;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,YAAY,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,oBAAoB,EAAE,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,oBAAqB,SAAQ,MAAM;IAClD,CAAC,EAAE,sBAAsB,CAAC;CAC3B;AAED,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,YAAY,CAAC;IAC3B,sBAAsB,EAAE,sBAAsB,CAAC;CAChD;AAKD,wBAAgB,uBAAuB,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAE3F;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,YAAY,CAAC,eAAe,EAAE,UAAU,EAAE,EAAE,EAAE,eAAe,CAAC,CAkChE;AAED,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,IAAI,CAAC,eAAe,EAAE,aAAa,GAAG,iBAAiB,CAAC,CAoC1D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,oBAAoB,CAQ5D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,eAAe,CAAC,EAAE,QAAQ,EAAE,oBAAoB,GAAG,IAAI,CAGzG"}
1
+ {"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAsB,gBAAgB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEtF,OAAO,EAAE,M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,EAAE,EAAE,EAAE,eAAe,CAAC,CAkChE;AAED,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,IAAI,CAAC,eAAe,EAAE,aAAa,GAAG,iBAAiB,CAAC,CAoC1D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,oBAAoB,CAQ5D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,eAAe,CAAC,EAAE,QAAQ,EAAE,oBAAoB,GAAG,IAAI,CAGzG"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { getPanelKeyFromRef, LayoutDefinition, PanelGroupId } from '@perses-dev/core';\nimport { WritableDraft } from 'immer/dist/internal';\nimport { Layout } from 'react-grid-layout';\nimport { StateCreator } from 'zustand';\nimport { generateId, Middleware } from './common';\n\n/**\n * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.\n */\nexport interface PanelGroupSlice {\n /**\n * Panel groups indexed by their ID.\n */\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>;\n\n /**\n * An array of panel group IDs, representing their order in the dashboard.\n */\n panelGroupOrder: PanelGroupId[];\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Update the item layouts for a panel group when, for example, a panel is moved or resized.\n */\n updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;\n}\n\nexport interface PanelGroupDefinition {\n id: PanelGroupId;\n isCollapsed: boolean;\n title?: string;\n itemLayouts: PanelGroupItemLayout[];\n itemPanelKeys: Record<PanelGroupItemLayoutId, string>;\n}\n\nexport interface PanelGroupItemLayout extends Layout {\n i: PanelGroupItemLayoutId;\n}\n\nexport type PanelGroupItemLayoutId = string;\n\n/**\n * Uniquely identifies an item in a PanelGroup.\n */\nexport interface PanelGroupItemId {\n panelGroupId: PanelGroupId;\n panelGroupItemLayoutId: PanelGroupItemLayoutId;\n}\n\n/*\n * Check if two PanelGroupItemId are equal\n */\nexport function isPanelGroupItemIdEqual(a?: PanelGroupItemId, b?: PanelGroupItemId): boolean {\n return a?.panelGroupId === b?.panelGroupId && a?.panelGroupItemLayoutId === b?.panelGroupItemLayoutId;\n}\n\n/**\n * Curried function for creating a PanelGroupSlice.\n */\nexport function createPanelGroupSlice(\n layouts: LayoutDefinition[]\n): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice> {\n const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);\n\n // Return the state creator function for Zustand\n return (set) => ({\n panelGroups,\n panelGroupOrder,\n\n swapPanelGroups(x, y): void {\n set((state) => {\n if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {\n throw new Error('index out of bound');\n }\n const xPanelGroup = state.panelGroupOrder[x];\n const yPanelGroup = state.panelGroupOrder[y];\n\n if (xPanelGroup === undefined || yPanelGroup === undefined) {\n throw new Error('panel group is undefined');\n }\n // assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups\n [state.panelGroupOrder[x], state.panelGroupOrder[y]] = [yPanelGroup, xPanelGroup];\n });\n },\n\n updatePanelGroupLayouts(panelGroupId, itemLayouts): void {\n set((state) => {\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Cannot find panel group ${panelGroupId}`);\n }\n group.itemLayouts = itemLayouts;\n });\n },\n });\n}\n\nexport function convertLayoutsToPanelGroups(\n layouts: LayoutDefinition[]\n): Pick<PanelGroupSlice, 'panelGroups' | 'panelGroupOrder'> {\n // Convert the initial layouts from the JSON\n const panelGroups: PanelGroupSlice['panelGroups'] = {};\n const panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'] = [];\n for (const layout of layouts) {\n const itemLayouts: PanelGroupDefinition['itemLayouts'] = [];\n const itemPanelKeys: PanelGroupDefinition['itemPanelKeys'] = {};\n\n // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels\n for (const item of layout.spec.items) {\n const panelGroupLayoutId = generateId().toString();\n itemLayouts.push({\n i: panelGroupLayoutId,\n w: item.width,\n h: item.height,\n x: item.x,\n y: item.y,\n });\n itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);\n }\n\n // Create the panel group and keep track of the ID order\n const panelGroupId = generateId();\n panelGroups[panelGroupId] = {\n id: panelGroupId,\n isCollapsed: layout.spec.display?.collapse?.open === false,\n title: layout.spec.display?.title,\n itemLayouts,\n itemPanelKeys,\n };\n panelGroupIdOrder.push(panelGroupId);\n }\n return {\n panelGroups,\n panelGroupOrder: panelGroupIdOrder,\n };\n}\n\n/**\n * Private helper function for creating an empty panel group.\n */\nexport function createEmptyPanelGroup(): PanelGroupDefinition {\n return {\n id: generateId(),\n title: undefined,\n isCollapsed: false,\n itemLayouts: [],\n itemPanelKeys: {},\n };\n}\n\n/**\n * Private helper function that modifies panel group state to add a new panel\n */\nexport function addPanelGroup(draft: WritableDraft<PanelGroupSlice>, newGroup: PanelGroupDefinition): void {\n draft.panelGroups[newGroup.id] = newGroup;\n draft.panelGroupOrder.unshift(newGroup.id);\n}\n"],"names":["getPanelKeyFromRef","generateId","isPanelGroupItemIdEqual","a","b","panelGroupId","panelGroupItemLayoutId","createPanelGroupSlice","layouts","panelGroups","panelGroupOrder","convertLayoutsToPanelGroups","set","swapPanelGroups","x","y","state","length","Error","xPanelGroup","yPanelGroup","undefined","updatePanelGroupLayouts","itemLayouts","group","panelGroupIdOrder","layout","itemPanelKeys","item","spec","items","panelGroupLayoutId","toString","push","i","w","width","h","height","content","id","isCollapsed","display","collapse","open","title","createEmptyPanelGroup","addPanelGroup","draft","newGroup","unshift"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,kBAAkB,QAAwC,mBAAmB;AAItF,SAASC,UAAU,QAAoB,WAAW;AAiDlD;;CAEC,GACD,OAAO,SAASC,wBAAwBC,CAAoB,EAAEC,CAAoB;IAChF,OAAOD,GAAGE,iBAAiBD,GAAGC,gBAAgBF,GAAGG,2BAA2BF,GAAGE;AACjF;AAEA;;CAEC,GACD,OAAO,SAASC,sBACdC,OAA2B;IAE3B,MAAM,EAAEC,WAAW,EAAEC,eAAe,EAAE,GAAGC,4BAA4BH;IAErE,gDAAgD;IAChD,OAAO,CAACI,MAAS,CAAA;YACfH;YACAC;YAEAG,iBAAgBC,CAAC,EAAEC,CAAC;gBAClBH,IAAI,CAACI;oBACH,IAAIF,IAAI,KAAKA,KAAKE,MAAMN,eAAe,CAACO,MAAM,IAAIF,IAAI,KAAKA,KAAKC,MAAMN,eAAe,CAACO,MAAM,EAAE;wBAC5F,MAAM,IAAIC,MAAM;oBAClB;oBACA,MAAMC,cAAcH,MAAMN,eAAe,CAACI,EAAE;oBAC5C,MAAMM,cAAcJ,MAAMN,eAAe,CAACK,EAAE;oBAE5C,IAAII,gBAAgBE,aAAaD,gBAAgBC,WAAW;wBAC1D,MAAM,IAAIH,MAAM;oBAClB;oBACA,8FAA8F;oBAC9F,CAACF,MAAMN,eAAe,CAACI,EAAE,EAAEE,MAAMN,eAAe,CAACK,EAAE,CAAC,GAAG;wBAACK;wBAAaD;qBAAY;gBACnF;YACF;YAEAG,yBAAwBjB,YAAY,EAAEkB,WAAW;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C,EAAEC,QAA8B;IACjGD,MAAMvC,WAAW,CAACwC,SAAST,EAAE,CAAC,GAAGS;IACjCD,MAAMtC,eAAe,CAACwC,OAAO,CAACD,SAAST,EAAE;AAC3C"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { getPanelKeyFromRef, LayoutDefinition, PanelGroupId } from '@perses-dev/core';\n\nimport { Layout } from 'react-grid-layout';\nimport { StateCreator } from 'zustand';\nimport { WritableDraft } from 'immer';\nimport { generateId, Middleware } from './common';\n\n/**\n * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.\n */\nexport interface PanelGroupSlice {\n /**\n * Panel groups indexed by their ID.\n */\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>;\n\n /**\n * An array of panel group IDs, representing their order in the dashboard.\n */\n panelGroupOrder: PanelGroupId[];\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Update the item layouts for a panel group when, for example, a panel is moved or resized.\n */\n updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;\n}\n\nexport interface PanelGroupDefinition {\n id: PanelGroupId;\n isCollapsed: boolean;\n title?: string;\n itemLayouts: PanelGroupItemLayout[];\n itemPanelKeys: Record<PanelGroupItemLayoutId, string>;\n}\n\nexport interface PanelGroupItemLayout extends Layout {\n i: PanelGroupItemLayoutId;\n}\n\nexport type PanelGroupItemLayoutId = string;\n\n/**\n * Uniquely identifies an item in a PanelGroup.\n */\nexport interface PanelGroupItemId {\n panelGroupId: PanelGroupId;\n panelGroupItemLayoutId: PanelGroupItemLayoutId;\n}\n\n/*\n * Check if two PanelGroupItemId are equal\n */\nexport function isPanelGroupItemIdEqual(a?: PanelGroupItemId, b?: PanelGroupItemId): boolean {\n return a?.panelGroupId === b?.panelGroupId && a?.panelGroupItemLayoutId === b?.panelGroupItemLayoutId;\n}\n\n/**\n * Curried function for creating a PanelGroupSlice.\n */\nexport function createPanelGroupSlice(\n layouts: LayoutDefinition[]\n): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice> {\n const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);\n\n // Return the state creator function for Zustand\n return (set) => ({\n panelGroups,\n panelGroupOrder,\n\n swapPanelGroups(x, y): void {\n set((state) => {\n if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {\n throw new Error('index out of bound');\n }\n const xPanelGroup = state.panelGroupOrder[x];\n const yPanelGroup = state.panelGroupOrder[y];\n\n if (xPanelGroup === undefined || yPanelGroup === undefined) {\n throw new Error('panel group is undefined');\n }\n // assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups\n [state.panelGroupOrder[x], state.panelGroupOrder[y]] = [yPanelGroup, xPanelGroup];\n });\n },\n\n updatePanelGroupLayouts(panelGroupId, itemLayouts): void {\n set((state) => {\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Cannot find panel group ${panelGroupId}`);\n }\n group.itemLayouts = itemLayouts;\n });\n },\n });\n}\n\nexport function convertLayoutsToPanelGroups(\n layouts: LayoutDefinition[]\n): Pick<PanelGroupSlice, 'panelGroups' | 'panelGroupOrder'> {\n // Convert the initial layouts from the JSON\n const panelGroups: PanelGroupSlice['panelGroups'] = {};\n const panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'] = [];\n for (const layout of layouts) {\n const itemLayouts: PanelGroupDefinition['itemLayouts'] = [];\n const itemPanelKeys: PanelGroupDefinition['itemPanelKeys'] = {};\n\n // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels\n for (const item of layout.spec.items) {\n const panelGroupLayoutId = generateId().toString();\n itemLayouts.push({\n i: panelGroupLayoutId,\n w: item.width,\n h: item.height,\n x: item.x,\n y: item.y,\n });\n itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);\n }\n\n // Create the panel group and keep track of the ID order\n const panelGroupId = generateId();\n panelGroups[panelGroupId] = {\n id: panelGroupId,\n isCollapsed: layout.spec.display?.collapse?.open === false,\n title: layout.spec.display?.title,\n itemLayouts,\n itemPanelKeys,\n };\n panelGroupIdOrder.push(panelGroupId);\n }\n return {\n panelGroups,\n panelGroupOrder: panelGroupIdOrder,\n };\n}\n\n/**\n * Private helper function for creating an empty panel group.\n */\nexport function createEmptyPanelGroup(): PanelGroupDefinition {\n return {\n id: generateId(),\n title: undefined,\n isCollapsed: false,\n itemLayouts: [],\n itemPanelKeys: {},\n };\n}\n\n/**\n * Private helper function that modifies panel group state to add a new panel\n */\nexport function addPanelGroup(draft: WritableDraft<PanelGroupSlice>, newGroup: PanelGroupDefinition): void {\n draft.panelGroups[newGroup.id] = newGroup;\n draft.panelGroupOrder.unshift(newGroup.id);\n}\n"],"names":["getPanelKeyFromRef","generateId","isPanelGroupItemIdEqual","a","b","panelGroupId","panelGroupItemLayoutId","createPanelGroupSlice","layouts","panelGroups","panelGroupOrder","convertLayoutsToPanelGroups","set","swapPanelGroups","x","y","state","length","Error","xPanelGroup","yPanelGroup","undefined","updatePanelGroupLayouts","itemLayouts","group","panelGroupIdOrder","layout","itemPanelKeys","item","spec","items","panelGroupLayoutId","toString","push","i","w","width","h","height","content","id","isCollapsed","display","collapse","open","title","createEmptyPanelGroup","addPanelGroup","draft","newGroup","unshift"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,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A,OAAO,SAASZ,4BACdH,OAA2B;IAE3B,4CAA4C;IAC5C,MAAMC,cAA8C,CAAC;IACrD,MAAMgB,oBAAwD,EAAE;IAChE,KAAK,MAAMC,UAAUlB,QAAS;QAC5B,MAAMe,cAAmD,EAAE;QAC3D,MAAMI,gBAAuD,CAAC;QAE9D,6GAA6G;QAC7G,KAAK,MAAMC,QAAQF,OAAOG,IAAI,CAACC,KAAK,CAAE;YACpC,MAAMC,qBAAqB9B,aAAa+B,QAAQ;YAChDT,YAAYU,IAAI,CAAC;gBACfC,GAAGH;gBACHI,GAAGP,KAAKQ,KAAK;gBACbC,GAAGT,KAAKU,MAAM;gBACdxB,GAAGc,KAAKd,CAAC;gBACTC,GAAGa,KAAKb,CAAC;YACX;YACAY,aAAa,CAACI,mBAAmB,GAAG/B,mBAAmB4B,KAAKW,OAAO;QACrE;QAEA,wDAAwD;QACxD,MAAMlC,eAAeJ;QACrBQ,WAAW,CAACJ,aAAa,GAAG;YAC1BmC,IAAInC;YACJoC,aAAaf,OAAOG,IAAI,CAACa,OAAO,EAAEC,UAAUC,SAAS;YACrDC,OAAOnB,OAAOG,IAAI,CAACa,OAAO,EAAEG;YAC5BtB;YACAI;QACF;QACAF,kBAAkBQ,IAAI,CAAC5B;IACzB;IACA,OAAO;QACLI;QACAC,iBAAiBe;IACnB;AACF;AAEA;;CAEC,GACD,OAAO,SAASqB;IACd,OAAO;QACLN,IAAIvC;QACJ4C,OAAOxB;QACPoB,aAAa;QACblB,aAAa,EAAE;QACfI,eAAe,CAAC;IAClB;AACF;AAEA;;CAEC,GACD,OAAO,SAASoB,cAAcC,KAAqC,EAAEC,QAA8B;IACjGD,MAAMvC,WAAW,CAACwC,SAAST,EAAE,CAAC,GAAGS;IACjCD,MAAMtC,eAAe,CAACwC,OAAO,CAACD,SAAST,EAAE;AAC3C"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/DatasourceStoreProvider.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ReactElement, ReactNode, useCallback, useMemo, useState } from 'react';\nimport {\n DashboardResource,\n DashboardSpec,\n DatasourceResource,\n DatasourceSelector,\n DatasourceSpec,\n GlobalDatasourceResource,\n useEvent,\n EphemeralDashboardResource,\n DatasourceDefinition,\n} from '@perses-dev/core';\nimport {\n DatasourceStoreContext,\n DatasourceStore,\n DatasourceSelectItemGroup,\n usePluginRegistry,\n DatasourceClient,\n DatasourceSelectItem,\n} from '@perses-dev/plugin-system';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource?: DashboardResource | EphemeralDashboardResource;\n projectName?: string;\n datasourceApi: DatasourceApi;\n children?: ReactNode;\n savedDatasources?: Record<string, DatasourceSpec>;\n onCreate?: (client: DatasourceClient) => DatasourceClient;\n}\n\nexport type BuildDatasourceProxyUrlParams = {\n project?: string;\n dashboard?: string;\n name: string;\n};\n\nexport type BuildDatasourceProxyUrlFunc = (p: BuildDatasourceProxyUrlParams) => string;\n\n/**\n * The external API for fetching datasource resources\n */\nexport interface DatasourceApi {\n buildProxyUrl?: BuildDatasourceProxyUrlFunc;\n getDatasource: (project: string, selector: DatasourceSelector) => Promise<DatasourceResource | undefined>;\n getGlobalDatasource: (selector: DatasourceSelector) => Promise<GlobalDatasourceResource | undefined>;\n listDatasources: (project: string, pluginKind?: string) => Promise<DatasourceResource[]>;\n listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasourceResource[]>;\n}\n\n/**\n * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.\n */\nexport function DatasourceStoreProvider(props: DatasourceStoreProviderProps): ReactElement {\n const { projectName, datasourceApi, onCreate, children } = props;\n const [dashboardResource, setDashboardResource] = useState(props.dashboardResource);\n const [savedDatasources, setSavedDatasources] = useState<Record<string, DatasourceSpec>>(\n props.savedDatasources ?? {}\n );\n const project = projectName ?? dashboardResource?.metadata.project;\n\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n const findDatasource = useEvent(async (selector: DatasourceSelector) => {\n // Try to find it in dashboard spec\n if (dashboardResource) {\n const { datasources } = dashboardResource.spec;\n const dashboardDatasource = findDashboardDatasource(datasources, selector);\n if (dashboardDatasource !== undefined) {\n return {\n spec: dashboardDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: dashboardResource.metadata.project,\n dashboard: dashboardResource.metadata.name,\n name: dashboardDatasource.name,\n }),\n };\n }\n }\n\n if (project) {\n // Try to find it at the project level as a Datasource resource\n const datasource = await datasourceApi.getDatasource(project, selector);\n if (datasource !== undefined) {\n return {\n spec: datasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: datasource.metadata.project,\n name: datasource.metadata.name,\n }),\n };\n }\n }\n\n // Try to find it at the global level as a GlobalDatasource resource\n const globalDatasource = await datasourceApi.getGlobalDatasource(selector);\n if (globalDatasource !== undefined) {\n return {\n spec: globalDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n name: globalDatasource.metadata.name,\n }),\n };\n }\n\n throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);\n });\n\n // Gets a datasource spec for a given selector\n const getDatasource = useCallback(\n async (selector: DatasourceSelector): Promise<DatasourceSpec> => {\n const { spec } = await findDatasource(selector);\n return spec;\n },\n [findDatasource]\n );\n\n // Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client\n const getDatasourceClient = useCallback(\n async function getClient<Client extends DatasourceClient>(selector: DatasourceSelector): Promise<Client> {\n const { kind } = selector;\n const [{ spec, proxyUrl }, plugin] = await Promise.all([findDatasource(selector), getPlugin('Datasource', kind)]);\n\n // allows extending client\n const client = plugin.createClient(spec.plugin.spec, { proxyUrl }) as Client;\n if (onCreate !== undefined) {\n return onCreate(client) as Client;\n }\n return client;\n },\n [findDatasource, getPlugin, onCreate]\n );\n\n const listDatasourceSelectItems = useEvent(\n async (datasourcePluginName: string): Promise<DatasourceSelectItemGroup[]> => {\n const [pluginMetadata, datasources, globalDatasources] = await Promise.all([\n listPluginMetadata(['Datasource']),\n project ? datasourceApi.listDatasources(project, datasourcePluginName) : [],\n datasourceApi.listGlobalDatasources(datasourcePluginName),\n ]);\n\n // Find the metadata for the plugin type they asked for, so we can use it for the name of the default datasource\n const datasourcePluginMetadata = pluginMetadata.find((metadata) => metadata.spec.name === datasourcePluginName);\n if (datasourcePluginMetadata === undefined) {\n throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginName}'`);\n }\n\n // Get helper for computing results properly\n const { results, addItem } = buildDatasourceSelectItemGroups(datasourcePluginMetadata.spec.display.name);\n\n // Start with dashboard datasources with the highest precedence\n if (dashboardResource?.spec.datasources) {\n for (const selectorName in dashboardResource.spec.datasources) {\n const spec = dashboardResource.spec.datasources[selectorName];\n if (spec === undefined || spec.plugin.kind !== datasourcePluginName) continue;\n\n const saved = selectorName in savedDatasources;\n addItem({ spec, selectorName, selectorGroup: 'dashboard', saved });\n }\n }\n\n // Now look at project-level datasources\n for (const datasource of datasources) {\n const selectorName = datasource.metadata.name;\n addItem({\n spec: datasource.spec,\n selectorName,\n selectorGroup: 'project',\n editLink: `/projects/${project}/datasources`,\n });\n }\n\n // And finally global datasources\n for (const globalDatasource of globalDatasources) {\n const selectorName = globalDatasource.metadata.name;\n addItem({ spec: globalDatasource.spec, selectorName, selectorGroup: 'global', editLink: '/admin/datasources' });\n }\n\n return results;\n }\n );\n\n const getLocalDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return dashboardResource?.spec.datasources ?? {};\n }, [dashboardResource]);\n\n const getSavedDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return savedDatasources;\n }, [savedDatasources]);\n\n const setLocalDatasources = useCallback(\n (datasources: Record<string, DatasourceSpec>) => {\n if (dashboardResource) {\n setDashboardResource(\n dashboardResource.kind === 'Dashboard'\n ? ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as DashboardResource)\n : ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as EphemeralDashboardResource)\n );\n }\n },\n [dashboardResource]\n );\n\n const ctxValue: DatasourceStore = useMemo(\n () =>\n ({\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n setSavedDatasources,\n getSavedDatasources,\n listDatasourceSelectItems,\n }) as DatasourceStore,\n [\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n listDatasourceSelectItems,\n setSavedDatasources,\n getSavedDatasources,\n ]\n );\n\n return <DatasourceStoreContext.Provider value={ctxValue}>{children}</DatasourceStoreContext.Provider>;\n}\n\nfunction buildDatasourceProxyUrl(api: DatasourceApi, params: BuildDatasourceProxyUrlParams): string {\n return api.buildProxyUrl ? api.buildProxyUrl(params) : '';\n}\n\n// Helper to find a datasource in the list embedded in a dashboard spec\nfunction findDashboardDatasource(\n dashboardDatasources: DashboardSpec['datasources'],\n selector: DatasourceSelector\n): DatasourceDefinition | undefined {\n if (dashboardDatasources === undefined) return undefined;\n\n // If using a name in the selector...\n if (selector.name !== undefined) {\n const named = dashboardDatasources[selector.name];\n if (named === undefined) return undefined;\n return named.plugin.kind === selector.kind ? { name: selector.name, spec: named } : undefined;\n }\n\n // If only using a kind, try to find one with that kind that is the default\n const result = Object.entries(dashboardDatasources).find(\n (entry) => entry[1].plugin.kind === selector.kind && entry[1].default\n );\n if (!result) {\n return undefined;\n }\n return { name: result[0], spec: result[1] };\n}\n\ninterface AddDatasouceSelectItemParams {\n spec: DatasourceSpec;\n selectorName: string;\n selectorGroup?: string;\n editLink?: string;\n saved?: boolean;\n}\n\ntype AddDatasourceSelectItemFunc = (params: AddDatasouceSelectItemParams) => void;\n\n/**\n * Helper for building a list of DatasourceSelectItemGroup results.\n * @param pluginDisplayName\n */\nfunction buildDatasourceSelectItemGroups(pluginDisplayName: string): {\n results: DatasourceSelectItemGroup[];\n addItem: AddDatasourceSelectItemFunc;\n} {\n const results: DatasourceSelectItemGroup[] = [];\n const usedNames = new Set<string>();\n let isFirst = true;\n let explicitDefaultAdded = false;\n const groupIndices: Record<string, number> = {};\n let currentGroupIndex = 1; // 0 is the default group, always there as it contains at least the first item.\n\n const addItem = ({\n spec,\n selectorName,\n selectorGroup: group,\n editLink,\n saved,\n }: AddDatasouceSelectItemParams): void => {\n group = group ?? '';\n\n // Ensure the default group is always present as soon as an item is added.\n if (isFirst) {\n results.push({\n group: `Default ${pluginDisplayName}`,\n items: [],\n });\n }\n\n // Create the group if necessary\n let selectItemGroup = results[groupIndices[group] ?? -1];\n if (!selectItemGroup) {\n groupIndices[group] = currentGroupIndex;\n selectItemGroup = { items: [], group, editLink };\n results[currentGroupIndex] = selectItemGroup;\n currentGroupIndex++;\n }\n\n // Add item to the group\n const isOverridden = usedNames.has(selectorName);\n selectItemGroup.items.push({\n name: spec.display?.name ?? selectorName,\n overridden: isOverridden,\n saved,\n selector: {\n kind: spec.plugin.kind,\n name: selectorName,\n group,\n },\n });\n usedNames.add(selectorName);\n\n const isExplicitDefault = !isOverridden && spec.default && !explicitDefaultAdded;\n if (results[0] && (isFirst || isExplicitDefault)) {\n // If we haven't added a default yet and this is a default, add default option to the beginning of the results\n results[0].items = [\n {\n name: `Default (${selectorName} from ${group})`,\n selector: {\n kind: spec.plugin.kind,\n },\n },\n ];\n // We consider that we added the default datasource only if it has been explicitly set as default.\n // If we add this datasource as default just because it's the first, it still needs to be overridable by\n // another datasource explicitly set as default.\n explicitDefaultAdded = isExplicitDefault;\n }\n\n // At the end, we make sure the overriding item(s) is well flagged so\n if (isOverridden) {\n for (let i = explicitDefaultAdded ? 1 : 0; i < currentGroupIndex; i++) {\n (results[i]?.items ?? [])\n .filter((item: DatasourceSelectItem) => item.selector.name === selectorName)\n .forEach((item: DatasourceSelectItem) => {\n item.overriding = true;\n });\n }\n }\n\n isFirst = false;\n };\n\n return { results, addItem };\n}\n"],"names":["useCallback","useMemo","useState","useEvent","DatasourceStoreContext","usePluginRegistry","DatasourceStoreProvider","props","projectName","datasourceApi","onCreate","children","dashboardResource","setDashboardResource","savedDatasources","setSavedDatasources","project","metadata","getPlugin","listPluginMetadata","findDatasource","selector","datasources","spec","dashboardDatasource","findDashboardDatasource","undefined","proxyUrl","buildDatasourceProxyUrl","dashboard","name","datasource","getDatasource","globalDatasource","getGlobalDatasource","Error","kind","getDatasourceClient","getClient","plugin","Promise","all","client","createClient","listDatasourceSelectItems","datasourcePluginName","pluginMetadata","globalDatasources","listDatasources","listGlobalDatasources","datasourcePluginMetadata","find","results","addItem","buildDatasourceSelectItemGroups","display","selectorName","saved","selectorGroup","editLink","getLocalDatasources","getSavedDatasources","setLocalDatasources","ctxValue","Provider","value","api","params","buildProxyUrl","dashboardDatasources","named","result","Object","entries","entry","default","pluginDisplayName","usedNames","Set","isFirst","explicitDefaultAdded","groupIndices","currentGroupIndex","group","push","items","selectItemGroup","isOverridden","has","overridden","add","isExplicitDefault","i","filter","item","forEach","overriding"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAAkCA,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAChF,SAOEC,QAAQ,QAGH,mBAAmB;AAC1B,SACEC,sBAAsB,EAGtBC,iBAAiB,QAGZ,4BAA4B;AA8BnC;;CAEC,GACD,OAAO,SAASC,wBAAwBC,KAAmC;IACzE,MAAM,EAAEC,WAAW,EAAEC,aAAa,EAAEC,QAAQ,EA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M,EAAE2B,MAAM,CAAC,CAAC;oBAC/C9D,UAAU;wBACRe,MAAMb,KAAKgB,MAAM,CAACH,IAAI;oBACxB;gBACF;aACD;YACD,kGAAkG;YAClG,wGAAwG;YACxG,gDAAgD;YAChD4C,uBAAuBW;QACzB;QAEA,qEAAqE;QACrE,IAAIJ,cAAc;YAChB,IAAK,IAAIK,IAAIZ,uBAAuB,IAAI,GAAGY,IAAIV,mBAAmBU,IAAK;gBACpExC,CAAAA,OAAO,CAACwC,EAAE,EAAEP,SAAS,EAAE,AAAD,EACpBQ,MAAM,CAAC,CAACC,OAA+BA,KAAKzE,QAAQ,CAACS,IAAI,KAAK0B,cAC9DuC,OAAO,CAAC,CAACD;oBACRA,KAAKE,UAAU,GAAG;gBACpB;YACJ;QACF;QAEAjB,UAAU;IACZ;IAEA,OAAO;QAAE3B;QAASC;IAAQ;AAC5B"}
1
+ {"version":3,"sources":["../../src/context/DatasourceStoreProvider.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ReactElement, ReactNode, useCallback, useMemo, useState } from 'react';\nimport {\n DashboardResource,\n DashboardSpec,\n DatasourceResource,\n DatasourceSelector,\n DatasourceSpec,\n GlobalDatasourceResource,\n useEvent,\n EphemeralDashboardResource,\n DatasourceDefinition,\n} from '@perses-dev/core';\nimport {\n DatasourceStoreContext,\n DatasourceStore,\n DatasourceSelectItemGroup,\n usePluginRegistry,\n DatasourceClient,\n DatasourceSelectItem,\n} from '@perses-dev/plugin-system';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource?: DashboardResource | EphemeralDashboardResource;\n projectName?: string;\n datasourceApi: DatasourceApi;\n children?: ReactNode;\n savedDatasources?: Record<string, DatasourceSpec>;\n onCreate?: (client: DatasourceClient) => DatasourceClient;\n}\n\nexport type BuildDatasourceProxyUrlParams = {\n project?: string;\n dashboard?: string;\n name: string;\n};\n\nexport type BuildDatasourceProxyUrlFunc = (p: BuildDatasourceProxyUrlParams) => string;\n\n/**\n * The external API for fetching datasource resources\n */\nexport interface DatasourceApi {\n buildProxyUrl?: BuildDatasourceProxyUrlFunc;\n getDatasource: (project: string, selector: DatasourceSelector) => Promise<DatasourceResource | undefined>;\n getGlobalDatasource: (selector: DatasourceSelector) => Promise<GlobalDatasourceResource | undefined>;\n listDatasources: (project: string, pluginKind?: string) => Promise<DatasourceResource[]>;\n listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasourceResource[]>;\n}\n\n/**\n * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.\n */\nexport function DatasourceStoreProvider(props: DatasourceStoreProviderProps): ReactElement {\n const { projectName, datasourceApi, onCreate, children } = props;\n const [dashboardResource, setDashboardResource] = useState(props.dashboardResource);\n const [savedDatasources, setSavedDatasources] = useState<Record<string, DatasourceSpec>>(\n props.savedDatasources ?? {}\n );\n const project = projectName ?? dashboardResource?.metadata.project;\n\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n const findDatasource = useEvent(async (selector: DatasourceSelector) => {\n // Try to find it in dashboard spec\n if (dashboardResource) {\n const { datasources } = dashboardResource.spec;\n const dashboardDatasource = findDashboardDatasource(datasources, selector);\n if (dashboardDatasource !== undefined) {\n return {\n spec: dashboardDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: dashboardResource.metadata.project,\n dashboard: dashboardResource.metadata.name,\n name: dashboardDatasource.name,\n }),\n };\n }\n }\n\n if (project) {\n // Try to find it at the project level as a Datasource resource\n const datasource = await datasourceApi.getDatasource(project, selector);\n if (datasource !== undefined) {\n return {\n spec: datasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: datasource.metadata.project,\n name: datasource.metadata.name,\n }),\n };\n }\n }\n\n // Try to find it at the global level as a GlobalDatasource resource\n const globalDatasource = await datasourceApi.getGlobalDatasource(selector);\n if (globalDatasource !== undefined) {\n return {\n spec: globalDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n name: globalDatasource.metadata.name,\n }),\n };\n }\n\n throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);\n });\n\n // Gets a datasource spec for a given selector\n const getDatasource = useCallback(\n async (selector: DatasourceSelector): Promise<DatasourceSpec> => {\n const { spec } = await findDatasource(selector);\n return spec;\n },\n [findDatasource]\n );\n\n // Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client\n const getDatasourceClient = useCallback(\n async function getClient<Client extends DatasourceClient>(selector: DatasourceSelector): Promise<Client> {\n const { kind } = selector;\n const [{ spec, proxyUrl }, plugin] = await Promise.all([findDatasource(selector), getPlugin('Datasource', kind)]);\n\n // allows extending client\n const client = plugin.createClient(spec.plugin.spec, { proxyUrl }) as Client;\n if (onCreate !== undefined) {\n return onCreate(client) as Client;\n }\n return client;\n },\n [findDatasource, getPlugin, onCreate]\n );\n\n const listDatasourceSelectItems = useEvent(\n async (datasourcePluginName: string): Promise<DatasourceSelectItemGroup[]> => {\n const [pluginMetadata, datasources, globalDatasources] = await Promise.all([\n listPluginMetadata(['Datasource']),\n project ? datasourceApi.listDatasources(project, datasourcePluginName) : [],\n datasourceApi.listGlobalDatasources(datasourcePluginName),\n ]);\n\n // Find the metadata for the plugin type they asked for, so we can use it for the name of the default datasource\n const datasourcePluginMetadata = pluginMetadata.find((metadata) => metadata.spec.name === datasourcePluginName);\n if (datasourcePluginMetadata === undefined) {\n throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginName}'`);\n }\n\n // Get helper for computing results properly\n const { results, addItem } = buildDatasourceSelectItemGroups(datasourcePluginMetadata.spec.display.name);\n\n // Start with dashboard datasources with the highest precedence\n if (dashboardResource?.spec.datasources) {\n for (const selectorName in dashboardResource.spec.datasources) {\n const spec = dashboardResource.spec.datasources[selectorName];\n if (spec === undefined || spec.plugin.kind !== datasourcePluginName) continue;\n\n const saved = selectorName in savedDatasources;\n addItem({ spec, selectorName, selectorGroup: 'dashboard', saved });\n }\n }\n\n // Now look at project-level datasources\n for (const datasource of datasources) {\n const selectorName = datasource.metadata.name;\n addItem({\n spec: datasource.spec,\n selectorName,\n selectorGroup: 'project',\n editLink: `/projects/${project}/datasources`,\n });\n }\n\n // And finally global datasources\n for (const globalDatasource of globalDatasources) {\n const selectorName = globalDatasource.metadata.name;\n addItem({ spec: globalDatasource.spec, selectorName, selectorGroup: 'global', editLink: '/admin/datasources' });\n }\n\n return results;\n }\n );\n\n const getLocalDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return dashboardResource?.spec.datasources ?? {};\n }, [dashboardResource]);\n\n const getSavedDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return savedDatasources;\n }, [savedDatasources]);\n\n const setLocalDatasources = useCallback(\n (datasources: Record<string, DatasourceSpec>) => {\n if (dashboardResource) {\n setDashboardResource(\n dashboardResource.kind === 'Dashboard'\n ? ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as DashboardResource)\n : ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as EphemeralDashboardResource)\n );\n }\n },\n [dashboardResource]\n );\n\n const ctxValue: DatasourceStore = useMemo(\n () =>\n ({\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n setSavedDatasources,\n getSavedDatasources,\n listDatasourceSelectItems,\n }) as DatasourceStore,\n [\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n listDatasourceSelectItems,\n setSavedDatasources,\n getSavedDatasources,\n ]\n );\n\n return <DatasourceStoreContext.Provider value={ctxValue}>{children}</DatasourceStoreContext.Provider>;\n}\n\nfunction buildDatasourceProxyUrl(api: DatasourceApi, params: BuildDatasourceProxyUrlParams): string {\n return api.buildProxyUrl ? api.buildProxyUrl(params) : '';\n}\n\n// Helper to find a datasource in the list embedded in a dashboard spec\nfunction findDashboardDatasource(\n dashboardDatasources: DashboardSpec['datasources'],\n selector: DatasourceSelector\n): DatasourceDefinition | undefined {\n if (dashboardDatasources === undefined) return undefined;\n\n // If using a name in the selector...\n if (selector.name !== undefined) {\n const named = dashboardDatasources[selector.name];\n if (named === undefined) return undefined;\n return named.plugin.kind === selector.kind ? { name: selector.name, spec: named } : undefined;\n }\n\n // If only using a kind, try to find one with that kind that is the default\n const result = Object.entries(dashboardDatasources).find(\n (entry) => entry[1].plugin.kind === selector.kind && entry[1].default\n );\n if (!result) {\n return undefined;\n }\n return { name: result[0], spec: result[1] };\n}\n\ninterface AddDatasouceSelectItemParams {\n spec: DatasourceSpec;\n selectorName: string;\n selectorGroup?: string;\n editLink?: string;\n saved?: boolean;\n}\n\ntype AddDatasourceSelectItemFunc = (params: AddDatasouceSelectItemParams) => void;\n\n/**\n * Helper for building a list of DatasourceSelectItemGroup results.\n * @param pluginDisplayName\n */\nfunction buildDatasourceSelectItemGroups(pluginDisplayName: string): {\n results: DatasourceSelectItemGroup[];\n addItem: AddDatasourceSelectItemFunc;\n} {\n const results: DatasourceSelectItemGroup[] = [];\n const usedNames = new Set<string>();\n let isFirst = true;\n let explicitDefaultAdded = false;\n const groupIndices: Record<string, number> = {};\n let currentGroupIndex = 1; // 0 is the default group, always there as it contains at least the first item.\n\n const addItem = ({\n spec,\n selectorName,\n selectorGroup: group,\n editLink,\n saved,\n }: AddDatasouceSelectItemParams): void => {\n group = group ?? '';\n\n // Ensure the default group is always present as soon as an item is added.\n if (isFirst) {\n results.push({\n group: `Default ${pluginDisplayName}`,\n items: [],\n });\n }\n\n // Create the group if necessary\n let selectItemGroup = results[groupIndices[group] ?? -1];\n if (!selectItemGroup) {\n groupIndices[group] = currentGroupIndex;\n selectItemGroup = { items: [], group, editLink };\n results[currentGroupIndex] = selectItemGroup;\n currentGroupIndex++;\n }\n\n // Add item to the group\n const isOverridden = usedNames.has(selectorName);\n selectItemGroup.items.push({\n name: spec.display?.name ?? selectorName,\n overridden: isOverridden,\n saved,\n selector: {\n kind: spec.plugin.kind,\n name: selectorName,\n group,\n },\n });\n usedNames.add(selectorName);\n\n const isExplicitDefault = !isOverridden && spec.default && !explicitDefaultAdded;\n if (results[0] && (isFirst || isExplicitDefault)) {\n // If we haven't added a default yet and this is a default, add default option to the beginning of the results\n results[0].items = [\n {\n name: `Default (${selectorName} from ${group})`,\n selector: {\n kind: spec.plugin.kind,\n },\n },\n ];\n // We consider that we added the default datasource only if it has been explicitly set as default.\n // If we add this datasource as default just because it's the first, it still needs to be overridable by\n // another datasource explicitly set as default.\n explicitDefaultAdded = isExplicitDefault;\n }\n\n // At the end, we make sure the overriding item(s) is well flagged so\n if (isOverridden) {\n for (let i = explicitDefaultAdded ? 1 : 0; i < currentGroupIndex; i++) {\n (results[i]?.items ?? [])\n .filter((item: DatasourceSelectItem) => item.selector.name === selectorName)\n .forEach((item: DatasourceSelectItem) => {\n item.overriding = true;\n });\n }\n }\n\n isFirst = false;\n };\n\n return { results, addItem };\n}\n"],"names":["useCallback","useMemo","useState","useEvent","DatasourceStoreContext","usePluginRegistry","DatasourceStoreProvider","props","projectName","datasourceApi","onCreate","children","dashboardResource","setDashboardResource","savedDatasources","setSavedDatasources","project","metadata","getPlugin","listPluginMetadata","findDatasource","selector","datasources","spec","dashboardDatasource","findDashboardDatasource","undefined","proxyUrl","buildDatasourceProxyUrl","dashboard","name","datasource","getDatasource","globalDatasource","getGlobalDatasource","Error","kind","getDatasourceClient","getClient","plugin","Promise","all","client","createClient","listDatasourceSelectItems","datasourcePluginName","pluginMetadata","globalDatasources","listDatasources","listGlobalDatasources","datasourcePluginMetadata","find","results","addItem","buildDatasourceSelectItemGroups","display","selectorName","saved","selectorGroup","editLink","getLocalDatasources","getSavedDatasources","setLocalDatasources","ctxValue","Provider","value","api","params","buildProxyUrl","dashboardDatasources","named","result","Object","entries","entry","default","pluginDisplayName","usedNames","Set","isFirst","explicitDefaultAdded","groupIndices","currentGroupIndex","group","push","items","selectItemGroup","isOverridden","has","overridden","add","isExplicitDefault","i","filter","item","forEach","overriding"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAAkCA,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAChF,SAOEC,QAAQ,QAGH,mBAAmB;AAC1B,SACEC,sBAAsB,EAGtBC,iBAAiB,QAGZ,4BAA4B;AA8BnC;;CAEC,GACD,OAAO,SAASC,wBAAwBC,KAAmC;IACzE,MAAM,EAAEC,WAAW,EAAEC,aAAa,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGJ;IAC3D,MAAM,CAACK,mBAAmBC,qBAAqB,GAAGX,SAASK,MAAMK,iBAAiB;IAClF,MAAM,CAACE,kBAAkBC,oBAAoB,GAAGb,SAC9CK,MAAMO,gBAAgB,IAAI,CAAC;IAE7B,MAAME,UAAUR,eAAeI,mBAAmBK,SAASD;IAE3D,MAAM,EAAEE,SAAS,EAAEC,kBAAkB,EAAE,GAAGd;IAE1C,MAAMe,iBAAiBjB,SAAS,OAAOkB;QACrC,mCAAmC;QACnC,IAAIT,mBAAmB;YACrB,MAAM,EAAEU,WAAW,EAAE,GAAGV,kBAAkBW,IAAI;YAC9C,MAAMC,sBAAsBC,wBAAwBH,aAAaD;YACjE,IAAIG,wBAAwBE,WAAW;gBACrC,OAAO;oBACLH,MAAMC,oBAAoBD,IAAI;oBAC9BI,UAAUC,wBAAwBnB,eAAe;wBAC/CO,SAASJ,kBAAkBK,QAAQ,CAACD,OAAO;wBAC3Ca,WA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,MAAM,CAAC;KACtB,CAAC;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,kBAAkB,EAAE,CAAC;CACnC,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,SAAS,CAAC;IACpB,0BAA0B,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAClD,2BAA2B,CAAC,EAAE,0BAA0B,EAAE,CAAC;IAC3D,0BAA0B,CAAC,EAAE,yBAAyB,EAAE,CAAC;CAC1D;AAGD,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,0BAA+B,EAC/B,2BAAgC,EAChC,0BAA+B,GAChC,EAAE,qBAAqB,GAAG,YAAY,CAQtC;AAED,wBAAgB,+BAA+B,CAAC,EAC9C,QAAQ,EACR,0BAA+B,EAC/B,2BAAgC,EAChC,0BAA0B,EAAE,gBAAqB,GAClD,EAAE,qBAAqB,GAAG,YAAY,CAYtC"}
1
+ {"version":3,"file":"VariableProvider.d.ts","sourceRoot":"","sources":["../../../src/context/VariableProvider/VariableProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAiB,YAAY,EAAE,SAAS,EAAiC,MAAM,OAAO,CAAC;AAC9F,OAAO,EAAe,QAAQ,EAAY,MAAM,SAAS,CAAC;AAM1D,OAAO,EAEL,gBAAgB,EAChB,aAAa,EACb,qBAAqB,EACrB,cAAc,EAGf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,YAAY,EACZ,aAAa,EACb,kBAAkB,EAGlB,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;AAK1B;;;;;;GAMG;AACH,KAAK,uBAAuB,GAAG;IAC7B;;;;;;;;OAQG;IACH,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C;;;;;;;;;;OAUG;IACH,2BAA2B,EAAE,0BAA0B,EAAE,CAAC;IAC1D;;;;OAIG;IACH,aAAa,EAAE,qBAAqB,CAAC;IACrC;;;;;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 -16,7 +16,8 @@ import { createStore, useStore } from 'zustand';
16
16
  import { useStoreWithEqualityFn } from 'zustand/traditional';
17
17
  import { immer } from 'zustand/middleware/immer';
18
18
  import { devtools } from 'zustand/middleware';
19
- import produce from 'immer';
19
+ import { shallow } from 'zustand/shallow';
20
+ import { produce } from 'immer';
20
21
  import { VariableContext, BuiltinVariableContext, useTimeRange } from '@perses-dev/plugin-system';
21
22
  import { DEFAULT_ALL_VALUE as ALL_VALUE, formatDuration, intervalToPrometheusDuration } from '@perses-dev/core';
22
23
  import { checkSavedDefaultVariableStatus, findVariableDefinitionByName, mergeVariableDefinitions } from './utils';
@@ -88,7 +89,7 @@ export function useVariableDefinitionStates(variableNames) {
88
89
  }
89
90
  export function useVariableDefinitionActions() {
90
91
  const store = useVariableDefinitionStoreCtx();
91
- return useStore(store, (s)=>{
92
+ return useStoreWithEqualityFn(store, (s)=>{
92
93
  return {
93
94
  setVariableValue: s.setVariableValue,
94
95
  setVariableLoading: s.setVariableLoading,
@@ -97,7 +98,7 @@ export function useVariableDefinitionActions() {
97
98
  setVariableDefaultValues: s.setVariableDefaultValues,
98
99
  getSavedVariablesStatus: s.getSavedVariablesStatus
99
100
  };
100
- });
101
+ }, shallow);
101
102
  }
102
103
  export function useVariableDefinitions() {
103
104
  const store = useVariableDefinitionStoreCtx();
@@ -333,10 +334,10 @@ function createVariableDefinitionStore({ initialVariableDefinitions = [], extern
333
334
  }
334
335
  // TODO: merge the different providers related to Variables under a single one (and keep "VariableProvider" as a name)
335
336
  export function VariableProvider({ children, initialVariableDefinitions = [], externalVariableDefinitions = [], builtinVariableDefinitions = [] }) {
336
- const [store] = useState(createVariableDefinitionStore({
337
- initialVariableDefinitions,
338
- externalVariableDefinitions
339
- }));
337
+ const [store] = useState(()=>createVariableDefinitionStore({
338
+ initialVariableDefinitions,
339
+ externalVariableDefinitions
340
+ }));
340
341
  return /*#__PURE__*/ _jsx(VariableDefinitionStoreContext.Provider, {
341
342
  value: store,
342
343
  children: /*#__PURE__*/ _jsx(PluginProvider, {
@@ -348,11 +349,11 @@ export function VariableProvider({ children, initialVariableDefinitions = [], ex
348
349
  export function VariableProviderWithQueryParams({ children, initialVariableDefinitions = [], externalVariableDefinitions = [], builtinVariableDefinitions: builtinVariables = [] }) {
349
350
  const allVariableDefs = mergeVariableDefinitions(initialVariableDefinitions, externalVariableDefinitions);
350
351
  const queryParams = useVariableQueryParams(allVariableDefs);
351
- const [store] = useState(createVariableDefinitionStore({
352
- initialVariableDefinitions,
353
- externalVariableDefinitions,
354
- queryParams
355
- }));
352
+ const [store] = useState(()=>createVariableDefinitionStore({
353
+ initialVariableDefinitions,
354
+ externalVariableDefinitions,
355
+ queryParams
356
+ }));
356
357
  return /*#__PURE__*/ _jsx(VariableDefinitionStoreContext.Provider, {
357
358
  value: store,
358
359
  children: /*#__PURE__*/ _jsx(PluginProvider, {