@perses-dev/dashboards 0.52.0-rc.1 → 0.52.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/context/DashboardProvider/DashboardProviderWithQueryParams.js +5 -27
- package/dist/cjs/context/DashboardProvider/duplicate-panel-slice.js +1 -1
- package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +1 -2
- package/dist/cjs/context/VariableProvider/query-params.js +14 -12
- package/dist/cjs/test/render.js +8 -6
- package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.js +5 -27
- package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.js.map +1 -1
- package/dist/context/DashboardProvider/duplicate-panel-slice.js +2 -2
- package/dist/context/DashboardProvider/duplicate-panel-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js +2 -3
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
- package/dist/context/VariableProvider/query-params.d.ts +3 -4
- package/dist/context/VariableProvider/query-params.d.ts.map +1 -1
- package/dist/context/VariableProvider/query-params.js +14 -9
- package/dist/context/VariableProvider/query-params.js.map +1 -1
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +8 -6
- package/dist/test/render.js.map +1 -1
- package/dist/utils/panelUtils.d.ts +3 -0
- package/dist/utils/panelUtils.d.ts.map +1 -1
- package/dist/utils/panelUtils.js +3 -0
- package/dist/utils/panelUtils.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2025 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
|
|
@@ -21,37 +21,15 @@ Object.defineProperty(exports, "DashboardProviderWithQueryParams", {
|
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
const _jsxruntime = require("react/jsx-runtime");
|
|
24
|
-
const
|
|
25
|
-
const _react = require("react");
|
|
26
|
-
const _nuqs = require("nuqs");
|
|
24
|
+
const _usequeryparams = require("use-query-params");
|
|
27
25
|
const _DashboardProvider = require("./DashboardProvider");
|
|
28
26
|
function DashboardProviderWithQueryParams({ children, initialState }) {
|
|
29
|
-
const [viewPanelRef, setViewPanelRef] = (0,
|
|
30
|
-
ref: _zod.z.string(),
|
|
31
|
-
repeatVariable: _zod.z.tuple([
|
|
32
|
-
_zod.z.string(),
|
|
33
|
-
_zod.z.string()
|
|
34
|
-
]).optional()
|
|
35
|
-
}).optional()));
|
|
36
|
-
// nuqs returns null when the query param is not present, but our state expects undefined when not present
|
|
37
|
-
const viewPanelRefNotNull = (0, _react.useMemo)(()=>{
|
|
38
|
-
return viewPanelRef ?? undefined;
|
|
39
|
-
}, [
|
|
40
|
-
viewPanelRef
|
|
41
|
-
]);
|
|
42
|
-
const handleSetViewPanelRef = (0, _react.useCallback)((panelRef)=>{
|
|
43
|
-
if (panelRef) {
|
|
44
|
-
return setViewPanelRef(panelRef);
|
|
45
|
-
}
|
|
46
|
-
return setViewPanelRef(null);
|
|
47
|
-
}, [
|
|
48
|
-
setViewPanelRef
|
|
49
|
-
]);
|
|
27
|
+
const [viewPanelRef, setViewPanelRef] = (0, _usequeryparams.useQueryParam)('viewPanelRef', _usequeryparams.JsonParam);
|
|
50
28
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_DashboardProvider.DashboardProvider, {
|
|
51
29
|
initialState: {
|
|
52
30
|
...initialState,
|
|
53
|
-
viewPanelRef:
|
|
54
|
-
setViewPanelRef:
|
|
31
|
+
viewPanelRef: viewPanelRef ?? undefined,
|
|
32
|
+
setViewPanelRef: setViewPanelRef
|
|
55
33
|
},
|
|
56
34
|
children: children
|
|
57
35
|
});
|
|
@@ -49,7 +49,7 @@ function createDuplicatePanelSlice() {
|
|
|
49
49
|
if (matchingLayout === undefined) {
|
|
50
50
|
throw new Error(`Cannot find layout for Panel with key '${panelKey}'`);
|
|
51
51
|
}
|
|
52
|
-
const dupePanelKey = (
|
|
52
|
+
const dupePanelKey = crypto.randomUUID().replaceAll('-', '');
|
|
53
53
|
state.panels[dupePanelKey] = panelToDupe;
|
|
54
54
|
const duplicateLayout = {
|
|
55
55
|
i: (0, _common.generateId)().toString(),
|
|
@@ -110,8 +110,7 @@ function createPanelEditorSlice() {
|
|
|
110
110
|
panelDefinition: get().initialValues?.panelDefinition ?? (0, _common.createPanelDefinition)()
|
|
111
111
|
},
|
|
112
112
|
applyChanges: (next)=>{
|
|
113
|
-
const
|
|
114
|
-
const panelKey = (0, _utils.getValidPanelKey)(name, get().panels);
|
|
113
|
+
const panelKey = crypto.randomUUID().replaceAll('-', '');
|
|
115
114
|
set((state)=>{
|
|
116
115
|
// Add a panel
|
|
117
116
|
state.panels[panelKey] = next.panelDefinition;
|
|
@@ -33,14 +33,11 @@ _export(exports, {
|
|
|
33
33
|
getURLQueryParamName: function() {
|
|
34
34
|
return getURLQueryParamName;
|
|
35
35
|
},
|
|
36
|
-
parseAsVariableValue: function() {
|
|
37
|
-
return parseAsVariableValue;
|
|
38
|
-
},
|
|
39
36
|
useVariableQueryParams: function() {
|
|
40
37
|
return useVariableQueryParams;
|
|
41
38
|
}
|
|
42
39
|
});
|
|
43
|
-
const
|
|
40
|
+
const _usequeryparams = require("use-query-params");
|
|
44
41
|
const variableQueryParameterPrefix = 'var-';
|
|
45
42
|
function getURLQueryParamName(name) {
|
|
46
43
|
return `${variableQueryParameterPrefix}${name}`;
|
|
@@ -49,7 +46,7 @@ function encodeVariableValue(value) {
|
|
|
49
46
|
if (Array.isArray(value)) {
|
|
50
47
|
return value.join(',');
|
|
51
48
|
}
|
|
52
|
-
return value
|
|
49
|
+
return value;
|
|
53
50
|
}
|
|
54
51
|
function decodeVariableValue(value) {
|
|
55
52
|
if (!value) {
|
|
@@ -61,18 +58,23 @@ function decodeVariableValue(value) {
|
|
|
61
58
|
}
|
|
62
59
|
return values;
|
|
63
60
|
}
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
const VariableValueParam = {
|
|
62
|
+
encode: encodeVariableValue,
|
|
63
|
+
decode: (v)=>{
|
|
64
|
+
if (typeof v === 'string') {
|
|
65
|
+
return decodeVariableValue(v);
|
|
66
|
+
}
|
|
67
|
+
return '';
|
|
68
|
+
}
|
|
69
|
+
};
|
|
68
70
|
function useVariableQueryParams(defs) {
|
|
69
71
|
const config = {};
|
|
70
72
|
defs.forEach((def)=>{
|
|
71
73
|
const name = getURLQueryParamName(def.spec.name);
|
|
72
|
-
config[name] =
|
|
74
|
+
config[name] = VariableValueParam;
|
|
73
75
|
});
|
|
74
|
-
return (0,
|
|
75
|
-
|
|
76
|
+
return (0, _usequeryparams.useQueryParams)(config, {
|
|
77
|
+
updateType: 'replaceIn'
|
|
76
78
|
});
|
|
77
79
|
}
|
|
78
80
|
function getInitalValuesFromQueryParameters(queryParamValues) {
|
package/dist/cjs/test/render.js
CHANGED
|
@@ -28,7 +28,8 @@ const _react = require("@testing-library/react");
|
|
|
28
28
|
const _history = require("history");
|
|
29
29
|
const _react1 = require("react");
|
|
30
30
|
const _reactrouterdom = require("react-router-dom");
|
|
31
|
-
const
|
|
31
|
+
const _usequeryparams = require("use-query-params");
|
|
32
|
+
const _reactrouter6 = require("use-query-params/adapters/react-router-6");
|
|
32
33
|
const _context = require("../context");
|
|
33
34
|
const _test = require("../test");
|
|
34
35
|
const _pluginregistry = require("./plugin-registry");
|
|
@@ -62,11 +63,12 @@ function renderWithContext(ui, options, history) {
|
|
|
62
63
|
});
|
|
63
64
|
const customHistory = history ?? (0, _history.createMemoryHistory)();
|
|
64
65
|
const mockRegistry = (0, _pluginsystem.mockPluginRegistry)(..._pluginregistry.MOCK_PLUGINS);
|
|
65
|
-
const BaseRender = ()=>/*#__PURE__*/ (0, _jsxruntime.jsx)(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
const BaseRender = ()=>/*#__PURE__*/ (0, _jsxruntime.jsx)(CustomRouter, {
|
|
67
|
+
history: customHistory,
|
|
68
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_reactquery.QueryClientProvider, {
|
|
69
|
+
client: queryClient,
|
|
70
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_usequeryparams.QueryParamProvider, {
|
|
71
|
+
adapter: _reactrouter6.ReactRouter6Adapter,
|
|
70
72
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.SnackbarProvider, {
|
|
71
73
|
anchorOrigin: {
|
|
72
74
|
vertical: 'bottom',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DashboardProviderWithQueryParams.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/DashboardProviderWithQueryParams.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DashboardProviderWithQueryParams.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/DashboardProviderWithQueryParams.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErC,OAAO,EAAqB,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAEhF,wBAAgB,gCAAgC,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,sBAAsB,GAAG,YAAY,CAcjH"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2025 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
|
|
@@ -11,37 +11,15 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import {
|
|
15
|
-
import { useCallback, useMemo } from 'react';
|
|
16
|
-
import { parseAsJson, useQueryState } from 'nuqs';
|
|
14
|
+
import { JsonParam, useQueryParam } from 'use-query-params';
|
|
17
15
|
import { DashboardProvider } from './DashboardProvider';
|
|
18
16
|
export function DashboardProviderWithQueryParams({ children, initialState }) {
|
|
19
|
-
const [viewPanelRef, setViewPanelRef] =
|
|
20
|
-
ref: z.string(),
|
|
21
|
-
repeatVariable: z.tuple([
|
|
22
|
-
z.string(),
|
|
23
|
-
z.string()
|
|
24
|
-
]).optional()
|
|
25
|
-
}).optional()));
|
|
26
|
-
// nuqs returns null when the query param is not present, but our state expects undefined when not present
|
|
27
|
-
const viewPanelRefNotNull = useMemo(()=>{
|
|
28
|
-
return viewPanelRef ?? undefined;
|
|
29
|
-
}, [
|
|
30
|
-
viewPanelRef
|
|
31
|
-
]);
|
|
32
|
-
const handleSetViewPanelRef = useCallback((panelRef)=>{
|
|
33
|
-
if (panelRef) {
|
|
34
|
-
return setViewPanelRef(panelRef);
|
|
35
|
-
}
|
|
36
|
-
return setViewPanelRef(null);
|
|
37
|
-
}, [
|
|
38
|
-
setViewPanelRef
|
|
39
|
-
]);
|
|
17
|
+
const [viewPanelRef, setViewPanelRef] = useQueryParam('viewPanelRef', JsonParam);
|
|
40
18
|
return /*#__PURE__*/ _jsx(DashboardProvider, {
|
|
41
19
|
initialState: {
|
|
42
20
|
...initialState,
|
|
43
|
-
viewPanelRef:
|
|
44
|
-
setViewPanelRef:
|
|
21
|
+
viewPanelRef: viewPanelRef ?? undefined,
|
|
22
|
+
setViewPanelRef: setViewPanelRef
|
|
45
23
|
},
|
|
46
24
|
children: children
|
|
47
25
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/DashboardProviderWithQueryParams.tsx"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/DashboardProviderWithQueryParams.tsx"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ReactElement } from 'react';\nimport { JsonParam, useQueryParam } from 'use-query-params';\nimport { DashboardProvider, DashboardProviderProps } from './DashboardProvider';\n\nexport function DashboardProviderWithQueryParams({ children, initialState }: DashboardProviderProps): ReactElement {\n const [viewPanelRef, setViewPanelRef] = useQueryParam('viewPanelRef', JsonParam);\n\n return (\n <DashboardProvider\n initialState={{\n ...initialState,\n viewPanelRef: viewPanelRef ?? undefined, // viewPanelRef can be null, forcing to undefined\n setViewPanelRef: setViewPanelRef,\n }}\n >\n {children}\n </DashboardProvider>\n );\n}\n"],"names":["JsonParam","useQueryParam","DashboardProvider","DashboardProviderWithQueryParams","children","initialState","viewPanelRef","setViewPanelRef","undefined"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,SAAS,EAAEC,aAAa,QAAQ,mBAAmB;AAC5D,SAASC,iBAAiB,QAAgC,sBAAsB;AAEhF,OAAO,SAASC,iCAAiC,EAAEC,QAAQ,EAAEC,YAAY,EAA0B;IACjG,MAAM,CAACC,cAAcC,gBAAgB,GAAGN,cAAc,gBAAgBD;IAEtE,qBACE,KAACE;QACCG,cAAc;YACZ,GAAGA,YAAY;YACfC,cAAcA,gBAAgBE;YAC9BD,iBAAiBA;QACnB;kBAECH;;AAGP"}
|
|
@@ -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 {
|
|
13
|
+
import { insertPanelInLayout } from '../../utils/panelUtils';
|
|
14
14
|
import { generateId } from './common';
|
|
15
15
|
/**
|
|
16
16
|
* Curried function for duplicating a panel.
|
|
@@ -41,7 +41,7 @@ import { generateId } from './common';
|
|
|
41
41
|
if (matchingLayout === undefined) {
|
|
42
42
|
throw new Error(`Cannot find layout for Panel with key '${panelKey}'`);
|
|
43
43
|
}
|
|
44
|
-
const dupePanelKey =
|
|
44
|
+
const dupePanelKey = crypto.randomUUID().replaceAll('-', '');
|
|
45
45
|
state.panels[dupePanelKey] = panelToDupe;
|
|
46
46
|
const duplicateLayout = {
|
|
47
47
|
i: generateId().toString(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/duplicate-panel-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/context/DashboardProvider/duplicate-panel-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { insertPanelInLayout, UnpositionedPanelGroupItemLayout } from '../../utils/panelUtils';\nimport { generateId, Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupItemId } from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles duplicating Panels.\n */\nexport interface DuplicatePanelSlice {\n /**\n * Duplicate panel.\n */\n duplicatePanel: (panelGroupItemId: PanelGroupItemId) => void;\n}\n\n/**\n * Curried function for duplicating a panel.\n */\nexport function createDuplicatePanelSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n DuplicatePanelSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n DuplicatePanelSlice\n> {\n return (set) => ({\n duplicatePanel(panelGroupItemId: PanelGroupItemId): void {\n set((state) => {\n const panels = state.panels;\n\n // Figure out the panel key at that location\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n const panelKey = group.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);\n }\n\n // Find the panel to edit\n const panelToDupe = panels[panelKey];\n if (panelToDupe === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n // Find the layout for the item being duped\n const matchingLayout = group.itemLayouts.find((itemLayout) => {\n return itemLayout.i === panelGroupLayoutId;\n });\n\n if (matchingLayout === undefined) {\n throw new Error(`Cannot find layout for Panel with key '${panelKey}'`);\n }\n\n const dupePanelKey = crypto.randomUUID().replaceAll('-', '');\n\n state.panels[dupePanelKey] = panelToDupe;\n\n const duplicateLayout: UnpositionedPanelGroupItemLayout = {\n i: generateId().toString(),\n w: matchingLayout.w,\n h: matchingLayout.h,\n };\n\n group.itemLayouts = insertPanelInLayout(duplicateLayout, matchingLayout, group.itemLayouts);\n\n group.itemPanelKeys[duplicateLayout.i] = dupePanelKey;\n });\n },\n });\n}\n"],"names":["insertPanelInLayout","generateId","createDuplicatePanelSlice","set","duplicatePanel","panelGroupItemId","state","panels","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","group","panelGroups","undefined","Error","panelKey","itemPanelKeys","panelToDupe","matchingLayout","itemLayouts","find","itemLayout","i","dupePanelKey","crypto","randomUUID","replaceAll","duplicateLayout","toString","w","h"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,mBAAmB,QAA0C,yBAAyB;AAC/F,SAASC,UAAU,QAAoB,WAAW;AAclD;;CAEC,GACD,OAAO,SAASC;IAOd,OAAO,CAACC,MAAS,CAAA;YACfC,gBAAeC,gBAAkC;gBAC/CF,IAAI,CAACG;oBACH,MAAMC,SAASD,MAAMC,MAAM;oBAE3B,4CAA4C;oBAC5C,MAAM,EAAEC,YAAY,EAAEC,wBAAwBC,kBAAkB,EAAE,GAAGL;oBACrE,MAAMM,QAAQL,MAAMM,WAAW,CAACJ,aAAa;oBAC7C,IAAIG,UAAUE,WAAW;wBACvB,MAAM,IAAIC,MAAM,CAAC,oBAAoB,EAAEN,cAAc;oBACvD;oBACA,MAAMO,WAAWJ,MAAMK,aAAa,CAACN,mBAAmB;oBACxD,IAAIK,aAAaF,WAAW;wBAC1B,MAAM,IAAIC,MAAM,CAAC,gCAAgC,EAAET,kBAAkB;oBACvE;oBAEA,yBAAyB;oBACzB,MAAMY,cAAcV,MAAM,CAACQ,SAAS;oBACpC,IAAIE,gBAAgBJ,WAAW;wBAC7B,MAAM,IAAIC,MAAM,CAAC,4BAA4B,EAAEC,SAAS,CAAC,CAAC;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OAEG;IACH,aAAa,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAE5D;;OAEG;IACH,YAAY,EAAE,CAAC,YAAY,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC;CACrD;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAKb,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;OAEG;IACH,aAAa,EAAE,iBAAiB,CAAC;IAEjC;;OAEG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAEhD;;OAEG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,YAAY,CAEpD,gBAAgB,GAAG,UAAU,GAAG,eAAe,EAC/C,UAAU,EACV;CAAE,EACF,gBAAgB,CACjB,
|
|
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;IAKb,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;OAEG;IACH,aAAa,EAAE,iBAAiB,CAAC;IAEjC;;OAEG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAEhD;;OAEG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,YAAY,CAEpD,gBAAgB,GAAG,UAAU,GAAG,eAAe,EAC/C,UAAU,EACV;CAAE,EACF,gBAAgB,CACjB,CA2IA"}
|
|
@@ -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
|
|
13
|
+
import { getYForNewRow } from '../../utils';
|
|
14
14
|
import { generateId, createPanelDefinition } from './common';
|
|
15
15
|
import { addPanelGroup, createEmptyPanelGroup } from './panel-group-slice';
|
|
16
16
|
/**
|
|
@@ -102,8 +102,7 @@ import { addPanelGroup, createEmptyPanelGroup } from './panel-group-slice';
|
|
|
102
102
|
panelDefinition: get().initialValues?.panelDefinition ?? createPanelDefinition()
|
|
103
103
|
},
|
|
104
104
|
applyChanges: (next)=>{
|
|
105
|
-
const
|
|
106
|
-
const panelKey = getValidPanelKey(name, get().panels);
|
|
105
|
+
const panelKey = crypto.randomUUID().replaceAll('-', '');
|
|
107
106
|
set((state)=>{
|
|
108
107
|
// Add a panel
|
|
109
108
|
state.panels[panelKey] = next.panelDefinition;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Action, PanelEditorValues, PanelGroupId } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { getYForNewRow, getValidPanelKey } from '../../utils';\nimport { generateId, Middleware, createPanelDefinition } from './common';\nimport {\n PanelGroupSlice,\n PanelGroupItemId,\n PanelGroupDefinition,\n PanelGroupItemLayout,\n addPanelGroup,\n createEmptyPanelGroup,\n} from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and actions for adding or editing Panels.\n */\nexport interface PanelEditorSlice {\n /**\n * Initial values for add panel if default panel kind is defined\n */\n initialValues?: Pick<PanelEditorValues, 'panelDefinition'>;\n\n /**\n * State for the panel editor when its open, otherwise undefined when it's closed.\n */\n panelEditor?: PanelEditorState;\n\n /**\n * Opens the editor for editing an existing panel by providing its layout coordinates.\n */\n openEditPanel: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * Opens the editor for adding a new Panel to a panel group.\n */\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n}\n\nexport interface PanelEditorState {\n /**\n * Whether we're adding a new panel, or editing an existing panel.\n */\n mode: Action;\n\n /*\n * Original item in a PanelGroup edited\n */\n panelGroupItemId?: PanelGroupItemId;\n\n /**\n * Initial values for the things that can be edited about a panel.\n */\n initialValues: PanelEditorValues;\n\n /**\n * Applies changes, but doesn't close the editor.\n */\n applyChanges: (next: PanelEditorValues) => void;\n\n /**\n * Close the editor.\n */\n close: () => void;\n}\n\n/**\n * Curried function for creating the PanelEditorSlice.\n */\nexport function createPanelEditorSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n PanelEditorSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelEditorSlice\n> {\n // Return the state creator function for Zustand that uses the panels provided as intitial state\n return (set, get) => ({\n panelEditor: undefined,\n\n openEditPanel(panelGroupItemId): void {\n const { panels, panelGroups } = get();\n\n // Figure out the panel key at that location\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const panelKey = panelGroups[panelGroupId]?.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);\n }\n\n // Find the panel to edit\n const panelToEdit = panels[panelKey];\n if (panelToEdit === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n const editorState: PanelEditorState = {\n mode: 'update',\n panelGroupItemId: panelGroupItemId,\n initialValues: {\n groupId: panelGroupItemId.panelGroupId,\n panelDefinition: panelToEdit,\n },\n applyChanges: (next) => {\n set((state) => {\n state.panels[panelKey] = next.panelDefinition;\n\n // If the panel didn't change groups, nothing else to do\n if (next.groupId === panelGroupId) {\n return;\n }\n\n // Move panel to the new group\n const existingGroup = state.panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n\n const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout) => layout.i === panelGroupLayoutId);\n const existingLayout = existingGroup.itemLayouts[existingLayoutIdx];\n const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];\n if (existingLayoutIdx === -1 || existingLayout === undefined || existingPanelKey === undefined) {\n throw new Error(`Missing panel group item ${panelGroupLayoutId}`);\n }\n\n // Remove item from the old group\n existingGroup.itemLayouts.splice(existingLayoutIdx, 1);\n delete existingGroup.itemPanelKeys[panelGroupLayoutId];\n\n // Add item to the end of the new group\n const newGroup = state.panelGroups[next.groupId];\n if (newGroup === undefined) {\n throw new Error(`Could not find new group ${next.groupId}`);\n }\n\n newGroup.itemLayouts.push({\n i: existingLayout.i,\n x: 0,\n y: getYForNewRow(newGroup),\n w: existingLayout.w,\n h: existingLayout.h,\n });\n newGroup.itemPanelKeys[existingLayout.i] = existingPanelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n openAddPanel(panelGroupId): void {\n // If a panel group isn't supplied, add to the first group or create a group if there aren't any\n let newGroup: PanelGroupDefinition | undefined = undefined;\n panelGroupId ??= get().panelGroupOrder[0];\n if (panelGroupId === undefined) {\n newGroup = createEmptyPanelGroup();\n newGroup.title = 'Panel Group';\n panelGroupId = newGroup.id;\n }\n\n const editorState: PanelEditorState = {\n mode: 'create',\n initialValues: {\n groupId: panelGroupId,\n panelDefinition: get().initialValues?.panelDefinition ?? createPanelDefinition(),\n },\n applyChanges: (next) => {\n const name = next.panelDefinition.spec.display.name;\n const panelKey = getValidPanelKey(name, get().panels);\n\n set((state) => {\n // Add a panel\n state.panels[panelKey] = next.panelDefinition;\n\n // Also add a panel group item referencing the panel\n const group = state.panelGroups[next.groupId];\n if (group === undefined) {\n throw new Error(`Missing panel group ${next.groupId}`);\n }\n const layout: PanelGroupItemLayout = {\n i: generateId().toString(),\n x: 0,\n y: getYForNewRow(group),\n w: 12,\n h: 6,\n };\n group.itemLayouts.push(layout);\n group.itemPanelKeys[layout.i] = panelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n set((state) => {\n // Add the new panel group if one was created for the panel\n if (newGroup !== undefined) {\n addPanelGroup(state, newGroup);\n }\n\n // Open the editor with the new state\n state.panelEditor = editorState;\n });\n },\n });\n}\n"],"names":["getYForNewRow","getValidPanelKey","generateId","createPanelDefinition","addPanelGroup","createEmptyPanelGroup","createPanelEditorSlice","set","get","panelEditor","undefined","openEditPanel","panelGroupItemId","panels","panelGroups","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","panelKey","itemPanelKeys","Error","panelToEdit","editorState","mode","initialValues","groupId","panelDefinition","applyChanges","next","state","existingGroup","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingLayout","existingPanelKey","splice","newGroup","push","x","y","w","h","close","openAddPanel","panelGroupOrder","title","id","name","spec","display","group","toString"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,aAAa,EAAEC,gBAAgB,QAAQ,cAAc;AAC9D,SAASC,UAAU,EAAcC,qBAAqB,QAAQ,WAAW;AACzE,SAKEC,aAAa,EACbC,qBAAqB,QAChB,sBAAsB;AAuD7B;;CAEC,GACD,OAAO,SAASC;IAOd,gGAAgG;IAChG,OAAO,CAACC,KAAKC,MAAS,CAAA;YACpBC,aAAaC;YAEbC,eAAcC,gBAAgB;gBAC5B,MAAM,EAAEC,MAAM,EAAEC,WAAW,EAAE,GAAGN;gBAEhC,4CAA4C;gBAC5C,MAAM,EAAEO,YAAY,EAAEC,wBAAwBC,kBAAkB,EAAE,GAAGL;gBACrE,MAAMM,WAAWJ,WAAW,CAACC,aAAa,EAAEI,aAAa,CAACF,mBAAmB;gBAC7E,IAAIC,aAAaR,WAAW;oBAC1B,MAAM,IAAIU,MAAM,CAAC,gCAAgC,EAAER,kBAAkB;gBACvE;gBAEA,yBAAyB;gBACzB,MAAMS,cAAcR,MAAM,CAACK,SAAS;gBACpC,IAAIG,gBAAgBX,WAAW;oBAC7B,MAAM,IAAIU,MAAM,CAAC,4BAA4B,EAAEF,SAAS,CAAC,CAAC;gBAC5D;gBAEA,MAAMI,cAAgC;oBACpCC,MAAM;oBACNX,kBAAkBA;oBAClBY,eAAe;wBACbC,SAASb,iBAAiBG,YAAY;wBACtCW,iBAAiBL;oBACnB;oBACAM,cAAc,CAACC;w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BAC3D,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 } 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 * Original item in a PanelGroup edited\n */\n panelGroupItemId?: PanelGroupItemId;\n\n /**\n * Initial values for the things that can be edited about a panel.\n */\n initialValues: PanelEditorValues;\n\n /**\n * Applies changes, but doesn't close the editor.\n */\n applyChanges: (next: PanelEditorValues) => void;\n\n /**\n * Close the editor.\n */\n close: () => void;\n}\n\n/**\n * Curried function for creating the PanelEditorSlice.\n */\nexport function createPanelEditorSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n PanelEditorSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelEditorSlice\n> {\n // Return the state creator function for Zustand that uses the panels provided as intitial state\n return (set, get) => ({\n panelEditor: undefined,\n\n openEditPanel(panelGroupItemId): void {\n const { panels, panelGroups } = get();\n\n // Figure out the panel key at that location\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const panelKey = panelGroups[panelGroupId]?.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);\n }\n\n // Find the panel to edit\n const panelToEdit = panels[panelKey];\n if (panelToEdit === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n const editorState: PanelEditorState = {\n mode: 'update',\n panelGroupItemId: panelGroupItemId,\n initialValues: {\n groupId: panelGroupItemId.panelGroupId,\n panelDefinition: panelToEdit,\n },\n applyChanges: (next) => {\n set((state) => {\n state.panels[panelKey] = next.panelDefinition;\n\n // If the panel didn't change groups, nothing else to do\n if (next.groupId === panelGroupId) {\n return;\n }\n\n // Move panel to the new group\n const existingGroup = state.panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n\n const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout) => layout.i === panelGroupLayoutId);\n const existingLayout = existingGroup.itemLayouts[existingLayoutIdx];\n const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];\n if (existingLayoutIdx === -1 || existingLayout === undefined || existingPanelKey === undefined) {\n throw new Error(`Missing panel group item ${panelGroupLayoutId}`);\n }\n\n // Remove item from the old group\n existingGroup.itemLayouts.splice(existingLayoutIdx, 1);\n delete existingGroup.itemPanelKeys[panelGroupLayoutId];\n\n // Add item to the end of the new group\n const newGroup = state.panelGroups[next.groupId];\n if (newGroup === undefined) {\n throw new Error(`Could not find new group ${next.groupId}`);\n }\n\n newGroup.itemLayouts.push({\n i: existingLayout.i,\n x: 0,\n y: getYForNewRow(newGroup),\n w: existingLayout.w,\n h: existingLayout.h,\n });\n newGroup.itemPanelKeys[existingLayout.i] = existingPanelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n openAddPanel(panelGroupId): void {\n // If a panel group isn't supplied, add to the first group or create a group if there aren't any\n let newGroup: PanelGroupDefinition | undefined = undefined;\n panelGroupId ??= get().panelGroupOrder[0];\n if (panelGroupId === undefined) {\n newGroup = createEmptyPanelGroup();\n newGroup.title = 'Panel Group';\n panelGroupId = newGroup.id;\n }\n\n const editorState: PanelEditorState = {\n mode: 'create',\n initialValues: {\n groupId: panelGroupId,\n panelDefinition: get().initialValues?.panelDefinition ?? createPanelDefinition(),\n },\n applyChanges: (next) => {\n const panelKey = crypto.randomUUID().replaceAll('-', '');\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","generateId","createPanelDefinition","addPanelGroup","createEmptyPanelGroup","createPanelEditorSlice","set","get","panelEditor","undefined","openEditPanel","panelGroupItemId","panels","panelGroups","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","panelKey","itemPanelKeys","Error","panelToEdit","editorState","mode","initialValues","groupId","panelDefinition","applyChanges","next","state","existingGroup","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingLayout","existingPanelKey","splice","newGroup","push","x","y","w","h","close","openAddPanel","panelGroupOrder","title","id","crypto","randomUUID","replaceAll","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,QAAQ,cAAc;AAC5C,SAASC,UAAU,EAAcC,qBAAqB,QAAQ,WAAW;AACzE,SAKEC,aAAa,EACbC,qBAAqB,QAChB,sBAAsB;AAuD7B;;CAEC,GACD,OAAO,SAASC;IAOd,gGAAgG;IAChG,OAAO,CAACC,KAAKC,MAAS,CAAA;YACpBC,aAAaC;YAEbC,eAAcC,gBAAgB;gBAC5B,MAAM,EAAEC,MAAM,EAAEC,WAAW,EAAE,GAAGN;gBAEhC,4CAA4C;gBAC5C,MAAM,EAAEO,YAAY,EAAEC,wBAAwBC,kBAAkB,EAAE,GAAGL;gBACrE,MAAMM,WAAWJ,WAAW,CAACC,aAAa,EAAEI,aAAa,CAACF,mBAAmB;gBAC7E,IAAIC,aAAaR,WAAW;oBAC1B,MAAM,IAAIU,MAAM,CAAC,gCAAgC,EAAER,kBAAkB;gBACvE;gBAEA,yBAAyB;gBACzB,MAAMS,cAAcR,MAAM,CAACK,SAAS;gBACpC,IAAIG,gBAAgBX,WAAW;oBAC7B,MAAM,IAAIU,MAAM,CAAC,4BAA4B,EAAEF,SAAS,C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AACsB;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,9 +1,8 @@
|
|
|
1
1
|
import { VariableValue, VariableDefinition } from '@perses-dev/core';
|
|
2
|
-
import {
|
|
2
|
+
import { useQueryParams } from 'use-query-params';
|
|
3
3
|
export declare function getURLQueryParamName(name: string): string;
|
|
4
|
-
export declare function encodeVariableValue(value: VariableValue): string;
|
|
4
|
+
export declare function encodeVariableValue(value: VariableValue): string | null;
|
|
5
5
|
export declare function decodeVariableValue(value: string): VariableValue;
|
|
6
|
-
export declare
|
|
7
|
-
export declare function useVariableQueryParams(defs: VariableDefinition[]): ReturnType<typeof useQueryStates>;
|
|
6
|
+
export declare function useVariableQueryParams(defs: VariableDefinition[]): ReturnType<typeof useQueryParams>;
|
|
8
7
|
export declare function getInitalValuesFromQueryParameters(queryParamValues: Record<string, VariableValue>): Record<string, VariableValue>;
|
|
9
8
|
//# sourceMappingURL=query-params.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-params.d.ts","sourceRoot":"","sources":["../../../src/context/VariableProvider/query-params.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,
|
|
1
|
+
{"version":3,"file":"query-params.d.ts","sourceRoot":"","sources":["../../../src/context/VariableProvider/query-params.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAoB,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIpE,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI,CAKvE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAShE;AAYD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,kBAAkB,EAAE,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAOpG;AAED,wBAAgB,kCAAkC,CAChD,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAC9C,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAW/B"}
|
|
@@ -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 {
|
|
13
|
+
import { useQueryParams } from 'use-query-params';
|
|
14
14
|
const variableQueryParameterPrefix = 'var-';
|
|
15
15
|
export function getURLQueryParamName(name) {
|
|
16
16
|
return `${variableQueryParameterPrefix}${name}`;
|
|
@@ -19,7 +19,7 @@ export function encodeVariableValue(value) {
|
|
|
19
19
|
if (Array.isArray(value)) {
|
|
20
20
|
return value.join(',');
|
|
21
21
|
}
|
|
22
|
-
return value
|
|
22
|
+
return value;
|
|
23
23
|
}
|
|
24
24
|
export function decodeVariableValue(value) {
|
|
25
25
|
if (!value) {
|
|
@@ -31,18 +31,23 @@ export function decodeVariableValue(value) {
|
|
|
31
31
|
}
|
|
32
32
|
return values;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
const VariableValueParam = {
|
|
35
|
+
encode: encodeVariableValue,
|
|
36
|
+
decode: (v)=>{
|
|
37
|
+
if (typeof v === 'string') {
|
|
38
|
+
return decodeVariableValue(v);
|
|
39
|
+
}
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
};
|
|
38
43
|
export function useVariableQueryParams(defs) {
|
|
39
44
|
const config = {};
|
|
40
45
|
defs.forEach((def)=>{
|
|
41
46
|
const name = getURLQueryParamName(def.spec.name);
|
|
42
|
-
config[name] =
|
|
47
|
+
config[name] = VariableValueParam;
|
|
43
48
|
});
|
|
44
|
-
return
|
|
45
|
-
|
|
49
|
+
return useQueryParams(config, {
|
|
50
|
+
updateType: 'replaceIn'
|
|
46
51
|
});
|
|
47
52
|
}
|
|
48
53
|
export function getInitalValuesFromQueryParameters(queryParamValues) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/VariableProvider/query-params.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 { VariableValue, VariableDefinition } from '@perses-dev/core';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/context/VariableProvider/query-params.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 { VariableValue, VariableDefinition } from '@perses-dev/core';\nimport { QueryParamConfig, useQueryParams } from 'use-query-params';\n\nconst variableQueryParameterPrefix = 'var-';\n\nexport function getURLQueryParamName(name: string): string {\n return `${variableQueryParameterPrefix}${name}`;\n}\n\nexport function encodeVariableValue(value: VariableValue): string | null {\n if (Array.isArray(value)) {\n return value.join(',');\n }\n return value;\n}\n\nexport function decodeVariableValue(value: string): VariableValue {\n if (!value) {\n return null;\n }\n const values = value.split(',');\n if (values.length === 1) {\n return values[0] as string;\n }\n return values;\n}\n\nconst VariableValueParam: QueryParamConfig<VariableValue> = {\n encode: encodeVariableValue,\n decode: (v) => {\n if (typeof v === 'string') {\n return decodeVariableValue(v);\n }\n return '';\n },\n};\n\nexport function useVariableQueryParams(defs: VariableDefinition[]): ReturnType<typeof useQueryParams> {\n const config: Record<string, typeof VariableValueParam> = {};\n defs.forEach((def) => {\n const name = getURLQueryParamName(def.spec.name);\n config[name] = VariableValueParam;\n });\n return useQueryParams(config, { updateType: 'replaceIn' });\n}\n\nexport function getInitalValuesFromQueryParameters(\n queryParamValues: Record<string, VariableValue>\n): Record<string, VariableValue> {\n const values: Record<string, VariableValue> = {};\n Object.keys(queryParamValues).forEach((key) => {\n const value = queryParamValues[key];\n if (!value) {\n return;\n }\n const name = key.replace(variableQueryParameterPrefix, '');\n values[name] = value;\n });\n return values;\n}\n"],"names":["useQueryParams","variableQueryParameterPrefix","getURLQueryParamName","name","encodeVariableValue","value","Array","isArray","join","decodeVariableValue","values","split","length","VariableValueParam","encode","decode","v","useVariableQueryParams","defs","config","forEach","def","spec","updateType","getInitalValuesFromQueryParameters","queryParamValues","Object","keys","key","replace"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAA2BA,cAAc,QAAQ,mBAAmB;AAEpE,MAAMC,+BAA+B;AAErC,OAAO,SAASC,qBAAqBC,IAAY;IAC/C,OAAO,GAAGF,+BAA+BE,MAAM;AACjD;AAEA,OAAO,SAASC,oBAAoBC,KAAoB;IACtD,IAAIC,MAAMC,OAAO,CAACF,QAAQ;QACxB,OAAOA,MAAMG,IAAI,CAAC;IACpB;IACA,OAAOH;AACT;AAEA,OAAO,SAASI,oBAAoBJ,KAAa;IAC/C,IAAI,CAACA,OAAO;QACV,OAAO;IACT;IACA,MAAMK,SAASL,MAAMM,KAAK,CAAC;IAC3B,IAAID,OAAOE,MAAM,KAAK,GAAG;QACvB,OAAOF,MAAM,CAAC,EAAE;IAClB;IACA,OAAOA;AACT;AAEA,MAAMG,qBAAsD;IAC1DC,QAAQV;IACRW,QAAQ,CAACC;QACP,IAAI,OAAOA,MAAM,UAAU;YACzB,OAAOP,oBAAoBO;QAC7B;QACA,OAAO;IACT;AACF;AAEA,OAAO,SAASC,uBAAuBC,IAA0B;IAC/D,MAAMC,SAAoD,CAAC;IAC3DD,KAAKE,OAAO,CAAC,CAACC;QACZ,MAAMlB,OAAOD,qBAAqBmB,IAAIC,IAAI,CAACnB,IAAI;QAC/CgB,MAAM,CAAChB,KAAK,GAAGU;IACjB;IACA,OAAOb,eAAemB,QAAQ;QAAEI,YAAY;IAAY;AAC1D;AAEA,OAAO,SAASC,mCACdC,gBAA+C;IAE/C,MAAMf,SAAwC,CAAC;IAC/CgB,OAAOC,IAAI,CAACF,kBAAkBL,OAAO,CAAC,CAACQ;QACrC,MAAMvB,QAAQoB,gBAAgB,CAACG,IAAI;QACnC,IAAI,CAACvB,OAAO;YACV;QACF;QACA,MAAMF,OAAOyB,IAAIC,OAAO,CAAC5B,8BAA8B;QACvDS,MAAM,CAACP,KAAK,GAAGE;IACjB;IACA,OAAOK;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/test/render.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAU,aAAa,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAuB,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/test/render.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAU,aAAa,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAuB,aAAa,EAAE,MAAM,SAAS,CAAC;AAiC7D;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,KAAK,CAAC,YAAY,EACtB,OAAO,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,EACxC,OAAO,CAAC,EAAE,aAAa,GACtB,YAAY,CA4Bd"}
|
package/dist/test/render.js
CHANGED
|
@@ -18,7 +18,8 @@ import { render } from '@testing-library/react';
|
|
|
18
18
|
import { createMemoryHistory } from 'history';
|
|
19
19
|
import { useLayoutEffect, useState } from 'react';
|
|
20
20
|
import { Router } from 'react-router-dom';
|
|
21
|
-
import {
|
|
21
|
+
import { QueryParamProvider } from 'use-query-params';
|
|
22
|
+
import { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6';
|
|
22
23
|
import { DatasourceStoreProvider } from '../context';
|
|
23
24
|
import { defaultDatasourceProps } from '../test';
|
|
24
25
|
import { MOCK_PLUGINS } from './plugin-registry';
|
|
@@ -54,11 +55,12 @@ import { MOCK_PLUGINS } from './plugin-registry';
|
|
|
54
55
|
});
|
|
55
56
|
const customHistory = history ?? createMemoryHistory();
|
|
56
57
|
const mockRegistry = mockPluginRegistry(...MOCK_PLUGINS);
|
|
57
|
-
const BaseRender = ()=>/*#__PURE__*/ _jsx(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
const BaseRender = ()=>/*#__PURE__*/ _jsx(CustomRouter, {
|
|
59
|
+
history: customHistory,
|
|
60
|
+
children: /*#__PURE__*/ _jsx(QueryClientProvider, {
|
|
61
|
+
client: queryClient,
|
|
62
|
+
children: /*#__PURE__*/ _jsx(QueryParamProvider, {
|
|
63
|
+
adapter: ReactRouter6Adapter,
|
|
62
64
|
children: /*#__PURE__*/ _jsx(SnackbarProvider, {
|
|
63
65
|
anchorOrigin: {
|
|
64
66
|
vertical: 'bottom',
|
package/dist/test/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/test/render.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ChartsProvider, SnackbarProvider, testChartsTheme } from '@perses-dev/components';\nimport { mockPluginRegistry, PluginRegistry } from '@perses-dev/plugin-system';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { render, RenderOptions, RenderResult } from '@testing-library/react';\nimport { createMemoryHistory, MemoryHistory } from 'history';\nimport { ReactElement, useLayoutEffect, useState } from 'react';\nimport { Router } from 'react-router-dom';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/test/render.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ChartsProvider, SnackbarProvider, testChartsTheme } from '@perses-dev/components';\nimport { mockPluginRegistry, PluginRegistry } from '@perses-dev/plugin-system';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { render, RenderOptions, RenderResult } from '@testing-library/react';\nimport { createMemoryHistory, MemoryHistory } from 'history';\nimport { ReactElement, useLayoutEffect, useState } from 'react';\nimport { Router } from 'react-router-dom';\nimport { QueryParamProvider } from 'use-query-params';\nimport { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6';\nimport { DatasourceStoreProvider } from '../context';\nimport { defaultDatasourceProps } from '../test';\nimport { MOCK_PLUGINS } from './plugin-registry';\n\ninterface CustomRouterProps {\n history: MemoryHistory;\n children: React.ReactNode;\n}\n\n/*\n * Workaround for React router upgrade type errors.\n * More details: https://stackoverflow.com/a/69948457/17575201\n */\nconst CustomRouter: React.FC<CustomRouterProps> = ({ history, children }) => {\n const [state, setState] = useState({\n action: history.action,\n location: history.location,\n });\n\n useLayoutEffect(() => history.listen(setState), [history]);\n\n return (\n <Router location={state.location} navigationType={state.action} navigator={history}>\n {children}\n </Router>\n );\n};\n\n/**\n * Test helper to render a React component with some common app-level providers wrapped around it.\n */\nexport function renderWithContext(\n ui: React.ReactElement,\n options?: Omit<RenderOptions, 'queries'>,\n history?: MemoryHistory\n): RenderResult {\n // Create a new QueryClient for each test to avoid caching issues\n const queryClient = new QueryClient({ defaultOptions: { queries: { refetchOnWindowFocus: false, retry: false } } });\n\n const customHistory = history ?? createMemoryHistory();\n\n const mockRegistry = mockPluginRegistry(...MOCK_PLUGINS);\n\n const BaseRender = (): ReactElement => (\n <CustomRouter history={customHistory}>\n <QueryClientProvider client={queryClient}>\n <QueryParamProvider adapter={ReactRouter6Adapter}>\n <SnackbarProvider anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}>\n <ChartsProvider chartsTheme={testChartsTheme}>\n <PluginRegistry\n pluginLoader={mockRegistry.pluginLoader}\n defaultPluginKinds={mockRegistry.defaultPluginKinds}\n >\n <DatasourceStoreProvider {...defaultDatasourceProps}>{ui}</DatasourceStoreProvider>\n </PluginRegistry>\n </ChartsProvider>\n </SnackbarProvider>\n </QueryParamProvider>\n </QueryClientProvider>\n </CustomRouter>\n );\n\n return render(<BaseRender />, options);\n}\n"],"names":["ChartsProvider","SnackbarProvider","testChartsTheme","mockPluginRegistry","PluginRegistry","QueryClient","QueryClientProvider","render","createMemoryHistory","useLayoutEffect","useState","Router","QueryParamProvider","ReactRouter6Adapter","DatasourceStoreProvider","defaultDatasourceProps","MOCK_PLUGINS","CustomRouter","history","children","state","setState","action","location","listen","navigationType","navigator","renderWithContext","ui","options","queryClient","defaultOptions","queries","refetchOnWindowFocus","retry","customHistory","mockRegistry","BaseRender","client","adapter","anchorOrigin","vertical","horizontal","chartsTheme","pluginLoader","defaultPluginKinds"],"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,cAAc,EAAEC,gBAAgB,EAAEC,eAAe,QAAQ,yBAAyB;AAC3F,SAASC,kBAAkB,EAAEC,cAAc,QAAQ,4BAA4B;AAC/E,SAASC,WAAW,EAAEC,mBAAmB,QAAQ,wBAAwB;AACzE,SAASC,MAAM,QAAqC,yBAAyB;AAC7E,SAASC,mBAAmB,QAAuB,UAAU;AAC7D,SAAuBC,eAAe,EAAEC,QAAQ,QAAQ,QAAQ;AAChE,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,kBAAkB,QAAQ,mBAAmB;AACtD,SAASC,mBAAmB,QAAQ,2CAA2C;AAC/E,SAASC,uBAAuB,QAAQ,aAAa;AACrD,SAASC,sBAAsB,QAAQ,UAAU;AACjD,SAASC,YAAY,QAAQ,oBAAoB;AAOjD;;;CAGC,GACD,MAAMC,eAA4C,CAAC,EAAEC,OAAO,EAAEC,QAAQ,EAAE;IACtE,MAAM,CAACC,OAAOC,SAAS,GAAGX,SAAS;QACjCY,QAAQJ,QAAQI,MAAM;QACtBC,UAAUL,QAAQK,QAAQ;IAC5B;IAEAd,gBAAgB,IAAMS,QAAQM,MAAM,CAACH,WAAW;QAACH;KAAQ;IAEzD,qBACE,KAACP;QAAOY,UAAUH,MAAMG,QAAQ;QAAEE,gBAAgBL,MAAME,MAAM;QAAEI,WAAWR;kBACxEC;;AAGP;AAEA;;CAEC,GACD,OAAO,SAASQ,kBACdC,EAAsB,EACtBC,OAAwC,EACxCX,OAAuB;IAEvB,iEAAiE;IACjE,MAAMY,cAAc,IAAIzB,YAAY;QAAE0B,gBAAgB;YAAEC,SAAS;gBAAEC,sBAAsB;gBAAOC,OAAO;YAAM;QAAE;IAAE;IAEjH,MAAMC,gBAAgBjB,WAAWV;IAEjC,MAAM4B,eAAejC,sBAAsBa;IAE3C,MAAMqB,aAAa,kBACjB,KAACpB;YAAaC,SAASiB;sBACrB,cAAA,KAAC7B;gBAAoBgC,QAAQR;0BAC3B,cAAA,KAAClB;oBAAmB2B,SAAS1B;8BAC3B,cAAA,KAACZ;wBAAiBuC,cAAc;4BAAEC,UAAU;4BAAUC,YAAY;wBAAQ;kCACxE,cAAA,KAAC1C;4BAAe2C,aAAazC;sCAC3B,cAAA,KAACE;gCACCwC,cAAcR,aAAaQ,YAAY;gCACvCC,oBAAoBT,aAAaS,kBAAkB;0CAEnD,cAAA,KAAC/B;oCAAyB,GAAGC,sBAAsB;8CAAGa;;;;;;;;IASpE,OAAOrB,qBAAO,KAAC8B,iBAAeR;AAChC"}
|
|
@@ -19,9 +19,12 @@ export type UnpositionedPanelGroupItemLayout = Omit<PanelGroupItemLayout, 'x' |
|
|
|
19
19
|
*/
|
|
20
20
|
export declare function insertPanelInLayout(newLayout: UnpositionedPanelGroupItemLayout, referenceLayout: PanelGroupItemLayout, itemLayouts: PanelGroupItemLayout[]): PanelGroupItemLayout[];
|
|
21
21
|
/**
|
|
22
|
+
* @deprecated
|
|
23
|
+
*
|
|
22
24
|
* Get a valid panel key, where a valid key:
|
|
23
25
|
* - does not include invalid characters
|
|
24
26
|
* - is unique
|
|
27
|
+
* TODO: It is not clear why too much complexity is needed for generating a panel key
|
|
25
28
|
*/
|
|
26
29
|
export declare function getValidPanelKey(panelKey: string, panels: Record<string, PanelDefinition>): string;
|
|
27
30
|
//# sourceMappingURL=panelUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panelUtils.d.ts","sourceRoot":"","sources":["../../src/utils/panelUtils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAIxE,wBAAgB,aAAa,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,CASjE;AA8BD,MAAM,MAAM,gCAAgC,GAAG,IAAI,CAAC,oBAAoB,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;AAErF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,gCAAgC,EAC3C,eAAe,EAAE,oBAAoB,EACrC,WAAW,EAAE,oBAAoB,EAAE,GAClC,oBAAoB,EAAE,CAyExB;AAED
|
|
1
|
+
{"version":3,"file":"panelUtils.d.ts","sourceRoot":"","sources":["../../src/utils/panelUtils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAIxE,wBAAgB,aAAa,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,CASjE;AA8BD,MAAM,MAAM,gCAAgC,GAAG,IAAI,CAAC,oBAAoB,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;AAErF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,gCAAgC,EAC3C,eAAe,EAAE,oBAAoB,EACrC,WAAW,EAAE,oBAAoB,EAAE,GAClC,oBAAoB,EAAE,CAyExB;AAED;;;;;;;GAOG;AAEH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,MAAM,CASlG"}
|
package/dist/utils/panelUtils.js
CHANGED
|
@@ -122,9 +122,12 @@ function getPanelBounds({ x, y, w, h }) {
|
|
|
122
122
|
];
|
|
123
123
|
}
|
|
124
124
|
/**
|
|
125
|
+
* @deprecated
|
|
126
|
+
*
|
|
125
127
|
* Get a valid panel key, where a valid key:
|
|
126
128
|
* - does not include invalid characters
|
|
127
129
|
* - is unique
|
|
130
|
+
* TODO: It is not clear why too much complexity is needed for generating a panel key
|
|
128
131
|
*/ export function getValidPanelKey(panelKey, panels) {
|
|
129
132
|
const uniquePanelKeys = getUniquePanelKeys(panels);
|
|
130
133
|
let normalizedPanelKey = getPanelKeyParts(removeWhiteSpaces(panelKey)).name;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/panelUtils.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 { PanelDefinition } from '@perses-dev/core';\nimport { PanelGroupDefinition, PanelGroupItemLayout } from '../context';\nimport { GRID_LAYOUT_SMALL_BREAKPOINT, GRID_LAYOUT_COLS } from '../constants';\n\n// Given a PanelGroup, will find the Y coordinate for adding a new row to the grid, taking into account the items present\nexport function getYForNewRow(group: PanelGroupDefinition): number {\n let newRowY = 0;\n for (const layout of group.itemLayouts) {\n const itemMaxY = layout.y + layout.h;\n if (itemMaxY > newRowY) {\n newRowY = itemMaxY;\n }\n }\n return newRowY;\n}\n\ntype PanelGroupItemBounds = {\n /**\n * Left horizontal position.\n */\n x1: number;\n /**\n * Right horizontal position.\n */\n x2: number;\n /**\n * Top vertical position.\n */\n y1: number;\n /**\n * Bottom vertical position\n */\n y2: number;\n};\n\nfunction getPanelBounds({ x, y, w, h }: PanelGroupItemLayout): PanelGroupItemBounds {\n return {\n x1: x,\n x2: x + w,\n y1: y,\n y2: y + h,\n };\n}\n\nexport type UnpositionedPanelGroupItemLayout = Omit<PanelGroupItemLayout, 'x' | 'y'>;\n\n/**\n * Inserts a new panel into the layout with placement determined by a specified\n * reference panel. The new panel is placed:\n * - To the right of the reference panel if there is space available without\n * moving other panels.\n * - Otherwise, directly below the reference panel. If other panels are below\n * this location, they will also shift downward because the grid uses\n * vertical-based compacting.\n *\n * @param newLayout - Layout for new panel to insert into the grid.\n * @param referenceLayout - Layout for reference panel used to determine the\n * placement of the new panel.\n * @param itemLayouts - Full grid layout.\n * @returns - Item layouts modified to insert the new panel.\n */\nexport function insertPanelInLayout(\n newLayout: UnpositionedPanelGroupItemLayout,\n referenceLayout: PanelGroupItemLayout,\n itemLayouts: PanelGroupItemLayout[]\n): PanelGroupItemLayout[] {\n const MAX_LAYOUT_WIDTH = GRID_LAYOUT_COLS[GRID_LAYOUT_SMALL_BREAKPOINT];\n\n const referenceBounds = getPanelBounds(referenceLayout);\n\n // Organize layouts based on vertical relation to the item being inserted\n // after.\n const aboveInsertRow: PanelGroupItemLayout[] = [];\n const insertRow: PanelGroupItemLayout[] = [];\n const belowInsertRow: PanelGroupItemLayout[] = [];\n itemLayouts.forEach((itemLayout) => {\n const itemBounds = getPanelBounds(itemLayout);\n\n if (itemBounds.y2 <= referenceBounds.y1) {\n aboveInsertRow.push(itemLayout);\n } else if (itemBounds.y1 >= referenceBounds.y2) {\n belowInsertRow.push(itemLayout);\n } else {\n insertRow.push(itemLayout);\n }\n });\n\n // Cannot safely assume that the order of item layouts array is strictly\n // left to right. Sorting the row by horizontal position to more easily find\n // gaps.\n insertRow.sort((a, b) => a.x - b.x);\n const insertAfterIndex = insertRow.findIndex((item) => item.i === referenceLayout.i);\n\n if (insertAfterIndex === insertRow.length - 1) {\n // Insert to the right when space is available and the reference is the last\n // item in the row.\n if (referenceBounds.x2 + newLayout.w <= MAX_LAYOUT_WIDTH) {\n return [\n ...aboveInsertRow,\n ...insertRow,\n {\n ...newLayout,\n x: referenceBounds.x2,\n y: referenceBounds.y1,\n },\n ...belowInsertRow,\n ];\n }\n } else if (insertAfterIndex >= 0) {\n const nextItem = insertRow[insertAfterIndex + 1];\n\n if (nextItem && getPanelBounds(nextItem).x1 - referenceBounds.x2 >= newLayout.w) {\n // Insert to the right when space is available between the reference and\n // the next item in the row.\n insertRow.splice(insertAfterIndex + 1, 0, {\n ...newLayout,\n x: referenceBounds.x2,\n y: referenceBounds.y1,\n });\n\n return [...aboveInsertRow, ...insertRow, ...belowInsertRow];\n }\n }\n\n // Insert the new item below the original and shift the items below the\n // row where the reference is located.\n return [\n ...aboveInsertRow,\n ...insertRow,\n { x: referenceBounds.x1, y: referenceBounds.y2, ...newLayout },\n ...belowInsertRow.map((itemLayout) => {\n // Note: the grid will not necessarily display all of these items shifted\n // all the way down because of vertical compacting, but shifing their\n // y position ensures the new item gets vertical precedence over items\n // below it in that compacting.\n return { ...itemLayout, y: itemLayout.y + newLayout.h };\n }),\n ];\n}\n\n/**\n * Get a valid panel key, where a valid key:\n * - does not include invalid characters\n * - is unique\n */\nexport function getValidPanelKey(panelKey: string, panels: Record<string, PanelDefinition>): string {\n const uniquePanelKeys = getUniquePanelKeys(panels);\n let normalizedPanelKey = getPanelKeyParts(removeWhiteSpaces(panelKey)).name;\n\n const matchingKey = uniquePanelKeys[normalizedPanelKey];\n if (typeof matchingKey === 'number') {\n normalizedPanelKey += `-${matchingKey + 1}`;\n }\n return normalizedPanelKey;\n}\n\ntype PanelKeyParts = {\n name: string;\n number?: number;\n};\n\nconst removeWhiteSpaces = (str: string): string => {\n return str.replace(/\\s+/g, '');\n};\n\n/**\n * Breaks the specified panel key into the name and the optional `-number` used\n * for deduping panels with the same name.\n */\nfunction getPanelKeyParts(panelKey: string): PanelKeyParts {\n const parts = panelKey.match(/(.+)-([0-9]+)/);\n if (parts && parts[1] && parts[2]) {\n return {\n name: parts[1],\n number: parseInt(parts[2], 10),\n };\n }\n\n return {\n name: panelKey,\n };\n}\n\n// Find all the unique panel keys and the largest number used for each.\n// ex: cpu, cpu-1, cpu-2 count as the same panel key since these panels have the same name\nfunction getUniquePanelKeys(panels: Record<string, PanelDefinition>): Record<string, number> {\n const uniquePanelKeys: Record<string, number> = {};\n Object.keys(panels).forEach((panelKey) => {\n const { name, number } = getPanelKeyParts(panelKey);\n if (uniquePanelKeys[name] === undefined) {\n uniquePanelKeys[name] = 0;\n }\n const currentValue = uniquePanelKeys[name];\n if (typeof currentValue === 'number' && number) {\n // Check for the maximum value because we cannot rely on a sequential\n // set of numbers when panels are modified.\n uniquePanelKeys[name] = Math.max(currentValue, number);\n }\n });\n return uniquePanelKeys;\n}\n"],"names":["GRID_LAYOUT_SMALL_BREAKPOINT","GRID_LAYOUT_COLS","getYForNewRow","group","newRowY","layout","itemLayouts","itemMaxY","y","h","getPanelBounds","x","w","x1","x2","y1","y2","insertPanelInLayout","newLayout","referenceLayout","MAX_LAYOUT_WIDTH","referenceBounds","aboveInsertRow","insertRow","belowInsertRow","forEach","itemLayout","itemBounds","push","sort","a","b","insertAfterIndex","findIndex","item","i","length","nextItem","splice","map","getValidPanelKey","panelKey","panels","uniquePanelKeys","getUniquePanelKeys","normalizedPanelKey","getPanelKeyParts","removeWhiteSpaces","name","matchingKey","str","replace","parts","match","number","parseInt","Object","keys","undefined","currentValue","Math","max"],"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,4BAA4B,EAAEC,gBAAgB,QAAQ,eAAe;AAE9E,yHAAyH;AACzH,OAAO,SAASC,cAA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IACA,OAAOJ;AACT;AAOA,MAAME,oBAAoB,CAACG;IACzB,OAAOA,IAAIC,OAAO,CAAC,QAAQ;AAC7B;AAEA;;;CAGC,GACD,SAASL,iBAAiBL,QAAgB;IACxC,MAAMW,QAAQX,SAASY,KAAK,CAAC;IAC7B,IAAID,SAASA,KAAK,CAAC,EAAE,IAAIA,KAAK,CAAC,EAAE,EAAE;QACjC,OAAO;YACLJ,MAAMI,KAAK,CAAC,EAAE;YACdE,QAAQC,SAASH,KAAK,CAAC,EAAE,EAAE;QAC7B;IACF;IAEA,OAAO;QACLJ,MAAMP;IACR;AACF;AAEA,uEAAuE;AACvE,0FAA0F;AAC1F,SAASG,mBAAmBF,MAAuC;IACjE,MAAMC,kBAA0C,CAAC;IACjDa,OAAOC,IAAI,CAACf,QAAQjB,OAAO,CAAC,CAACgB;QAC3B,MAAM,EAAEO,IAAI,EAAEM,MAAM,EAAE,GAAGR,iBAAiBL;QAC1C,IAAIE,eAAe,CAACK,KAAK,KAAKU,WAAW;YACvCf,eAAe,CAACK,KAAK,GAAG;QAC1B;QACA,MAAMW,eAAehB,eAAe,CAACK,KAAK;QAC1C,IAAI,OAAOW,iBAAiB,YAAYL,QAAQ;YAC9C,qEAAqE;YACrE,2CAA2C;YAC3CX,eAAe,CAACK,KAAK,GAAGY,KAAKC,GAAG,CAACF,cAAcL;QACjD;IACF;IACA,OAAOX;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/panelUtils.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 { PanelDefinition } from '@perses-dev/core';\nimport { PanelGroupDefinition, PanelGroupItemLayout } from '../context';\nimport { GRID_LAYOUT_SMALL_BREAKPOINT, GRID_LAYOUT_COLS } from '../constants';\n\n// Given a PanelGroup, will find the Y coordinate for adding a new row to the grid, taking into account the items present\nexport function getYForNewRow(group: PanelGroupDefinition): number {\n let newRowY = 0;\n for (const layout of group.itemLayouts) {\n const itemMaxY = layout.y + layout.h;\n if (itemMaxY > newRowY) {\n newRowY = itemMaxY;\n }\n }\n return newRowY;\n}\n\ntype PanelGroupItemBounds = {\n /**\n * Left horizontal position.\n */\n x1: number;\n /**\n * Right horizontal position.\n */\n x2: number;\n /**\n * Top vertical position.\n */\n y1: number;\n /**\n * Bottom vertical position\n */\n y2: number;\n};\n\nfunction getPanelBounds({ x, y, w, h }: PanelGroupItemLayout): PanelGroupItemBounds {\n return {\n x1: x,\n x2: x + w,\n y1: y,\n y2: y + h,\n };\n}\n\nexport type UnpositionedPanelGroupItemLayout = Omit<PanelGroupItemLayout, 'x' | 'y'>;\n\n/**\n * Inserts a new panel into the layout with placement determined by a specified\n * reference panel. The new panel is placed:\n * - To the right of the reference panel if there is space available without\n * moving other panels.\n * - Otherwise, directly below the reference panel. If other panels are below\n * this location, they will also shift downward because the grid uses\n * vertical-based compacting.\n *\n * @param newLayout - Layout for new panel to insert into the grid.\n * @param referenceLayout - Layout for reference panel used to determine the\n * placement of the new panel.\n * @param itemLayouts - Full grid layout.\n * @returns - Item layouts modified to insert the new panel.\n */\nexport function insertPanelInLayout(\n newLayout: UnpositionedPanelGroupItemLayout,\n referenceLayout: PanelGroupItemLayout,\n itemLayouts: PanelGroupItemLayout[]\n): PanelGroupItemLayout[] {\n const MAX_LAYOUT_WIDTH = GRID_LAYOUT_COLS[GRID_LAYOUT_SMALL_BREAKPOINT];\n\n const referenceBounds = getPanelBounds(referenceLayout);\n\n // Organize layouts based on vertical relation to the item being inserted\n // after.\n const aboveInsertRow: PanelGroupItemLayout[] = [];\n const insertRow: PanelGroupItemLayout[] = [];\n const belowInsertRow: PanelGroupItemLayout[] = [];\n itemLayouts.forEach((itemLayout) => {\n const itemBounds = getPanelBounds(itemLayout);\n\n if (itemBounds.y2 <= referenceBounds.y1) {\n aboveInsertRow.push(itemLayout);\n } else if (itemBounds.y1 >= referenceBounds.y2) {\n belowInsertRow.push(itemLayout);\n } else {\n insertRow.push(itemLayout);\n }\n });\n\n // Cannot safely assume that the order of item layouts array is strictly\n // left to right. Sorting the row by horizontal position to more easily find\n // gaps.\n insertRow.sort((a, b) => a.x - b.x);\n const insertAfterIndex = insertRow.findIndex((item) => item.i === referenceLayout.i);\n\n if (insertAfterIndex === insertRow.length - 1) {\n // Insert to the right when space is available and the reference is the last\n // item in the row.\n if (referenceBounds.x2 + newLayout.w <= MAX_LAYOUT_WIDTH) {\n return [\n ...aboveInsertRow,\n ...insertRow,\n {\n ...newLayout,\n x: referenceBounds.x2,\n y: referenceBounds.y1,\n },\n ...belowInsertRow,\n ];\n }\n } else if (insertAfterIndex >= 0) {\n const nextItem = insertRow[insertAfterIndex + 1];\n\n if (nextItem && getPanelBounds(nextItem).x1 - referenceBounds.x2 >= newLayout.w) {\n // Insert to the right when space is available between the reference and\n // the next item in the row.\n insertRow.splice(insertAfterIndex + 1, 0, {\n ...newLayout,\n x: referenceBounds.x2,\n y: referenceBounds.y1,\n });\n\n return [...aboveInsertRow, ...insertRow, ...belowInsertRow];\n }\n }\n\n // Insert the new item below the original and shift the items below the\n // row where the reference is located.\n return [\n ...aboveInsertRow,\n ...insertRow,\n { x: referenceBounds.x1, y: referenceBounds.y2, ...newLayout },\n ...belowInsertRow.map((itemLayout) => {\n // Note: the grid will not necessarily display all of these items shifted\n // all the way down because of vertical compacting, but shifing their\n // y position ensures the new item gets vertical precedence over items\n // below it in that compacting.\n return { ...itemLayout, y: itemLayout.y + newLayout.h };\n }),\n ];\n}\n\n/**\n * @deprecated\n *\n * Get a valid panel key, where a valid key:\n * - does not include invalid characters\n * - is unique\n * TODO: It is not clear why too much complexity is needed for generating a panel key\n */\n\nexport function getValidPanelKey(panelKey: string, panels: Record<string, PanelDefinition>): string {\n const uniquePanelKeys = getUniquePanelKeys(panels);\n let normalizedPanelKey = getPanelKeyParts(removeWhiteSpaces(panelKey)).name;\n\n const matchingKey = uniquePanelKeys[normalizedPanelKey];\n if (typeof matchingKey === 'number') {\n normalizedPanelKey += `-${matchingKey + 1}`;\n }\n return normalizedPanelKey;\n}\n\ntype PanelKeyParts = {\n name: string;\n number?: number;\n};\n\nconst removeWhiteSpaces = (str: string): string => {\n return str.replace(/\\s+/g, '');\n};\n\n/**\n * Breaks the specified panel key into the name and the optional `-number` used\n * for deduping panels with the same name.\n */\nfunction getPanelKeyParts(panelKey: string): PanelKeyParts {\n const parts = panelKey.match(/(.+)-([0-9]+)/);\n if (parts && parts[1] && parts[2]) {\n return {\n name: parts[1],\n number: parseInt(parts[2], 10),\n };\n }\n\n return {\n name: panelKey,\n };\n}\n\n// Find all the unique panel keys and the largest number used for each.\n// ex: cpu, cpu-1, cpu-2 count as the same panel key since these panels have the same name\nfunction getUniquePanelKeys(panels: Record<string, PanelDefinition>): Record<string, number> {\n const uniquePanelKeys: Record<string, number> = {};\n Object.keys(panels).forEach((panelKey) => {\n const { name, number } = getPanelKeyParts(panelKey);\n if (uniquePanelKeys[name] === undefined) {\n uniquePanelKeys[name] = 0;\n }\n const currentValue = uniquePanelKeys[name];\n if (typeof currentValue === 'number' && number) {\n // Check for the maximum value because we cannot rely on a sequential\n // set of numbers when panels are modified.\n uniquePanelKeys[name] = Math.max(currentValue, number);\n }\n });\n return uniquePanelKeys;\n}\n"],"names":["GRID_LAYOUT_SMALL_BREAKPOINT","GRID_LAYOUT_COLS","getYForNewRow","group","newRowY","layout","itemLayouts","itemMaxY","y","h","getPanelBounds","x","w","x1","x2","y1","y2","insertPanelInLayout","newLayout","referenceLayout","MAX_LAYOUT_WIDTH","referenceBounds","aboveInsertRow","insertRow","belowInsertRow","forEach","itemLayout","itemBounds","push","sort","a","b","insertAfterIndex","findIndex","item","i","length","nextItem","splice","map","getValidPanelKey","panelKey","panels","uniquePanelKeys","getUniquePanelKeys","normalizedPanelKey","getPanelKeyParts","removeWhiteSpaces","name","matchingKey","str","replace","parts","match","number","parseInt","Object","keys","undefined","currentValue","Math","max"],"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,4BAA4B,EAAEC,gBAAgB,QAAQ,eAAe;AAE9E,yHAAyH;AACzH,OAAO,SAASC,cAAcC,KAA2B;IACvD,IAAIC,UAAU;IACd,KAAK,MAAMC,UAAUF,MAAMG,WAAW,CAAE;QACtC,MAAMC,WAAWF,OAAOG,CAAC,GAAGH,OAAOI,CAAC;QACpC,IAAIF,WAAWH,SAAS;YACtBA,UAAUG;QACZ;IACF;IACA,OAAOH;AACT;AAqBA,SAASM,eAAe,EAAEC,CAAC,EAAEH,CAAC,EAAEI,CAAC,EAAEH,CAAC,EAAwB;IAC1D,OAAO;QACLI,IAAIF;QACJG,IAAIH,IAAIC;QACRG,IAAIP;QACJQ,IAAIR,IAAIC;IACV;AACF;AAIA;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASQ,oBACdC,SAA2C,EAC3CC,eAAqC,EACrCb,WAAmC;IAEnC,MAAMc,mBAAmBnB,gBAAgB,CAACD,6BAA6B;IAEvE,MAAMqB,kBAAkBX,eAAeS;IAEvC,yEAAyE;IACzE,SAAS;IACT,MAAMG,iBAAyC,EAAE;IACjD,MAAMC,YAAoC,EAAE;IAC5C,MAAMC,iBAAyC,EAAE;IACjDlB,YAAYmB,OAAO,CAAC,CAACC;QACnB,MAAMC,aAAajB,eAAegB;QAElC,IAAIC,WAAWX,EAAE,IAAIK,gBAAgBN,EAAE,EAAE;YACvCO,eAAeM,IAAI,CAACF;QACtB,OAAO,IAAIC,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KAAKC,GAAG,CAACF,cAAcL;QACjD;IACF;IACA,OAAOX;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/dashboards",
|
|
3
|
-
"version": "0.52.0
|
|
3
|
+
"version": "0.52.0",
|
|
4
4
|
"description": "The dashboards feature in Perses",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -29,24 +29,24 @@
|
|
|
29
29
|
"lint:fix": "eslint --fix src --ext .ts,.tsx"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@perses-dev/components": "0.52.0
|
|
33
|
-
"@perses-dev/core": "0.52.0
|
|
34
|
-
"@perses-dev/plugin-system": "0.52.0
|
|
32
|
+
"@perses-dev/components": "0.52.0",
|
|
33
|
+
"@perses-dev/core": "0.52.0",
|
|
34
|
+
"@perses-dev/plugin-system": "0.52.0",
|
|
35
35
|
"@types/react-grid-layout": "^1.3.2",
|
|
36
36
|
"date-fns": "^4.1.0",
|
|
37
37
|
"immer": "^10.1.1",
|
|
38
38
|
"mdi-material-ui": "^7.9.2",
|
|
39
|
-
"nuqs": "^2.5.1",
|
|
40
39
|
"react-grid-layout": "^1.3.4",
|
|
41
40
|
"react-hook-form": "^7.46.1",
|
|
42
41
|
"react-intersection-observer": "^9.4.0",
|
|
43
42
|
"use-immer": "^0.11.0",
|
|
43
|
+
"use-query-params": "^2.2.1",
|
|
44
44
|
"use-resize-observer": "^9.0.0",
|
|
45
45
|
"yaml": "^2.7.0",
|
|
46
46
|
"zustand": "^4.3.3"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@perses-dev/internal-utils": "0.52.0
|
|
49
|
+
"@perses-dev/internal-utils": "0.52.0",
|
|
50
50
|
"history": "^5.3.0",
|
|
51
51
|
"intersection-observer": "^0.12.2"
|
|
52
52
|
},
|