@perses-dev/dashboards 0.54.0-beta.5 → 0.54.0-beta.7

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 (101) hide show
  1. package/dist/cjs/components/Annotations/AnnotationsEditor.js +302 -0
  2. package/dist/cjs/components/Annotations/EditAnnotationsButton.js +83 -0
  3. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +3 -1
  4. package/dist/cjs/components/Variables/VariableEditor.js +2 -2
  5. package/dist/cjs/constants/user-interface-text.js +1 -0
  6. package/dist/cjs/context/AnnotationProvider/AnnotationHydrationWrapper.js +50 -0
  7. package/dist/cjs/context/AnnotationProvider/AnnotationProvider.js +145 -0
  8. package/dist/cjs/{model/DashboardResource.js → context/AnnotationProvider/index.js} +14 -0
  9. package/dist/cjs/context/DatasourceStoreProvider.js +34 -4
  10. package/dist/cjs/context/index.js +1 -0
  11. package/dist/cjs/context/useDashboard.js +8 -0
  12. package/dist/cjs/model/index.js +0 -1
  13. package/dist/cjs/views/ViewDashboard/DashboardApp.js +2 -1
  14. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +29 -25
  15. package/dist/components/Annotations/AnnotationsEditor.d.ts +8 -0
  16. package/dist/components/Annotations/AnnotationsEditor.d.ts.map +1 -0
  17. package/dist/components/Annotations/AnnotationsEditor.js +289 -0
  18. package/dist/components/Annotations/AnnotationsEditor.js.map +1 -0
  19. package/dist/components/Annotations/EditAnnotationsButton.d.ts +18 -0
  20. package/dist/components/Annotations/EditAnnotationsButton.d.ts.map +1 -0
  21. package/dist/components/Annotations/EditAnnotationsButton.js +70 -0
  22. package/dist/components/Annotations/EditAnnotationsButton.js.map +1 -0
  23. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +1 -0
  24. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  25. package/dist/components/DashboardToolbar/DashboardToolbar.js +3 -1
  26. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  27. package/dist/components/Datasources/DatasourceEditor.d.ts.map +1 -1
  28. package/dist/components/Datasources/DatasourceEditor.js.map +1 -1
  29. package/dist/components/DownloadButton/serializeDashboard.d.ts +1 -1
  30. package/dist/components/DownloadButton/serializeDashboard.d.ts.map +1 -1
  31. package/dist/components/DownloadButton/serializeDashboard.js.map +1 -1
  32. package/dist/components/LeaveDialog/LeaveDialog.d.ts +1 -1
  33. package/dist/components/LeaveDialog/LeaveDialog.d.ts.map +1 -1
  34. package/dist/components/LeaveDialog/LeaveDialog.js.map +1 -1
  35. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +1 -1
  36. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  37. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  38. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  39. package/dist/components/Variables/VariableEditor.js +2 -2
  40. package/dist/components/Variables/VariableEditor.js.map +1 -1
  41. package/dist/constants/user-interface-text.d.ts +1 -0
  42. package/dist/constants/user-interface-text.d.ts.map +1 -1
  43. package/dist/constants/user-interface-text.js +1 -0
  44. package/dist/constants/user-interface-text.js.map +1 -1
  45. package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.d.ts +7 -0
  46. package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.d.ts.map +1 -0
  47. package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.js +48 -0
  48. package/dist/context/AnnotationProvider/AnnotationHydrationWrapper.js.map +1 -0
  49. package/dist/context/AnnotationProvider/AnnotationProvider.d.ts +40 -0
  50. package/dist/context/AnnotationProvider/AnnotationProvider.d.ts.map +1 -0
  51. package/dist/context/AnnotationProvider/AnnotationProvider.js +114 -0
  52. package/dist/context/AnnotationProvider/AnnotationProvider.js.map +1 -0
  53. package/dist/context/AnnotationProvider/index.d.ts +2 -0
  54. package/dist/context/AnnotationProvider/index.d.ts.map +1 -0
  55. package/dist/{model/DashboardResource.js → context/AnnotationProvider/index.js} +2 -2
  56. package/dist/context/AnnotationProvider/index.js.map +1 -0
  57. package/dist/context/DashboardProvider/DashboardProvider.d.ts +1 -2
  58. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  59. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  60. package/dist/context/DashboardProvider/common.d.ts +1 -1
  61. package/dist/context/DashboardProvider/common.d.ts.map +1 -1
  62. package/dist/context/DashboardProvider/common.js.map +1 -1
  63. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +2 -1
  64. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  65. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  66. package/dist/context/DashboardProvider/panel-editor-slice.d.ts +1 -1
  67. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  68. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  69. package/dist/context/DatasourceStoreProvider.d.ts +1 -2
  70. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  71. package/dist/context/DatasourceStoreProvider.js +35 -5
  72. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  73. package/dist/context/index.d.ts +1 -0
  74. package/dist/context/index.d.ts.map +1 -1
  75. package/dist/context/index.js +1 -0
  76. package/dist/context/index.js.map +1 -1
  77. package/dist/context/useDashboard.d.ts +1 -1
  78. package/dist/context/useDashboard.d.ts.map +1 -1
  79. package/dist/context/useDashboard.js +8 -0
  80. package/dist/context/useDashboard.js.map +1 -1
  81. package/dist/model/index.d.ts +0 -1
  82. package/dist/model/index.d.ts.map +1 -1
  83. package/dist/model/index.js +0 -1
  84. package/dist/model/index.js.map +1 -1
  85. package/dist/test/dashboard-provider.d.ts +1 -1
  86. package/dist/test/dashboard-provider.d.ts.map +1 -1
  87. package/dist/test/dashboard-provider.js.map +1 -1
  88. package/dist/test/testDashboard.d.ts +1 -1
  89. package/dist/test/testDashboard.d.ts.map +1 -1
  90. package/dist/test/testDashboard.js.map +1 -1
  91. package/dist/views/ViewDashboard/DashboardApp.d.ts +2 -1
  92. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  93. package/dist/views/ViewDashboard/DashboardApp.js +2 -1
  94. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  95. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  96. package/dist/views/ViewDashboard/ViewDashboard.js +30 -26
  97. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  98. package/package.json +5 -4
  99. package/dist/model/DashboardResource.d.ts +0 -9
  100. package/dist/model/DashboardResource.d.ts.map +0 -1
  101. package/dist/model/DashboardResource.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/common.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,iBAAiB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAEjF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC,CAAC;AAEjF,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1C;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAKnC;AAGD,wBAAgB,qBAAqB,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,WAAW,GAAG,eAAe,CAehH"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/common.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEhE,MAAM,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,iBAAiB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAEjF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC,CAAC;AAEjF,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1C;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAKnC;AAGD,wBAAgB,qBAAqB,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,WAAW,GAAG,eAAe,CAehH"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/common.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PanelDefinition, UnknownSpec } from '@perses-dev/spec';\nimport { DashboardResource } from '../../model';\n\nexport type OnSaveDashboard = (dashboard: DashboardResource) => Promise<unknown>;\n\n/**\n * The middleware applied to the DashboardStore (can be used as generic argument in StateCreator).\n */\nexport type Middleware = [['zustand/immer', never], ['zustand/devtools', never]];\n\ndeclare global {\n // eslint-disable-next-line no-var\n var dashboardStoreId: number | undefined;\n}\n\n/**\n * Helper function to generate unique IDs for things in the dashboard store that don't have a \"natural\" ID.\n */\nexport function generateId(): number {\n if (globalThis.dashboardStoreId === undefined) {\n globalThis.dashboardStoreId = 0;\n }\n return globalThis.dashboardStoreId++;\n}\n\n// Helper function to create initial PanelDefinitions\nexport function createPanelDefinition(defaultPanelKind?: string, defaultPanelSpec?: UnknownSpec): PanelDefinition {\n return {\n kind: 'Panel',\n spec: {\n display: {\n name: '',\n description: undefined,\n },\n plugin: {\n kind: defaultPanelKind ?? '',\n spec: defaultPanelSpec ?? {},\n },\n queries: [],\n },\n };\n}\n"],"names":["generateId","globalThis","dashboardStoreId","undefined","createPanelDefinition","defaultPanelKind","defaultPanelSpec","kind","spec","display","name","description","plugin","queries"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAiBjC;;CAEC,GACD,OAAO,SAASA;IACd,IAAIC,WAAWC,gBAAgB,KAAKC,WAAW;QAC7CF,WAAWC,gBAAgB,GAAG;IAChC;IACA,OAAOD,WAAWC,gBAAgB;AACpC;AAEA,qDAAqD;AACrD,OAAO,SAASE,sBAAsBC,gBAAyB,EAAEC,gBAA8B;IAC7F,OAAO;QACLC,MAAM;QACNC,MAAM;YACJC,SAAS;gBACPC,MAAM;gBACNC,aAAaR;YACf;YACAS,QAAQ;gBACNL,MAAMF,oBAAoB;gBAC1BG,MAAMF,oBAAoB,CAAC;YAC7B;YACAO,SAAS,EAAE;QACb;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/common.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DashboardResource } from '@perses-dev/client';\nimport { PanelDefinition, UnknownSpec } from '@perses-dev/spec';\n\nexport type OnSaveDashboard = (dashboard: DashboardResource) => Promise<unknown>;\n\n/**\n * The middleware applied to the DashboardStore (can be used as generic argument in StateCreator).\n */\nexport type Middleware = [['zustand/immer', never], ['zustand/devtools', never]];\n\ndeclare global {\n // eslint-disable-next-line no-var\n var dashboardStoreId: number | undefined;\n}\n\n/**\n * Helper function to generate unique IDs for things in the dashboard store that don't have a \"natural\" ID.\n */\nexport function generateId(): number {\n if (globalThis.dashboardStoreId === undefined) {\n globalThis.dashboardStoreId = 0;\n }\n return globalThis.dashboardStoreId++;\n}\n\n// Helper function to create initial PanelDefinitions\nexport function createPanelDefinition(defaultPanelKind?: string, defaultPanelSpec?: UnknownSpec): PanelDefinition {\n return {\n kind: 'Panel',\n spec: {\n display: {\n name: '',\n description: undefined,\n },\n plugin: {\n kind: defaultPanelKind ?? '',\n spec: defaultPanelSpec ?? {},\n },\n queries: [],\n },\n };\n}\n"],"names":["generateId","globalThis","dashboardStoreId","undefined","createPanelDefinition","defaultPanelKind","defaultPanelSpec","kind","spec","display","name","description","plugin","queries"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAiBjC;;CAEC,GACD,OAAO,SAASA;IACd,IAAIC,WAAWC,gBAAgB,KAAKC,WAAW;QAC7CF,WAAWC,gBAAgB,GAAG;IAChC;IACA,OAAOD,WAAWC,gBAAgB;AACpC;AAEA,qDAAqD;AACrD,OAAO,SAASE,sBAAsBC,gBAAyB,EAAEC,gBAA8B;IAC7F,OAAO;QACLC,MAAM;QACNC,MAAM;YACJC,SAAS;gBACPC,MAAM;gBACNC,aAAaR;YACf;YACAS,QAAQ;gBACNL,MAAMF,oBAAoB;gBAC1BG,MAAMF,oBAAoB,CAAC;YAC7B;YACAO,SAAS,EAAE;QACb;IACF;AACF"}
@@ -1,5 +1,6 @@
1
1
  import { DurationString, Link, PanelDefinition, PanelGroupId } from '@perses-dev/spec';
2
- import { DashboardResource, PanelGroupDefinition, PanelGroupItemId, PanelGroupItemLayout } from '../../model';
2
+ import { DashboardResource } from '@perses-dev/client';
3
+ import { PanelGroupDefinition, PanelGroupItemId, PanelGroupItemLayout } from '../../model';
3
4
  import { DeletePanelGroupDialogState } from './delete-panel-group-slice';
4
5
  import { PanelGroupEditor } from './panel-group-editor-slice';
5
6
  import { PanelEditorState } from './panel-editor-slice';
@@ -1 +1 @@
1
- {"version":3,"file":"dashboard-provider-api.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/dashboard-provider-api.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE9G,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,kCAAkC,EAAE,MAAM,6BAA6B,CAAC;AACjF,OAAO,EAAE,qCAAqC,EAAE,MAAM,gCAAgC,CAAC;AACvF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAMpD,wBAAgB,WAAW,IAAI;IAAE,WAAW,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IAAC,UAAU,EA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C,iCAAiC,EAAE,CAAC,6BAA6B,EAAE,kCAAkC,KAAK,IAAI,CAAC;IAC/G,6BAA6B,EAAE,kCAAkC,GAAG,SAAS,CAAC;CAC/E,CAEA;AAqBD,wBAAgB,mCAAmC,IAAI;IACrD,gCAAgC,EAAE,qCAAqC,GAAG,SAAS,CAAC;IACpF,qCAAqC,EAAE,MAAM,IAAI,CAAC;IAClD,oCAAoC,EAAE,CACpC,gCAAgC,EAAE,qCAAqC,KACpE,IAAI,CAAC;CACX,CAEA;AAWD;;GAEG;AACH,wBAAgB,iBAAiB,IAAI;IACnC,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,mBAAmB,EAAE,MAAM,IAAI,CAAC;IAChC,cAAc,EAAE,mBAAmB,GAAG,SAAS,CAAC;CACjD,CAEA"}
1
+ {"version":3,"file":"dashboard-provider-api.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/dashboard-provider-api.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE3F,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,kCAAkC,EAAE,MAAM,6BAA6B,CAAC;AACjF,OAAO,EAAE,qCAAqC,EAAE,MAAM,gCAAgC,CAAC;AACvF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAo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iB,IAAI,gBAAgB,GAAG,SAAS,CAEhE;AAmBD,wBAAgB,gCAAgC,IAAI;IAClD,kCAAkC,EAAE,MAAM,IAAI,CAAC;IAC/C,iCAAiC,EAAE,CAAC,6BAA6B,EAAE,kCAAkC,KAAK,IAAI,CAAC;IAC/G,6BAA6B,EAAE,kCAAkC,GAAG,SAAS,CAAC;CAC/E,CAEA;AAqBD,wBAAgB,mCAAmC,IAAI;IACrD,gCAAgC,EAAE,qCAAqC,GAAG,SAAS,CAAC;IACpF,qCAAqC,EAAE,MAAM,IAAI,CAAC;IAClD,oCAAoC,EAAE,CACpC,gCAAgC,EAAE,qCAAqC,KACpE,IAAI,CAAC;CACX,CAEA;AAWD;;GAEG;AACH,wBAAgB,iBAAiB,IAAI;IACnC,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,mBAAmB,EAAE,MAAM,IAAI,CAAC;IAChC,cAAc,EAAE,mBAAmB,GAAG,SAAS,CAAC;CACjD,CAEA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/dashboard-provider-api.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useCallback, useMemo } from 'react';\nimport { DurationString, Link, PanelDefinition, PanelGroupId } from '@perses-dev/spec';\nimport { DashboardResource, PanelGroupDefinition, PanelGroupItemId, PanelGroupItemLayout } from '../../model';\nimport { DashboardStoreState, useDashboardStore } from './DashboardProvider';\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) => 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) => void;\n} {\n const { setDashboard, openAddPanelGroup, openAddPanel } = useDashboardStore(selectDashboardActions);\n return {\n setDashboard,\n openAddPanelGroup: () => openAddPanelGroup(),\n openAddPanel: () => openAddPanel(),\n };\n}\n\nconst selectDashboardLinks: (state: DashboardStoreState) => Link[] | undefined = (state: DashboardStoreState) =>\n state.links;\n/**\n * Returns the dashboard links.\n */\nexport function useDashboardLinks(): Link[] {\n return useDashboardStore(selectDashboardLinks) ?? [];\n}\n\nexport interface DashboardLinksActions {\n setLinks?: (links: Link[]) => void;\n}\n\nconst selectDashboardLinksActions: (state: DashboardStoreState) => DashboardLinksActions = (\n state: DashboardStoreState\n) => ({\n setLinks: state.setLinks,\n});\n/**\n * Returns actions that can be performed on dashboard links.\n */\nexport function useDashboardLinksActions(): DashboardLinksActions {\n return useDashboardStore(selectDashboardLinksActions);\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\nexport function usePanelKey(panelGroupItemId?: PanelGroupItemId): string | undefined {\n const panelKey = useDashboardStore(\n useCallback(\n (store) => {\n if (panelGroupItemId === undefined) {\n return undefined;\n }\n\n return store.panelGroups[panelGroupItemId.panelGroupId]?.itemPanelKeys[panelGroupItemId.panelGroupItemLayoutId];\n },\n [panelGroupItemId]\n )\n );\n return panelKey;\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","selectDashboardLinks","state","links","useDashboardLinks","selectDashboardLinksActions","setLinks","useDashboardLinksActions","selectPanelGroupOrder","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","usePanelKey","panelGroupItemId","panelKey","itemPanelKeys","panelGroupItemLayoutId","usePanel","panelGroupLayoutId","panel","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,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,WAAW,EAAEC,OAAO,QAAQ,QAAQ;AAG7C,SAA8BC,iBAAiB,QAAQ,sBAAsB;AAU7E,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,OAAO,SAASC;IAKd,MAAM,EAAEH,YAAY,EAAEC,iBAAiB,EAAEC,YAAY,EAAE,GAAGR,kBAAkBK;IAC5E,OAAO;QACLC;QACAC,mBAAmB,IAAMA;QACzBC,cAAc,IAAMA;IACtB;AACF;AAEA,MAAME,uBAA2E,CAACC,QAChFA,MAAMC,KAAK;AACb;;CAEC,GACD,OAAO,SAASC;IACd,OAAOb,kBAAkBU,yBAAyB,EAAE;AACtD;AAMA,MAAMI,8BAAqF,CACzFH,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ardProvider/dashboard-provider-api.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useCallback, useMemo } from 'react';\nimport { DurationString, Link, PanelDefinition, PanelGroupId } from '@perses-dev/spec';\nimport { DashboardResource } from '@perses-dev/client';\nimport { PanelGroupDefinition, PanelGroupItemId, PanelGroupItemLayout } from '../../model';\nimport { DashboardStoreState, useDashboardStore } from './DashboardProvider';\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) => 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) => void;\n} {\n const { setDashboard, openAddPanelGroup, openAddPanel } = useDashboardStore(selectDashboardActions);\n return {\n setDashboard,\n openAddPanelGroup: () => openAddPanelGroup(),\n openAddPanel: () => openAddPanel(),\n };\n}\n\nconst selectDashboardLinks: (state: DashboardStoreState) => Link[] | undefined = (state: DashboardStoreState) =>\n state.links;\n/**\n * Returns the dashboard links.\n */\nexport function useDashboardLinks(): Link[] {\n return useDashboardStore(selectDashboardLinks) ?? [];\n}\n\nexport interface DashboardLinksActions {\n setLinks?: (links: Link[]) => void;\n}\n\nconst selectDashboardLinksActions: (state: DashboardStoreState) => DashboardLinksActions = (\n state: DashboardStoreState\n) => ({\n setLinks: state.setLinks,\n});\n/**\n * Returns actions that can be performed on dashboard links.\n */\nexport function useDashboardLinksActions(): DashboardLinksActions {\n return useDashboardStore(selectDashboardLinksActions);\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\nexport function usePanelKey(panelGroupItemId?: PanelGroupItemId): string | undefined {\n const panelKey = useDashboardStore(\n useCallback(\n (store) => {\n if (panelGroupItemId === undefined) {\n return undefined;\n }\n\n return store.panelGroups[panelGroupItemId.panelGroupId]?.itemPanelKeys[panelGroupItemId.panelGroupItemLayoutId];\n },\n [panelGroupItemId]\n )\n );\n return panelKey;\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","selectDashboardLinks","state","links","useDashboardLinks","selectDashboardLinksActions","setLinks","useDashboardLinksActions","selectPanelGroupOrder","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","usePanelKey","panelGroupItemId","panelKey","itemPanelKeys","panelGroupItemLayoutId","usePanel","panelGroupLayoutId","panel","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,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,WAAW,EAAEC,OAAO,QAAQ,QAAQ;AAI7C,SAA8BC,iBAAiB,QAAQ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D,OAAO,SAASI;IACd,OAAOzF,kBAAkBwF;AAC3B;AAEA,MAAME,sCAQF,CAAC,EACHC,6BAA6B,EAC7BC,iCAAiC,EACjCC,kCAAkC,EACd,GAAM,CAAA;QAC1BF;QACAC;QACAC;IACF,CAAA;AACA,OAAO,SAASC;IAKd,OAAO9F,kBAAkB0F;AAC3B;AAEA,MAAMK,yCAUF,CAAC,EACHC,gCAAgC,EAChCC,oCAAoC,EACpCC,qCAAqC,EACjB,GAAM,CAAA;QAC1BF;QACAC;QACAC;IACF,CAAA;AACA,OAAO,SAASC;IAOd,OAAOnG,kBAAkB+F;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,OAAOxG,kBAAkBoG;AAC3B"}
@@ -1,6 +1,6 @@
1
- import { Action } from '@perses-dev/components';
2
1
  import { PanelEditorValues, PanelGroupId } from '@perses-dev/spec';
3
2
  import { StateCreator } from 'zustand';
3
+ import { Action } from '@perses-dev/client';
4
4
  import { PanelGroupItemId } from '../../model';
5
5
  import { Middleware } from './common';
6
6
  import { PanelGroupSlice } from './panel-group-slice';
@@ -1 +1 @@
1
- {"version":3,"file":"panel-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAwB,gBAAgB,EAAwB,MAAM,aAAa,CAAC;AAC3F,OAAO,EAAc,UAAU,EAAyB,MAAM,UAAU,CAAC;AACzE,OAAO,EAAE,eAAe,EAAwC,MAAM,qBAAqB,CAAC;AAC5F,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,aAAa,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;IAE3D;;OAEG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAE/B;;OAEG;IACH,aAAa,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAE5D;;OAEG;IACH,YAAY,EAAE,CAAC,YAAY,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC;CACrD;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAKb,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;OAEG;IACH,aAAa,EAAE,iBAAiB,CAAC;IAEjC;;OAEG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAEhD;;OAEG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,YAAY,CAEpD,gBAAgB,GAAG,UAAU,GAAG,eAAe,EAC/C,UAAU,EACV;CAAE,EACF,gBAAgB,CACjB,CA2IA"}
1
+ {"version":3,"file":"panel-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAwB,gBAAgB,EAAwB,MAAM,aAAa,CAAC;AAC3F,OAAO,EAAc,UAAU,EAAyB,MAAM,UAAU,CAAC;AACzE,OAAO,EAAE,eAAe,EAAwC,MAAM,qBAAqB,CAAC;AAC5F,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,aAAa,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;IAE3D;;OAEG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAE/B;;OAEG;IACH,aAAa,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAE5D;;OAEG;IACH,YAAY,EAAE,CAAC,YAAY,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC;CACrD;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAKb,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;OAEG;IACH,aAAa,EAAE,iBAAiB,CAAC;IAEjC;;OAEG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAEhD;;OAEG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,YAAY,CAEpD,gBAAgB,GAAG,UAAU,GAAG,eAAe,EAC/C,UAAU,EACV;CAAE,EACF,gBAAgB,CACjB,CA2IA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Action } from '@perses-dev/components';\nimport { PanelEditorValues, PanelGroupId } from '@perses-dev/spec';\nimport { StateCreator } from 'zustand';\nimport { generatePanelKey, getYForNewRow } from '../../utils';\nimport { PanelGroupDefinition, PanelGroupItemId, PanelGroupItemLayout } from '../../model';\nimport { generateId, Middleware, createPanelDefinition } from './common';\nimport { PanelGroupSlice, addPanelGroup, createEmptyPanelGroup } 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 * Original item in a PanelGroup edited\n */\n panelGroupItemId?: PanelGroupItemId;\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 panelGroupItemId: panelGroupItemId,\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 panelKey = generatePanelKey();\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":["generatePanelKey","getYForNewRow","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","group","toString"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAKjC,SAASA,gBAAgB,EA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ASV;wBACTW,iBAAiBlB,MAAMgB,aAAa,EAAEE,mBAAmBvB;oBAC3D;oBACAwB,cAAc,CAACC;wBACb,MAAMV,WAAWlB;wBACjBO,IAAI,CAACsB;4BACH,cAAc;4BACdA,MAAMhB,MAAM,CAACK,SAAS,GAAGU,KAAKF,eAAe;4BAE7C,oDAAoD;4BACpD,MAAMwB,QAAQrB,MAAMf,WAAW,CAACc,KAAKH,OAAO,CAAC;4BAC7C,IAAIyB,UAAUxC,WAAW;gCACvB,MAAM,IAAIU,MAAM,CAAC,oBAAoB,EAAEQ,KAAKH,OAAO,EAAE;4BACvD;4BACA,MAAMS,SAA+B;gCACnCC,GAAGjC,aAAaiD,QAAQ;gCACxBV,GAAG;gCACHC,GAAGzC,cAAciD;gCACjBP,GAAG;gCACHC,GAAG;4BACL;4BACAM,MAAMlB,WAAW,CAACQ,IAAI,CAACN;4BACvBgB,MAAM/B,aAAa,CAACe,OAAOC,CAAC,CAAC,GAAGjB;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
+ {"version":3,"sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PanelEditorValues, PanelGroupId } from '@perses-dev/spec';\nimport { StateCreator } from 'zustand';\nimport { Action } from '@perses-dev/client';\nimport { generatePanelKey, getYForNewRow } from '../../utils';\nimport { PanelGroupDefinition, PanelGroupItemId, PanelGroupItemLayout } from '../../model';\nimport { generateId, Middleware, createPanelDefinition } from './common';\nimport { PanelGroupSlice, addPanelGroup, createEmptyPanelGroup } 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 * Original item in a PanelGroup edited\n */\n panelGroupItemId?: PanelGroupItemId;\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 panelGroupItemId: panelGroupItemId,\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 panelKey = generatePanelKey();\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":["generatePanelKey","getYForNewRow","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","group","toString"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2E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gBAEA,MAAM3B,cAAgC;oBACpCC,MAAM;oBACNC,eAAe;wBACbC,SAASV;wBACTW,iBAAiBlB,MAAMgB,aAAa,EAAEE,mBAAmBvB;oBAC3D;oBACAwB,cAAc,CAACC;wBACb,MAAMV,WAAWlB;wBACjBO,IAAI,CAACsB;4BACH,cAAc;4BACdA,MAAMhB,MAAM,CAACK,SAAS,GAAGU,KAAKF,eAAe;4BAE7C,oDAAoD;4BACpD,MAAMwB,QAAQrB,MAAMf,WAAW,CAACc,KAAKH,OAAO,CAAC;4BAC7C,IAAIyB,UAAUxC,WAAW;gCACvB,MAAM,IAAIU,MAAM,CAAC,oBAAoB,EAAEQ,KAAKH,OAAO,EAAE;4BACvD;4BACA,MAAMS,SAA+B;gCACnCC,GAAGjC,aAAaiD,QAAQ;gCACxBV,GAAG;gCACHC,GAAGzC,cAAciD;gCACjBP,GAAG;gCACHC,GAAG;4BACL;4BACAM,MAAMlB,WAAW,CAACQ,IAAI,CAACN;4BACvBgB,MAAM/B,aAAa,CAACe,OAAOC,CAAC,CAAC,GAAGjB;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,8 +1,7 @@
1
1
  import { ReactElement, ReactNode } from 'react';
2
2
  import { DatasourceSpec } from '@perses-dev/spec';
3
3
  import { DatasourceClient } from '@perses-dev/plugin-system';
4
- import { DatasourceApi } from '@perses-dev/client';
5
- import { DashboardResource } from '../model/DashboardResource';
4
+ import { DashboardResource, DatasourceApi } from '@perses-dev/client';
6
5
  export interface DatasourceStoreProviderProps {
7
6
  dashboardResource?: DashboardResource;
8
7
  projectName?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"DatasourceStoreProvider.d.ts","sourceRoot":"","sources":["../../src/context/DatasourceStoreProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAC;AAChF,OAAO,EAAqC,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACrF,OAAO,EAML,gBAAgB,EAEjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAiC,aAAa,EAAwB,MAAM,oBAAoB,CAAC;AACxG,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,WAAW,4BAA4B;IAC3C,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAClD,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,gBAAgB,CAAC;CAC3D;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,4BAA4B,GAAG,YAAY,CAkLzF"}
1
+ {"version":3,"file":"DatasourceStoreProvider.d.ts","sourceRoot":"","sources":["../../src/context/DatasourceStoreProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,SAAS,EAA0C,MAAM,OAAO,CAAC;AACxF,OAAO,EAAqC,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACrF,OAAO,EAML,gBAAgB,EAEjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,iBAAiB,EACjB,aAAa,EAEd,MAAM,oBAAoB,CAAC;AAE5B,MAAM,WAAW,4BAA4B;IAC3C,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAClD,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,gBAAgB,CAAC;CAC3D;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,4BAA4B,GAAG,YAAY,CAoNzF"}
@@ -11,7 +11,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- import { useCallback, useMemo, useState } from 'react';
14
+ import { useCallback, useMemo, useRef, useState } from 'react';
15
15
  import { DatasourceStoreContext, usePluginRegistry, useEvent } from '@perses-dev/plugin-system';
16
16
  /**
17
17
  * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.
@@ -19,15 +19,24 @@ import { DatasourceStoreContext, usePluginRegistry, useEvent } from '@perses-dev
19
19
  const { projectName, datasourceApi, onCreate, children } = props;
20
20
  const [dashboardResource, setDashboardResource] = useState(props.dashboardResource);
21
21
  const [savedDatasources, setSavedDatasources] = useState(props.savedDatasources ?? {});
22
+ // Cache for synchronous datasource spec access
23
+ const datasourceSpecCache = useRef(new Map());
22
24
  const project = projectName ?? dashboardResource?.metadata.project;
23
25
  const { getPlugin, listPluginMetadata } = usePluginRegistry();
26
+ // Helper to create cache key from DatasourceSelector
27
+ const createCacheKey = useCallback((selector)=>{
28
+ const name = selector.name === undefined ? '__undefined__' : selector.name;
29
+ return `${selector.kind}:${name}:${project ?? 'global'}`;
30
+ }, [
31
+ project
32
+ ]);
24
33
  const findDatasource = useEvent(async (selector)=>{
25
34
  // Try to find it in dashboard spec
26
35
  if (dashboardResource) {
27
36
  const { datasources } = dashboardResource.spec;
28
37
  const dashboardDatasource = findDashboardDatasource(datasources, selector);
29
38
  if (dashboardDatasource !== undefined) {
30
- return {
39
+ const result = {
31
40
  spec: dashboardDatasource.spec,
32
41
  proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
33
42
  project: dashboardResource.metadata.project,
@@ -35,30 +44,42 @@ import { DatasourceStoreContext, usePluginRegistry, useEvent } from '@perses-dev
35
44
  name: dashboardDatasource.name
36
45
  })
37
46
  };
47
+ // Cache the spec for synchronous access
48
+ const cacheKey = createCacheKey(selector);
49
+ datasourceSpecCache.current.set(cacheKey, result.spec);
50
+ return result;
38
51
  }
39
52
  }
40
53
  if (project) {
41
54
  // Try to find it at the project level as a Datasource resource
42
55
  const datasource = await datasourceApi.getDatasource(String(project), selector);
43
56
  if (datasource !== undefined) {
44
- return {
57
+ const result = {
45
58
  spec: datasource.spec,
46
59
  proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
47
60
  project: datasource.metadata.project,
48
61
  name: datasource.metadata.name
49
62
  })
50
63
  };
64
+ // Cache the spec for synchronous access
65
+ const cacheKey = createCacheKey(selector);
66
+ datasourceSpecCache.current.set(cacheKey, result.spec);
67
+ return result;
51
68
  }
52
69
  }
53
70
  // Try to find it at the global level as a GlobalDatasource resource
54
71
  const globalDatasource = await datasourceApi.getGlobalDatasource(selector);
55
72
  if (globalDatasource !== undefined) {
56
- return {
73
+ const result = {
57
74
  spec: globalDatasource.spec,
58
75
  proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
59
76
  name: globalDatasource.metadata.name
60
77
  })
61
78
  };
79
+ // Cache the spec for synchronous access
80
+ const cacheKey = createCacheKey(selector);
81
+ datasourceSpecCache.current.set(cacheKey, result.spec);
82
+ return result;
62
83
  }
63
84
  throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);
64
85
  });
@@ -153,6 +174,13 @@ import { DatasourceStoreContext, usePluginRegistry, useEvent } from '@perses-dev
153
174
  }, [
154
175
  savedDatasources
155
176
  ]);
177
+ // Gets a cached datasource spec synchronously if available
178
+ const getDatasourceSpecSync = useCallback((selector)=>{
179
+ const cacheKey = createCacheKey(selector);
180
+ return datasourceSpecCache.current.get(cacheKey);
181
+ }, [
182
+ createCacheKey
183
+ ]);
156
184
  const setLocalDatasources = useCallback((datasources)=>{
157
185
  if (dashboardResource) {
158
186
  setDashboardResource({
@@ -169,6 +197,7 @@ import { DatasourceStoreContext, usePluginRegistry, useEvent } from '@perses-dev
169
197
  const ctxValue = useMemo(()=>({
170
198
  getDatasource,
171
199
  getDatasourceClient,
200
+ getDatasourceSpecSync,
172
201
  getLocalDatasources,
173
202
  setLocalDatasources,
174
203
  setSavedDatasources,
@@ -177,6 +206,7 @@ import { DatasourceStoreContext, usePluginRegistry, useEvent } from '@perses-dev
177
206
  }), [
178
207
  getDatasource,
179
208
  getDatasourceClient,
209
+ getDatasourceSpecSync,
180
210
  getLocalDatasources,
181
211
  setLocalDatasources,
182
212
  listDatasourceSelectItems,
@@ -258,7 +288,7 @@ function findDashboardDatasource(dashboardDatasources, selector) {
258
288
  });
259
289
  usedNames.add(selectorName);
260
290
  const isExplicitDefault = !isOverridden && spec.default && !explicitDefaultAdded;
261
- if (results[0] && (isFirst || isExplicitDefault)) {
291
+ if (results[0] && isExplicitDefault) {
262
292
  // If we haven't added a default yet and this is a default, add default option to the beginning of the results
263
293
  results[0].items = [
264
294
  {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/DatasourceStoreProvider.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ReactElement, ReactNode, useCallback, useMemo, useState } from 'react';\nimport { DashboardSpec, DatasourceSelector, DatasourceSpec } from '@perses-dev/spec';\nimport {\n DatasourceStoreContext,\n DatasourceStore,\n DatasourceSelectItemGroup,\n usePluginRegistry,\n useEvent,\n DatasourceClient,\n DatasourceSelectItem,\n} from '@perses-dev/plugin-system';\nimport { BuildDatasourceProxyUrlParams, DatasourceApi, DatasourceDefinition } from '@perses-dev/client';\nimport { DashboardResource } from '../model/DashboardResource';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource?: DashboardResource;\n projectName?: string;\n datasourceApi: DatasourceApi;\n children?: ReactNode;\n savedDatasources?: Record<string, DatasourceSpec>;\n onCreate?: (client: DatasourceClient) => DatasourceClient;\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(String(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([\n findDatasource(selector),\n getPlugin({ kind: 'Datasource', name: kind }),\n ]);\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(String(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,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\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","DatasourceStoreContext","usePluginRegistry","useEvent","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","String","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,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1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AAUa,GAAG,CAAClC;QAEd,MAAMmC,oBAAoB,CAACJ,gBAAgBjE,KAAKqD,OAAO,IAAI,CAACK;QAC5D,IAAI5B,OAAO,CAAC,EAAE,IAAK2B,CAAAA,WAAWY,iBAAgB,GAAI;YAChD,8GAA8G;YAC9GvC,OAAO,CAAC,EAAE,CAACiC,KAAK,GAAG;gBACjB;oBACExD,MAAM,CAAC,SAAS,EAAE2B,aAAa,MAAM,EAAE2B,MAAM,CAAC,CAAC;oBAC/C/D,UAAU;wBACRgB,MAAMd,KAAKiB,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,KAAK1E,QAAQ,CAACS,IAAI,KAAK2B,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 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, useRef, useState } from 'react';\nimport { DashboardSpec, DatasourceSelector, DatasourceSpec } from '@perses-dev/spec';\nimport {\n DatasourceStoreContext,\n DatasourceStore,\n DatasourceSelectItemGroup,\n usePluginRegistry,\n useEvent,\n DatasourceClient,\n DatasourceSelectItem,\n} from '@perses-dev/plugin-system';\nimport {\n BuildDatasourceProxyUrlParams,\n DashboardResource,\n DatasourceApi,\n DatasourceDefinition,\n} from '@perses-dev/client';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource?: DashboardResource;\n projectName?: string;\n datasourceApi: DatasourceApi;\n children?: ReactNode;\n savedDatasources?: Record<string, DatasourceSpec>;\n onCreate?: (client: DatasourceClient) => DatasourceClient;\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 // Cache for synchronous datasource spec access\n const datasourceSpecCache = useRef<Map<string, DatasourceSpec>>(new Map());\n const project = projectName ?? dashboardResource?.metadata.project;\n\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n // Helper to create cache key from DatasourceSelector\n const createCacheKey = useCallback(\n (selector: DatasourceSelector): string => {\n const name = selector.name === undefined ? '__undefined__' : selector.name;\n return `${selector.kind}:${name}:${project ?? 'global'}`;\n },\n [project]\n );\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 const result = {\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 // Cache the spec for synchronous access\n const cacheKey = createCacheKey(selector);\n datasourceSpecCache.current.set(cacheKey, result.spec);\n return result;\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(String(project), selector);\n if (datasource !== undefined) {\n const result = {\n spec: datasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: datasource.metadata.project,\n name: datasource.metadata.name,\n }),\n };\n // Cache the spec for synchronous access\n const cacheKey = createCacheKey(selector);\n datasourceSpecCache.current.set(cacheKey, result.spec);\n return result;\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 const result = {\n spec: globalDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n name: globalDatasource.metadata.name,\n }),\n };\n // Cache the spec for synchronous access\n const cacheKey = createCacheKey(selector);\n datasourceSpecCache.current.set(cacheKey, result.spec);\n return result;\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([\n findDatasource(selector),\n getPlugin({ kind: 'Datasource', name: kind }),\n ]);\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(String(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 // Gets a cached datasource spec synchronously if available\n const getDatasourceSpecSync = useCallback(\n (selector: DatasourceSelector): DatasourceSpec | undefined => {\n const cacheKey = createCacheKey(selector);\n return datasourceSpecCache.current.get(cacheKey);\n },\n [createCacheKey]\n );\n\n const setLocalDatasources = useCallback(\n (datasources: Record<string, DatasourceSpec>) => {\n if (dashboardResource) {\n setDashboardResource({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n });\n }\n },\n [dashboardResource]\n );\n\n const ctxValue: DatasourceStore = useMemo(\n () =>\n ({\n getDatasource,\n getDatasourceClient,\n getDatasourceSpecSync,\n getLocalDatasources,\n setLocalDatasources,\n setSavedDatasources,\n getSavedDatasources,\n listDatasourceSelectItems,\n }) as DatasourceStore,\n [\n getDatasource,\n getDatasourceClient,\n getDatasourceSpecSync,\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] && 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","useRef","useState","DatasourceStoreContext","usePluginRegistry","useEvent","DatasourceStoreProvider","props","projectName","datasourceApi","onCreate","children","dashboardResource","setDashboardResource","savedDatasources","setSavedDatasources","datasourceSpecCache","Map","project","metadata","getPlugin","listPluginMetadata","createCacheKey","selector","name","undefined","kind","findDatasource","datasources","spec","dashboardDatasource","findDashboardDatasource","result","proxyUrl","buildDatasourceProxyUrl","dashboard","cacheKey","current","set","datasource","getDatasource","String","globalDatasource","getGlobalDatasource","Error","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","getDatasourceSpecSync","get","setLocalDatasources","ctxValue","Provider","value","api","params","buildProxyUrl","dashboardDatasources","named","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,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAkCA,WAAW,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAExF,SACEC,sBAAsB,EAGtBC,iBAAiB,EACjBC,QAAQ,QAGH,4BAA4B;AAiBnC;;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,C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BAAOzB;YAAS;YAC/CP,OAAO,CAAC+B,kBAAkB,GAAGI;YAC7BJ;QACF;QAEA,wBAAwB;QACxB,MAAMK,eAAeV,UAAUW,GAAG,CAACjC;QACnC+B,gBAAgBD,KAAK,CAACD,IAAI,CAAC;YACzBrE,MAAMK,KAAKkC,OAAO,EAAEvC,QAAQwC;YAC5BkC,YAAYF;YACZ/B;YACA1C,UAAU;gBACRG,MAAMG,KAAKkB,MAAM,CAACrB,IAAI;gBACtBF,MAAMwC;gBACN4B;YACF;QACF;QACAN,UAAUa,GAAG,CAACnC;QAEd,MAAMoC,oBAAoB,CAACJ,gBAAgBnE,KAAKuD,OAAO,IAAI,CAACK;QAC5D,IAAI7B,OAAO,CAAC,EAAE,IAAIwC,mBAAmB;YACnC,8GAA8G;YAC9GxC,OAAO,CAAC,EAAE,CAACkC,KAAK,GAAG;gBACjB;oBACEtE,MAAM,CAAC,SAAS,EAAEwC,aAAa,MAAM,EAAE4B,MAAM,CAAC,CAAC;oBAC/CrE,UAAU;wBACRG,MAAMG,KAAKkB,MAAM,CAACrB,IAAI;oBACxB;gBACF;aACD;YACD,kGAAkG;YAClG,wGAAwG;YACxG,gDAAgD;YAChD+D,uBAAuBW;QACzB;QAEA,qEAAqE;QACrE,IAAIJ,cAAc;YAChB,IAAK,IAAIK,IAAIZ,uBAAuB,IAAI,GAAGY,IAAIV,mBAAmBU,IAAK;gBACpEzC,CAAAA,OAAO,CAACyC,EAAE,EAAEP,SAAS,EAAE,AAAD,EACpBQ,MAAM,CAAC,CAACC,OAA+BA,KAAKhF,QAAQ,CAACC,IAAI,KAAKwC,cAC9DwC,OAAO,CAAC,CAACD;oBACRA,KAAKE,UAAU,GAAG;gBACpB;YACJ;QACF;QAEAjB,UAAU;IACZ;IAEA,OAAO;QAAE5B;QAASC;IAAQ;AAC5B"}
@@ -1,3 +1,4 @@
1
+ export * from './AnnotationProvider';
1
2
  export * from './DashboardProvider';
2
3
  export * from './DatasourceStoreProvider';
3
4
  export * from './VariableProvider';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAaA,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC"}
@@ -10,6 +10,7 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
+ export * from './AnnotationProvider';
13
14
  export * from './DashboardProvider';
14
15
  export * from './DatasourceStoreProvider';
15
16
  export * from './VariableProvider';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/index.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './DashboardProvider';\nexport * from './DatasourceStoreProvider';\nexport * from './VariableProvider';\nexport * from './useDashboard';\nexport * from './PanelEditorProvider';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,sBAAsB;AACpC,cAAc,4BAA4B;AAC1C,cAAc,qBAAqB;AACnC,cAAc,iBAAiB;AAC/B,cAAc,wBAAwB"}
1
+ {"version":3,"sources":["../../src/context/index.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './AnnotationProvider';\nexport * from './DashboardProvider';\nexport * from './DatasourceStoreProvider';\nexport * from './VariableProvider';\nexport * from './useDashboard';\nexport * from './PanelEditorProvider';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,uBAAuB;AACrC,cAAc,sBAAsB;AACpC,cAAc,4BAA4B;AAC1C,cAAc,qBAAqB;AACnC,cAAc,iBAAiB;AAC/B,cAAc,wBAAwB"}
@@ -1,5 +1,5 @@
1
1
  import { DashboardSpec, DurationString } from '@perses-dev/spec';
2
- import { DashboardResource } from '../model';
2
+ import { DashboardResource } from '@perses-dev/client';
3
3
  type DashboardType = Omit<DashboardResource, 'spec'> & {
4
4
  spec: DashboardSpec & {
5
5
  ttl?: DurationString;
@@ -1 +1 @@
1
- {"version":3,"file":"useDashboard.d.ts","sourceRoot":"","sources":["../../src/context/useDashboard.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAkB,aAAa,EAAE,cAAc,EAAgC,MAAM,kBAAkB,CAAC;AAC/G,OAAO,EAAE,iBAAiB,EAAwB,MAAM,UAAU,CAAC;AAKnE,KAAK,aAAa,GAAG,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,aAAa,GAAG;QAAE,GAAG,CAAC,EAAE,cAAc,CAAA;KAAE,CAAA;CAAE,CAAC;AAC1G,wBAAgB,YAAY,IAAI;IAC9B,SAAS,EAAE,aAAa,CAAC;IACzB,YAAY,EAAE,CAAC,iBAAiB,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAC9D,CAwFA"}
1
+ {"version":3,"file":"useDashboard.d.ts","sourceRoot":"","sources":["../../src/context/useDashboard.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAkB,aAAa,EAAE,cAAc,EAAgC,MAAM,kBAAkB,CAAC;AAC/G,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAOvD,KAAK,aAAa,GAAG,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,aAAa,GAAG;QAAE,GAAG,CAAC,EAAE,cAAc,CAAA;KAAE,CAAA;CAAE,CAAC;AAC1G,wBAAgB,YAAY,IAAI;IAC9B,SAAS,EAAE,aAAa,CAAC;IACzB,YAAY,EAAE,CAAC,iBAAiB,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAC9D,CA+FA"}
@@ -13,6 +13,7 @@
13
13
  import { createPanelRef } from '@perses-dev/spec';
14
14
  import { useDashboardStore } from './DashboardProvider';
15
15
  import { useVariableDefinitionActions, useVariableDefinitions } from './VariableProvider';
16
+ import { useAnnotationActions, useAnnotationSpecs } from './AnnotationProvider';
16
17
  export function useDashboard() {
17
18
  const { panels, panelGroups, panelGroupOrder, setDashboard: setDashboardResource, kind, metadata, display, duration, refreshInterval, datasources, links, ttl } = useDashboardStore(({ panels, panelGroups, panelGroupOrder, setDashboard, kind, metadata, display, duration, refreshInterval, datasources, links, ttl })=>({
18
19
  panels,
@@ -29,7 +30,9 @@ export function useDashboard() {
29
30
  ttl
30
31
  }));
31
32
  const { setVariableDefinitions } = useVariableDefinitionActions();
33
+ const { setAnnotationSpecs } = useAnnotationActions();
32
34
  const variables = useVariableDefinitions();
35
+ const annotations = useAnnotationSpecs();
33
36
  const layouts = convertPanelGroupsToLayouts(panelGroups, panelGroupOrder);
34
37
  const dashboard = kind === 'Dashboard' ? {
35
38
  kind,
@@ -39,6 +42,7 @@ export function useDashboard() {
39
42
  panels,
40
43
  layouts,
41
44
  variables,
45
+ annotations,
42
46
  duration,
43
47
  refreshInterval,
44
48
  datasources,
@@ -52,6 +56,7 @@ export function useDashboard() {
52
56
  panels,
53
57
  layouts,
54
58
  variables,
59
+ annotations,
55
60
  duration,
56
61
  refreshInterval,
57
62
  datasources,
@@ -61,6 +66,9 @@ export function useDashboard() {
61
66
  };
62
67
  const setDashboard = (dashboardResource)=>{
63
68
  setVariableDefinitions(dashboardResource.spec.variables);
69
+ if (dashboardResource.spec.annotations) {
70
+ setAnnotationSpecs(dashboardResource.spec.annotations);
71
+ }
64
72
  setDashboardResource(dashboardResource);
65
73
  };
66
74
  return {