@perses-dev/dashboards 0.52.0 → 0.53.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/DashboardStickyToolbar/DashboardStickyToolbar.js +0 -2
- package/dist/cjs/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js +5 -20
- package/dist/cjs/components/GridLayout/GridItemContent.js +9 -67
- package/dist/cjs/components/GridLayout/GridLayout.js +1 -1
- package/dist/cjs/components/LeaveDialog/LeaveDialog.js +10 -1
- package/dist/cjs/components/Panel/Panel.js +4 -3
- package/dist/cjs/components/Panel/PanelHeader.js +1 -9
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +186 -183
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +3 -0
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +6 -21
- package/dist/cjs/components/QueryViewerDialog/QueryViewerDialog.js +121 -0
- package/dist/cjs/components/QueryViewerDialog/index.js +30 -0
- package/dist/cjs/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +18 -6
- package/dist/cjs/components/SaveDashboardButton/SaveDashboardButton.js +11 -6
- package/dist/cjs/components/Variables/ListVariableListBox.js +201 -0
- package/dist/cjs/components/Variables/Variable.js +164 -72
- package/dist/cjs/components/Variables/VariableList.js +2 -2
- package/dist/cjs/components/Variables/index.js +1 -0
- package/dist/cjs/components/index.js +2 -1
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +1 -1
- package/dist/cjs/context/DashboardProvider/delete-panel-slice.js +1 -1
- package/dist/cjs/context/DashboardProvider/duplicate-panel-slice.js +1 -1
- package/dist/cjs/context/DashboardProvider/index.js +1 -1
- package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +1 -1
- package/dist/cjs/context/DashboardProvider/panel-group-slice.js +1 -7
- package/dist/cjs/context/DashboardProvider/view-panel-slice.js +1 -1
- package/dist/cjs/context/DatasourceStoreProvider.js +3 -4
- package/dist/cjs/context/PanelEditorProvider/PanelEditorProvider.js +49 -0
- package/dist/cjs/context/PanelEditorProvider/index.js +23 -0
- package/dist/cjs/context/VariableProvider/VariableProvider.js +1 -1
- package/dist/cjs/context/VariableProvider/hydrationUtils.js +1 -1
- package/dist/cjs/context/VariableProvider/index.js +1 -1
- package/dist/cjs/context/VariableProvider/utils.js +1 -1
- package/dist/cjs/context/index.js +1 -0
- package/dist/cjs/context/useDashboard.js +1 -1
- package/dist/cjs/utils/panelUtils.js +1 -1
- package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.d.ts.map +1 -1
- package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js +0 -2
- package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js.map +1 -1
- package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -1
- package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js +5 -15
- package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js.map +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +10 -68
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +1 -1
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/GridLayout/Row.d.ts +2 -2
- package/dist/components/GridLayout/Row.d.ts.map +1 -1
- package/dist/components/GridLayout/Row.js.map +1 -1
- package/dist/components/LeaveDialog/LeaveDialog.d.ts +2 -1
- package/dist/components/LeaveDialog/LeaveDialog.d.ts.map +1 -1
- package/dist/components/LeaveDialog/LeaveDialog.js +10 -1
- package/dist/components/LeaveDialog/LeaveDialog.js.map +1 -1
- package/dist/components/Panel/Panel.d.ts +1 -2
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +5 -4
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
- package/dist/components/Panel/PanelHeader.js +2 -10
- package/dist/components/Panel/PanelHeader.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.js +186 -183
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.js +4 -1
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js +5 -15
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
- package/dist/components/QueryViewerDialog/QueryViewerDialog.d.ts +9 -0
- package/dist/components/QueryViewerDialog/QueryViewerDialog.d.ts.map +1 -0
- package/dist/components/QueryViewerDialog/QueryViewerDialog.js +72 -0
- package/dist/components/QueryViewerDialog/QueryViewerDialog.js.map +1 -0
- package/dist/components/QueryViewerDialog/index.d.ts +2 -0
- package/dist/components/QueryViewerDialog/index.d.ts.map +1 -0
- package/dist/components/QueryViewerDialog/index.js +15 -0
- package/dist/components/QueryViewerDialog/index.js.map +1 -0
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts.map +1 -1
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +19 -7
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -1
- package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts.map +1 -1
- package/dist/components/SaveDashboardButton/SaveDashboardButton.js +11 -6
- package/dist/components/SaveDashboardButton/SaveDashboardButton.js.map +1 -1
- package/dist/components/Variables/EditVariablesButton.d.ts.map +1 -1
- package/dist/components/Variables/EditVariablesButton.js.map +1 -1
- package/dist/components/Variables/ListVariableListBox.d.ts +16 -0
- package/dist/components/Variables/ListVariableListBox.d.ts.map +1 -0
- package/dist/components/Variables/ListVariableListBox.js +141 -0
- package/dist/components/Variables/ListVariableListBox.js.map +1 -0
- package/dist/components/Variables/Variable.d.ts.map +1 -1
- package/dist/components/Variables/Variable.js +168 -75
- package/dist/components/Variables/Variable.js.map +1 -1
- package/dist/components/Variables/VariableEditor.d.ts +1 -2
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditor.js.map +1 -1
- package/dist/components/Variables/VariableList.d.ts.map +1 -1
- package/dist/components/Variables/VariableList.js +2 -2
- package/dist/components/Variables/VariableList.js.map +1 -1
- package/dist/components/Variables/index.d.ts +1 -0
- package/dist/components/Variables/index.d.ts.map +1 -1
- package/dist/components/Variables/index.js +1 -0
- package/dist/components/Variables/index.js.map +1 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +2 -1
- package/dist/components/index.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +1 -2
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
- package/dist/context/DashboardProvider/delete-panel-slice.d.ts +2 -1
- package/dist/context/DashboardProvider/delete-panel-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/delete-panel-slice.js +1 -1
- package/dist/context/DashboardProvider/delete-panel-slice.js.map +1 -1
- package/dist/context/DashboardProvider/duplicate-panel-slice.d.ts +2 -1
- package/dist/context/DashboardProvider/duplicate-panel-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/duplicate-panel-slice.js +1 -1
- package/dist/context/DashboardProvider/duplicate-panel-slice.js.map +1 -1
- package/dist/context/DashboardProvider/index.d.ts +0 -1
- package/dist/context/DashboardProvider/index.d.ts.map +1 -1
- package/dist/context/DashboardProvider/index.js +1 -1
- package/dist/context/DashboardProvider/index.js.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts +2 -2
- 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-slice.d.ts +1 -24
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js +1 -6
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts +2 -1
- package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/save-changes-dialog-slice.js.map +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.d.ts +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.js +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.js.map +1 -1
- package/dist/context/DatasourceStoreProvider.d.ts +1 -17
- package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
- package/dist/context/DatasourceStoreProvider.js +2 -3
- package/dist/context/DatasourceStoreProvider.js.map +1 -1
- package/dist/context/PanelEditorProvider/PanelEditorProvider.d.ts +13 -0
- package/dist/context/PanelEditorProvider/PanelEditorProvider.d.ts.map +1 -0
- package/dist/context/PanelEditorProvider/PanelEditorProvider.js +33 -0
- package/dist/context/PanelEditorProvider/PanelEditorProvider.js.map +1 -0
- package/dist/context/PanelEditorProvider/index.d.ts +3 -0
- package/dist/context/PanelEditorProvider/index.d.ts.map +1 -0
- package/dist/context/PanelEditorProvider/index.js +16 -0
- package/dist/context/PanelEditorProvider/index.js.map +1 -0
- package/dist/context/VariableProvider/VariableProvider.d.ts +1 -10
- package/dist/context/VariableProvider/VariableProvider.d.ts.map +1 -1
- package/dist/context/VariableProvider/VariableProvider.js +1 -1
- package/dist/context/VariableProvider/VariableProvider.js.map +1 -1
- package/dist/context/VariableProvider/hydrationUtils.d.ts +1 -2
- package/dist/context/VariableProvider/hydrationUtils.d.ts.map +1 -1
- package/dist/context/VariableProvider/hydrationUtils.js +1 -1
- package/dist/context/VariableProvider/hydrationUtils.js.map +1 -1
- package/dist/context/VariableProvider/index.js +1 -1
- package/dist/context/VariableProvider/index.js.map +1 -1
- package/dist/context/VariableProvider/utils.d.ts +1 -2
- package/dist/context/VariableProvider/utils.d.ts.map +1 -1
- package/dist/context/VariableProvider/utils.js +1 -1
- package/dist/context/VariableProvider/utils.js.map +1 -1
- package/dist/context/index.d.ts +1 -0
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -0
- package/dist/context/index.js.map +1 -1
- package/dist/context/useDashboard.d.ts.map +1 -1
- package/dist/context/useDashboard.js +1 -1
- package/dist/context/useDashboard.js.map +1 -1
- package/dist/utils/panelUtils.d.ts +1 -2
- package/dist/utils/panelUtils.d.ts.map +1 -1
- package/dist/utils/panelUtils.js +1 -1
- package/dist/utils/panelUtils.js.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Copyright 2025 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import React, { forwardRef, useContext, useMemo } from 'react';
|
|
15
|
+
import { Checkbox, Divider } from '@mui/material';
|
|
16
|
+
import { DEFAULT_ALL_VALUE } from '@perses-dev/core';
|
|
17
|
+
const ListVariableListBoxContext = /*#__PURE__*/ React.createContext(undefined);
|
|
18
|
+
export function useListVariableListBoxContext() {
|
|
19
|
+
const ctx = useContext(ListVariableListBoxContext);
|
|
20
|
+
if (!ctx) throw new Error('ListVariableListBoxContext not found');
|
|
21
|
+
return ctx;
|
|
22
|
+
}
|
|
23
|
+
/*
|
|
24
|
+
* Handles the logic for toggling the global select checkbox in the ListBox header.
|
|
25
|
+
*
|
|
26
|
+
* If all options are selected, it will deselect all options.
|
|
27
|
+
* Except if filteredOptions is a subset of options, then it will only deselect the filtered options.
|
|
28
|
+
*
|
|
29
|
+
* If some options are selected, it will select all filtered options.
|
|
30
|
+
*
|
|
31
|
+
* If no options are selected, it will select all filtered options.
|
|
32
|
+
* Should be not possible since a ListVariable has always at least one value.
|
|
33
|
+
*
|
|
34
|
+
* If allowAllValue is true, it will handle the special "All" option logic.
|
|
35
|
+
* Main difference is if some options are selected and there is no filter, it will select the "All" option
|
|
36
|
+
*/ function handleGlobalSelectToggle(options, selectedOptions, filteredOptions, isIndeterminate, isAllSelected, allowAllValue, onChange) {
|
|
37
|
+
if (isAllSelected) {
|
|
38
|
+
if (filteredOptions.length !== options.length) {
|
|
39
|
+
onChange(selectedOptions.filter((o)=>!filteredOptions.includes(o)));
|
|
40
|
+
} else {
|
|
41
|
+
onChange([]);
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (isIndeterminate) {
|
|
46
|
+
if (allowAllValue) {
|
|
47
|
+
if (filteredOptions.length === options.length) {
|
|
48
|
+
if (selectedOptions[0]?.value === DEFAULT_ALL_VALUE) {
|
|
49
|
+
onChange(options.filter((o)=>o.value !== DEFAULT_ALL_VALUE));
|
|
50
|
+
} else {
|
|
51
|
+
onChange([
|
|
52
|
+
{
|
|
53
|
+
label: DEFAULT_ALL_VALUE,
|
|
54
|
+
value: DEFAULT_ALL_VALUE
|
|
55
|
+
}
|
|
56
|
+
]);
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
if (filteredOptions.every((o)=>selectedOptions.includes(o))) {
|
|
60
|
+
onChange(selectedOptions.filter((o)=>!filteredOptions.includes(o)));
|
|
61
|
+
} else {
|
|
62
|
+
onChange([
|
|
63
|
+
...selectedOptions,
|
|
64
|
+
...filteredOptions.filter((o)=>o.value !== DEFAULT_ALL_VALUE)
|
|
65
|
+
]);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
if (filteredOptions.length === options.length) {
|
|
70
|
+
onChange(options);
|
|
71
|
+
} else {
|
|
72
|
+
if (filteredOptions.every((o)=>selectedOptions.includes(o))) {
|
|
73
|
+
onChange(selectedOptions.filter((o)=>!filteredOptions.includes(o)));
|
|
74
|
+
} else {
|
|
75
|
+
onChange([
|
|
76
|
+
...selectedOptions,
|
|
77
|
+
...filteredOptions
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// Nothing selected, so select filtered options
|
|
85
|
+
onChange(filteredOptions);
|
|
86
|
+
}
|
|
87
|
+
export function ListVariableListBoxProvider({ value, children }) {
|
|
88
|
+
return /*#__PURE__*/ _jsx(ListVariableListBoxContext.Provider, {
|
|
89
|
+
value: value,
|
|
90
|
+
children: children
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
export const ListVariableListBox = /*#__PURE__*/ forwardRef(function ListVariableListBox(props, ref) {
|
|
94
|
+
const { children, ...rest } = props;
|
|
95
|
+
const { options, selectedOptions, filteredOptions, allowAllValue, onChange } = useListVariableListBoxContext();
|
|
96
|
+
// Derived selection metadata for context listbox header
|
|
97
|
+
const selectedCount = useMemo(()=>selectedOptions.length, [
|
|
98
|
+
selectedOptions
|
|
99
|
+
]);
|
|
100
|
+
const isIndeterminate = useMemo(()=>options.length > 0 && selectedCount > 0 && selectedCount !== options.length, [
|
|
101
|
+
selectedCount,
|
|
102
|
+
options
|
|
103
|
+
]);
|
|
104
|
+
const isAllSelected = useMemo(()=>options.length > 0 && selectedCount === options.length, [
|
|
105
|
+
selectedCount,
|
|
106
|
+
options
|
|
107
|
+
]);
|
|
108
|
+
return /*#__PURE__*/ _jsxs("ul", {
|
|
109
|
+
...rest,
|
|
110
|
+
ref: ref,
|
|
111
|
+
role: "listbox",
|
|
112
|
+
children: [
|
|
113
|
+
/*#__PURE__*/ _jsxs("li", {
|
|
114
|
+
style: {
|
|
115
|
+
display: 'flex',
|
|
116
|
+
alignItems: 'center'
|
|
117
|
+
},
|
|
118
|
+
children: [
|
|
119
|
+
/*#__PURE__*/ _jsx(Checkbox, {
|
|
120
|
+
indeterminate: isIndeterminate,
|
|
121
|
+
checked: isAllSelected,
|
|
122
|
+
// intentionally not passing event to underlying handler to mimic previous behavior
|
|
123
|
+
onChange: ()=>handleGlobalSelectToggle(options, selectedOptions, filteredOptions, isIndeterminate, isAllSelected, allowAllValue, onChange)
|
|
124
|
+
}),
|
|
125
|
+
/*#__PURE__*/ _jsxs("span", {
|
|
126
|
+
children: [
|
|
127
|
+
/*#__PURE__*/ _jsx("strong", {
|
|
128
|
+
children: selectedCount
|
|
129
|
+
}),
|
|
130
|
+
" Selected"
|
|
131
|
+
]
|
|
132
|
+
})
|
|
133
|
+
]
|
|
134
|
+
}),
|
|
135
|
+
/*#__PURE__*/ _jsx(Divider, {}),
|
|
136
|
+
children
|
|
137
|
+
]
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
//# sourceMappingURL=ListVariableListBox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Variables/ListVariableListBox.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 React, { ForwardedRef, HTMLAttributes, ReactNode, forwardRef, useContext, useMemo } from 'react';\nimport { Checkbox, Divider } from '@mui/material';\nimport { VariableOption } from '@perses-dev/plugin-system';\nimport { DEFAULT_ALL_VALUE } from '@perses-dev/core';\n\nexport interface ListVariableListBoxContextValue {\n options: VariableOption[];\n selectedOptions: VariableOption[];\n filteredOptions: VariableOption[];\n allowAllValue: boolean;\n onChange: (selectedOptions: VariableOption[]) => void;\n}\n\nconst ListVariableListBoxContext = React.createContext<ListVariableListBoxContextValue | undefined>(undefined);\n\nexport function useListVariableListBoxContext(): ListVariableListBoxContextValue {\n const ctx = useContext(ListVariableListBoxContext);\n if (!ctx) throw new Error('ListVariableListBoxContext not found');\n return ctx;\n}\n\n/*\n * Handles the logic for toggling the global select checkbox in the ListBox header.\n *\n * If all options are selected, it will deselect all options.\n * Except if filteredOptions is a subset of options, then it will only deselect the filtered options.\n *\n * If some options are selected, it will select all filtered options.\n *\n * If no options are selected, it will select all filtered options.\n * Should be not possible since a ListVariable has always at least one value.\n *\n * If allowAllValue is true, it will handle the special \"All\" option logic.\n * Main difference is if some options are selected and there is no filter, it will select the \"All\" option\n */\nfunction handleGlobalSelectToggle(\n options: VariableOption[],\n selectedOptions: VariableOption[],\n filteredOptions: VariableOption[],\n isIndeterminate: boolean,\n isAllSelected: boolean,\n allowAllValue: boolean,\n onChange: (selectedOptions: VariableOption[]) => void\n): void {\n if (isAllSelected) {\n if (filteredOptions.length !== options.length) {\n onChange(selectedOptions.filter((o) => !filteredOptions.includes(o)));\n } else {\n onChange([]);\n }\n return;\n }\n\n if (isIndeterminate) {\n if (allowAllValue) {\n if (filteredOptions.length === options.length) {\n if (selectedOptions[0]?.value === DEFAULT_ALL_VALUE) {\n onChange(options.filter((o) => o.value !== DEFAULT_ALL_VALUE));\n } else {\n onChange([{ label: DEFAULT_ALL_VALUE, value: DEFAULT_ALL_VALUE }]);\n }\n } else {\n if (filteredOptions.every((o) => selectedOptions.includes(o))) {\n onChange(selectedOptions.filter((o) => !filteredOptions.includes(o)));\n } else {\n onChange([...selectedOptions, ...filteredOptions.filter((o) => o.value !== DEFAULT_ALL_VALUE)]);\n }\n }\n } else {\n if (filteredOptions.length === options.length) {\n onChange(options);\n } else {\n if (filteredOptions.every((o) => selectedOptions.includes(o))) {\n onChange(selectedOptions.filter((o) => !filteredOptions.includes(o)));\n } else {\n onChange([...selectedOptions, ...filteredOptions]);\n }\n }\n }\n return;\n }\n\n // Nothing selected, so select filtered options\n onChange(filteredOptions);\n}\n\nexport function ListVariableListBoxProvider({\n value,\n children,\n}: {\n value: ListVariableListBoxContextValue;\n children: ReactNode;\n}): React.ReactElement {\n return <ListVariableListBoxContext.Provider value={value}>{children}</ListVariableListBoxContext.Provider>;\n}\n\nexport const ListVariableListBox = forwardRef(function ListVariableListBox(\n props: HTMLAttributes<HTMLUListElement>,\n ref: ForwardedRef<HTMLUListElement>\n) {\n const { children, ...rest } = props;\n const { options, selectedOptions, filteredOptions, allowAllValue, onChange } = useListVariableListBoxContext();\n\n // Derived selection metadata for context listbox header\n const selectedCount = useMemo(() => selectedOptions.length, [selectedOptions]);\n const isIndeterminate = useMemo(\n () => options.length > 0 && selectedCount > 0 && selectedCount !== options.length,\n [selectedCount, options]\n );\n const isAllSelected = useMemo(() => options.length > 0 && selectedCount === options.length, [selectedCount, options]);\n\n return (\n <ul {...rest} ref={ref} role=\"listbox\">\n <li style={{ display: 'flex', alignItems: 'center' }}>\n <Checkbox\n indeterminate={isIndeterminate}\n checked={isAllSelected}\n // intentionally not passing event to underlying handler to mimic previous behavior\n onChange={() =>\n handleGlobalSelectToggle(\n options,\n selectedOptions,\n filteredOptions,\n isIndeterminate,\n isAllSelected,\n allowAllValue,\n onChange\n )\n }\n />\n <span>\n <strong>{selectedCount}</strong> Selected\n </span>\n </li>\n <Divider />\n {children}\n </ul>\n );\n});\n"],"names":["React","forwardRef","useContext","useMemo","Checkbox","Divider","DEFAULT_ALL_VALUE","ListVariableListBoxContext","createContext","undefined","useListVariableListBoxContext","ctx","Error","handleGlobalSelectToggle","options","selectedOptions","filteredOptions","isIndeterminate","isAllSelected","allowAllValue","onChange","length","filter","o","includes","value","label","every","ListVariableListBoxProvider","children","Provider","ListVariableListBox","props","ref","rest","selectedCount","ul","role","li","style","display","alignItems","indeterminate","checked","span","strong"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,OAAOA,SAAkDC,UAAU,EAAEC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AACxG,SAASC,QAAQ,EAAEC,OAAO,QAAQ,gBAAgB;AAElD,SAASC,iBAAiB,QAAQ,mBAAmB;AAUrD,MAAMC,2CAA6BP,MAAMQ,aAAa,CAA8CC;AAEpG,OAAO,SAASC;IACd,MAAMC,MAAMT,WAAWK;IACvB,IAAI,CAACI,KAAK,MAAM,IAAIC,MAAM;IAC1B,OAAOD;AACT;AAEA;;;;;;;;;;;;;CAaC,GACD,SAASE,yBACPC,OAAyB,EACzBC,eAAiC,EACjCC,eAAiC,EACjCC,eAAwB,EACxBC,aAAsB,EACtBC,aAAsB,EACtBC,QAAqD;IAErD,IAAIF,eAAe;QACjB,IAAIF,gBAAgBK,MAAM,KAAKP,QAAQO,MAAM,EAAE;YAC7CD,SAASL,gBAAgBO,MAAM,CAAC,CAACC,IAAM,CAACP,gBAAgBQ,QAAQ,CAACD;QACnE,OAAO;YACLH,SAAS,EAAE;QACb;QACA;IACF;IAEA,IAAIH,iBAAiB;QACnB,IAAIE,e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AAEC,eAAe,EAAEG,aAAa,EAAEC,QAAQ,EAAE,GAAGV;IAE/E,wDAAwD;IACxD,MAAMyB,gBAAgBhC,QAAQ,IAAMY,gBAAgBM,MAAM,EAAE;QAACN;KAAgB;IAC7E,MAAME,kBAAkBd,QACtB,IAAMW,QAAQO,MAAM,GAAG,KAAKc,gBAAgB,KAAKA,kBAAkBrB,QAAQO,MAAM,EACjF;QAACc;QAAerB;KAAQ;IAE1B,MAAMI,gBAAgBf,QAAQ,IAAMW,QAAQO,MAAM,GAAG,KAAKc,kBAAkBrB,QAAQO,MAAM,EAAE;QAACc;QAAerB;KAAQ;IAEpH,qBACE,MAACsB;QAAI,GAAGF,IAAI;QAAED,KAAKA;QAAKI,MAAK;;0BAC3B,MAACC;gBAAGC,OAAO;oBAAEC,SAAS;oBAAQC,YAAY;gBAAS;;kCACjD,KAACrC;wBACCsC,eAAezB;wBACf0B,SAASzB;wBACT,mFAAmF;wBACnFE,UAAU,IACRP,yBACEC,SACAC,iBACAC,iBACAC,iBACAC,eACAC,eACAC;;kCAIN,MAACwB;;0CACC,KAACC;0CAAQV;;4BAAuB;;;;;0BAGpC,KAAC9B;YACAwB;;;AAGP,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Variable.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/Variable.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"Variable.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/Variable.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAA6C,MAAM,OAAO,CAAC;AAEhF,OAAO,EAGL,gBAAgB,EAEhB,YAAY,EACZ,aAAa,EACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAIL,cAAc,EACd,aAAa,EACd,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAKvD,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,YAAY,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAcF,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,aAAa,GAAG,YAAY,CAWtE;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,gBAAgB,GAAG,SAAS,EAClC,KAAK,EAAE,aAAa,GAAG,SAAS,EAChC,qBAAqB,EAAE,OAAO,CAAC,cAAc,CAAC,cAAc,EAAE,CAAC,CAAC,GAC/D;IAED,KAAK,EAAE,aAAa,GAAG,SAAS,CAAC;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC;IAEtC,eAAe,EAAE,cAAc,GAAG,cAAc,EAAE,CAAC;IAEnD,WAAW,EAAE,cAAc,EAAE,CAAC;CAC/B,CA4EA"}
|
|
@@ -11,12 +11,14 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
14
|
+
import { createElement as _createElement } from "react";
|
|
15
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
16
|
+
import { TextField, Popper, Checkbox, Autocomplete, createFilterOptions, Chip, Box } from '@mui/material';
|
|
16
17
|
import { DEFAULT_ALL_VALUE } from '@perses-dev/core';
|
|
17
|
-
import { useListVariablePluginValues } from '@perses-dev/plugin-system';
|
|
18
|
+
import { SORT_METHODS, useListVariablePluginValues } from '@perses-dev/plugin-system';
|
|
18
19
|
import { useVariableDefinitionAndState, useVariableDefinitionActions } from '../../context';
|
|
19
20
|
import { MAX_VARIABLE_WIDTH, MIN_VARIABLE_WIDTH } from '../../constants';
|
|
21
|
+
import { ListVariableListBoxProvider, ListVariableListBox } from './ListVariableListBox';
|
|
20
22
|
function variableOptionToVariableValue(options) {
|
|
21
23
|
if (options === null) {
|
|
22
24
|
return null;
|
|
@@ -73,22 +75,8 @@ export function useListVariableState(spec, state, variablesOptionsQuery) {
|
|
|
73
75
|
...options
|
|
74
76
|
] : [];
|
|
75
77
|
if (!sort || sort === 'none') return opts;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return opts.sort((a, b)=>a.label > b.label ? 1 : -1);
|
|
79
|
-
case 'alphabetical-desc':
|
|
80
|
-
return opts.sort((a, b)=>a.label > b.label ? -1 : 1);
|
|
81
|
-
case 'numerical-asc':
|
|
82
|
-
return opts.sort((a, b)=>parseInt(a.label) > parseInt(b.label) ? 1 : -1);
|
|
83
|
-
case 'numerical-desc':
|
|
84
|
-
return opts.sort((a, b)=>parseInt(a.label) < parseInt(b.label) ? 1 : -1);
|
|
85
|
-
case 'alphabetical-ci-asc':
|
|
86
|
-
return opts.sort((a, b)=>a.label.toLowerCase() > b.label.toLowerCase() ? 1 : -1);
|
|
87
|
-
case 'alphabetical-ci-desc':
|
|
88
|
-
return opts.sort((a, b)=>a.label.toLowerCase() > b.label.toLowerCase() ? -1 : 1);
|
|
89
|
-
default:
|
|
90
|
-
return opts;
|
|
91
|
-
}
|
|
78
|
+
const sortMethod = SORT_METHODS[sort];
|
|
79
|
+
return !sortMethod ? opts : sortMethod.sort(opts);
|
|
92
80
|
}, [
|
|
93
81
|
options,
|
|
94
82
|
sort
|
|
@@ -196,6 +184,15 @@ function ListVariable({ name, source }) {
|
|
|
196
184
|
const title = definition?.spec.display?.name ?? name;
|
|
197
185
|
const allowMultiple = definition?.spec.allowMultiple === true;
|
|
198
186
|
const allowAllValue = definition?.spec.allowAllValue === true;
|
|
187
|
+
const filterOptions = createFilterOptions({});
|
|
188
|
+
const filteredOptions = useMemo(()=>filterOptions(viewOptions, {
|
|
189
|
+
inputValue,
|
|
190
|
+
getOptionLabel: (o)=>o.label
|
|
191
|
+
}), [
|
|
192
|
+
inputValue,
|
|
193
|
+
viewOptions,
|
|
194
|
+
filterOptions
|
|
195
|
+
]);
|
|
199
196
|
// Update value when changed
|
|
200
197
|
useEffect(()=>{
|
|
201
198
|
if (value) {
|
|
@@ -227,64 +224,160 @@ function ListVariable({ name, source }) {
|
|
|
227
224
|
options,
|
|
228
225
|
source
|
|
229
226
|
]);
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
},
|
|
272
|
-
inputValue: allowMultiple ? inputValue : undefined,
|
|
273
|
-
onInputChange: (_, newInputValue)=>{
|
|
274
|
-
if (!allowMultiple) {
|
|
275
|
-
setInputWidth(getWidthPx(newInputValue, 'list'));
|
|
276
|
-
}
|
|
227
|
+
const handleGlobalSelect = useCallback((options)=>{
|
|
228
|
+
setVariableValue(name, variableOptionToVariableValue(options), source);
|
|
229
|
+
}, [
|
|
230
|
+
name,
|
|
231
|
+
setVariableValue,
|
|
232
|
+
source
|
|
233
|
+
]);
|
|
234
|
+
const listBoxProviderValue = useMemo(()=>({
|
|
235
|
+
options: viewOptions,
|
|
236
|
+
selectedOptions: selectedOptions,
|
|
237
|
+
filteredOptions: filteredOptions,
|
|
238
|
+
allowAllValue,
|
|
239
|
+
onChange: handleGlobalSelect
|
|
240
|
+
}), [
|
|
241
|
+
allowAllValue,
|
|
242
|
+
filteredOptions,
|
|
243
|
+
handleGlobalSelect,
|
|
244
|
+
selectedOptions,
|
|
245
|
+
viewOptions
|
|
246
|
+
]);
|
|
247
|
+
const autocompleteComponent = useMemo(()=>{
|
|
248
|
+
return /*#__PURE__*/ _jsx(Autocomplete, {
|
|
249
|
+
disablePortal: true,
|
|
250
|
+
loading: loading,
|
|
251
|
+
disableCloseOnSelect: allowMultiple,
|
|
252
|
+
multiple: allowMultiple,
|
|
253
|
+
fullWidth: true,
|
|
254
|
+
limitTags: 3,
|
|
255
|
+
size: "small",
|
|
256
|
+
disableClearable: true,
|
|
257
|
+
slotProps: {
|
|
258
|
+
listbox: {
|
|
259
|
+
component: allowMultiple ? ListVariableListBox : undefined
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
slots: {
|
|
263
|
+
popper: StyledPopper
|
|
264
|
+
},
|
|
265
|
+
sx: {
|
|
266
|
+
'& .MuiInputBase-root': {
|
|
267
|
+
minHeight: '38px'
|
|
277
268
|
},
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
269
|
+
'& .MuiAutocomplete-tag': {
|
|
270
|
+
margin: '1px 2px'
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
filterOptions: filterOptions,
|
|
274
|
+
options: viewOptions,
|
|
275
|
+
value: selectedOptions,
|
|
276
|
+
onChange: (_, value)=>{
|
|
277
|
+
if ((value === null || Array.isArray(value) && value.length === 0) && allowAllValue) {
|
|
278
|
+
setVariableValue(name, DEFAULT_ALL_VALUE, source);
|
|
279
|
+
} else {
|
|
280
|
+
setVariableValue(name, variableOptionToVariableValue(value), source);
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
inputValue: allowMultiple ? inputValue : undefined,
|
|
284
|
+
onInputChange: (_, newInputValue)=>{
|
|
285
|
+
if (!allowMultiple) {
|
|
286
|
+
setInputWidth(getWidthPx(newInputValue, 'list'));
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
onBlur: ()=>{
|
|
290
|
+
if (allowMultiple) {
|
|
291
|
+
setInputValue('');
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
renderInput: (params)=>{
|
|
295
|
+
return allowMultiple ? /*#__PURE__*/ _jsx(TextField, {
|
|
296
|
+
...params,
|
|
297
|
+
label: title,
|
|
298
|
+
onChange: (e)=>setInputValue(e.target.value)
|
|
299
|
+
}) : /*#__PURE__*/ _jsx(TextField, {
|
|
300
|
+
...params,
|
|
301
|
+
label: title,
|
|
302
|
+
style: {
|
|
303
|
+
width: `${inputWidth}px`
|
|
281
304
|
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
})
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
305
|
+
});
|
|
306
|
+
},
|
|
307
|
+
renderOption: (props, option, { selected })=>{
|
|
308
|
+
const { key, ...optionProps } = props;
|
|
309
|
+
return /*#__PURE__*/ _jsxs("li", {
|
|
310
|
+
...optionProps,
|
|
311
|
+
style: {
|
|
312
|
+
padding: 0
|
|
313
|
+
},
|
|
314
|
+
children: [
|
|
315
|
+
/*#__PURE__*/ _jsx(Checkbox, {
|
|
316
|
+
style: {
|
|
317
|
+
marginRight: 8
|
|
318
|
+
},
|
|
319
|
+
checked: selected
|
|
320
|
+
}),
|
|
321
|
+
option.label
|
|
322
|
+
]
|
|
323
|
+
}, key);
|
|
324
|
+
},
|
|
325
|
+
renderTags: (value, getTagProps, ownerState)=>{
|
|
326
|
+
// When focused, if there are too much value selected, it will use all screen place. Putting limit to 200px (~6 lines of chips)
|
|
327
|
+
if (ownerState.focused) {
|
|
328
|
+
return /*#__PURE__*/ _jsx(Box, {
|
|
329
|
+
sx: {
|
|
330
|
+
maxHeight: 200,
|
|
331
|
+
overflowY: 'auto'
|
|
332
|
+
},
|
|
333
|
+
children: value.map((option, index)=>/*#__PURE__*/ _createElement(Chip, {
|
|
334
|
+
...getTagProps({
|
|
335
|
+
index
|
|
336
|
+
}),
|
|
337
|
+
key: index,
|
|
338
|
+
label: option.label,
|
|
339
|
+
size: "small"
|
|
340
|
+
}))
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
const limitTags = ownerState.limitTags;
|
|
344
|
+
const numTags = value.length;
|
|
345
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
346
|
+
children: [
|
|
347
|
+
value.slice(0, limitTags).map((option, index)=>/*#__PURE__*/ _createElement(Chip, {
|
|
348
|
+
...getTagProps({
|
|
349
|
+
index
|
|
350
|
+
}),
|
|
351
|
+
key: index,
|
|
352
|
+
label: option.label,
|
|
353
|
+
size: "small"
|
|
354
|
+
})),
|
|
355
|
+
limitTags && numTags > limitTags && ` +${numTags - limitTags}`
|
|
356
|
+
]
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
}, [
|
|
361
|
+
allowAllValue,
|
|
362
|
+
allowMultiple,
|
|
363
|
+
filterOptions,
|
|
364
|
+
inputValue,
|
|
365
|
+
inputWidth,
|
|
366
|
+
loading,
|
|
367
|
+
name,
|
|
368
|
+
selectedOptions,
|
|
369
|
+
setVariableValue,
|
|
370
|
+
source,
|
|
371
|
+
title,
|
|
372
|
+
viewOptions
|
|
373
|
+
]);
|
|
374
|
+
if (allowMultiple) {
|
|
375
|
+
return /*#__PURE__*/ _jsx(ListVariableListBoxProvider, {
|
|
376
|
+
value: listBoxProviderValue,
|
|
377
|
+
children: autocompleteComponent
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
return autocompleteComponent;
|
|
288
381
|
}
|
|
289
382
|
function TextVariable({ name, source }) {
|
|
290
383
|
const ctx = useVariableDefinitionAndState(name, source);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Variables/Variable.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 { ReactElement, useEffect, useMemo, useState } from 'react';\nimport { LinearProgress, TextField, Autocomplete, Popper, PopperProps } from '@mui/material';\nimport {\n DEFAULT_ALL_VALUE,\n ListVariableDefinition,\n ListVariableSpec,\n TextVariableDefinition,\n VariableName,\n VariableValue,\n} from '@perses-dev/core';\nimport { useListVariablePluginValues, VariableOption, VariableState } from '@perses-dev/plugin-system';\nimport { UseQueryResult } from '@tanstack/react-query';\nimport { useVariableDefinitionAndState, useVariableDefinitionActions } from '../../context';\nimport { MAX_VARIABLE_WIDTH, MIN_VARIABLE_WIDTH } from '../../constants';\n\ntype VariableProps = {\n name: VariableName;\n source?: string;\n};\n\nfunction variableOptionToVariableValue(options: VariableOption | VariableOption[] | null): VariableValue {\n if (options === null) {\n return null;\n }\n if (Array.isArray(options)) {\n return options.map((v) => {\n return v.value;\n });\n }\n return options.value;\n}\n\nexport function Variable({ name, source }: VariableProps): ReactElement {\n const ctx = useVariableDefinitionAndState(name, source);\n const kind = ctx.definition?.kind;\n switch (kind) {\n case 'TextVariable':\n return <TextVariable name={name} source={source} />;\n case 'ListVariable':\n return <ListVariable name={name} source={source} />;\n }\n\n return <div>Unsupported Variable Kind: ${kind}</div>;\n}\n\nexport function useListVariableState(\n spec: ListVariableSpec | undefined,\n state: VariableState | undefined,\n variablesOptionsQuery: Partial<UseQueryResult<VariableOption[]>>\n): {\n // Value, Loading, Options are modified only when we want to save the changes made\n value: VariableValue | undefined;\n loading: boolean;\n options: VariableOption[] | undefined;\n // selectedOptions is/are the option(s) selected in the view\n selectedOptions: VariableOption | VariableOption[];\n // viewOptions are the options used in the view only (= options + All if allowed)\n viewOptions: VariableOption[];\n} {\n const allowMultiple = spec?.allowMultiple === true;\n const allowAllValue = spec?.allowAllValue === true;\n const sort = spec?.sort;\n const loading = useMemo(() => variablesOptionsQuery.isFetching ?? false, [variablesOptionsQuery.isFetching]);\n const options = useMemo(() => variablesOptionsQuery.data ?? [], [variablesOptionsQuery.data]);\n\n let value = state?.value;\n\n // Make sure value is an array if allowMultiple is true\n if (allowMultiple && !Array.isArray(value)) {\n value = typeof value === 'string' ? [value] : [];\n }\n\n // Sort the provided list of options according to the method defined\n const sortedOptions = useMemo((): VariableOption[] => {\n const opts = options ? [...options] : [];\n\n if (!sort || sort === 'none') return opts;\n\n switch (sort) {\n case 'alphabetical-asc':\n return opts.sort((a, b) => (a.label > b.label ? 1 : -1));\n case 'alphabetical-desc':\n return opts.sort((a, b) => (a.label > b.label ? -1 : 1));\n case 'numerical-asc':\n return opts.sort((a, b) => (parseInt(a.label) > parseInt(b.label) ? 1 : -1));\n case 'numerical-desc':\n return opts.sort((a, b) => (parseInt(a.label) < parseInt(b.label) ? 1 : -1));\n case 'alphabetical-ci-asc':\n return opts.sort((a, b) => (a.label.toLowerCase() > b.label.toLowerCase() ? 1 : -1));\n case 'alphabetical-ci-desc':\n return opts.sort((a, b) => (a.label.toLowerCase() > b.label.toLowerCase() ? -1 : 1));\n default:\n return opts;\n }\n }, [options, sort]);\n\n const viewOptions = useMemo(() => {\n let computedOptions = sortedOptions;\n\n // Add the all value if it's allowed\n if (allowAllValue) {\n computedOptions = [{ value: DEFAULT_ALL_VALUE, label: 'All' }, ...computedOptions];\n }\n return computedOptions;\n }, [allowAllValue, sortedOptions]);\n\n const valueIsInOptions = useMemo(\n () =>\n Boolean(\n viewOptions.find((v) => {\n if (allowMultiple) {\n return (value as string[]).includes(v.value);\n }\n return value === v.value;\n })\n ),\n [viewOptions, value, allowMultiple]\n );\n\n value = useMemo(() => {\n const firstOptionValue = viewOptions?.[allowAllValue ? 1 : 0]?.value;\n\n // If there is no value but there are options, or the value is not in options, we set the value to the first option.\n if (firstOptionValue) {\n if (!valueIsInOptions || !value || value.length === 0) {\n return allowMultiple ? [firstOptionValue] : firstOptionValue;\n }\n }\n\n return value;\n }, [viewOptions, value, valueIsInOptions, allowMultiple, allowAllValue]);\n\n const selectedOptions = useMemo(() => {\n // In the case Autocomplete.multiple equals false, Autocomplete.value expects a single object, not\n // an array, hence this conditional\n if (Array.isArray(value)) {\n return viewOptions.filter((o) => {\n return value?.includes(o.value);\n });\n } else {\n return (\n viewOptions.find((o) => {\n return value === o.value;\n }) ?? { value: '', label: '' }\n );\n }\n }, [value, viewOptions]);\n\n return { value, loading, options, selectedOptions, viewOptions };\n}\n\nconst StyledPopper = (props: PopperProps): ReactElement => (\n <Popper {...props} sx={{ minWidth: 'fit-content' }} placement=\"bottom-start\" />\n);\n\nconst LETTER_HSIZE = 8; // approximation\nconst ARROW_OFFSET = 40; // right offset for list variables (= take into account the dropdown toggle size)\nconst getWidthPx = (inputValue: string, kind: 'list' | 'text'): number => {\n const width = (inputValue.length + 1) * LETTER_HSIZE + (kind === 'list' ? ARROW_OFFSET : 0);\n if (width < MIN_VARIABLE_WIDTH) {\n return MIN_VARIABLE_WIDTH;\n } else if (width > MAX_VARIABLE_WIDTH) {\n return MAX_VARIABLE_WIDTH;\n } else {\n return width;\n }\n};\n\nfunction ListVariable({ name, source }: VariableProps): ReactElement {\n const ctx = useVariableDefinitionAndState(name, source);\n const definition = ctx.definition as ListVariableDefinition;\n const variablesOptionsQuery = useListVariablePluginValues(definition);\n const { setVariableValue, setVariableLoading, setVariableOptions } = useVariableDefinitionActions();\n const { selectedOptions, value, loading, options, viewOptions } = useListVariableState(\n definition?.spec,\n ctx.state,\n variablesOptionsQuery\n );\n const [inputWidth, setInputWidth] = useState(MIN_VARIABLE_WIDTH);\n // Used for multiple value variables, it will not clear variable input when selecting an option\n const [inputValue, setInputValue] = useState('');\n\n const title = definition?.spec.display?.name ?? name;\n const allowMultiple = definition?.spec.allowMultiple === true;\n const allowAllValue = definition?.spec.allowAllValue === true;\n\n // Update value when changed\n useEffect(() => {\n if (value) {\n setVariableValue(name, value, source);\n }\n }, [setVariableValue, name, value, source]);\n\n // Update loading when changed\n useEffect(() => {\n setVariableLoading(name, loading, source);\n }, [setVariableLoading, name, loading, source]);\n\n // Update options when changed\n useEffect(() => {\n if (options) {\n setVariableOptions(name, options, source);\n }\n }, [setVariableOptions, name, options, source]);\n\n return (\n <>\n <Autocomplete\n disablePortal\n disableCloseOnSelect={allowMultiple}\n multiple={allowMultiple}\n fullWidth\n limitTags={3}\n size=\"small\"\n disableClearable\n slots={{ popper: StyledPopper }}\n renderInput={(params) => {\n return allowMultiple ? (\n <TextField {...params} label={title} onChange={(e) => setInputValue(e.target.value)} />\n ) : (\n <TextField {...params} label={title} style={{ width: `${inputWidth}px` }} />\n );\n }}\n sx={{\n '& .MuiInputBase-root': {\n minHeight: '38px',\n },\n '& .MuiAutocomplete-tag': {\n margin: '1px 2px', // Default margin of 2px (Y axis) make min height of the autocomplete 40px\n },\n }}\n value={selectedOptions}\n onChange={(_, value) => {\n if ((value === null || (Array.isArray(value) && value.length === 0)) && allowAllValue) {\n setVariableValue(name, DEFAULT_ALL_VALUE, source);\n } else {\n setVariableValue(name, variableOptionToVariableValue(value), source);\n }\n }}\n inputValue={allowMultiple ? inputValue : undefined}\n onInputChange={(_, newInputValue) => {\n if (!allowMultiple) {\n setInputWidth(getWidthPx(newInputValue, 'list'));\n }\n }}\n onBlur={() => {\n if (allowMultiple) {\n setInputValue('');\n }\n }}\n options={viewOptions}\n />\n {loading && <LinearProgress />}\n </>\n );\n}\n\nfunction TextVariable({ name, source }: VariableProps): ReactElement {\n const ctx = useVariableDefinitionAndState(name, source);\n const state = ctx.state;\n const definition = ctx.definition as TextVariableDefinition;\n const [tempValue, setTempValue] = useState(state?.value ?? '');\n const [inputWidth, setInputWidth] = useState(getWidthPx(tempValue as string, 'text'));\n const { setVariableValue } = useVariableDefinitionActions();\n\n useEffect(() => {\n setTempValue(state?.value ?? '');\n }, [state?.value]);\n\n return (\n <TextField\n title={tempValue as string}\n value={tempValue}\n onChange={(e) => {\n setTempValue(e.target.value);\n setInputWidth(getWidthPx(e.target.value, 'text'));\n }}\n onBlur={() => setVariableValue(name, tempValue, source)}\n placeholder={name}\n label={definition?.spec.display?.name ?? name}\n slotProps={{\n input: {\n readOnly: definition?.spec.constant ?? false,\n },\n }}\n sx={{\n width: `${inputWidth}px`,\n '& .MuiInputBase-root': {\n minHeight: '38px',\n },\n '& .MuiInputBase-input': {\n textOverflow: 'ellipsis',\n },\n }}\n />\n );\n}\n"],"names":["useEffect","useMemo","useState","LinearProgress","TextField","Autocomplete","Popper","DEFAULT_ALL_VALUE","useListVariablePluginValues","useVariableDefinitionAndState","useVariableDefinitionActions","MAX_VARIABLE_WIDTH","MIN_VARIABLE_WIDTH","variableOptionToVariableValue","options","Array","isArray","map","v","value","Variable","name","source","ctx","kind","definition","TextVariable","ListVariable","div","useListVariableState","spec","state","variablesOptionsQuery","allowMultiple","allowAllValue","sort","loading","isFetching","data","sortedOptions","opts","a","b","label","parseInt","toLowerCase","viewOptions","computedOptions","valueIsInOptions","Boolean","find","includes","firstOptionValue","length","selectedOptions","filter","o","StyledPopper","props","sx","minWidth","placement","LETTER_HSIZE","ARROW_OFFSET","getWidthPx","inputValue","width","setVariableValue","setVariableLoading","setVariableOptions","inputWidth","setInputWidth","setInputValue","title","display","disablePortal","disableCloseOnSelect","multiple","fullWidth","limitTags","size","disableClearable","slots","popper","renderInput","params","onChange","e","target","style","minHeight","margin","_","undefined","onInputChange","newInputValue","onBlur","tempValue","setTempValue","placeholder","slotProps","input","readOnly","constant","textOverflow"],"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,SAAuBA,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACnE,SAASC,cAAc,EAAEC,SAAS,EAAEC,YAAY,EAAE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UAAU;IACjC,MAAM,CAACwE,WAAWC,aAAa,GAAGhG,SAAS6B,OAAOZ,SAAS;IAC3D,MAAM,CAACmD,YAAYC,cAAc,GAAGrE,SAAS8D,WAAWiC,WAAqB;IAC7E,MAAM,EAAE9B,gBAAgB,EAAE,GAAGzD;IAE7BV,UAAU;QACRkG,aAAanE,OAAOZ,SAAS;IAC/B,GAAG;QAACY,OAAOZ;KAAM;IAEjB,qBACE,KAACf;QACCqE,OAAOwB;QACP9E,OAAO8E;QACPX,UAAU,CAACC;YACTW,aAAaX,EAAEC,MAAM,CAACrE,KAAK;YAC3BoD,cAAcP,WAAWuB,EAAEC,MAAM,CAACrE,KAAK,EAAE;QAC3C;QACA6E,QAAQ,IAAM7B,iBAAiB9C,MAAM4E,WAAW3E;QAChD6E,aAAa9E;QACbsB,OAAOlB,YAAYK,KAAK4C,SAASrD,QAAQA;QACzC+E,WAAW;YACTC,OAAO;gBACLC,UAAU7E,YAAYK,KAAKyE,YAAY;YACzC;QACF;QACA5C,IAAI;YACFO,OAAO,GAAGI,WAAW,EAAE,CAAC;YACxB,wBAAwB;gBACtBoB,WAAW;YACb;YACA,yBAAyB;gBACvBc,cAAc;YAChB;QACF;;AAGN"}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Variables/Variable.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 { ReactElement, useCallback, useEffect, useMemo, useState } from 'react';\nimport { TextField, Popper, PopperProps, Checkbox, Autocomplete, createFilterOptions, Chip, Box } from '@mui/material';\nimport {\n DEFAULT_ALL_VALUE,\n ListVariableDefinition,\n ListVariableSpec,\n TextVariableDefinition,\n VariableName,\n VariableValue,\n} from '@perses-dev/core';\nimport {\n SORT_METHODS,\n SortMethodName,\n useListVariablePluginValues,\n VariableOption,\n VariableState,\n} from '@perses-dev/plugin-system';\nimport { UseQueryResult } from '@tanstack/react-query';\nimport { useVariableDefinitionAndState, useVariableDefinitionActions } from '../../context';\nimport { MAX_VARIABLE_WIDTH, MIN_VARIABLE_WIDTH } from '../../constants';\nimport { ListVariableListBoxProvider, ListVariableListBox } from './ListVariableListBox';\n\ntype VariableProps = {\n name: VariableName;\n source?: string;\n};\n\nfunction variableOptionToVariableValue(options: VariableOption | VariableOption[] | null): VariableValue {\n if (options === null) {\n return null;\n }\n if (Array.isArray(options)) {\n return options.map((v) => {\n return v.value;\n });\n }\n return options.value;\n}\n\nexport function Variable({ name, source }: VariableProps): ReactElement {\n const ctx = useVariableDefinitionAndState(name, source);\n const kind = ctx.definition?.kind;\n switch (kind) {\n case 'TextVariable':\n return <TextVariable name={name} source={source} />;\n case 'ListVariable':\n return <ListVariable name={name} source={source} />;\n }\n\n return <div>Unsupported Variable Kind: ${kind}</div>;\n}\n\nexport function useListVariableState(\n spec: ListVariableSpec | undefined,\n state: VariableState | undefined,\n variablesOptionsQuery: Partial<UseQueryResult<VariableOption[]>>\n): {\n // Value, Loading, Options are modified only when we want to save the changes made\n value: VariableValue | undefined;\n loading: boolean;\n options: VariableOption[] | undefined;\n // selectedOptions is/are the option(s) selected in the view\n selectedOptions: VariableOption | VariableOption[];\n // viewOptions are the options used in the view only (= options + All if allowed)\n viewOptions: VariableOption[];\n} {\n const allowMultiple = spec?.allowMultiple === true;\n const allowAllValue = spec?.allowAllValue === true;\n const sort = spec?.sort;\n const loading = useMemo(() => variablesOptionsQuery.isFetching ?? false, [variablesOptionsQuery.isFetching]);\n const options = useMemo(() => variablesOptionsQuery.data ?? [], [variablesOptionsQuery.data]);\n\n let value = state?.value;\n\n // Make sure value is an array if allowMultiple is true\n if (allowMultiple && !Array.isArray(value)) {\n value = typeof value === 'string' ? [value] : [];\n }\n\n // Sort the provided list of options according to the method defined\n const sortedOptions = useMemo((): VariableOption[] => {\n const opts = options ? [...options] : [];\n\n if (!sort || sort === 'none') return opts;\n const sortMethod = SORT_METHODS[sort as SortMethodName];\n return !sortMethod ? opts : sortMethod.sort(opts);\n }, [options, sort]);\n\n const viewOptions = useMemo(() => {\n let computedOptions = sortedOptions;\n\n // Add the all value if it's allowed\n if (allowAllValue) {\n computedOptions = [{ value: DEFAULT_ALL_VALUE, label: 'All' }, ...computedOptions];\n }\n return computedOptions;\n }, [allowAllValue, sortedOptions]);\n\n const valueIsInOptions = useMemo(\n () =>\n Boolean(\n viewOptions.find((v) => {\n if (allowMultiple) {\n return (value as string[]).includes(v.value);\n }\n return value === v.value;\n })\n ),\n [viewOptions, value, allowMultiple]\n );\n\n value = useMemo(() => {\n const firstOptionValue = viewOptions?.[allowAllValue ? 1 : 0]?.value;\n\n // If there is no value but there are options, or the value is not in options, we set the value to the first option.\n if (firstOptionValue) {\n if (!valueIsInOptions || !value || value.length === 0) {\n return allowMultiple ? [firstOptionValue] : firstOptionValue;\n }\n }\n\n return value;\n }, [viewOptions, value, valueIsInOptions, allowMultiple, allowAllValue]);\n\n const selectedOptions = useMemo(() => {\n // In the case Autocomplete.multiple equals false, Autocomplete.value expects a single object, not\n // an array, hence this conditional\n if (Array.isArray(value)) {\n return viewOptions.filter((o) => {\n return value?.includes(o.value);\n });\n } else {\n return (\n viewOptions.find((o) => {\n return value === o.value;\n }) ?? { value: '', label: '' }\n );\n }\n }, [value, viewOptions]);\n\n return { value, loading, options, selectedOptions, viewOptions };\n}\n\nconst StyledPopper = (props: PopperProps): ReactElement => (\n <Popper {...props} sx={{ minWidth: 'fit-content' }} placement=\"bottom-start\" />\n);\n\nconst LETTER_HSIZE = 8; // approximation\nconst ARROW_OFFSET = 40; // right offset for list variables (= take into account the dropdown toggle size)\nconst getWidthPx = (inputValue: string, kind: 'list' | 'text'): number => {\n const width = (inputValue.length + 1) * LETTER_HSIZE + (kind === 'list' ? ARROW_OFFSET : 0);\n if (width < MIN_VARIABLE_WIDTH) {\n return MIN_VARIABLE_WIDTH;\n } else if (width > MAX_VARIABLE_WIDTH) {\n return MAX_VARIABLE_WIDTH;\n } else {\n return width;\n }\n};\n\nfunction ListVariable({ name, source }: VariableProps): ReactElement {\n const ctx = useVariableDefinitionAndState(name, source);\n const definition = ctx.definition as ListVariableDefinition;\n const variablesOptionsQuery = useListVariablePluginValues(definition);\n const { setVariableValue, setVariableLoading, setVariableOptions } = useVariableDefinitionActions();\n const { selectedOptions, value, loading, options, viewOptions } = useListVariableState(\n definition?.spec,\n ctx.state,\n variablesOptionsQuery\n );\n const [inputWidth, setInputWidth] = useState(MIN_VARIABLE_WIDTH);\n // Used for multiple value variables, it will not clear variable input when selecting an option\n const [inputValue, setInputValue] = useState('');\n\n const title = definition?.spec.display?.name ?? name;\n const allowMultiple = definition?.spec.allowMultiple === true;\n const allowAllValue = definition?.spec.allowAllValue === true;\n\n const filterOptions = createFilterOptions<VariableOption>({});\n\n const filteredOptions = useMemo(\n () => filterOptions(viewOptions, { inputValue, getOptionLabel: (o) => o.label }),\n [inputValue, viewOptions, filterOptions]\n );\n\n // Update value when changed\n useEffect(() => {\n if (value) {\n setVariableValue(name, value, source);\n }\n }, [setVariableValue, name, value, source]);\n\n // Update loading when changed\n useEffect(() => {\n setVariableLoading(name, loading, source);\n }, [setVariableLoading, name, loading, source]);\n\n // Update options when changed\n useEffect(() => {\n if (options) {\n setVariableOptions(name, options, source);\n }\n }, [setVariableOptions, name, options, source]);\n\n const handleGlobalSelect = useCallback(\n (options: VariableOption[]): void => {\n setVariableValue(name, variableOptionToVariableValue(options), source);\n },\n [name, setVariableValue, source]\n );\n\n const listBoxProviderValue = useMemo(\n () => ({\n options: viewOptions,\n selectedOptions: selectedOptions as VariableOption[], // Only used when allowMultiple is true => selectedOptions is always an array\n filteredOptions: filteredOptions,\n allowAllValue,\n onChange: handleGlobalSelect,\n }),\n [allowAllValue, filteredOptions, handleGlobalSelect, selectedOptions, viewOptions]\n );\n\n const autocompleteComponent = useMemo(() => {\n return (\n <Autocomplete\n disablePortal\n loading={loading}\n disableCloseOnSelect={allowMultiple}\n multiple={allowMultiple}\n fullWidth\n limitTags={3}\n size=\"small\"\n disableClearable\n slotProps={{ listbox: { component: allowMultiple ? ListVariableListBox : undefined } }}\n slots={{ popper: StyledPopper }}\n sx={{\n '& .MuiInputBase-root': {\n minHeight: '38px',\n },\n '& .MuiAutocomplete-tag': {\n margin: '1px 2px', // Default margin of 2px (Y axis) make min height of the autocomplete 40px\n },\n }}\n filterOptions={filterOptions}\n options={viewOptions}\n value={selectedOptions}\n onChange={(_, value) => {\n if ((value === null || (Array.isArray(value) && value.length === 0)) && allowAllValue) {\n setVariableValue(name, DEFAULT_ALL_VALUE, source);\n } else {\n setVariableValue(name, variableOptionToVariableValue(value as VariableOption), source);\n }\n }}\n inputValue={allowMultiple ? inputValue : undefined}\n onInputChange={(_, newInputValue) => {\n if (!allowMultiple) {\n setInputWidth(getWidthPx(newInputValue, 'list'));\n }\n }}\n onBlur={() => {\n if (allowMultiple) {\n setInputValue('');\n }\n }}\n renderInput={(params) => {\n return allowMultiple ? (\n <TextField {...params} label={title} onChange={(e) => setInputValue(e.target.value)} />\n ) : (\n <TextField {...params} label={title} style={{ width: `${inputWidth}px` }} />\n );\n }}\n renderOption={(props, option, { selected }) => {\n const { key, ...optionProps } = props;\n return (\n <li key={key} {...optionProps} style={{ padding: 0 }}>\n <Checkbox style={{ marginRight: 8 }} checked={selected} />\n {option.label}\n </li>\n );\n }}\n renderTags={(value, getTagProps, ownerState) => {\n // When focused, if there are too much value selected, it will use all screen place. Putting limit to 200px (~6 lines of chips)\n if (ownerState.focused) {\n return (\n <Box sx={{ maxHeight: 200, overflowY: 'auto' }}>\n {value.map((option, index) => (\n <Chip {...getTagProps({ index })} key={index} label={option.label} size=\"small\" />\n ))}\n </Box>\n );\n }\n\n const limitTags: number | undefined = ownerState.limitTags;\n const numTags: number = value.length;\n\n return (\n <>\n {value.slice(0, limitTags).map((option, index) => (\n <Chip {...getTagProps({ index })} key={index} label={option.label} size=\"small\" />\n ))}\n\n {limitTags && numTags > limitTags && ` +${numTags - limitTags}`}\n </>\n );\n }}\n />\n );\n }, [\n allowAllValue,\n allowMultiple,\n filterOptions,\n inputValue,\n inputWidth,\n loading,\n name,\n selectedOptions,\n setVariableValue,\n source,\n title,\n viewOptions,\n ]);\n\n if (allowMultiple) {\n return (\n <ListVariableListBoxProvider value={listBoxProviderValue}>{autocompleteComponent}</ListVariableListBoxProvider>\n );\n }\n\n return autocompleteComponent;\n}\n\nfunction TextVariable({ name, source }: VariableProps): ReactElement {\n const ctx = useVariableDefinitionAndState(name, source);\n const state = ctx.state;\n const definition = ctx.definition as TextVariableDefinition;\n const [tempValue, setTempValue] = useState(state?.value ?? '');\n const [inputWidth, setInputWidth] = useState(getWidthPx(tempValue as string, 'text'));\n const { setVariableValue } = useVariableDefinitionActions();\n\n useEffect(() => {\n setTempValue(state?.value ?? '');\n }, [state?.value]);\n\n return (\n <TextField\n title={tempValue as string}\n value={tempValue}\n onChange={(e) => {\n setTempValue(e.target.value);\n setInputWidth(getWidthPx(e.target.value, 'text'));\n }}\n onBlur={() => setVariableValue(name, tempValue, source)}\n placeholder={name}\n label={definition?.spec.display?.name ?? name}\n slotProps={{\n input: {\n readOnly: definition?.spec.constant ?? false,\n },\n }}\n sx={{\n width: `${inputWidth}px`,\n '& .MuiInputBase-root': {\n minHeight: '38px',\n },\n '& .MuiInputBase-input': {\n textOverflow: 'ellipsis',\n },\n }}\n />\n );\n}\n"],"names":["useCallback","useEffect","useMemo","useState","TextField","Popper","Checkbox","Autocomplete","createFilterOptions","Chip","Box","DEFAULT_ALL_VALUE","SORT_METHODS","useListVariablePluginValues","useVariableDefinitionAndState","useVariableDefinitionActions","MAX_VARIABLE_WIDTH","MIN_VARIABLE_WIDTH","ListVariableListBoxProvider","ListVariableListBox","variableOptionToVariableValue","options","Array","isArray","map","v","value","Variable","name","source","ctx","kind","definition","TextVariable","ListVariable","div","useListVariableState","spec","state","variablesOptionsQuery","allowMultiple","allowAllValue","sort","loading","isFetching","data","sortedOptions","opts","sortMethod","viewOptions","computedOptions","label","valueIsInOptions","Boolean","find","includes","firstOptionValue","length","selectedOptions","filter","o","StyledPopper","props","sx","minWidth","placement","LETTER_HSIZE","ARROW_OFFSET","getWidthPx","inputValue","width","setVariableValue","setVariableLoading","setVariableOptions","inputWidth","setInputWidth","setInputValue","title","display","filterOptions","filteredOptions","getOptionLabel","handleGlobalSelect","listBoxProviderValue","onChange","autocompleteComponent","disablePortal","disableCloseOnSelect","multiple","fullWidth","limitTags","size","disableClearable","slotProps","listbox","component","undefined","slots","popper","minHeight","margin","_","onInputChange","newInputValue","onBlur","renderInput","params","e","target","style","renderOption","option","selected","key","optionProps","li","padding","marginRight","checked","renderTags","getTagProps","ownerState","focused","maxHeight","overflowY","index","numTags","slice","tempValue","setTempValue","placeholder","input","readOnly","constant","textOverflow"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;AAEjC,SAAuBA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAChF,SAASC,SAAS,EAAEC,MAAM,EAAeC,QAAQ,EAAEC,YAAY,EAAEC,mBAAmB,EAAEC,IAAI,EAAEC,GAAG,QAAQ,gBAAgB;AACvH,SACEC,iBAAiB,QAMZ,mBAAmB;AAC1B,SACEC,YAAY,EAEZC,2BAA2B,QAGtB,4BAA4B;AAEnC,SAASC,6BAA6B,EAAEC,4BAA4B,QAAQ,gBAAgB;AAC5F,SAASC,kBAAkB,EAAEC,kBAAkB,QAAQ,kBAAkB;AACzE,SAASC,2BAA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,aAAatB,EAAEC,MAAM,CAAClF,KAAK;YAC3BiD,cAAcP,WAAWuC,EAAEC,MAAM,CAAClF,KAAK,EAAE;QAC3C;QACA8E,QAAQ,IAAMjC,iBAAiB3C,MAAMoG,WAAWnG;QAChDqG,aAAatG;QACbuB,OAAOnB,YAAYK,KAAKyC,SAASlD,QAAQA;QACzCiE,WAAW;YACTsC,OAAO;gBACLC,UAAUpG,YAAYK,KAAKgG,YAAY;YACzC;QACF;QACAtE,IAAI;YACFO,OAAO,GAAGI,WAAW,EAAE,CAAC;YACxB,wBAAwB;gBACtByB,WAAW;YACb;YACA,yBAAyB;gBACvBmC,cAAc;YAChB;QACF;;AAGN"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import { BuiltinVariableDefinition, VariableDefinition } from '@perses-dev/core';
|
|
2
|
+
import { BuiltinVariableDefinition, VariableDefinition, ExternalVariableDefinition } from '@perses-dev/core';
|
|
3
3
|
import { VariableState } from '@perses-dev/plugin-system';
|
|
4
|
-
import { ExternalVariableDefinition } from '../../context';
|
|
5
4
|
export declare function VariableEditor(props: {
|
|
6
5
|
variableDefinitions: VariableDefinition[];
|
|
7
6
|
externalVariableDefinitions: ExternalVariableDefinition[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VariableEditor.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/VariableEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAqB,YAAY,EAAE,MAAM,OAAO,CAAC;AAuBxD,OAAO,
|
|
1
|
+
{"version":3,"file":"VariableEditor.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/VariableEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAqB,YAAY,EAAE,MAAM,OAAO,CAAC;AAuBxD,OAAO,EAEL,yBAAyB,EAEzB,kBAAkB,EAClB,0BAA0B,EAC3B,MAAM,kBAAkB,CAAC;AAU1B,OAAO,EAGL,aAAa,EAId,MAAM,2BAA2B,CAAC;AAyBnC,wBAAgB,cAAc,CAAC,KAAK,EAAE;IACpC,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C,2BAA2B,EAAE,0BAA0B,EAAE,CAAC;IAC1D,0BAA0B,EAAE,yBAAyB,EAAE,CAAC;IACxD,QAAQ,EAAE,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,KAAK,IAAI,CAAC;IAC9D,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,GAAG,YAAY,CA4Uf;AAMD,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,aAAa,GAAG,SAAS,CAAA;CAAE,GAAG,YAAY,CAoBpG"}
|