@perses-dev/dashboards 0.46.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/DashboardStickyToolbar/DashboardStickyToolbar.js +2 -2
- package/dist/cjs/components/Datasources/DatasourceEditor.js +15 -13
- package/dist/cjs/components/EmptyDashboard/EmptyDashboard.js +1 -1
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +30 -38
- package/dist/cjs/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +2 -2
- package/dist/cjs/components/SaveDashboardButton/SaveDashboardButton.js +2 -2
- package/dist/cjs/components/Variables/EditVariablesButton.js +4 -4
- package/dist/cjs/components/Variables/{TemplateVariable.js → Variable.js} +16 -19
- package/dist/cjs/components/Variables/VariableEditor.js +19 -17
- package/dist/cjs/components/Variables/VariableList.js +17 -17
- package/dist/cjs/components/Variables/index.js +2 -2
- package/dist/cjs/constants/styles.js +7 -7
- package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +4 -4
- package/dist/cjs/context/{TemplateVariableProvider/TemplateVariableProvider.js → VariableProvider/VariableProvider.js} +51 -56
- package/dist/cjs/context/{TemplateVariableProvider → VariableProvider}/hydrationUtils.js +8 -8
- package/dist/cjs/{validation → context/VariableProvider}/index.js +2 -2
- package/dist/cjs/context/{TemplateVariableProvider → VariableProvider}/query-params.js +1 -1
- package/dist/cjs/context/{TemplateVariableProvider → VariableProvider}/utils.js +1 -1
- package/dist/cjs/context/index.js +2 -2
- package/dist/cjs/context/useDashboard.js +4 -4
- package/dist/cjs/stories/decorators/{WithTemplateVariables.js → WithVariables.js} +8 -8
- package/dist/cjs/stories/decorators/index.js +2 -2
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +3 -3
- package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js +3 -3
- package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js.map +1 -1
- package/dist/components/Datasources/DatasourceEditor.d.ts.map +1 -1
- package/dist/components/Datasources/DatasourceEditor.js +16 -14
- package/dist/components/Datasources/DatasourceEditor.js.map +1 -1
- package/dist/components/EmptyDashboard/EmptyDashboard.js +1 -1
- package/dist/components/EmptyDashboard/EmptyDashboard.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/GridLayout/GridTitle.d.ts +1 -1
- package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
- package/dist/components/GridLayout/GridTitle.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts +1 -2
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.js +31 -39
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +3 -3
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -1
- package/dist/components/SaveDashboardButton/SaveDashboardButton.js +3 -3
- package/dist/components/SaveDashboardButton/SaveDashboardButton.js.map +1 -1
- package/dist/components/Variables/EditVariablesButton.js +5 -5
- package/dist/components/Variables/EditVariablesButton.js.map +1 -1
- package/dist/components/Variables/{TemplateVariable.d.ts → Variable.d.ts} +3 -3
- package/dist/components/Variables/Variable.d.ts.map +1 -0
- package/dist/components/Variables/{TemplateVariable.js → Variable.js} +17 -20
- package/dist/components/Variables/Variable.js.map +1 -0
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditor.js +20 -18
- package/dist/components/Variables/VariableEditor.js.map +1 -1
- package/dist/components/Variables/VariableList.d.ts +2 -2
- package/dist/components/Variables/VariableList.d.ts.map +1 -1
- package/dist/components/Variables/VariableList.js +15 -15
- package/dist/components/Variables/VariableList.js.map +1 -1
- package/dist/components/Variables/index.d.ts +1 -1
- package/dist/components/Variables/index.d.ts.map +1 -1
- package/dist/components/Variables/index.js +2 -2
- package/dist/components/Variables/index.js.map +1 -1
- package/dist/constants/styles.d.ts +2 -2
- package/dist/constants/styles.d.ts.map +1 -1
- package/dist/constants/styles.js +3 -3
- package/dist/constants/styles.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +2 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
- package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts +2 -1
- package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/delete-panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/index.d.ts +1 -2
- package/dist/context/DashboardProvider/index.d.ts.map +1 -1
- package/dist/context/DashboardProvider/index.js.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts +2 -9
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +2 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +1 -2
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.js.map +1 -1
- package/dist/context/DatasourceStoreProvider.d.ts +5 -5
- package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
- package/dist/context/DatasourceStoreProvider.js.map +1 -1
- package/dist/context/VariableProvider/VariableProvider.d.ts +126 -0
- package/dist/context/VariableProvider/VariableProvider.d.ts.map +1 -0
- package/dist/context/{TemplateVariableProvider/TemplateVariableProvider.js → VariableProvider/VariableProvider.js} +40 -41
- package/dist/context/VariableProvider/VariableProvider.js.map +1 -0
- package/dist/context/{TemplateVariableProvider → VariableProvider}/hydrationUtils.d.ts +1 -1
- package/dist/context/VariableProvider/hydrationUtils.d.ts.map +1 -0
- package/dist/context/{TemplateVariableProvider → VariableProvider}/hydrationUtils.js +6 -6
- package/dist/context/VariableProvider/hydrationUtils.js.map +1 -0
- package/dist/context/VariableProvider/index.d.ts +2 -0
- package/dist/context/VariableProvider/index.d.ts.map +1 -0
- package/dist/{validation → context/VariableProvider}/index.js +2 -2
- package/dist/context/VariableProvider/index.js.map +1 -0
- package/dist/context/VariableProvider/query-params.d.ts.map +1 -0
- package/dist/context/{TemplateVariableProvider → VariableProvider}/query-params.js +1 -1
- package/dist/context/VariableProvider/query-params.js.map +1 -0
- package/dist/context/VariableProvider/utils.d.ts.map +1 -0
- package/dist/context/{TemplateVariableProvider → VariableProvider}/utils.js +1 -1
- package/dist/context/VariableProvider/utils.js.map +1 -0
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +2 -2
- package/dist/context/index.js.map +1 -1
- package/dist/context/useDashboard.d.ts.map +1 -1
- package/dist/context/useDashboard.js +4 -4
- package/dist/context/useDashboard.js.map +1 -1
- package/dist/stories/decorators/{WithTemplateVariables.js → WithVariables.js} +8 -8
- package/dist/stories/decorators/WithVariables.js.map +1 -0
- package/dist/stories/decorators/index.js +2 -2
- package/dist/stories/decorators/index.js.map +1 -1
- package/dist/test/datasource-provider.d.ts +2 -2
- package/dist/test/datasource-provider.d.ts.map +1 -1
- package/dist/test/datasource-provider.js.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts +2 -2
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js +4 -4
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
- package/package.json +7 -7
- package/dist/cjs/context/TemplateVariableProvider/index.js +0 -30
- package/dist/cjs/validation/panel.js +0 -39
- package/dist/components/Variables/TemplateVariable.d.ts.map +0 -1
- package/dist/components/Variables/TemplateVariable.js.map +0 -1
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts +0 -77
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +0 -1
- package/dist/context/TemplateVariableProvider/hydrationUtils.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider/hydrationUtils.js.map +0 -1
- package/dist/context/TemplateVariableProvider/index.d.ts +0 -2
- package/dist/context/TemplateVariableProvider/index.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider/index.js +0 -15
- package/dist/context/TemplateVariableProvider/index.js.map +0 -1
- package/dist/context/TemplateVariableProvider/query-params.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider/query-params.js.map +0 -1
- package/dist/context/TemplateVariableProvider/utils.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider/utils.js.map +0 -1
- package/dist/stories/decorators/WithTemplateVariables.js.map +0 -1
- package/dist/validation/index.d.ts +0 -2
- package/dist/validation/index.d.ts.map +0 -1
- package/dist/validation/index.js.map +0 -1
- package/dist/validation/panel.d.ts +0 -67
- package/dist/validation/panel.d.ts.map +0 -1
- package/dist/validation/panel.js +0 -31
- package/dist/validation/panel.js.map +0 -1
- /package/dist/context/{TemplateVariableProvider → VariableProvider}/query-params.d.ts +0 -0
- /package/dist/context/{TemplateVariableProvider → VariableProvider}/utils.d.ts +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Variables/VariableList.tsx"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Variables/VariableList.tsx"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box } from '@mui/material';\nimport { VariableDefinition, VariableSpec } from '@perses-dev/core';\nimport {\n ExternalVariableDefinition,\n useExternalVariableDefinitions,\n useVariableDefinitionAndState,\n useVariableDefinitions,\n} from '../../context';\nimport { MAX_VARIABLE_WIDTH, MIN_VARIABLE_WIDTH } from '../../constants';\nimport { Variable } from './Variable';\n\nexport function VariableList() {\n const variableDefinitions: VariableDefinition[] = useVariableDefinitions();\n const externalVariableDefinitions: ExternalVariableDefinition[] = useExternalVariableDefinitions();\n\n return (\n <>\n {externalVariableDefinitions\n .slice()\n .reverse() // We reverse to have the most prioritized on top\n .map((def) =>\n def.definitions.map((v) => (\n <VariableListItem key={v.spec.name + def.source} spec={v.spec} source={def.source} />\n ))\n )}\n {variableDefinitions.map((v) => (\n <VariableListItem key={v.spec.name} spec={v.spec} />\n ))}\n </>\n );\n}\n\nexport function VariableListItem({ spec, source }: { spec: VariableSpec; source?: string }) {\n const ctx = useVariableDefinitionAndState(spec.name, source);\n if (ctx.state?.overridden) {\n return null;\n }\n return (\n <Box\n key={spec.name + source ?? ''}\n display={spec.display?.hidden ? 'none' : undefined}\n minWidth={`${MIN_VARIABLE_WIDTH}px`}\n maxWidth={`${MAX_VARIABLE_WIDTH}px`}\n flexShrink={0}\n data-testid={'variable-' + spec.name}\n >\n <Variable key={spec.name + source ?? ''} name={spec.name} source={source} />\n </Box>\n );\n}\n"],"names":["Box","useExternalVariableDefinitions","useVariableDefinitionAndState","useVariableDefinitions","MAX_VARIABLE_WIDTH","MIN_VARIABLE_WIDTH","Variable","VariableList","variableDefinitions","externalVariableDefinitions","slice","reverse","map","def","definitions","v","VariableListItem","spec","source","name","ctx","state","overridden","display","hidden","undefined","minWidth","maxWidth","flexShrink","data-testid"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,GAAG,QAAQ,gBAAgB;AAEpC,SAEEC,8BAA8B,EAC9BC,6BAA6B,EAC7BC,sBAAsB,QACjB,gBAAgB;AACvB,SAASC,kBAAkB,EAAEC,kBAAkB,QAAQ,kBAAkB;AACzE,SAASC,QAAQ,QAAQ,aAAa;AAEtC,OAAO,SAASC;IACd,MAAMC,sBAA4CL;IAClD,MAAMM,8BAA4DR;IAElE,qBACE;;YACGQ,4BACEC,KAAK,GACLC,OAAO,GAAG,iDAAiD;aAC3DC,GAAG,CAAC,CAACC,MACJA,IAAIC,WAAW,CAACF,GAAG,CAAC,CAACG,kBACnB,KAACC;wBAAgDC,MAAMF,EAAEE,IAAI;wBAAEC,QAAQL,IAAIK,MAAM;uBAA1DH,EAAEE,IAAI,CAACE,IAAI,GAAGN,IAAIK,MAAM;YAGpDV,oBAAoBI,GAAG,CAAC,CAACG,kBACxB,KAACC;oBAAmCC,MAAMF,EAAEE,IAAI;mBAAzBF,EAAEE,IAAI,CAACE,IAAI;;;AAI1C;AAEA,OAAO,SAASH,iBAAiB,EAAEC,IAAI,EAAEC,MAAM,EAA2C;QAEpFE,YAMSH;IAPb,MAAMG,MAAMlB,8BAA8Be,KAAKE,IAAI,EAAED;IACrD,KAAIE,aAAAA,IAAIC,KAAK,cAATD,iCAAAA,WAAWE,UAAU,EAAE;QACzB,OAAO;IACT;QAUmBL,MAPVA;IAFT,qBACE,KAACjB;QAECuB,SAASN,EAAAA,gBAAAA,KAAKM,OAAO,cAAZN,oCAAAA,cAAcO,MAAM,IAAG,SAASC;QACzCC,UAAU,CAAC,EAAErB,mBAAmB,EAAE,CAAC;QACnCsB,UAAU,CAAC,EAAEvB,mBAAmB,EAAE,CAAC;QACnCwB,YAAY;QACZC,eAAa,cAAcZ,KAAKE,IAAI;kBAEpC,cAAA,KAACb;YAAwCa,MAAMF,KAAKE,IAAI;YAAED,QAAQA;WAAnDD,CAAAA,OAAAA,KAAKE,IAAI,GAAGD,oBAAZD,kBAAAA,OAAsB;OAPhCA,CAAAA,QAAAA,KAAKE,IAAI,GAAGD,oBAAZD,mBAAAA,QAAsB;AAUjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/index.tsx"],"names":[],"mappings":"AAaA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/index.tsx"],"names":[],"mappings":"AAaA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
export * from './BuiltinVariableAccordions';
|
|
14
14
|
export * from './EditVariablesButton';
|
|
15
|
-
export * from './
|
|
15
|
+
export * from './Variable';
|
|
16
16
|
export * from './VariableEditor';
|
|
17
17
|
export * from './VariableList';
|
|
18
18
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Variables/index.tsx"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Variables/index.tsx"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './BuiltinVariableAccordions';\nexport * from './EditVariablesButton';\nexport * from './Variable';\nexport * from './VariableEditor';\nexport * from './VariableList';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,8BAA8B;AAC5C,cAAc,wBAAwB;AACtC,cAAc,aAAa;AAC3B,cAAc,mBAAmB;AACjC,cAAc,iBAAiB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SxProps, Theme } from '@mui/material';
|
|
2
2
|
export declare const editButtonStyle: SxProps<Theme>;
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
3
|
+
export declare const MIN_VARIABLE_WIDTH = 120;
|
|
4
|
+
export declare const MAX_VARIABLE_WIDTH = 500;
|
|
5
5
|
//# sourceMappingURL=styles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../src/constants/styles.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAE/C,eAAO,MAAM,eAAe,EAAE,OAAO,CAAC,KAAK,CAM1C,CAAC;AAEF,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../src/constants/styles.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAE/C,eAAO,MAAM,eAAe,EAAE,OAAO,CAAC,KAAK,CAM1C,CAAC;AAEF,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,kBAAkB,MAAM,CAAC"}
|
package/dist/constants/styles.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -17,7 +17,7 @@ export const editButtonStyle = {
|
|
|
17
17
|
marginRight: 0.5
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
-
export const
|
|
21
|
-
export const
|
|
20
|
+
export const MIN_VARIABLE_WIDTH = 120;
|
|
21
|
+
export const MAX_VARIABLE_WIDTH = 500;
|
|
22
22
|
|
|
23
23
|
//# sourceMappingURL=styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/constants/styles.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../src/constants/styles.ts"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { SxProps, Theme } from '@mui/material';\n\nexport const editButtonStyle: SxProps<Theme> = {\n whiteSpace: 'nowrap',\n minWidth: 'auto',\n '& .MuiButton-startIcon': {\n marginRight: 0.5,\n },\n};\n\nexport const MIN_VARIABLE_WIDTH = 120;\nexport const MAX_VARIABLE_WIDTH = 500;\n"],"names":["editButtonStyle","whiteSpace","minWidth","marginRight","MIN_VARIABLE_WIDTH","MAX_VARIABLE_WIDTH"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,OAAO,MAAMA,kBAAkC;IAC7CC,YAAY;IACZC,UAAU;IACV,0BAA0B;QACxBC,aAAa;IACf;AACF,EAAE;AAEF,OAAO,MAAMC,qBAAqB,IAAI;AACtC,OAAO,MAAMC,qBAAqB,IAAI"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PanelGroupId } from '@perses-dev/core';
|
|
2
|
+
import { PanelGroupItemId, PanelGroupItemLayout } from './panel-group-slice';
|
|
2
3
|
export declare function useEditMode(): {
|
|
3
4
|
isEditMode: boolean;
|
|
4
5
|
setEditMode: (isEditMode: boolean) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dashboard-provider-api.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/dashboard-provider-api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dashboard-provider-api.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/dashboard-provider-api.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAG7E,wBAAgB,WAAW;;;EAE1B;AAOD;;GAEG;AACH,wBAAgB,mBAAmB;;;;EAOlC;AAGD;;GAEG;AACH,wBAAgB,gBAAgB,aAE/B;AAGD;;GAEG;AACH,wBAAgB,kBAAkB,yDAYjC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,YAAY,EAAE,YAAY,sDAMvD;AAaD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,YAAY;;;;;;2CAWpB,oBAAoB,EAAE;EAGhE;AA4BD;;GAEG;AACH,wBAAgB,mBAAmB,sEAElC;AAaD;;GAEG;AACH,wBAAgB,yBAAyB;;;;;EASxC;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,sFAiB1D;AAcD;;GAEG;AACH,wBAAgB,eAAe,CAAC,gBAAgB,EAAE,gBAAgB;;;;mCAM/B,gBAAgB;EAElD;AAGD;;GAEG;AACH,wBAAgB,cAAc,gEAE7B;AAQD;;GAEG;AACH,wBAAgB,oBAAoB;;;;EAGnC;AAGD,wBAAgB,oBAAoB,8CAEnC;AAGD;;GAEG;AACH,wBAAgB,YAAY,iCAE3B;AAWD,wBAAgB,gCAAgC;;;;EAE/C;AAWD,wBAAgB,mCAAmC;;;;EAElD;AAOD;;GAEG;AACH,wBAAgB,iBAAiB;;;;EAEhC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/dashboard-provider-api.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useCallback, useMemo } from 'react';\nimport { DashboardStoreState, useDashboardStore } from './DashboardProvider';\nimport { PanelGroupItemId, PanelGroupId, PanelGroupItemLayout } from './panel-group-slice';\n\nconst selectEditMode = ({ isEditMode, setEditMode }: DashboardStoreState) => ({ isEditMode, setEditMode });\nexport function useEditMode() {\n return useDashboardStore(selectEditMode);\n}\n\nconst selectDashboardActions = ({ 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 const { setDashboard, openAddPanelGroup, openAddPanel } = useDashboardStore(selectDashboardActions);\n return {\n setDashboard,\n openAddPanelGroup: () => openAddPanelGroup(),\n openAddPanel: () => openAddPanel(),\n };\n}\n\nconst selectPanelGroupOrder = (state: DashboardStoreState) => state.panelGroupOrder;\n/**\n * Returns an array of PanelGroupIds in the order they appear in the dashboard.\n */\nexport function usePanelGroupIds() {\n return useDashboardStore(selectPanelGroupOrder);\n}\n\nconst selectPanelGroups = (state: DashboardStoreState) => state.panelGroups;\n/**\n * Returns an array of PanelGroupDefinitions in the order they appear in the dashboard.\n */\nexport function useListPanelGroups() {\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) {\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 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 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) => state.swapPanelGroups;\nconst selectPanelGroupsLength = (state: DashboardStoreState) => 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 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 = () => swapPanelGroups(currentIndex, currentIndex - 1);\n const moveDown = () => 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) => state.panelGroupEditor;\n/**\n * Gets the Panel Group editor state.\n */\nexport function usePanelGroupEditor() {\n return useDashboardStore(selectPanelGroupEditor);\n}\n\nconst selectDeletePanelGroupDialog = ({\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 const { deletePanelGroupDialog, openDeletePanelGroupDialog, closeDeletePanelGroupDialog, deletePanelGroup } =\n useDashboardStore(selectDeletePanelGroupDialog);\n return {\n deletePanelGroupDialog,\n deletePanelGroup,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog: () => closeDeletePanelGroupDialog(),\n };\n}\n\n/**\n * Gets an individual panel in the store. Throws if the panel can't be found.\n */\nexport function usePanel(panelGroupItemId: PanelGroupItemId) {\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 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 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) => state.panelEditor;\n/**\n * Gets the state for the Panel Editor.\n */\nexport function usePanelEditor() {\n return useDashboardStore(selectPanelEditor);\n}\n\nconst selectDeletePanelDialog = ({ 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 // 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) => state.duration;\nexport function useDashboardDuration() {\n return useDashboardStore(selectDashboardDuration);\n}\n\nconst selectViewPanel = (state: DashboardStoreState) => state.getViewPanel();\n/**\n * Gets the current panel viewed in max size (\"full screen\").\n */\nexport function useViewPanel() {\n return useDashboardStore(selectViewPanel);\n}\n\nconst selectSaveChangesConfirmationDialog = ({\n saveChangesConfirmationDialog,\n openSaveChangesConfirmationDialog,\n closeSaveChangesConfirmationDialog,\n}: DashboardStoreState) => ({\n saveChangesConfirmationDialog,\n openSaveChangesConfirmationDialog,\n closeSaveChangesConfirmationDialog,\n});\nexport function useSaveChangesConfirmationDialog() {\n return useDashboardStore(selectSaveChangesConfirmationDialog);\n}\n\nconst selectDiscardChangesConfirmationDialog = ({\n discardChangesConfirmationDialog,\n openDiscardChangesConfirmationDialog,\n closeDiscardChangesConfirmationDialog,\n}: DashboardStoreState) => ({\n discardChangesConfirmationDialog,\n openDiscardChangesConfirmationDialog,\n closeDiscardChangesConfirmationDialog,\n});\nexport function useDiscardChangesConfirmationDialog() {\n return useDashboardStore(selectDiscardChangesConfirmationDialog);\n}\n\nconst selectEditJsonDialog = ({ 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 return useDashboardStore(selectEditJsonDialog);\n}\n"],"names":["useCallback","useMemo","useDashboardStore","selectEditMode","isEditMode","setEditMode","useEditMode","selectDashboardActions","setDashboard","openAddPanelGroup","openAddPanel","useDashboardActions","selectPanelGroupOrder","state","panelGroupOrder","usePanelGroupIds","selectPanelGroups","panelGroups","useListPanelGroups","panelGroupIds","map","id","group","undefined","Error","usePanelGroup","panelGroupId","panelGroup","selectPanelGroupActions","openEditPanelGroup","deletePanelGroup","updatePanelGroupLayouts","usePanelGroupActions","moveUp","moveDown","useMovePanelGroup","itemLayouts","selectSwapPanelGroups","swapPanelGroups","selectPanelGroupsLength","length","currentIndex","store","findIndex","panelGroupsLength","selectPanelGroupEditor","panelGroupEditor","usePanelGroupEditor","selectDeletePanelGroupDialog","deletePanelGroupDialog","openDeletePanelGroupDialog","closeDeletePanelGroupDialog","useDeletePanelGroupDialog","usePanel","panelGroupItemId","panelGroupItemLayoutId","panelGroupLayoutId","panel","panelKey","itemPanelKeys","panels","selectPanelActions","openEditPanel","openDeletePanelDialog","duplicatePanel","setViewPanel","usePanelActions","viewPanel","selectPanelEditor","panelEditor","usePanelEditor","selectDeletePanelDialog","deletePanelDialog","deletePanel","closeDeletePanelDialog","useDeletePanelDialog","selectDashboardDuration","duration","useDashboardDuration","selectViewPanel","getViewPanel","useViewPanel","selectSaveChangesConfirmationDialog","saveChangesConfirmationDialog","openSaveChangesConfirmationDialog","closeSaveChangesConfirmationDialog","useSaveChangesConfirmationDialog","selectDiscardChangesConfirmationDialog","discardChangesConfirmationDialog","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","useDiscardChangesConfirmationDialog","selectEditJsonDialog","editJsonDialog","openEditJsonDialog","closeEditJsonDialog","useEditJsonDialog"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,o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kBAAkB0F;AAC3B"}
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/dashboard-provider-api.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useCallback, useMemo } from 'react';\nimport { PanelGroupId } from '@perses-dev/core';\nimport { DashboardStoreState, useDashboardStore } from './DashboardProvider';\nimport { PanelGroupItemId, PanelGroupItemLayout } from './panel-group-slice';\n\nconst selectEditMode = ({ isEditMode, setEditMode }: DashboardStoreState) => ({ isEditMode, setEditMode });\nexport function useEditMode() {\n return useDashboardStore(selectEditMode);\n}\n\nconst selectDashboardActions = ({ 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 const { setDashboard, openAddPanelGroup, openAddPanel } = useDashboardStore(selectDashboardActions);\n return {\n setDashboard,\n openAddPanelGroup: () => openAddPanelGroup(),\n openAddPanel: () => openAddPanel(),\n };\n}\n\nconst selectPanelGroupOrder = (state: DashboardStoreState) => state.panelGroupOrder;\n/**\n * Returns an array of PanelGroupIds in the order they appear in the dashboard.\n */\nexport function usePanelGroupIds() {\n return useDashboardStore(selectPanelGroupOrder);\n}\n\nconst selectPanelGroups = (state: DashboardStoreState) => state.panelGroups;\n/**\n * Returns an array of PanelGroupDefinitions in the order they appear in the dashboard.\n */\nexport function useListPanelGroups() {\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) {\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 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 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) => state.swapPanelGroups;\nconst selectPanelGroupsLength = (state: DashboardStoreState) => 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 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 = () => swapPanelGroups(currentIndex, currentIndex - 1);\n const moveDown = () => 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) => state.panelGroupEditor;\n/**\n * Gets the Panel Group editor state.\n */\nexport function usePanelGroupEditor() {\n return useDashboardStore(selectPanelGroupEditor);\n}\n\nconst selectDeletePanelGroupDialog = ({\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 const { deletePanelGroupDialog, openDeletePanelGroupDialog, closeDeletePanelGroupDialog, deletePanelGroup } =\n useDashboardStore(selectDeletePanelGroupDialog);\n return {\n deletePanelGroupDialog,\n deletePanelGroup,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog: () => closeDeletePanelGroupDialog(),\n };\n}\n\n/**\n * Gets an individual panel in the store. Throws if the panel can't be found.\n */\nexport function usePanel(panelGroupItemId: PanelGroupItemId) {\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 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 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) => state.panelEditor;\n/**\n * Gets the state for the Panel Editor.\n */\nexport function usePanelEditor() {\n return useDashboardStore(selectPanelEditor);\n}\n\nconst selectDeletePanelDialog = ({ 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 // 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) => state.duration;\nexport function useDashboardDuration() {\n return useDashboardStore(selectDashboardDuration);\n}\n\nconst selectViewPanel = (state: DashboardStoreState) => state.getViewPanel();\n/**\n * Gets the current panel viewed in max size (\"full screen\").\n */\nexport function useViewPanel() {\n return useDashboardStore(selectViewPanel);\n}\n\nconst selectSaveChangesConfirmationDialog = ({\n saveChangesConfirmationDialog,\n openSaveChangesConfirmationDialog,\n closeSaveChangesConfirmationDialog,\n}: DashboardStoreState) => ({\n saveChangesConfirmationDialog,\n openSaveChangesConfirmationDialog,\n closeSaveChangesConfirmationDialog,\n});\nexport function useSaveChangesConfirmationDialog() {\n return useDashboardStore(selectSaveChangesConfirmationDialog);\n}\n\nconst selectDiscardChangesConfirmationDialog = ({\n discardChangesConfirmationDialog,\n openDiscardChangesConfirmationDialog,\n closeDiscardChangesConfirmationDialog,\n}: DashboardStoreState) => ({\n discardChangesConfirmationDialog,\n openDiscardChangesConfirmationDialog,\n closeDiscardChangesConfirmationDialog,\n});\nexport function useDiscardChangesConfirmationDialog() {\n return useDashboardStore(selectDiscardChangesConfirmationDialog);\n}\n\nconst selectEditJsonDialog = ({ 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 return useDashboardStore(selectEditJsonDialog);\n}\n"],"names":["useCallback","useMemo","useDashboardStore","selectEditMode","isEditMode","setEditMode","useEditMode","selectDashboardActions","setDashboard","openAddPanelGroup","openAddPanel","useDashboardActions","selectPanelGroupOrder","state","panelGroupOrder","usePanelGroupIds","selectPanelGroups","panelGroups","useListPanelGroups","panelGroupIds","map","id","group","undefined","Error","usePanelGroup","panelGroupId","panelGroup","selectPanelGroupActions","openEditPanelGroup","deletePanelGroup","updatePanelGroupLayouts","usePanelGroupActions","moveUp","moveDown","useMovePanelGroup","itemLayouts","selectSwapPanelGroups","swapPanelGroups","selectPanelGroupsLength","length","currentIndex","store","findIndex","panelGroupsLength","selectPanelGroupEditor","panelGroupEditor","usePanelGroupEditor","selectDeletePanelGroupDialog","deletePanelGroupDialog","openDeletePanelGroupDialog","closeDeletePanelGroupDialog","useDeletePanelGroupDialog","usePanel","panelGroupItemId","panelGroupItemLayoutId","panelGroupLayoutId","panel","panelKey","itemPanelKeys","panels","selectPanelActions","openEditPanel","openDeletePanelDialog","duplicatePanel","setViewPanel","usePanelActions","viewPanel","selectPanelEditor","panelEditor","usePanelEditor","selectDeletePanelDialog","deletePanelDialog","deletePanel","closeDeletePanelDialog","useDeletePanelDialog","selectDashboardDuration","duration","useDashboardDuration","selectViewPanel","getViewPanel","useViewPanel","selectSaveChangesConfirmationDialog","saveChangesConfirmationDialog","openSaveChangesConfirmationDialog","closeSaveChangesConfirmationDialog","useSaveChangesConfirmationDialog","selectDiscardChangesConfirmationDialog","discardChangesConfirmationDialog","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","useDiscardChangesConfirmationDialog","selectEditJsonDialog","editJsonDialog","openEditJsonDialog","closeEditJsonDialog","useEditJsonDialog"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,WAAW,EAAEC,OAAO,QAAQ,QAAQ;AAE7C,SAA8BC,iBAAiB,QAAQ,sBAAsB;AAG7E,MAAMC,iBAAiB,CAAC,EAAEC,UAAU,EAAEC,WAAW,EAAuB,GAAM,CAAA;QAAED;QAAYC;IAAY,CAAA;AACxG,OAAO,SAASC;IACd,OAAOJ,kBAAkBC;AAC3B;AAEA,MAAMI,yBAAyB,CAAC,EAAEC,YAAY,EAAEC,iBAAiB,EAAEC,YAAY,EAAuB,GAAM,CAAA;QAC1GF;QACAC;QACAC;IACF,CAAA;AACA;;CAEC,GACD,OAAO,SAASC;IACd,MAAM,EAAEH,YAAY,EAAEC,iBAAiB,EAAEC,YAAY,EAAE,GAAGR,kBAAkBK;IAC5E,OAAO;QACLC;QACAC,mBAAmB,IAAMA;QACzBC,cAAc,IAAMA;IACtB;AACF;AAEA,MAAME,wBAAwB,CAACC,QAA+BA,MAAMC,eAAe;AACnF;;CAEC,GACD,OAAO,SAASC;IACd,OAAOb,kBAAkBU;AAC3B;AAEA,MAAMI,oBAAoB,CAACH,QAA+BA,MAAMI,WAAW;AAC3E;;CAEC,GACD,OAAO,SAASC;IACd,MAAMC,gBAAgBJ;IACtB,MAAME,cAAcf,kBAAkBc;IACtC,OAAOf,QAAQ;QACb,OAAOkB,cAAc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C;IACd,OAAOpF,kBAAkBgF;AAC3B;AAEA,MAAMK,yCAAyC,CAAC,EAC9CC,gCAAgC,EAChCC,oCAAoC,EACpCC,qCAAqC,EACjB,GAAM,CAAA;QAC1BF;QACAC;QACAC;IACF,CAAA;AACA,OAAO,SAASC;IACd,OAAOzF,kBAAkBqF;AAC3B;AAEA,MAAMK,uBAAuB,CAAC,EAAEC,cAAc,EAAEC,kBAAkB,EAAEC,mBAAmB,EAAuB,GAAM,CAAA;QAClHF;QACAC;QACAC;IACF,CAAA;AACA;;CAEC,GACD,OAAO,SAASC;IACd,OAAO9F,kBAAkB0F;AAC3B"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StateCreator } from 'zustand';
|
|
2
|
+
import { PanelGroupId } from '@perses-dev/core';
|
|
2
3
|
import { Middleware } from './common';
|
|
3
|
-
import {
|
|
4
|
+
import { PanelGroupSlice } from './panel-group-slice';
|
|
4
5
|
import { PanelSlice } from './panel-slice';
|
|
5
6
|
/**
|
|
6
7
|
* Slice that handles the visual editor state and related actions for deleting a Panel Group.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete-panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/delete-panel-group-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"delete-panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/delete-panel-group-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,sBAAsB,CAAC,EAAE,2BAA2B,CAAC;IAErD;;OAEG;IACH,gBAAgB,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;IAEvD,0BAA0B,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;IACjE,2BAA2B,EAAE,MAAM,IAAI,CAAC;CACzC;AAED,MAAM,WAAW,2BAA2B;IAC1C,YAAY,EAAE,YAAY,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,2BAA2B,EAAE,YAAY,CAEpD,qBAAqB,GAAG,eAAe,GAAG,UAAU,EACpD,UAAU,EACV;CAAE,EACF,qBAAqB,CA6CrB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/delete-panel-group-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/delete-panel-group-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { PanelGroupId } from '@perses-dev/core';\nimport { Middleware } from './common';\nimport { PanelGroupSlice } from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and related actions for deleting a Panel Group.\n */\nexport interface DeletePanelGroupSlice {\n deletePanelGroupDialog?: DeletePanelGroupDialogState;\n\n /**\n * Delete panel group and all the panels within the group\n */\n deletePanelGroup: (panelGroupId: PanelGroupId) => void;\n\n openDeletePanelGroupDialog: (panelGroupId: PanelGroupId) => void;\n closeDeletePanelGroupDialog: () => void;\n}\n\nexport interface DeletePanelGroupDialogState {\n panelGroupId: PanelGroupId;\n panelGroupName?: string;\n}\n\nexport const createDeletePanelGroupSlice: StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n DeletePanelGroupSlice & PanelGroupSlice & PanelSlice,\n Middleware,\n [],\n DeletePanelGroupSlice\n> = (set, get) => ({\n deletePanelGroup(panelGroupId) {\n const { panelGroups, panelGroupOrder } = get();\n const group = panelGroups[panelGroupId];\n const idIndex = panelGroupOrder.findIndex((id) => id === panelGroupId);\n if (group === undefined || idIndex === -1) {\n throw new Error(`Panel group ${panelGroupId} not found`);\n }\n\n // Get the panel keys for all the panel items in the group we're going to delete\n const panelKeys = Object.values(group.itemPanelKeys);\n\n set((draft) => {\n // Delete the panel group which also deletes all its items\n delete draft.panelGroups[panelGroupId];\n draft.panelGroupOrder.splice(idIndex, 1);\n\n // Get all remaining panel keys in use\n const usedPanelKeys = getUsedPanelKeys(draft.panelGroups);\n\n // For the panel keys of the items that were just deleted, see if they're still used and if not, also delete the\n // panel definition\n for (const panelKey of panelKeys) {\n if (usedPanelKeys.has(panelKey)) continue;\n\n delete draft.panels[panelKey];\n }\n });\n },\n\n openDeletePanelGroupDialog: (panelGroupId) => {\n const panelGroup = get().panelGroups[panelGroupId];\n if (panelGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} not found`);\n }\n set((state) => {\n state.deletePanelGroupDialog = { panelGroupId, panelGroupName: panelGroup.title };\n });\n },\n\n closeDeletePanelGroupDialog: () =>\n set((state) => {\n state.deletePanelGroupDialog = undefined;\n }),\n});\n\n// Helper to get the panel keys of all groups, returning a set to eliminate duplicates\nfunction getUsedPanelKeys(panelGroups: PanelGroupSlice['panelGroups']): Set<string> {\n const usedPanelKeys = new Set<string>();\n for (const group of Object.values(panelGroups)) {\n for (const panelKey of Object.values(group.itemPanelKeys)) {\n usedPanelKeys.add(panelKey);\n }\n }\n return usedPanelKeys;\n}\n"],"names":["createDeletePanelGroupSlice","set","get","deletePanelGroup","panelGroupId","panelGroups","panelGroupOrder","group","idIndex","findIndex","id","undefined","Error","panelKeys","Object","values","itemPanelKeys","draft","splice","usedPanelKeys","getUsedPanelKeys","panelKey","has","panels","openDeletePanelGroupDialog","panelGroup","state","deletePanelGroupDialog","panelGroupName","title","closeDeletePanelGroupDialog","Set","add"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AA4BjC,OAAO,MAAMA,8BAMT,CAACC,KAAKC,MAAS,CAAA;QACjBC,kBAAiBC,YAAY;YAC3B,MAAM,EAAEC,WAAW,EAAEC,eAAe,EAAE,GAAGJ;YACzC,MAAMK,QAAQF,WAAW,CAACD,aAAa;YACvC,MAAMI,UAAUF,gBAAgBG,SAAS,CAAC,CAACC,KAAOA,OAAON;YACzD,IAAIG,UAAUI,aAAaH,YAAY,CAAC,GAAG;gBACzC,MAAM,IAAII,MAAM,CAAC,YAAY,EAAER,aAAa,UAAU,CAAC;YACzD;YAEA,gFAAgF;YAChF,MAAMS,YAAYC,OAAOC,MAAM,CAACR,MAAMS,aAAa;YAEnDf,IAAI,CAACgB;gBACH,0DAA0D;gBAC1D,OAAOA,MAAMZ,WAAW,CAACD,aAAa;gBACtCa,MAAMX,eAAe,CAACY,MAAM,CAACV,SAAS;gBAEtC,sCAAsC;gBACtC,MAAMW,gBAAgBC,iBAAiBH,MAAMZ,WAAW;gBAExD,gHAAgH;gBAChH,mBAAmB;gBACnB,KAAK,MAAMgB,YAAYR,UAAW;oBAChC,IAAIM,cAAcG,GAAG,CAACD,WAAW;oBAEjC,OAAOJ,MAAMM,MAAM,CAACF,SAAS;gBAC/B;YACF;QACF;QAEAG,4BAA4B,CAACpB;YAC3B,MAAMqB,aAAavB,MAAMG,WAAW,CAACD,aAAa;YAClD,IAAIqB,eAAed,WAAW;gBAC5B,MAAM,IAAIC,MAAM,CAAC,oBAAoB,EAAER,aAAa,UAAU,CAAC;YACjE;YACAH,IAAI,CAACyB;gBACHA,MAAMC,sBAAsB,GAAG;oBAAEvB;oBAAcwB,gBAAgBH,WAAWI,KAAK;gBAAC;YAClF;QACF;QAEAC,6BAA6B,IAC3B7B,IAAI,CAACyB;gBACHA,MAAMC,sBAAsB,GAAGhB;YACjC;IACJ,CAAA,EAAG;AAEH,sFAAsF;AACtF,SAASS,iBAAiBf,WAA2C;IACnE,MAAMc,gBAAgB,IAAIY;IAC1B,KAAK,MAAMxB,SAASO,OAAOC,MAAM,CAACV,aAAc;QAC9C,KAAK,MAAMgB,YAAYP,OAAOC,MAAM,CAACR,MAAMS,aAAa,EAAG;YACzDG,cAAca,GAAG,CAACX;QACpB;IACF;IACA,OAAOF;AACT"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export * from './common';
|
|
2
2
|
export * from './dashboard-provider-api';
|
|
3
3
|
export * from './DashboardProvider';
|
|
4
|
-
export type {
|
|
4
|
+
export type { PanelGroupDefinition, PanelGroupItemId, PanelGroupItemLayoutId, PanelGroupItemLayout, } from './panel-group-slice';
|
|
5
5
|
export type { PanelGroupEditor, PanelGroupEditorValues } from './panel-group-editor-slice';
|
|
6
6
|
export type { DeletePanelDialogState } from './delete-panel-slice';
|
|
7
7
|
export type { DiscardChangesConfirmationDialogState } from './discard-changes-dialog-slice';
|
|
8
|
-
export type { PanelEditorValues } from './panel-editor-slice';
|
|
9
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/index.ts"],"names":[],"mappings":"AAaA,cAAc,UAAU,CAAC;AACzB,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,YAAY,EACV,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/index.ts"],"names":[],"mappings":"AAaA,cAAc,UAAU,CAAC;AACzB,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,YAAY,EACV,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAC3F,YAAY,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnE,YAAY,EAAE,qCAAqC,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './common';\nexport * from './dashboard-provider-api';\nexport * from './DashboardProvider';\nexport type {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './common';\nexport * from './dashboard-provider-api';\nexport * from './DashboardProvider';\nexport type {\n PanelGroupDefinition,\n PanelGroupItemId,\n PanelGroupItemLayoutId,\n PanelGroupItemLayout,\n} from './panel-group-slice';\nexport type { PanelGroupEditor, PanelGroupEditorValues } from './panel-group-editor-slice';\nexport type { DeletePanelDialogState } from './delete-panel-slice';\nexport type { DiscardChangesConfirmationDialogState } from './discard-changes-dialog-slice';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,WAAW;AACzB,cAAc,2BAA2B;AACzC,cAAc,sBAAsB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Action,
|
|
1
|
+
import { Action, PanelEditorValues, PanelGroupId } from '@perses-dev/core';
|
|
2
2
|
import { StateCreator } from 'zustand';
|
|
3
3
|
import { Middleware } from './common';
|
|
4
|
-
import { PanelGroupSlice, PanelGroupItemId
|
|
4
|
+
import { PanelGroupSlice, PanelGroupItemId } from './panel-group-slice';
|
|
5
5
|
import { PanelSlice } from './panel-slice';
|
|
6
6
|
/**
|
|
7
7
|
* Slice that handles the visual editor state and actions for adding or editing Panels.
|
|
@@ -42,13 +42,6 @@ export interface PanelEditorState {
|
|
|
42
42
|
*/
|
|
43
43
|
close: () => void;
|
|
44
44
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Panel values that can be edited in the panel editor.
|
|
47
|
-
*/
|
|
48
|
-
export interface PanelEditorValues {
|
|
49
|
-
groupId: PanelGroupId;
|
|
50
|
-
panelDefinition: PanelDefinition;
|
|
51
|
-
}
|
|
52
45
|
/**
|
|
53
46
|
* Curried function for creating the PanelEditorSlice.
|
|
54
47
|
*/
|
|
@@ -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,
|
|
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,iBAAiB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAc,UAAU,EAAyB,MAAM,UAAU,CAAC;AACzE,OAAO,EACL,eAAe,EACf,gBAAgB,EAKjB,MAAM,qBAAqB,CAAC;AAC7B,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;IAEb;;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,CA4IA"}
|
|
@@ -10,7 +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
|
-
import { getYForNewRow, getValidPanelKey } from '../../utils
|
|
13
|
+
import { getYForNewRow, getValidPanelKey } from '../../utils';
|
|
14
14
|
import { generateId, createPanelDefinition } from './common';
|
|
15
15
|
import { addPanelGroup, createEmptyPanelGroup } from './panel-group-slice';
|
|
16
16
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Action, PanelDefinition } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { getYForNewRow, getValidPanelKey } from '../../utils/panelUtils';\nimport { generateId, Middleware, createPanelDefinition } from './common';\nimport {\n PanelGroupSlice,\n PanelGroupItemId,\n PanelGroupId,\n PanelGroupDefinition,\n PanelGroupItemLayout,\n addPanelGroup,\n createEmptyPanelGroup,\n} from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and actions for adding or editing Panels.\n */\nexport interface PanelEditorSlice {\n /**\n * Initial values for add panel if default panel kind is defined\n */\n initialValues?: Pick<PanelEditorValues, 'panelDefinition'>;\n\n /**\n * State for the panel editor when its open, otherwise undefined when it's closed.\n */\n panelEditor?: PanelEditorState;\n\n /**\n * Opens the editor for editing an existing panel by providing its layout coordinates.\n */\n openEditPanel: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * Opens the editor for adding a new Panel to a panel group.\n */\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n}\n\nexport interface PanelEditorState {\n /**\n * Whether we're adding a new panel, or editing an existing panel.\n */\n mode: Action;\n\n /**\n * Initial values for the things that can be edited about a panel.\n */\n initialValues: PanelEditorValues;\n\n /**\n * Applies changes, but doesn't close the editor.\n */\n applyChanges: (next: PanelEditorValues) => void;\n\n /**\n * Close the editor.\n */\n close: () => void;\n}\n\n/**\n * Panel values that can be edited in the panel editor.\n */\nexport interface PanelEditorValues {\n groupId: PanelGroupId;\n panelDefinition: PanelDefinition;\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) {\n const { panels, panelGroups } = get();\n\n // Figure out the panel key at that location\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const panelKey = panelGroups[panelGroupId]?.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);\n }\n\n // Find the panel to edit\n const panelToEdit = panels[panelKey];\n if (panelToEdit === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n const editorState: PanelEditorState = {\n mode: 'update',\n initialValues: {\n groupId: panelGroupItemId.panelGroupId,\n panelDefinition: panelToEdit,\n },\n applyChanges: (next) => {\n set((state) => {\n state.panels[panelKey] = next.panelDefinition;\n\n // If the panel didn't change groups, nothing else to do\n if (next.groupId === panelGroupId) {\n return;\n }\n\n // Move panel to the new group\n const existingGroup = state.panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n\n const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout) => layout.i === panelGroupLayoutId);\n const existingLayout = existingGroup.itemLayouts[existingLayoutIdx];\n const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];\n if (existingLayoutIdx === -1 || existingLayout === undefined || existingPanelKey === undefined) {\n throw new Error(`Missing panel group item ${panelGroupLayoutId}`);\n }\n\n // Remove item from the old group\n existingGroup.itemLayouts.splice(existingLayoutIdx, 1);\n delete existingGroup.itemPanelKeys[panelGroupLayoutId];\n\n // Add item to the end of the new group\n const newGroup = state.panelGroups[next.groupId];\n if (newGroup === undefined) {\n throw new Error(`Could not find new group ${next.groupId}`);\n }\n\n newGroup.itemLayouts.push({\n i: existingLayout.i,\n x: 0,\n y: getYForNewRow(newGroup),\n w: existingLayout.w,\n h: existingLayout.h,\n });\n newGroup.itemPanelKeys[existingLayout.i] = existingPanelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n openAddPanel(panelGroupId) {\n // If a panel group isn't supplied, add to the first group or create a group if there aren't any\n let newGroup: PanelGroupDefinition | undefined = undefined;\n panelGroupId ??= get().panelGroupOrder[0];\n if (panelGroupId === undefined) {\n newGroup = createEmptyPanelGroup();\n newGroup.title = 'Panel Group';\n panelGroupId = newGroup.id;\n }\n\n const editorState: PanelEditorState = {\n mode: 'create',\n initialValues: {\n groupId: panelGroupId,\n panelDefinition: get().initialValues?.panelDefinition ?? createPanelDefinition(),\n },\n applyChanges: (next) => {\n const name = next.panelDefinition.spec.display.name;\n const panelKey = getValidPanelKey(name, get().panels);\n\n set((state) => {\n // Add a panel\n state.panels[panelKey] = next.panelDefinition;\n\n // Also add a panel group item referencing the panel\n const group = state.panelGroups[next.groupId];\n if (group === undefined) {\n throw new Error(`Missing panel group ${next.groupId}`);\n }\n const layout: PanelGroupItemLayout = {\n i: generateId().toString(),\n x: 0,\n y: getYForNewRow(group),\n w: 12,\n h: 6,\n };\n group.itemLayouts.push(layout);\n group.itemPanelKeys[layout.i] = panelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n set((state) => {\n // Add the new panel group if one was created for the panel\n if (newGroup !== undefined) {\n addPanelGroup(state, newGroup);\n }\n\n // Open the editor with the new state\n state.panelEditor = editorState;\n });\n },\n });\n}\n"],"names":["getYForNewRow","getValidPanelKey","generateId","createPanelDefinition","addPanelGroup","createEmptyPanelGroup","createPanelEditorSlice","set","get","panelEditor","undefined","openEditPanel","panelGroupItemId","panelGroups","panels","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","panelKey","itemPanelKeys","Error","panelToEdit","editorState","mode","initialValues","groupId","panelDefinition","applyChanges","next","state","existingGroup","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingLayout","existingPanelKey","splice","newGroup","push","x","y","w","h","close","openAddPanel","panelGroupOrder","title","id","name","spec","display","group","toString"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,aAAa,EAAEC,gBAAgB,QAAQ,yBAAyB;AACzE,SAASC,UAAU,EAAcC,qBAAqB,QAAQ,WAAW;AACzE,SAMEC,aAA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W,iBAAiBlB,CAAAA,sCAAAA,qBAAAA,MAAMgB,aAAa,cAAnBhB,yCAAAA,mBAAqBkB,eAAe,cAApClB,gDAAAA,qCAAwCL;oBAC3D;oBACAwB,cAAc,CAACC;wBACb,MAAMsB,OAAOtB,KAAKF,eAAe,CAACyB,IAAI,CAACC,OAAO,CAACF,IAAI;wBACnD,MAAMhC,WAAWjB,iBAAiBiD,MAAM1C,MAAMM,MAAM;wBAEpDP,IAAI,CAACsB;4BACH,cAAc;4BACdA,MAAMf,MAAM,CAACI,SAAS,GAAGU,KAAKF,eAAe;4BAE7C,oDAAoD;4BACpD,MAAM2B,QAAQxB,MAAMhB,WAAW,CAACe,KAAKH,OAAO,CAAC;4BAC7C,IAAI4B,UAAU3C,WAAW;gCACvB,MAAM,IAAIU,MAAM,CAAC,oBAAoB,EAAEQ,KAAKH,OAAO,CAAC,CAAC;4BACvD;4BACA,MAAMS,SAA+B;gCACnCC,GAAGjC,aAAaoD,QAAQ;gCACxBb,GAAG;gCACHC,GAAG1C,cAAcqD;gCACjBV,GAAG;gCACHC,GAAG;4BACL;4BACAS,MAAMrB,WAAW,CAACQ,IAAI,CAACN;4BACvBmB,MAAMlC,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 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Action, PanelEditorValues, PanelGroupId } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { getYForNewRow, getValidPanelKey } from '../../utils';\nimport { generateId, Middleware, createPanelDefinition } from './common';\nimport {\n PanelGroupSlice,\n PanelGroupItemId,\n PanelGroupDefinition,\n PanelGroupItemLayout,\n addPanelGroup,\n createEmptyPanelGroup,\n} from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and actions for adding or editing Panels.\n */\nexport interface PanelEditorSlice {\n /**\n * Initial values for add panel if default panel kind is defined\n */\n initialValues?: Pick<PanelEditorValues, 'panelDefinition'>;\n\n /**\n * State for the panel editor when its open, otherwise undefined when it's closed.\n */\n panelEditor?: PanelEditorState;\n\n /**\n * Opens the editor for editing an existing panel by providing its layout coordinates.\n */\n openEditPanel: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * Opens the editor for adding a new Panel to a panel group.\n */\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n}\n\nexport interface PanelEditorState {\n /**\n * Whether we're adding a new panel, or editing an existing panel.\n */\n mode: Action;\n\n /**\n * Initial values for the things that can be edited about a panel.\n */\n initialValues: PanelEditorValues;\n\n /**\n * Applies changes, but doesn't close the editor.\n */\n applyChanges: (next: PanelEditorValues) => void;\n\n /**\n * Close the editor.\n */\n close: () => void;\n}\n\n/**\n * Curried function for creating the PanelEditorSlice.\n */\nexport function createPanelEditorSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n PanelEditorSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelEditorSlice\n> {\n // Return the state creator function for Zustand that uses the panels provided as intitial state\n return (set, get) => ({\n panelEditor: undefined,\n\n openEditPanel(panelGroupItemId) {\n const { panels, panelGroups } = get();\n\n // Figure out the panel key at that location\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const panelKey = panelGroups[panelGroupId]?.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);\n }\n\n // Find the panel to edit\n const panelToEdit = panels[panelKey];\n if (panelToEdit === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n const editorState: PanelEditorState = {\n mode: 'update',\n initialValues: {\n groupId: panelGroupItemId.panelGroupId,\n panelDefinition: panelToEdit,\n },\n applyChanges: (next) => {\n set((state) => {\n state.panels[panelKey] = next.panelDefinition;\n\n // If the panel didn't change groups, nothing else to do\n if (next.groupId === panelGroupId) {\n return;\n }\n\n // Move panel to the new group\n const existingGroup = state.panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n\n const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout) => layout.i === panelGroupLayoutId);\n const existingLayout = existingGroup.itemLayouts[existingLayoutIdx];\n const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];\n if (existingLayoutIdx === -1 || existingLayout === undefined || existingPanelKey === undefined) {\n throw new Error(`Missing panel group item ${panelGroupLayoutId}`);\n }\n\n // Remove item from the old group\n existingGroup.itemLayouts.splice(existingLayoutIdx, 1);\n delete existingGroup.itemPanelKeys[panelGroupLayoutId];\n\n // Add item to the end of the new group\n const newGroup = state.panelGroups[next.groupId];\n if (newGroup === undefined) {\n throw new Error(`Could not find new group ${next.groupId}`);\n }\n\n newGroup.itemLayouts.push({\n i: existingLayout.i,\n x: 0,\n y: getYForNewRow(newGroup),\n w: existingLayout.w,\n h: existingLayout.h,\n });\n newGroup.itemPanelKeys[existingLayout.i] = existingPanelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n openAddPanel(panelGroupId) {\n // If a panel group isn't supplied, add to the first group or create a group if there aren't any\n let newGroup: PanelGroupDefinition | undefined = undefined;\n panelGroupId ??= get().panelGroupOrder[0];\n if (panelGroupId === undefined) {\n newGroup = createEmptyPanelGroup();\n newGroup.title = 'Panel Group';\n panelGroupId = newGroup.id;\n }\n\n const editorState: PanelEditorState = {\n mode: 'create',\n initialValues: {\n groupId: panelGroupId,\n panelDefinition: get().initialValues?.panelDefinition ?? createPanelDefinition(),\n },\n applyChanges: (next) => {\n const name = next.panelDefinition.spec.display.name;\n const panelKey = getValidPanelKey(name, get().panels);\n\n set((state) => {\n // Add a panel\n state.panels[panelKey] = next.panelDefinition;\n\n // Also add a panel group item referencing the panel\n const group = state.panelGroups[next.groupId];\n if (group === undefined) {\n throw new Error(`Missing panel group ${next.groupId}`);\n }\n const layout: PanelGroupItemLayout = {\n i: generateId().toString(),\n x: 0,\n y: getYForNewRow(group),\n w: 12,\n h: 6,\n };\n group.itemLayouts.push(layout);\n group.itemPanelKeys[layout.i] = panelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n set((state) => {\n // Add the new panel group if one was created for the panel\n if (newGroup !== undefined) {\n addPanelGroup(state, newGroup);\n }\n\n // Open the editor with the new state\n state.panelEditor = editorState;\n });\n },\n });\n}\n"],"names":["getYForNewRow","getValidPanelKey","generateId","createPanelDefinition","addPanelGroup","createEmptyPanelGroup","createPanelEditorSlice","set","get","panelEditor","undefined","openEditPanel","panelGroupItemId","panelGroups","panels","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","panelKey","itemPanelKeys","Error","panelToEdit","editorState","mode","initialValues","groupId","panelDefinition","applyChanges","next","state","existingGroup","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingLayout","existingPanelKey","splice","newGroup","push","x","y","w","h","close","openAddPanel","panelGroupOrder","title","id","name","spec","display","group","toString"],"mappings":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,cAAcyB,OAAOU;oBACvB;oBAEA,qCAAqC;oBACrCV,MAAMpB,WAAW,GAAGa;gBACtB;YACF;QACF,CAAA;AACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StateCreator } from 'zustand';
|
|
2
|
+
import { PanelGroupId } from '@perses-dev/core';
|
|
2
3
|
import { Middleware } from './common';
|
|
3
|
-
import { PanelGroupSlice
|
|
4
|
+
import { PanelGroupSlice } from './panel-group-slice';
|
|
4
5
|
export interface PanelGroupEditor {
|
|
5
6
|
mode: 'Add' | 'Edit';
|
|
6
7
|
initialValues: PanelGroupEditorValues;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panel-group-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"panel-group-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAwC,MAAM,qBAAqB,CAAC;AAE5F,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IACrB,aAAa,EAAE,sBAAsB,CAAC;IACtC,YAAY,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACrD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;OAEG;IACH,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAE9B;;OAEG;IACH,kBAAkB,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;CAC1D;AAED,eAAO,MAAM,2BAA2B,EAAE,YAAY,CAEpD,qBAAqB,GAAG,eAAe,EACvC,UAAU,EACV;CAAE,EACF,qBAAqB,CAoErB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\nimport { PanelGroupSlice,
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { PanelGroupId } from '@perses-dev/core';\nimport { Middleware } from './common';\nimport { PanelGroupSlice, addPanelGroup, createEmptyPanelGroup } from './panel-group-slice';\n\nexport interface PanelGroupEditor {\n mode: 'Add' | 'Edit';\n initialValues: PanelGroupEditorValues;\n applyChanges: (next: PanelGroupEditorValues) => void;\n close: () => void;\n}\n\nexport interface PanelGroupEditorValues {\n title: string;\n isCollapsed: boolean;\n}\n\n/**\n * Slice that handles the visual editor state and related actions for adding or editing Panel Groups.\n */\nexport interface PanelGroupEditorSlice {\n /**\n * State that's present when the panel group editor is open.\n */\n panelGroupEditor?: PanelGroupEditor;\n\n /**\n * Opens the panel group editor to add a new panel group.\n */\n openAddPanelGroup: () => void;\n\n /**\n * Opens the panel group editor to edit an existing panel group.\n */\n openEditPanelGroup: (panelGroupId: PanelGroupId) => void;\n}\n\nexport const createPanelGroupEditorSlice: StateCreator<\n // Actions in here need to modify Panel Group state\n PanelGroupEditorSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelGroupEditorSlice\n> = (set, get) => ({\n panelGroupEditor: undefined,\n\n openAddPanelGroup: () => {\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Add',\n initialValues: {\n title: '',\n isCollapsed: false,\n },\n applyChanges(next) {\n const newGroup = createEmptyPanelGroup();\n newGroup.title = next.title;\n newGroup.isCollapsed = next.isCollapsed;\n set((draft) => {\n addPanelGroup(draft, newGroup);\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n\n openEditPanelGroup: (panelGroupId) => {\n const existingGroup = get().panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Edit',\n initialValues: {\n title: existingGroup.title ?? '',\n isCollapsed: existingGroup.isCollapsed,\n },\n applyChanges(next) {\n set((draft) => {\n const group = draft.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n group.title = next.title;\n group.isCollapsed = next.isCollapsed;\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n});\n"],"names":["addPanelGroup","createEmptyPanelGroup","createPanelGroupEditorSlice","set","get","panelGroupEditor","undefined","openAddPanelGroup","editor","mode","initialValues","title","isCollapsed","applyChanges","next","newGroup","draft","close","openEditPanelGroup","panelGroupId","existingGroup","panelGroups","Error","group"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAKjC,SAA0BA,aAAa,EAAEC,qBAAqB,QAAQ,sBAAsB;AAkC5F,OAAO,MAAMC,8BAMT,CAACC,KAAKC,MAAS,CAAA;QACjBC,kBAAkBC;QAElBC,mBAAmB;YACjB,0BAA0B;YAC1B,MAAMC,SAA2B;gBAC/BC,MAAM;gBACNC,eAAe;oBACbC,OAAO;oBACPC,aAAa;gBACf;gBACAC,cAAaC,IAAI;oBACf,MAAMC,WAAWd;oBACjBc,SAASJ,KAAK,GAAGG,KAAKH,KAAK;oBAC3BI,SAASH,WAAW,GAAGE,KAAKF,WAAW;oBACvCT,IAAI,CAACa;wBACHhB,cAAcgB,OAAOD;oBACvB;gBACF;gBACAE;oBACEd,IAAI,CAACa;wBACHA,MAAMX,gBAAgB,GAAGC;oBAC3B;gBACF;YACF;YAEA,kBAAkB;YAClBH,IAAI,CAACa;gBACHA,MAAMX,gBAAgB,GAAGG;YAC3B;QACF;QAEAU,oBAAoB,CAACC;YACnB,MAAMC,gBAAgBhB,MAAMiB,WAAW,CAACF,aAAa;YACrD,IAAIC,kBAAkBd,WAAW;gBAC/B,MAAM,IAAIgB,MAAM,CAAC,oBAAoB,EAAEH,aAAa,eAAe,CAAC;YACtE;gBAMWC;YAJX,0BAA0B;YAC1B,MAAMZ,SAA2B;gBAC/BC,MAAM;gBACNC,eAAe;oBACbC,OAAOS,CAAAA,uBAAAA,cAAcT,KAAK,cAAnBS,kCAAAA,uBAAuB;oBAC9BR,aAAaQ,cAAcR,WAAW;gBACxC;gBACAC,cAAaC,IAAI;oBACfX,IAAI,CAACa;wBACH,MAAMO,QAAQP,MAAMK,WAAW,CAACF,aAAa;wBAC7C,IAAII,UAAUjB,WAAW;4BACvB,MAAM,IAAIgB,MAAM,CAAC,oBAAoB,EAAEH,aAAa,eAAe,CAAC;wBACtE;wBACAI,MAAMZ,KAAK,GAAGG,KAAKH,KAAK;wBACxBY,MAAMX,WAAW,GAAGE,KAAKF,WAAW;oBACtC;gBACF;gBACAK;oBACEd,IAAI,CAACa;wBACHA,MAAMX,gBAAgB,GAAGC;oBAC3B;gBACF;YACF;YAEA,kBAAkB;YAClBH,IAAI,CAACa;gBACHA,MAAMX,gBAAgB,GAAGG;YAC3B;QACF;IACF,CAAA,EAAG"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LayoutDefinition } from '@perses-dev/core';
|
|
1
|
+
import { LayoutDefinition, PanelGroupId } from '@perses-dev/core';
|
|
2
2
|
import { WritableDraft } from 'immer/dist/internal';
|
|
3
3
|
import { Layout } from 'react-grid-layout';
|
|
4
4
|
import { StateCreator } from 'zustand';
|
|
@@ -24,7 +24,6 @@ export interface PanelGroupSlice {
|
|
|
24
24
|
*/
|
|
25
25
|
updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;
|
|
26
26
|
}
|
|
27
|
-
export type PanelGroupId = number;
|
|
28
27
|
export interface PanelGroupDefinition {
|
|
29
28
|
id: PanelGroupId;
|
|
30
29
|
isCollapsed: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAsB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAsB,gBAAgB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC;IAExD;;OAEG;IACH,eAAe,EAAE,YAAY,EAAE,CAAC;IAEhC;;OAEG;IACH,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAE1D;;OAEG;IACH,uBAAuB,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC;CACjH;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,YAAY,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,oBAAoB,EAAE,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,oBAAqB,SAAQ,MAAM;IAClD,CAAC,EAAE,sBAAsB,CAAC;CAC3B;AAED,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,YAAY,CAAC;IAC3B,sBAAsB,EAAE,sBAAsB,CAAC;CAChD;AAKD,wBAAgB,uBAAuB,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC,EAAE,gBAAgB,WAEjF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,YAAY,CAAC,eAAe,EAAE,UAAU,EAAE,EAAE,EAAE,eAAe,CAAC,CAkChE;AAED,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,IAAI,CAAC,eAAe,EAAE,aAAa,GAAG,iBAAiB,CAAC,CAoC1D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,oBAAoB,CAQ5D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,eAAe,CAAC,EAAE,QAAQ,EAAE,oBAAoB,QAGlG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { getPanelKeyFromRef, LayoutDefinition } from '@perses-dev/core';\nimport { WritableDraft } from 'immer/dist/internal';\nimport { Layout } from 'react-grid-layout';\nimport { StateCreator } from 'zustand';\nimport { generateId, Middleware } from './common';\n\n/**\n * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.\n */\nexport interface PanelGroupSlice {\n /**\n * Panel groups indexed by their ID.\n */\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>;\n\n /**\n * An array of panel group IDs, representing their order in the dashboard.\n */\n panelGroupOrder: PanelGroupId[];\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Update the item layouts for a panel group when, for example, a panel is moved or resized.\n */\n updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;\n}\n\nexport
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { getPanelKeyFromRef, LayoutDefinition, PanelGroupId } from '@perses-dev/core';\nimport { WritableDraft } from 'immer/dist/internal';\nimport { Layout } from 'react-grid-layout';\nimport { StateCreator } from 'zustand';\nimport { generateId, Middleware } from './common';\n\n/**\n * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.\n */\nexport interface PanelGroupSlice {\n /**\n * Panel groups indexed by their ID.\n */\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>;\n\n /**\n * An array of panel group IDs, representing their order in the dashboard.\n */\n panelGroupOrder: PanelGroupId[];\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Update the item layouts for a panel group when, for example, a panel is moved or resized.\n */\n updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;\n}\n\nexport interface PanelGroupDefinition {\n id: PanelGroupId;\n isCollapsed: boolean;\n title?: string;\n itemLayouts: PanelGroupItemLayout[];\n itemPanelKeys: Record<PanelGroupItemLayoutId, string>;\n}\n\nexport interface PanelGroupItemLayout extends Layout {\n i: PanelGroupItemLayoutId;\n}\n\nexport type PanelGroupItemLayoutId = string;\n\n/**\n * Uniquely identifies an item in a PanelGroup.\n */\nexport interface PanelGroupItemId {\n panelGroupId: PanelGroupId;\n panelGroupItemLayoutId: PanelGroupItemLayoutId;\n}\n\n/*\n * Check if two PanelGroupItemId are equal\n */\nexport function isPanelGroupItemIdEqual(a?: PanelGroupItemId, b?: PanelGroupItemId) {\n return a?.panelGroupId === b?.panelGroupId && a?.panelGroupItemLayoutId === b?.panelGroupItemLayoutId;\n}\n\n/**\n * Curried function for creating a PanelGroupSlice.\n */\nexport function createPanelGroupSlice(\n layouts: LayoutDefinition[]\n): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice> {\n const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);\n\n // Return the state creator function for Zustand\n return (set) => ({\n panelGroups,\n panelGroupOrder,\n\n swapPanelGroups(x, y) {\n set((state) => {\n if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {\n throw new Error('index out of bound');\n }\n const xPanelGroup = state.panelGroupOrder[x];\n const yPanelGroup = state.panelGroupOrder[y];\n\n if (xPanelGroup === undefined || yPanelGroup === undefined) {\n throw new Error('panel group is undefined');\n }\n // assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups\n [state.panelGroupOrder[x], state.panelGroupOrder[y]] = [yPanelGroup, xPanelGroup];\n });\n },\n\n updatePanelGroupLayouts(panelGroupId, itemLayouts) {\n set((state) => {\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Cannot find panel group ${panelGroupId}`);\n }\n group.itemLayouts = itemLayouts;\n });\n },\n });\n}\n\nexport function convertLayoutsToPanelGroups(\n layouts: LayoutDefinition[]\n): Pick<PanelGroupSlice, 'panelGroups' | 'panelGroupOrder'> {\n // Convert the initial layouts from the JSON\n const panelGroups: PanelGroupSlice['panelGroups'] = {};\n const panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'] = [];\n for (const layout of layouts) {\n const itemLayouts: PanelGroupDefinition['itemLayouts'] = [];\n const itemPanelKeys: PanelGroupDefinition['itemPanelKeys'] = {};\n\n // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels\n for (const item of layout.spec.items) {\n const panelGroupLayoutId = generateId().toString();\n itemLayouts.push({\n i: panelGroupLayoutId,\n w: item.width,\n h: item.height,\n x: item.x,\n y: item.y,\n });\n itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);\n }\n\n // Create the panel group and keep track of the ID order\n const panelGroupId = generateId();\n panelGroups[panelGroupId] = {\n id: panelGroupId,\n isCollapsed: layout.spec.display?.collapse?.open === false,\n title: layout.spec.display?.title,\n itemLayouts,\n itemPanelKeys,\n };\n panelGroupIdOrder.push(panelGroupId);\n }\n return {\n panelGroups,\n panelGroupOrder: panelGroupIdOrder,\n };\n}\n\n/**\n * Private helper function for creating an empty panel group.\n */\nexport function createEmptyPanelGroup(): PanelGroupDefinition {\n return {\n id: generateId(),\n title: undefined,\n isCollapsed: false,\n itemLayouts: [],\n itemPanelKeys: {},\n };\n}\n\n/**\n * Private helper function that modifies panel group state to add a new panel\n */\nexport function addPanelGroup(draft: WritableDraft<PanelGroupSlice>, newGroup: PanelGroupDefinition) {\n draft.panelGroups[newGroup.id] = newGroup;\n draft.panelGroupOrder.unshift(newGroup.id);\n}\n"],"names":["getPanelKeyFromRef","generateId","isPanelGroupItemIdEqual","a","b","panelGroupId","panelGroupItemLayoutId","createPanelGroupSlice","layouts","panelGroups","panelGroupOrder","convertLayoutsToPanelGroups","set","swapPanelGroups","x","y","state","length","Error","xPanelGroup","yPanelGroup","undefined","updatePanelGroupLayouts","itemLayouts","group","panelGroupIdOrder","layout","itemPanelKeys","item","spec","items","panelGroupLayoutId","toString","push","i","w","width","h","height","content","id","isCollapsed","display","collapse","open","title","createEmptyPanelGroup","addPanelGroup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O;QACLN,IAAIvC;QACJ4C,OAAOxB;QACPoB,aAAa;QACblB,aAAa,EAAE;QACfI,eAAe,CAAC;IAClB;AACF;AAEA;;CAEC,GACD,OAAO,SAASoB,cAAcC,KAAqC,EAAEC,QAA8B;IACjGD,MAAMvC,WAAW,CAACwC,SAAST,EAAE,CAAC,GAAGS;IACjCD,MAAMtC,eAAe,CAACwC,OAAO,CAACD,SAAST,EAAE;AAC3C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view-panel-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/view-panel-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,
|
|
1
|
+
{"version":3,"file":"view-panel-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/view-panel-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAwB,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAEhF,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,cAAc,CAAC;IAC1B,YAAY,EAAE,MAAM,gBAAgB,GAAG,SAAS,CAAC;IACjD,YAAY,EAAE,CAAC,gBAAgB,CAAC,EAAE,gBAAgB,KAAK,IAAI,CAAC;CAC7D;AAED,MAAM,WAAW,cAAc;IAE7B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,YAAY,CAAC,EAAE,MAAM,EACrB,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,GAClD,YAAY,CAAC,cAAc,GAAG,eAAe,EAAE,UAAU,EAAE,EAAE,EAAE,cAAc,CAAC,CAwBhF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/view-panel-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { PanelGroupDefinition,
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/view-panel-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { PanelGroupDefinition, PanelGroupItemId } from '@perses-dev/dashboards';\nimport { PanelGroupId } from '@perses-dev/core';\nimport { Middleware } from './common';\nimport { PanelGroupSlice } from './panel-group-slice';\n\n/**\n * Slice that handles viewing Panels in max size (\"full screen\").\n */\nexport interface ViewPanelSlice {\n viewPanel: ViewPanelState;\n getViewPanel: () => PanelGroupItemId | undefined;\n setViewPanel: (panelGroupItemId?: PanelGroupItemId) => void;\n}\n\nexport interface ViewPanelState {\n // Do not use directly, use `getViewPanel()` instead for getting the current viewed PanelGroupItemId!\n panelGroupItemId?: PanelGroupItemId;\n panelRef?: string;\n}\n\n/**\n * Curried function for viewing panel in max size (\"full screen\").\n */\nexport function createViewPanelSlice(\n viewPanelRef?: string,\n setViewPanelRef?: (ref: string | undefined) => void\n): StateCreator<ViewPanelSlice & PanelGroupSlice, Middleware, [], ViewPanelSlice> {\n return (set, get) => ({\n viewPanel: {\n panelGroupItemId: undefined,\n panelRef: viewPanelRef,\n },\n\n getViewPanel(): PanelGroupItemId | undefined {\n return getViewPanelGroupId(get().panelGroups, get().viewPanel.panelGroupItemId, get().viewPanel.panelRef);\n },\n\n setViewPanel(panelGroupItemId?: PanelGroupItemId) {\n set((state) => {\n state.viewPanel = {\n panelRef: undefined,\n panelGroupItemId: panelGroupItemId,\n };\n const panelRef = findPanelRefOfPanelGroupItemId(get().panelGroups, panelGroupItemId);\n if (setViewPanelRef) {\n setViewPanelRef(panelRef);\n }\n });\n },\n });\n}\n\nfunction getViewPanelGroupId(\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>,\n panelGroupItemId?: PanelGroupItemId,\n panelRef?: string\n): PanelGroupItemId | undefined {\n if (panelGroupItemId) {\n return panelGroupItemId;\n }\n\n if (panelRef) {\n return findPanelGroupItemIdOfPanelRef(panelGroups, panelRef);\n }\n\n return undefined;\n}\n\n// Find the PanelGroupItemId of a Panel from a PanelRef\nfunction findPanelGroupItemIdOfPanelRef(\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>,\n panelRef?: string\n): PanelGroupItemId | undefined {\n for (const panelGroup of Object.values(panelGroups)) {\n const itemPanel = Object.entries(panelGroup.itemPanelKeys ?? []).find(([_, value]) => value === panelRef);\n if (itemPanel) {\n const [key] = itemPanel;\n return {\n panelGroupId: panelGroup.id,\n panelGroupItemLayoutId: key,\n };\n }\n }\n return undefined;\n}\n\n// Find the PanelRef from a PanelGroupItemId\nfunction findPanelRefOfPanelGroupItemId(\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>,\n panelGroupItemId?: PanelGroupItemId\n): string | undefined {\n if (!panelGroupItemId) {\n return undefined;\n }\n const panelGroup = panelGroups[panelGroupItemId.panelGroupId];\n if (panelGroup) {\n return panelGroup.itemPanelKeys[panelGroupItemId.panelGroupItemLayoutId];\n }\n return undefined;\n}\n"],"names":["createViewPanelSlice","viewPanelRef","setViewPanelRef","set","get","viewPanel","panelGroupItemId","undefined","panelRef","getViewPanel","getViewPanelGroupId","panelGroups","setViewPanel","state","findPanelRefOfPanelGroupItemId","findPanelGroupItemIdOfPanelRef","panelGroup","Object","values","itemPanel","entries","itemPanelKeys","find","_","value","key","panelGroupId","id","panelGroupItemLayoutId"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAuBjC;;CAEC,GACD,OAAO,SAASA,qBACdC,YAAqB,EACrBC,eAAmD;IAEnD,OAAO,CAACC,KAAKC,MAAS,CAAA;YACpBC,WAAW;gBACTC,kBAAkBC;gBAClBC,UAAUP;YACZ;YAEAQ;gBACE,OAAOC,oBAAoBN,MAAMO,WAAW,EAAEP,MAAMC,SAAS,CAACC,gBAAgB,EAAEF,MAAMC,SAAS,CAACG,QAAQ;YAC1G;YAEAI,cAAaN,gBAAmC;gBAC9CH,IAAI,CAACU;oBACHA,MAAMR,SAAS,GAAG;wBAChBG,UAAUD;wBACVD,kBAAkBA;oBACpB;oBACA,MAAME,WAAWM,+BAA+BV,MAAMO,WAAW,EAAEL;oBACnE,IAAIJ,iBAAiB;wBACnBA,gBAAgBM;oBAClB;gBACF;YACF;QACF,CAAA;AACF;AAEA,SAASE,oBACPC,WAAuD,EACvDL,gBAAmC,EACnCE,QAAiB;IAEjB,IAAIF,kBAAkB;QACpB,OAAOA;IACT;IAEA,IAAIE,UAAU;QACZ,OAAOO,+BAA+BJ,aAAaH;IACrD;IAEA,OAAOD;AACT;AAEA,uDAAuD;AACvD,SAASQ,+BACPJ,WAAuD,EACvD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