@perses-dev/plugin-system 0.52.0-rc.1 → 0.53.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/{DatasourceSelect.js → DatasourceSelect/DatasourceSelect.js} +4 -3
- package/dist/cjs/components/DatasourceSelect/index.js +30 -0
- package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +73 -73
- package/dist/cjs/components/PluginEditor/PluginEditor.js +9 -10
- package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +6 -3
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +25 -34
- package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +33 -19
- package/dist/cjs/components/Variables/VariableEditorForm/index.js +1 -0
- package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +47 -0
- package/dist/cjs/components/Variables/variable-model.js +3 -3
- package/dist/cjs/components/index.js +0 -1
- package/dist/cjs/context/index.js +0 -1
- package/dist/cjs/remote/remotePluginLoader.js +19 -4
- package/dist/cjs/runtime/TimeRangeProvider/query-params.js +27 -27
- package/dist/cjs/runtime/UsageMetricsProvider.js +4 -3
- package/dist/cjs/runtime/time-series-queries.js +4 -4
- package/dist/cjs/test/mock-data.js +158 -0
- package/dist/components/{DatasourceSelect.d.ts → DatasourceSelect/DatasourceSelect.d.ts} +1 -1
- package/dist/components/DatasourceSelect/DatasourceSelect.d.ts.map +1 -0
- package/dist/components/{DatasourceSelect.js → DatasourceSelect/DatasourceSelect.js} +4 -3
- package/dist/components/DatasourceSelect/DatasourceSelect.js.map +1 -0
- package/dist/components/DatasourceSelect/index.d.ts +2 -0
- package/dist/components/DatasourceSelect/index.d.ts.map +1 -0
- package/dist/components/DatasourceSelect/index.js +15 -0
- package/dist/components/DatasourceSelect/index.js.map +1 -0
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +75 -75
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.js +9 -10
- package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.js +7 -4
- package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +25 -34
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +2 -0
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js +33 -19
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/index.d.ts +1 -0
- package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/index.js +1 -0
- package/dist/components/Variables/VariableEditorForm/index.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +6 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +44 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
- package/dist/components/Variables/variable-model.js +3 -3
- package/dist/components/Variables/variable-model.js.map +1 -1
- package/dist/components/index.d.ts +0 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +0 -1
- package/dist/components/index.js.map +1 -1
- package/dist/context/index.d.ts +0 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +0 -1
- package/dist/context/index.js.map +1 -1
- package/dist/model/time-series-queries.d.ts +1 -1
- package/dist/model/time-series-queries.d.ts.map +1 -1
- package/dist/model/time-series-queries.js.map +1 -1
- package/dist/model/variables.d.ts +1 -1
- package/dist/model/variables.d.ts.map +1 -1
- package/dist/model/variables.js.map +1 -1
- package/dist/remote/remotePluginLoader.d.ts +18 -1
- package/dist/remote/remotePluginLoader.d.ts.map +1 -1
- package/dist/remote/remotePluginLoader.js +22 -4
- package/dist/remote/remotePluginLoader.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/query-params.d.ts +12 -7
- package/dist/runtime/TimeRangeProvider/query-params.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/query-params.js +23 -20
- package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -1
- package/dist/runtime/UsageMetricsProvider.d.ts +3 -1
- package/dist/runtime/UsageMetricsProvider.d.ts.map +1 -1
- package/dist/runtime/UsageMetricsProvider.js +4 -3
- package/dist/runtime/UsageMetricsProvider.js.map +1 -1
- package/dist/runtime/time-series-queries.d.ts.map +1 -1
- package/dist/runtime/time-series-queries.js +4 -4
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/dist/test/mock-data.d.ts +134 -0
- package/dist/test/mock-data.d.ts.map +1 -1
- package/dist/test/mock-data.js +135 -0
- package/dist/test/mock-data.js.map +1 -1
- package/package.json +5 -5
- package/dist/cjs/components/ProjectSelect.js +0 -96
- package/dist/cjs/context/ProjectStoreProvider.js +0 -81
- package/dist/cjs/context/query-params.js +0 -49
- package/dist/components/DatasourceSelect.d.ts.map +0 -1
- package/dist/components/DatasourceSelect.js.map +0 -1
- package/dist/components/ProjectSelect.d.ts +0 -15
- package/dist/components/ProjectSelect.d.ts.map +0 -1
- package/dist/components/ProjectSelect.js +0 -91
- package/dist/components/ProjectSelect.js.map +0 -1
- package/dist/context/ProjectStoreProvider.d.ts +0 -16
- package/dist/context/ProjectStoreProvider.d.ts.map +0 -1
- package/dist/context/ProjectStoreProvider.js +0 -59
- package/dist/context/ProjectStoreProvider.js.map +0 -1
- package/dist/context/query-params.d.ts +0 -5
- package/dist/context/query-params.d.ts.map +0 -1
- package/dist/context/query-params.js +0 -41
- package/dist/context/query-params.js.map +0 -1
|
@@ -10,8 +10,8 @@
|
|
|
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 { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
-
import { Switch } from '@mui/material';
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
+
import { Switch, ToggleButtonGroup, ToggleButton } from '@mui/material';
|
|
15
15
|
import { DEFAULT_LEGEND, getLegendMode, getLegendPosition, getLegendSize } from '@perses-dev/core';
|
|
16
16
|
import { ErrorAlert, OptionsEditorControl, OptionsEditorGroup, SettingsAutocomplete } from '@perses-dev/components';
|
|
17
17
|
import { useMemo } from 'react';
|
|
@@ -22,12 +22,6 @@ const POSITION_OPTIONS = Object.entries(LEGEND_POSITIONS_CONFIG).map(([id, confi
|
|
|
22
22
|
...config
|
|
23
23
|
};
|
|
24
24
|
});
|
|
25
|
-
const MODE_OPTIONS = Object.entries(LEGEND_MODE_CONFIG).map(([id, config])=>{
|
|
26
|
-
return {
|
|
27
|
-
id: id,
|
|
28
|
-
...config
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
25
|
const SIZE_OPTIONS = Object.entries(LEGEND_SIZE_CONFIG).map(([id, config])=>{
|
|
32
26
|
return {
|
|
33
27
|
id: id,
|
|
@@ -48,13 +42,6 @@ export function LegendOptionsEditor({ value, onChange, showValuesEditor = true,
|
|
|
48
42
|
position: newValue.id
|
|
49
43
|
});
|
|
50
44
|
};
|
|
51
|
-
const handleLegendModeChange = (_, newValue)=>{
|
|
52
|
-
onChange({
|
|
53
|
-
...value,
|
|
54
|
-
position: currentPosition,
|
|
55
|
-
mode: newValue.id
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
45
|
const handleLegendSizeChange = (_, newValue)=>{
|
|
59
46
|
onChange({
|
|
60
47
|
...value,
|
|
@@ -75,7 +62,6 @@ export function LegendOptionsEditor({ value, onChange, showValuesEditor = true,
|
|
|
75
62
|
const currentPosition = getLegendPosition(value?.position);
|
|
76
63
|
const legendPositionConfig = LEGEND_POSITIONS_CONFIG[currentPosition];
|
|
77
64
|
const currentMode = getLegendMode(value?.mode);
|
|
78
|
-
const legendModeConfig = LEGEND_MODE_CONFIG[currentMode];
|
|
79
65
|
const currentSize = getLegendSize(value?.size);
|
|
80
66
|
const legendSizeConfig = LEGEND_SIZE_CONFIG[currentSize];
|
|
81
67
|
const legendValuesConfig = useMemo(()=>{
|
|
@@ -137,65 +123,79 @@ export function LegendOptionsEditor({ value, onChange, showValuesEditor = true,
|
|
|
137
123
|
onChange: handleLegendShowChange
|
|
138
124
|
})
|
|
139
125
|
}),
|
|
140
|
-
/*#__PURE__*/
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
126
|
+
value && /*#__PURE__*/ _jsxs(_Fragment, {
|
|
127
|
+
children: [
|
|
128
|
+
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
129
|
+
label: "Position",
|
|
130
|
+
control: /*#__PURE__*/ _jsx(SettingsAutocomplete, {
|
|
131
|
+
value: {
|
|
132
|
+
...legendPositionConfig,
|
|
133
|
+
id: currentPosition
|
|
134
|
+
},
|
|
135
|
+
options: POSITION_OPTIONS,
|
|
136
|
+
onChange: handleLegendPositionChange,
|
|
137
|
+
disableClearable: true
|
|
138
|
+
})
|
|
139
|
+
}),
|
|
140
|
+
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
141
|
+
label: "Mode",
|
|
142
|
+
control: /*#__PURE__*/ _jsx(ToggleButtonGroup, {
|
|
143
|
+
color: "primary",
|
|
144
|
+
exclusive: true,
|
|
145
|
+
value: currentMode,
|
|
146
|
+
"aria-label": "Mode",
|
|
147
|
+
onChange: (__, newValue)=>{
|
|
148
|
+
onChange({
|
|
149
|
+
...value,
|
|
150
|
+
position: currentPosition,
|
|
151
|
+
mode: newValue
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
children: Object.entries(LEGEND_MODE_CONFIG).map(([modeId, config])=>/*#__PURE__*/ _jsx(ToggleButton, {
|
|
155
|
+
value: modeId,
|
|
156
|
+
selected: currentMode === modeId,
|
|
157
|
+
"aria-label": `display ${modeId} mode`,
|
|
158
|
+
children: config.label
|
|
159
|
+
}, modeId))
|
|
160
|
+
})
|
|
161
|
+
}),
|
|
162
|
+
currentMode === 'table' && /*#__PURE__*/ _jsxs(_Fragment, {
|
|
163
|
+
children: [
|
|
164
|
+
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
165
|
+
label: "Size",
|
|
166
|
+
control: /*#__PURE__*/ _jsx(SettingsAutocomplete, {
|
|
167
|
+
value: {
|
|
168
|
+
...legendSizeConfig,
|
|
169
|
+
id: currentSize
|
|
170
|
+
},
|
|
171
|
+
options: SIZE_OPTIONS,
|
|
172
|
+
onChange: handleLegendSizeChange,
|
|
173
|
+
// TODO: enable sizes for list mode when we normalize the layout of
|
|
174
|
+
// lists to more closely match tables.
|
|
175
|
+
disableClearable: true
|
|
176
|
+
})
|
|
177
|
+
}),
|
|
178
|
+
showValuesEditor && /*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
179
|
+
label: "Values",
|
|
180
|
+
control: // For some reason, the inferred option type doesn't always seem to work
|
|
181
|
+
// quite right when `multiple` is true. Explicitly setting the generics
|
|
182
|
+
// to work around this.
|
|
183
|
+
/*#__PURE__*/ _jsx(SettingsAutocomplete, {
|
|
184
|
+
multiple: true,
|
|
185
|
+
disableCloseOnSelect: true,
|
|
186
|
+
disableClearable: true,
|
|
187
|
+
value: legendValuesConfig,
|
|
188
|
+
options: valueOptions,
|
|
189
|
+
onChange: handleLegendValueChange,
|
|
190
|
+
limitTags: 1,
|
|
191
|
+
ChipProps: {
|
|
192
|
+
size: 'small'
|
|
193
|
+
}
|
|
194
|
+
})
|
|
195
|
+
})
|
|
196
|
+
]
|
|
197
|
+
})
|
|
198
|
+
]
|
|
199
199
|
})
|
|
200
200
|
]
|
|
201
201
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/LegendOptionsEditor/LegendOptionsEditor.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 { Switch, SwitchProps } from '@mui/material';\nimport { DEFAULT_LEGEND, getLegendMode, getLegendPosition, getLegendSize } from '@perses-dev/core';\nimport { ErrorAlert, OptionsEditorControl, OptionsEditorGroup, SettingsAutocomplete } from '@perses-dev/components';\nimport { ReactElement, useMemo } from 'react';\nimport {\n LEGEND_MODE_CONFIG,\n LEGEND_POSITIONS_CONFIG,\n LegendSpecOptions,\n LegendSingleSelectConfig,\n validateLegendSpec,\n LEGEND_VALUE_CONFIG,\n LegendValue,\n LEGEND_SIZE_CONFIG,\n comparisonLegends,\n ComparisonValues,\n} from '../../model';\n\ntype LegendPositionOption = LegendSingleSelectConfig & { id: LegendSpecOptions['position'] };\n\nconst POSITION_OPTIONS: LegendPositionOption[] = Object.entries(LEGEND_POSITIONS_CONFIG).map(([id, config]) => {\n return {\n id: id as LegendSpecOptions['position'],\n ...config,\n };\n});\n\ntype LegendModeOption = LegendSingleSelectConfig & { id: Required<LegendSpecOptions>['mode'] };\n\nconst MODE_OPTIONS: LegendModeOption[] = Object.entries(LEGEND_MODE_CONFIG).map(([id, config]) => {\n return {\n id: id as Required<LegendSpecOptions>['mode'],\n ...config,\n };\n});\n\ntype LegendSizeOption = LegendSingleSelectConfig & { id: Required<LegendSpecOptions>['size'] };\n\nconst SIZE_OPTIONS: LegendSizeOption[] = Object.entries(LEGEND_SIZE_CONFIG).map(([id, config]) => {\n return {\n id: id as Required<LegendSpecOptions>['size'],\n ...config,\n };\n});\n\ntype LegendValueOption = LegendSingleSelectConfig & { id: LegendValue | ComparisonValues };\n\nexport interface LegendOptionsEditorProps {\n value?: LegendSpecOptions;\n onChange: (legend?: LegendSpecOptions) => void;\n showValuesEditor?: boolean;\n calculation?: 'aggregation' | 'comparison';\n}\n\nexport function LegendOptionsEditor({\n value,\n onChange,\n showValuesEditor = true,\n calculation = 'aggregation',\n}: LegendOptionsEditorProps): ReactElement {\n const handleLegendShowChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n // legend is hidden when legend obj is undefined\n const legendValue = checked === true ? { position: DEFAULT_LEGEND.position } : undefined;\n onChange(legendValue);\n };\n\n const handleLegendPositionChange = (_: unknown, newValue: LegendPositionOption): void => {\n onChange({\n ...value,\n position: newValue.id,\n });\n };\n\n const handleLegendModeChange = (_: unknown, newValue: LegendModeOption): void => {\n onChange({\n ...value,\n position: currentPosition,\n mode: newValue.id,\n });\n };\n\n const handleLegendSizeChange = (_: unknown, newValue: LegendSizeOption): void => {\n onChange({\n ...value,\n position: currentPosition,\n size: newValue.id,\n });\n };\n\n const handleLegendValueChange = (_: unknown, newValue: LegendValueOption[]): void => {\n onChange({\n ...value,\n position: currentPosition,\n values: newValue.map((value) => {\n return value.id;\n }),\n });\n };\n\n const isValidLegend = validateLegendSpec(value);\n const currentPosition = getLegendPosition(value?.position);\n const legendPositionConfig = LEGEND_POSITIONS_CONFIG[currentPosition];\n\n const currentMode = getLegendMode(value?.mode);\n const legendModeConfig = LEGEND_MODE_CONFIG[currentMode];\n\n const currentSize = getLegendSize(value?.size);\n const legendSizeConfig = LEGEND_SIZE_CONFIG[currentSize];\n\n const legendValuesConfig = useMemo(() => {\n const currentValues = value?.values;\n if (!currentValues?.length) return [];\n\n if (calculation === 'aggregation') {\n return currentValues.reduce((result, item) => {\n const config = LEGEND_VALUE_CONFIG[item as LegendValue];\n if (config) {\n result.push({ ...config, id: item });\n }\n return result;\n }, [] as LegendValueOption[]);\n }\n\n return currentValues.map((id) => {\n const { label, description } = comparisonLegends[id as ComparisonValues];\n return {\n id,\n label,\n description,\n };\n });\n }, [calculation, value?.values]);\n\n const valueOptions = useMemo(() => {\n if (calculation === 'aggregation') {\n return Object.entries(LEGEND_VALUE_CONFIG || {}).map(([id, config]) => {\n return {\n id: id as LegendValue,\n ...config,\n };\n });\n }\n\n return Object.entries(comparisonLegends).map(([id, config]) => ({\n id: id as ComparisonValues,\n ...config,\n }));\n }, [calculation]);\n\n return (\n <OptionsEditorGroup title=\"Legend\">\n {!isValidLegend && <ErrorAlert error={{ name: 'invalid-legend', message: 'Invalid legend spec' }} />}\n <OptionsEditorControl label=\"Show\" control={<Switch checked={!!value} onChange={handleLegendShowChange} />} />\n <OptionsEditorControl\n label=\"Position\"\n control={\n <SettingsAutocomplete\n value={{\n ...legendPositionConfig,\n id: currentPosition,\n }}\n options={POSITION_OPTIONS}\n onChange={handleLegendPositionChange}\n disabled={value === undefined}\n disableClearable\n ></SettingsAutocomplete>\n }\n />\n <OptionsEditorControl\n label=\"Mode\"\n control={\n <SettingsAutocomplete\n value={{\n ...legendModeConfig,\n id: currentMode,\n }}\n options={MODE_OPTIONS}\n onChange={handleLegendModeChange}\n disabled={!value}\n disableClearable\n ></SettingsAutocomplete>\n }\n />\n <OptionsEditorControl\n label=\"Size\"\n control={\n <SettingsAutocomplete\n value={{\n ...legendSizeConfig,\n id: currentSize,\n }}\n options={SIZE_OPTIONS}\n onChange={handleLegendSizeChange}\n // TODO: enable sizes for list mode when we normalize the layout of\n // lists to more closely match tables.\n disabled={!value || currentMode !== 'table'}\n disableClearable\n ></SettingsAutocomplete>\n }\n />\n {showValuesEditor && (\n <OptionsEditorControl\n label=\"Values\"\n control={\n // For some reason, the inferred option type doesn't always seem to work\n // quite right when `multiple` is true. Explicitly setting the generics\n // to work around this.\n <SettingsAutocomplete<LegendValueOption, true, true>\n multiple={true}\n disableCloseOnSelect\n disableClearable\n value={legendValuesConfig}\n options={valueOptions}\n onChange={handleLegendValueChange}\n disabled={!value || currentMode !== 'table'}\n limitTags={1}\n ChipProps={{\n size: 'small',\n }}\n />\n }\n />\n )}\n </OptionsEditorGroup>\n );\n}\n"],"names":["Switch","DEFAULT_LEGEND","getLegendMode","getLegendPosition","getLegendSize","ErrorAlert","OptionsEditorControl","OptionsEditorGroup","SettingsAutocomplete","useMemo","LEGEND_MODE_CONFIG","LEGEND_POSITIONS_CONFIG","validateLegendSpec","LEGEND_VALUE_CONFIG","LEGEND_SIZE_CONFIG","comparisonLegends","POSITION_OPTIONS","Object","entries","map","id","config","MODE_OPTIONS","SIZE_OPTIONS","LegendOptionsEditor","value","onChange","showValuesEditor","calculation","handleLegendShowChange","_","checked","legendValue","position","undefined","handleLegendPositionChange","newValue","handleLegendModeChange","currentPosition","mode","handleLegendSizeChange","size","handleLegendValueChange","values","isValidLegend","legendPositionConfig","currentMode","legendModeConfig","currentSize","legendSizeConfig","legendValuesConfig","currentValues","length","reduce","result","item","push","label","description","valueOptions","title","error","name","message","control","options","disabled","disableClearable","multiple","disableCloseOnSelect","limitTags","ChipProps"],"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,MAAM,QAAqB,gBAAgB;AACpD,SAASC,cAAc,EAAEC,aAAa,EAAEC,iBAAiB,EAAEC,aAAa,QAAQ,mBAAmB;AACnG,SAASC,UAAU,EAAEC,oBAAoB,EAAEC,kBAAkB,EAAEC,oBAAoB,QAAQ,yBAAyB;AACpH,SAAuBC,OAAO,QAAQ,QAAQ;AAC9C,SACEC,kBAAkB,EAClBC,uBAAuB,EAGvBC,kBAAkB,EAClBC,mBAAmB,EAEnBC,kBAAkB,EAClBC,iBAAiB,QAEZ,cAAc;AAIrB,MAAMC,mBAA2CC,OAAOC,OAAO,CAACP,yBAAyBQ,GAAG,CAAC,CAAC,CAACC,IAAIC,OAAO;IACxG,OAAO;QACLD,IAAIA;QACJ,GAAGC,MAAM;IACX;AACF;AAIA,MAAMC,eAAmCL,OAAOC,OAAO,CAACR,oBAAoBS,GAAG,CAAC,CAAC,CAACC,IAAIC,OAAO;IAC3F,OAAO;QACLD,IAAIA;QACJ,GAAGC,MAAM;IACX;AACF;AAIA,MAAME,eAAmCN,OAAOC,OAAO,CAACJ,oBAAoBK,GAAG,CAAC,CAAC,CAACC,IAAIC,OAAO;IAC3F,OAAO;QACLD,IAAIA;QACJ,GAAGC,MAAM;IACX;AACF;AAWA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ACL,GAAGsB,gBAAgB;wBACnB3B,IAAI0B;oBACN;oBACAmB,SAAS3C;oBACTI,UAAUW;oBACV6B,UAAU,CAACzC;oBACX0C,gBAAgB;;;0BAItB,KAAC7D;gBACCmD,OAAM;gBACNO,uBACE,KAACxD;oBACCiB,OAAO;wBACL,GAAGwB,gBAAgB;wBACnB7B,IAAI4B;oBACN;oBACAiB,SAAS1C;oBACTG,UAAUc;oBACV,mEAAmE;oBACnE,sCAAsC;oBACtC0B,UAAU,CAACzC,SAASqB,gBAAgB;oBACpCqB,gBAAgB;;;YAIrBxC,kCACC,KAACrB;gBACCmD,OAAM;gBACNO,SACE,wEAAwE;gBACxE,uEAAuE;gBACvE,uBAAuB;8BACvB,KAACxD;oBACC4D,UAAU;oBACVC,oBAAoB;oBACpBF,gBAAgB;oBAChB1C,OAAOyB;oBACPe,SAASN;oBACTjC,UAAUgB;oBACVwB,UAAU,CAACzC,SAASqB,gBAAgB;oBACpCwB,WAAW;oBACXC,WAAW;wBACT9B,MAAM;oBACR;;;;;AAOd"}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/LegendOptionsEditor/LegendOptionsEditor.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 { Switch, SwitchProps, ToggleButtonGroup, ToggleButton } from '@mui/material';\nimport { DEFAULT_LEGEND, getLegendMode, getLegendPosition, getLegendSize } from '@perses-dev/core';\nimport { ErrorAlert, OptionsEditorControl, OptionsEditorGroup, SettingsAutocomplete } from '@perses-dev/components';\nimport { ReactElement, useMemo } from 'react';\nimport {\n LEGEND_MODE_CONFIG,\n LEGEND_POSITIONS_CONFIG,\n LegendSpecOptions,\n LegendSingleSelectConfig,\n validateLegendSpec,\n LEGEND_VALUE_CONFIG,\n LegendValue,\n LEGEND_SIZE_CONFIG,\n comparisonLegends,\n ComparisonValues,\n} from '../../model';\n\ntype LegendPositionOption = LegendSingleSelectConfig & { id: LegendSpecOptions['position'] };\n\nconst POSITION_OPTIONS: LegendPositionOption[] = Object.entries(LEGEND_POSITIONS_CONFIG).map(([id, config]) => {\n return {\n id: id as LegendSpecOptions['position'],\n ...config,\n };\n});\n\ntype LegendSizeOption = LegendSingleSelectConfig & { id: Required<LegendSpecOptions>['size'] };\n\nconst SIZE_OPTIONS: LegendSizeOption[] = Object.entries(LEGEND_SIZE_CONFIG).map(([id, config]) => {\n return {\n id: id as Required<LegendSpecOptions>['size'],\n ...config,\n };\n});\n\ntype LegendValueOption = LegendSingleSelectConfig & { id: LegendValue | ComparisonValues };\n\nexport interface LegendOptionsEditorProps {\n value?: LegendSpecOptions;\n onChange: (legend?: LegendSpecOptions) => void;\n showValuesEditor?: boolean;\n calculation?: 'aggregation' | 'comparison';\n}\n\nexport function LegendOptionsEditor({\n value,\n onChange,\n showValuesEditor = true,\n calculation = 'aggregation',\n}: LegendOptionsEditorProps): ReactElement {\n const handleLegendShowChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n // legend is hidden when legend obj is undefined\n const legendValue = checked === true ? { position: DEFAULT_LEGEND.position } : undefined;\n onChange(legendValue);\n };\n\n const handleLegendPositionChange = (_: unknown, newValue: LegendPositionOption): void => {\n onChange({\n ...value,\n position: newValue.id,\n });\n };\n\n const handleLegendSizeChange = (_: unknown, newValue: LegendSizeOption): void => {\n onChange({\n ...value,\n position: currentPosition,\n size: newValue.id,\n });\n };\n\n const handleLegendValueChange = (_: unknown, newValue: LegendValueOption[]): void => {\n onChange({\n ...value,\n position: currentPosition,\n values: newValue.map((value) => {\n return value.id;\n }),\n });\n };\n\n const isValidLegend = validateLegendSpec(value);\n const currentPosition = getLegendPosition(value?.position);\n const legendPositionConfig = LEGEND_POSITIONS_CONFIG[currentPosition];\n\n const currentMode = getLegendMode(value?.mode);\n\n const currentSize = getLegendSize(value?.size);\n const legendSizeConfig = LEGEND_SIZE_CONFIG[currentSize];\n\n const legendValuesConfig = useMemo(() => {\n const currentValues = value?.values;\n if (!currentValues?.length) return [];\n\n if (calculation === 'aggregation') {\n return currentValues.reduce((result, item) => {\n const config = LEGEND_VALUE_CONFIG[item as LegendValue];\n if (config) {\n result.push({ ...config, id: item });\n }\n return result;\n }, [] as LegendValueOption[]);\n }\n\n return currentValues.map((id) => {\n const { label, description } = comparisonLegends[id as ComparisonValues];\n return {\n id,\n label,\n description,\n };\n });\n }, [calculation, value?.values]);\n\n const valueOptions = useMemo(() => {\n if (calculation === 'aggregation') {\n return Object.entries(LEGEND_VALUE_CONFIG || {}).map(([id, config]) => {\n return {\n id: id as LegendValue,\n ...config,\n };\n });\n }\n\n return Object.entries(comparisonLegends).map(([id, config]) => ({\n id: id as ComparisonValues,\n ...config,\n }));\n }, [calculation]);\n\n return (\n <OptionsEditorGroup title=\"Legend\">\n {!isValidLegend && <ErrorAlert error={{ name: 'invalid-legend', message: 'Invalid legend spec' }} />}\n <OptionsEditorControl label=\"Show\" control={<Switch checked={!!value} onChange={handleLegendShowChange} />} />\n {value && (\n <>\n <OptionsEditorControl\n label=\"Position\"\n control={\n <SettingsAutocomplete\n value={{\n ...legendPositionConfig,\n id: currentPosition,\n }}\n options={POSITION_OPTIONS}\n onChange={handleLegendPositionChange}\n disableClearable\n />\n }\n />\n <OptionsEditorControl\n label=\"Mode\"\n control={\n <ToggleButtonGroup\n color=\"primary\"\n exclusive\n value={currentMode}\n aria-label=\"Mode\"\n onChange={(__, newValue) => {\n onChange({\n ...value,\n position: currentPosition,\n mode: newValue,\n });\n }}\n >\n {Object.entries(LEGEND_MODE_CONFIG).map(([modeId, config]) => (\n <ToggleButton\n key={modeId}\n value={modeId}\n selected={currentMode === modeId}\n aria-label={`display ${modeId} mode`}\n >\n {config.label}\n </ToggleButton>\n ))}\n </ToggleButtonGroup>\n }\n />\n {currentMode === 'table' && (\n <>\n <OptionsEditorControl\n label=\"Size\"\n control={\n <SettingsAutocomplete\n value={{\n ...legendSizeConfig,\n id: currentSize,\n }}\n options={SIZE_OPTIONS}\n onChange={handleLegendSizeChange}\n // TODO: enable sizes for list mode when we normalize the layout of\n // lists to more closely match tables.\n disableClearable\n />\n }\n />\n {showValuesEditor && (\n <OptionsEditorControl\n label=\"Values\"\n control={\n // For some reason, the inferred option type doesn't always seem to work\n // quite right when `multiple` is true. Explicitly setting the generics\n // to work around this.\n <SettingsAutocomplete<LegendValueOption, true, true>\n multiple={true}\n disableCloseOnSelect\n disableClearable\n value={legendValuesConfig}\n options={valueOptions}\n onChange={handleLegendValueChange}\n limitTags={1}\n ChipProps={{\n size: 'small',\n }}\n />\n }\n />\n )}\n </>\n )}\n </>\n )}\n </OptionsEditorGroup>\n );\n}\n"],"names":["Switch","ToggleButtonGroup","ToggleButton","DEFAULT_LEGEND","getLegendMode","getLegendPosition","getLegendSize","ErrorAlert","OptionsEditorControl","OptionsEditorGroup","SettingsAutocomplete","useMemo","LEGEND_MODE_CONFIG","LEGEND_POSITIONS_CONFIG","validateLegendSpec","LEGEND_VALUE_CONFIG","LEGEND_SIZE_CONFIG","comparisonLegends","POSITION_OPTIONS","Object","entries","map","id","config","SIZE_OPTIONS","LegendOptionsEditor","value","onChange","showValuesEditor","calculation","handleLegendShowChange","_","checked","legendValue","position","undefined","handleLegendPositionChange","newValue","handleLegendSizeChange","currentPosition","size","handleLegendValueChange","values","isValidLegend","legendPositionConfig","currentMode","mode","currentSize","legendSizeConfig","legendValuesConfig","currentValues","length","reduce","result","item","push","label","description","valueOptions","title","error","name","message","control","options","disableClearable","color","exclusive","aria-label","__","modeId","selected","multiple","disableCloseOnSelect","limitTags","ChipProps"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AA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gCACNO,SACE,wEAAwE;gCACxE,uEAAuE;gCACvE,uBAAuB;8CACvB,KAACrD;oCACC8D,UAAU;oCACVC,oBAAoB;oCACpBR,gBAAgB;oCAChBvC,OAAOuB;oCACPe,SAASN;oCACT/B,UAAUc;oCACViC,WAAW;oCACXC,WAAW;wCACTnC,MAAM;oCACR;;;;;;;;;AAWtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"names":[],"mappings":";AAoBA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAmB,MAAM,qBAAqB,CAAC;AAE1F;;;;;;;GAOG;AAEH,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"PluginEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"names":[],"mappings":";AAoBA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAmB,MAAM,qBAAqB,CAAC;AAE1F;;;;;;;GAOG;AAEH,eAAO,MAAM,YAAY,4HAwFvB,CAAC"}
|
|
@@ -72,13 +72,16 @@ import { usePluginEditor } from './plugin-editor-api';
|
|
|
72
72
|
/*#__PURE__*/ _jsxs(Box, {
|
|
73
73
|
sx: {
|
|
74
74
|
display: 'flex',
|
|
75
|
-
flexDirection: 'row'
|
|
75
|
+
flexDirection: 'row',
|
|
76
|
+
alignItems: 'center',
|
|
77
|
+
justifyContent: 'space-between',
|
|
78
|
+
gap: 1,
|
|
79
|
+
mb: 1
|
|
76
80
|
},
|
|
77
81
|
children: [
|
|
78
82
|
/*#__PURE__*/ _jsx(PluginKindSelect, {
|
|
79
83
|
fullWidth: false,
|
|
80
84
|
sx: {
|
|
81
|
-
mb: 2,
|
|
82
85
|
minWidth: 120
|
|
83
86
|
},
|
|
84
87
|
margin: "dense",
|
|
@@ -86,8 +89,10 @@ import { usePluginEditor } from './plugin-editor-api';
|
|
|
86
89
|
pluginTypes: pluginTypes,
|
|
87
90
|
disabled: isLoading,
|
|
88
91
|
value: pendingSelection ? pendingSelection : value.selection,
|
|
89
|
-
|
|
90
|
-
|
|
92
|
+
slotProps: {
|
|
93
|
+
input: {
|
|
94
|
+
readOnly: isReadonly
|
|
95
|
+
}
|
|
91
96
|
},
|
|
92
97
|
error: !!error,
|
|
93
98
|
helperText: error?.message,
|
|
@@ -96,12 +101,6 @@ import { usePluginEditor } from './plugin-editor-api';
|
|
|
96
101
|
withRunQueryButton && !isLoading && /*#__PURE__*/ _jsx(Button, {
|
|
97
102
|
"data-testid": "run_query_button",
|
|
98
103
|
variant: "contained",
|
|
99
|
-
sx: {
|
|
100
|
-
marginTop: 1.5,
|
|
101
|
-
marginBottom: 1.5,
|
|
102
|
-
paddingTop: 0.5,
|
|
103
|
-
marginLeft: 'auto'
|
|
104
|
-
},
|
|
105
104
|
startIcon: /*#__PURE__*/ _jsx(Reload, {}),
|
|
106
105
|
onClick: runQueryHandler,
|
|
107
106
|
children: "Run Query"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PluginEditor/PluginEditor.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 { Box, Button } from '@mui/material';\nimport Reload from 'mdi-material-ui/Reload';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { forwardRef, ReactElement, useCallback, useImperativeHandle, useMemo, useState } from 'react';\nimport { UnknownSpec } from '@perses-dev/core';\nimport { PluginKindSelect } from '../PluginKindSelect';\nimport { PluginSpecEditor } from '../PluginSpecEditor';\nimport { PluginEditorProps, PluginEditorRef, usePluginEditor } from './plugin-editor-api';\n\n/**\n * A combination `PluginKindSelect` and `PluginSpecEditor` component. This is meant for editing the `plugin` property\n * that's common in our JSON specs where a user selects a plugin `kind` and then edits the `spec` via that plugin's\n * editor component. It takes care of transitioning from one plugin kind to another \"all at once\" so that when the\n * plugin's kind changes, the spec is also changed at the same time so those options editor components don't see a\n * previous plugin's spec state. If you just want this behavior, but in a different UI layout from this, try the\n * `usePluginEditor` hook that powers this component.\n */\n\nexport const PluginEditor = forwardRef<PluginEditorRef, PluginEditorProps>((props, ref): ReactElement => {\n const {\n value,\n withRunQueryButton = true,\n pluginTypes,\n pluginKindLabel,\n onChange: _,\n isReadonly,\n postExecuteRunQuery: refresh,\n ...others\n } = props;\n const { pendingSelection, isLoading, error, onSelectionChange, onSpecChange } = usePluginEditor(props);\n\n /* \n We could technically merge the watchedQuery, watchedOtherSpecs into a single watched-object,\n because at the end of the day, they are all specs.\n However, let's have them separated to keep the code simple and readable.\n Reason: Only Query string field is common between all of them. Other specs may be different\n Example: Legend, and MinSteps\n */\n const [watchedQuery, setWatchQuery] = useState<string>(value.spec['query'] as string);\n const [watchedOtherSpecs, setWatchOtherSpecs] = useState<UnknownSpec>(value.spec);\n\n const runQueryHandler = useCallback((): void => {\n onSpecChange({ ...value.spec, ...watchedOtherSpecs, query: watchedQuery });\n refresh?.();\n }, [value.spec, onSpecChange, watchedQuery, watchedOtherSpecs, refresh]);\n\n const queryHandlerSettings = useMemo(() => {\n return withRunQueryButton\n ? {\n runWithOnBlur: false,\n watchQueryChanges: (query: string): void => {\n setWatchQuery(query);\n },\n setWatchOtherSpecs: (otherSpecs: UnknownSpec): void => {\n setWatchOtherSpecs(otherSpecs);\n },\n }\n : undefined;\n }, [withRunQueryButton]);\n\n useImperativeHandle(ref, () => ({ flushChanges: runQueryHandler }));\n\n return (\n <Box {...others}>\n <Box
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PluginEditor/PluginEditor.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 { Box, Button } from '@mui/material';\nimport Reload from 'mdi-material-ui/Reload';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { forwardRef, ReactElement, useCallback, useImperativeHandle, useMemo, useState } from 'react';\nimport { UnknownSpec } from '@perses-dev/core';\nimport { PluginKindSelect } from '../PluginKindSelect';\nimport { PluginSpecEditor } from '../PluginSpecEditor';\nimport { PluginEditorProps, PluginEditorRef, usePluginEditor } from './plugin-editor-api';\n\n/**\n * A combination `PluginKindSelect` and `PluginSpecEditor` component. This is meant for editing the `plugin` property\n * that's common in our JSON specs where a user selects a plugin `kind` and then edits the `spec` via that plugin's\n * editor component. It takes care of transitioning from one plugin kind to another \"all at once\" so that when the\n * plugin's kind changes, the spec is also changed at the same time so those options editor components don't see a\n * previous plugin's spec state. If you just want this behavior, but in a different UI layout from this, try the\n * `usePluginEditor` hook that powers this component.\n */\n\nexport const PluginEditor = forwardRef<PluginEditorRef, PluginEditorProps>((props, ref): ReactElement => {\n const {\n value,\n withRunQueryButton = true,\n pluginTypes,\n pluginKindLabel,\n onChange: _,\n isReadonly,\n postExecuteRunQuery: refresh,\n ...others\n } = props;\n const { pendingSelection, isLoading, error, onSelectionChange, onSpecChange } = usePluginEditor(props);\n\n /* \n We could technically merge the watchedQuery, watchedOtherSpecs into a single watched-object,\n because at the end of the day, they are all specs.\n However, let's have them separated to keep the code simple and readable.\n Reason: Only Query string field is common between all of them. Other specs may be different\n Example: Legend, and MinSteps\n */\n const [watchedQuery, setWatchQuery] = useState<string>(value.spec['query'] as string);\n const [watchedOtherSpecs, setWatchOtherSpecs] = useState<UnknownSpec>(value.spec);\n\n const runQueryHandler = useCallback((): void => {\n onSpecChange({ ...value.spec, ...watchedOtherSpecs, query: watchedQuery });\n refresh?.();\n }, [value.spec, onSpecChange, watchedQuery, watchedOtherSpecs, refresh]);\n\n const queryHandlerSettings = useMemo(() => {\n return withRunQueryButton\n ? {\n runWithOnBlur: false,\n watchQueryChanges: (query: string): void => {\n setWatchQuery(query);\n },\n setWatchOtherSpecs: (otherSpecs: UnknownSpec): void => {\n setWatchOtherSpecs(otherSpecs);\n },\n }\n : undefined;\n }, [withRunQueryButton]);\n\n useImperativeHandle(ref, () => ({ flushChanges: runQueryHandler }));\n\n return (\n <Box {...others}>\n <Box\n sx={{\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: 1,\n mb: 1,\n }}\n >\n <PluginKindSelect\n fullWidth={false}\n sx={{ minWidth: 120 }}\n margin=\"dense\"\n label={pluginKindLabel}\n pluginTypes={pluginTypes}\n disabled={isLoading}\n value={pendingSelection ? pendingSelection : value.selection}\n slotProps={{ input: { readOnly: isReadonly } }}\n error={!!error}\n helperText={error?.message}\n onChange={onSelectionChange}\n />\n\n {withRunQueryButton && !isLoading && (\n <Button data-testid=\"run_query_button\" variant=\"contained\" startIcon={<Reload />} onClick={runQueryHandler}>\n Run Query\n </Button>\n )}\n </Box>\n\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <PluginSpecEditor\n pluginSelection={value.selection}\n value={value.spec}\n onChange={onSpecChange}\n isReadonly={isReadonly}\n queryHandlerSettings={queryHandlerSettings}\n />\n </ErrorBoundary>\n </Box>\n );\n});\n\nPluginEditor.displayName = 'PluginEditor';\n"],"names":["Box","Button","Reload","ErrorAlert","ErrorBoundary","forwardRef","useCallback","useImperativeHandle","useMemo","useState","PluginKindSelect","PluginSpecEditor","usePluginEditor","PluginEditor","props","ref","value","withRunQueryButton","pluginTypes","pluginKindLabel","onChange","_","isReadonly","postExecuteRunQuery","refresh","others","pendingSelection","isLoading","error","onSelectionChange","onSpecChange","watchedQuery","setWatchQuery","spec","watchedOtherSpecs","setWatchOtherSpecs","runQueryHandler","query","queryHandlerSettings","runWithOnBlur","watchQueryChanges","otherSpecs","undefined","flushChanges","sx","display","flexDirection","alignItems","justifyContent","gap","mb","fullWidth","minWidth","margin","label","disabled","selection","slotProps","input","readOnly","helperText","message","data-testid","variant","startIcon","onClick","FallbackComponent","pluginSelection","displayName"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,GAAG,EAAEC,MAAM,QAAQ,gBAAgB;AAC5C,OAAOC,YAAY,yBAAyB;AAC5C,SAASC,UAAU,EAAEC,aAAa,QAAQ,yBAAyB;AACnE,SAASC,UAAU,EAAgBC,WAAW,EAAEC,mBAAmB,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAEtG,SAASC,gBAAgB,QAAQ,sBAAsB;AACvD,SAASC,gBAAgB,QAAQ,sBAAsB;AACvD,SAA6CC,eAAe,QAAQ,sBAAsB;AAE1F;;;;;;;CAOC,GAED,OAAO,MAAMC,6BAAeR,WAA+C,CAACS,OAAOC;IACjF,MAAM,EACJC,KAAK,EACLC,qBAAqB,IAAI,EACzBC,WAAW,EACXC,eAAe,EACfC,UAAUC,CAAC,EACXC,UAAU,EACVC,qBAAqBC,OAAO,EAC5B,GAAGC,QACJ,GAAGX;IACJ,MAAM,EAAEY,gBAAgB,EAAEC,SAAS,EAAEC,KAAK,EAAEC,iBAAiB,EAAEC,YAAY,EAAE,GAAGlB,gBAAgBE;IAEhG;;;;;;IAME,GACF,MAAM,CAACiB,cAAcC,cAAc,GAAGvB,SAAiBO,MAAMiB,IAAI,CAAC,QAAQ;IAC1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AAUU;oBACVR,YAAYA;oBACZgB,sBAAsBA;;;;;AAKhC,GAAG;AAEHzB,aAAauD,WAAW,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginKindSelect.d.ts","sourceRoot":"","sources":["../../../src/components/PluginKindSelect/PluginKindSelect.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAuB,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,cAAc,EAAE,OAAO,GAAG,UAAU,GAAG,UAAU,CAAC;IACpG,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,qBAAqB,CAAC;IAC9B,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC;CAC/C;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"PluginKindSelect.d.ts","sourceRoot":"","sources":["../../../src/components/PluginKindSelect/PluginKindSelect.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAuB,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,cAAc,EAAE,OAAO,GAAG,UAAU,GAAG,UAAU,CAAC;IACpG,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,qBAAqB,CAAC;IAC9B,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC;CAC/C;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,wHAoD3B,CAAC"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { MenuItem, TextField } from '@mui/material';
|
|
15
|
-
import { forwardRef, useCallback } from 'react';
|
|
15
|
+
import { forwardRef, useCallback, useMemo } from 'react';
|
|
16
16
|
import { useListPluginMetadata } from '../../runtime';
|
|
17
17
|
/**
|
|
18
18
|
* Displays a MUI Select input for selecting a plugin's kind from a list of all the available plugins of some specific
|
|
@@ -23,6 +23,9 @@ import { useListPluginMetadata } from '../../runtime';
|
|
|
23
23
|
*/ export const PluginKindSelect = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
24
24
|
const { pluginTypes, value: propValue, onChange, ...others } = props;
|
|
25
25
|
const { data, isLoading } = useListPluginMetadata(pluginTypes);
|
|
26
|
+
const sortedData = useMemo(()=>data?.sort((a, b)=>a.spec.display.name.localeCompare(b.spec.display.name)), [
|
|
27
|
+
data
|
|
28
|
+
]);
|
|
26
29
|
// Pass an empty value while options are still loading so MUI doesn't complain about us using an "out of range" value
|
|
27
30
|
const value = !propValue || isLoading ? '' : selectionToOptionValue(propValue);
|
|
28
31
|
const handleChange = (event)=>{
|
|
@@ -33,9 +36,9 @@ import { useListPluginMetadata } from '../../runtime';
|
|
|
33
36
|
return '';
|
|
34
37
|
}
|
|
35
38
|
const selectedValue = optionValueToSelection(selected);
|
|
36
|
-
return
|
|
39
|
+
return sortedData?.find((v)=>v.kind === selectedValue.type && v.spec.name === selectedValue.kind)?.spec.display.name;
|
|
37
40
|
}, [
|
|
38
|
-
|
|
41
|
+
sortedData
|
|
39
42
|
]);
|
|
40
43
|
// TODO: Does this need a loading indicator of some kind?
|
|
41
44
|
return /*#__PURE__*/ _jsxs(TextField, {
|
|
@@ -54,7 +57,7 @@ import { useListPluginMetadata } from '../../runtime';
|
|
|
54
57
|
value: "",
|
|
55
58
|
children: "Loading..."
|
|
56
59
|
}),
|
|
57
|
-
|
|
60
|
+
sortedData?.map((metadata)=>/*#__PURE__*/ _jsx(MenuItem, {
|
|
58
61
|
"data-testid": "option",
|
|
59
62
|
value: selectionToOptionValue({
|
|
60
63
|
type: metadata.kind,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PluginKindSelect/PluginKindSelect.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 { MenuItem, TextField, TextFieldProps } from '@mui/material';\nimport { forwardRef, ReactElement, useCallback } from 'react';\nimport { PluginType } from '../../model';\nimport { useListPluginMetadata } from '../../runtime';\nimport { PluginEditorSelection } from '../PluginEditor';\n\nexport interface PluginKindSelectProps extends Omit<TextFieldProps, 'value' | 'onChange' | 'children'> {\n pluginTypes: PluginType[];\n value?: PluginEditorSelection;\n onChange?: (s: PluginEditorSelection) => void;\n}\n\n/**\n * Displays a MUI Select input for selecting a plugin's kind from a list of all the available plugins of some specific\n * plugin types. (e.g. \"Show a list of all the Panel plugins\", or \"Show a list of all the Variable plugins\", or \"Show\n * a list of all the TimeSeriesQuery, TraceQuery, ProfileQuery, and LogQuery plugins\").\n * The value of the select is the kind of the plugin, but you can also listen to the `onPluginTypeChange` event to know\n * when the user changes the plugin type (it fires at start for the default value.)\n */\nexport const PluginKindSelect = forwardRef((props: PluginKindSelectProps, ref): ReactElement => {\n const { pluginTypes, value: propValue, onChange, ...others } = props;\n const { data, isLoading } = useListPluginMetadata(pluginTypes);\n\n // Pass an empty value while options are still loading so MUI doesn't complain about us using an \"out of range\" value\n const value = !propValue || isLoading ? '' : selectionToOptionValue(propValue);\n\n const handleChange = (event: { target: { value: string } }): void => {\n onChange?.(optionValueToSelection(event.target.value));\n };\n\n const renderValue = useCallback(\n (selected: unknown) => {\n if (selected === '') {\n return '';\n }\n const selectedValue = optionValueToSelection(selected as string);\n return
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PluginKindSelect/PluginKindSelect.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 { MenuItem, TextField, TextFieldProps } from '@mui/material';\nimport { forwardRef, ReactElement, useCallback, useMemo } from 'react';\nimport { PluginType } from '../../model';\nimport { useListPluginMetadata } from '../../runtime';\nimport { PluginEditorSelection } from '../PluginEditor';\n\nexport interface PluginKindSelectProps extends Omit<TextFieldProps, 'value' | 'onChange' | 'children'> {\n pluginTypes: PluginType[];\n value?: PluginEditorSelection;\n onChange?: (s: PluginEditorSelection) => void;\n}\n\n/**\n * Displays a MUI Select input for selecting a plugin's kind from a list of all the available plugins of some specific\n * plugin types. (e.g. \"Show a list of all the Panel plugins\", or \"Show a list of all the Variable plugins\", or \"Show\n * a list of all the TimeSeriesQuery, TraceQuery, ProfileQuery, and LogQuery plugins\").\n * The value of the select is the kind of the plugin, but you can also listen to the `onPluginTypeChange` event to know\n * when the user changes the plugin type (it fires at start for the default value.)\n */\nexport const PluginKindSelect = forwardRef((props: PluginKindSelectProps, ref): ReactElement => {\n const { pluginTypes, value: propValue, onChange, ...others } = props;\n const { data, isLoading } = useListPluginMetadata(pluginTypes);\n\n const sortedData = useMemo(\n () => data?.sort((a, b) => a.spec.display.name.localeCompare(b.spec.display.name)),\n [data]\n );\n\n // Pass an empty value while options are still loading so MUI doesn't complain about us using an \"out of range\" value\n const value = !propValue || isLoading ? '' : selectionToOptionValue(propValue);\n\n const handleChange = (event: { target: { value: string } }): void => {\n onChange?.(optionValueToSelection(event.target.value));\n };\n\n const renderValue = useCallback(\n (selected: unknown) => {\n if (selected === '') {\n return '';\n }\n const selectedValue = optionValueToSelection(selected as string);\n return sortedData?.find((v) => v.kind === selectedValue.type && v.spec.name === selectedValue.kind)?.spec.display\n .name;\n },\n [sortedData]\n );\n\n // TODO: Does this need a loading indicator of some kind?\n return (\n <TextField\n select\n inputRef={ref}\n {...others}\n value={value}\n aria-label={value}\n onChange={handleChange}\n SelectProps={{ renderValue }}\n data-testid=\"plugin-kind-select\"\n >\n {isLoading && <MenuItem value=\"\">Loading...</MenuItem>}\n {sortedData?.map((metadata) => (\n <MenuItem\n data-testid=\"option\"\n key={metadata.kind + metadata.spec.name}\n value={selectionToOptionValue({ type: metadata.kind, kind: metadata.spec.name })}\n >\n {metadata.spec.display.name}\n </MenuItem>\n ))}\n </TextField>\n );\n});\nPluginKindSelect.displayName = 'PluginKindSelect';\n\n// Delimiter used to stringify/parse option values\nconst OPTION_VALUE_DELIMITER = '_____';\n\n/**\n * Given a PluginEditorSelection,\n * returns a string value like `{type}_____{kind}` that can be used as a Select input value.\n * @param selector\n */\nfunction selectionToOptionValue(selector: PluginEditorSelection): string {\n return [selector.type, selector.kind].join(OPTION_VALUE_DELIMITER);\n}\n\n/**\n * Given an option value name like `{type}_____{kind}`,\n * returns a PluginEditorSelection to be used by the query data model.\n * @param optionValue\n */\nfunction optionValueToSelection(optionValue: string): PluginEditorSelection {\n const words = optionValue.split(OPTION_VALUE_DELIMITER);\n const type = words[0] as PluginType | undefined;\n const kind = words[1];\n if (type === undefined || kind === undefined) {\n throw new Error('Invalid optionValue string');\n }\n return {\n type,\n kind,\n };\n}\n"],"names":["MenuItem","TextField","forwardRef","useCallback","useMemo","useListPluginMetadata","PluginKindSelect","props","ref","pluginTypes","value","propValue","onChange","others","data","isLoading","sortedData","sort","a","b","spec","display","name","localeCompare","selectionToOptionValue","handleChange","event","optionValueToSelection","target","renderValue","selected","selectedValue","find","v","kind","type","select","inputRef","aria-label","SelectProps","data-testid","map","metadata","displayName","OPTION_VALUE_DELIMITER","selector","join","optionValue","words","split","undefined","Error"],"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,QAAQ,EAAEC,SAAS,QAAwB,gBAAgB;AACpE,SAASC,UAAU,EAAgBC,WAAW,EAAEC,OAAO,QAAQ,QAAQ;AAEvE,SAASC,qBAAqB,QAAQ,gBAAgB;AAStD;;;;;;CAMC,GACD,OAAO,MAAMC,iCAAmBJ,WAAW,CAACK,OAA8BC;IACxE,MAAM,EAAEC,WAAW,EAAEC,OAAOC,SAAS,EAAEC,QAAQ,EAAE,GAAGC,QAAQ,GAAGN;IAC/D,MAAM,EAAEO,IAAI,EAAEC,SAAS,EAAE,GAAGV,sBAAsBI;IAElD,MAAMO,aAAaZ,QACjB,IAAMU,MAAMG,KAAK,CAACC,GAAGC,IAAMD,EAAEE,IAAI,CAACC,OAAO,CAACC,IAAI,CAACC,aAAa,CAACJ,EAAEC,IAAI,CAACC,OAAO,CAACC,IAAI,IAChF;QAACR;KAAK;IAGR,qHAAqH;IACrH,MAAMJ,QAAQ,CAACC,aAAaI,YAAY,KAAKS,uBAAuBb;IAEpE,MAAMc,eAAe,CAACC;QACpBd,WAAWe,uBAAuBD,MAAME,MAAM,CAAClB,KAAK;IACtD;IAEA,MAAMmB,cAAc1B,YAClB,CAAC2B;QACC,IAAIA,aAAa,IAAI;YACnB,OAAO;QACT;QACA,MAAMC,gBAAgBJ,uBAAuBG;QAC7C,OAAOd,YAAYgB,KAAK,CAACC,IAAMA,EAAEC,IAAI,KAAKH,cAAcI,IAAI,IAAIF,EAAEb,IAAI,CAACE,IAAI,KAAKS,cAAcG,IAAI,GAAGd,KAAKC,QACvGC;IACL,GACA;QAACN;KAAW;IAGd,yDAAyD;IACzD,qBACE,MAACf;QACCmC,MAAM;QACNC,UAAU7B;QACT,GAAGK,MAAM;QACVH,OAAOA;QACP4B,cAAY5B;QACZE,UAAUa;QACVc,aAAa;YAAEV;QAAY;QAC3BW,eAAY;;YAEXzB,2BAAa,KAACf;gBAASU,OAAM;0BAAG;;YAChCM,YAAYyB,IAAI,CAACC,yBAChB,KAAC1C;oBACCwC,eAAY;oBAEZ9B,OAAOc,uBAAuB;wBAAEW,MAAMO,SAASR,IAAI;wBAAEA,MAAMQ,SAAStB,IAAI,CAACE,IAAI;oBAAC;8BAE7EoB,SAAStB,IAAI,CAACC,OAAO,CAACC,IAAI;mBAHtBoB,SAASR,IAAI,GAAGQ,SAAStB,IAAI,CAACE,IAAI;;;AAQjD,GAAG;AACHhB,iBAAiBqC,WAAW,GAAG;AAE/B,kDAAkD;AAClD,MAAMC,yBAAyB;AAE/B;;;;CAIC,GACD,SAASpB,uBAAuBqB,QAA+B;IAC7D,OAAO;QAACA,SAASV,IAAI;QAAEU,SAASX,IAAI;KAAC,CAACY,IAAI,CAACF;AAC7C;AAEA;;;;CAIC,GACD,SAASjB,uBAAuBoB,WAAmB;IACjD,MAAMC,QAAQD,YAAYE,KAAK,CAACL;IAChC,MAAMT,OAAOa,KAAK,CAAC,EAAE;IACrB,MAAMd,OAAOc,KAAK,CAAC,EAAE;IACrB,IAAIb,SAASe,aAAahB,SAASgB,WAAW;QAC5C,MAAM,IAAIC,MAAM;IAClB;IACA,OAAO;QACLhB;QACAD;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VariableEditorForm.d.ts","sourceRoot":"","sources":["../../../../src/components/Variables/VariableEditorForm/VariableEditorForm.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAY,MAAM,OAAO,CAAC;AAEtE,OAAO,EAAE,kBAAkB,EAA0B,MAAM,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"VariableEditorForm.d.ts","sourceRoot":"","sources":["../../../../src/components/Variables/VariableEditorForm/VariableEditorForm.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAY,MAAM,OAAO,CAAC;AAEtE,OAAO,EAAE,kBAAkB,EAA0B,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAmUtF,UAAU,uBAAuB;IAC/B,yBAAyB,EAAE,kBAAkB,CAAC;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,MAAM,EAAE,CAAC,GAAG,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC1C,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,CAAC,EAAE,qBAAqB,CAAC;CAClC;AAED,wBAAgB,kBAAkB,CAAC,EACjC,yBAAyB,EACzB,MAAM,EACN,OAAO,EACP,UAAU,EACV,cAAc,EACd,MAAM,EACN,OAAO,EACP,QAAQ,GACT,EAAE,uBAAuB,GAAG,YAAY,CAoMxC"}
|
|
@@ -22,6 +22,7 @@ import { useValidationSchemas } from '../../../context';
|
|
|
22
22
|
import { VARIABLE_TYPES } from '../variable-model';
|
|
23
23
|
import { useTimeRange } from '../../../runtime';
|
|
24
24
|
import { VariableListPreview, VariablePreview } from './VariablePreview';
|
|
25
|
+
import { SORT_METHODS } from './variable-editor-form-model';
|
|
25
26
|
function FallbackPreview() {
|
|
26
27
|
return /*#__PURE__*/ _jsx("div", {
|
|
27
28
|
children: "Error previewing values"
|
|
@@ -107,6 +108,10 @@ function ListVariableEditorForm({ action, control }) {
|
|
|
107
108
|
control: control,
|
|
108
109
|
name: 'spec.allowAllValue'
|
|
109
110
|
});
|
|
111
|
+
const sortMethod = useWatch({
|
|
112
|
+
control: control,
|
|
113
|
+
name: 'spec.sort'
|
|
114
|
+
});
|
|
110
115
|
// When variable kind is selected we need to provide default values
|
|
111
116
|
// TODO: check if react-hook-form has a better way to do this
|
|
112
117
|
const values = form.getValues();
|
|
@@ -116,6 +121,15 @@ function ListVariableEditorForm({ action, control }) {
|
|
|
116
121
|
if (values.spec.allowMultiple === undefined) {
|
|
117
122
|
form.setValue('spec.allowMultiple', false);
|
|
118
123
|
}
|
|
124
|
+
if (!values.spec.plugin) {
|
|
125
|
+
form.setValue('spec.plugin', {
|
|
126
|
+
kind: 'StaticListVariable',
|
|
127
|
+
spec: {}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (!values.spec.sort) {
|
|
131
|
+
form.setValue('spec.sort', 'none');
|
|
132
|
+
}
|
|
119
133
|
const { refresh } = useTimeRange();
|
|
120
134
|
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
121
135
|
children: [
|
|
@@ -128,18 +142,17 @@ function ListVariableEditorForm({ action, control }) {
|
|
|
128
142
|
spacing: 2,
|
|
129
143
|
mb: 2,
|
|
130
144
|
children: [
|
|
131
|
-
|
|
145
|
+
/*#__PURE__*/ _jsx(Box, {
|
|
132
146
|
children: /*#__PURE__*/ _jsx(ErrorBoundary, {
|
|
133
147
|
FallbackComponent: FallbackPreview,
|
|
134
148
|
resetKeys: [
|
|
135
149
|
previewSpec
|
|
136
150
|
],
|
|
137
151
|
children: /*#__PURE__*/ _jsx(VariableListPreview, {
|
|
152
|
+
sortMethod: sortMethod,
|
|
138
153
|
definition: previewSpec
|
|
139
154
|
})
|
|
140
155
|
})
|
|
141
|
-
}) : /*#__PURE__*/ _jsx(VariablePreview, {
|
|
142
|
-
isLoading: true
|
|
143
156
|
}),
|
|
144
157
|
/*#__PURE__*/ _jsx(Stack, {
|
|
145
158
|
children: /*#__PURE__*/ _jsx(ErrorBoundary, {
|
|
@@ -205,7 +218,7 @@ function ListVariableEditorForm({ action, control }) {
|
|
|
205
218
|
children: /*#__PURE__*/ _jsx(Controller, {
|
|
206
219
|
control: control,
|
|
207
220
|
name: "spec.sort",
|
|
208
|
-
render: ({ field, fieldState })=>/*#__PURE__*/
|
|
221
|
+
render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(TextField, {
|
|
209
222
|
select: true,
|
|
210
223
|
...field,
|
|
211
224
|
fullWidth: true,
|
|
@@ -222,36 +235,14 @@ function ListVariableEditorForm({ action, control }) {
|
|
|
222
235
|
onChange: (event)=>{
|
|
223
236
|
field.onChange(event);
|
|
224
237
|
},
|
|
225
|
-
children:
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}),
|
|
234
|
-
/*#__PURE__*/ _jsx(MenuItem, {
|
|
235
|
-
value: "alphabetical-desc",
|
|
236
|
-
children: "Alphabetical, desc"
|
|
237
|
-
}),
|
|
238
|
-
/*#__PURE__*/ _jsx(MenuItem, {
|
|
239
|
-
value: "numerical-asc",
|
|
240
|
-
children: "Numerical, asc"
|
|
241
|
-
}),
|
|
242
|
-
/*#__PURE__*/ _jsx(MenuItem, {
|
|
243
|
-
value: "numerical-desc",
|
|
244
|
-
children: "Numerical, desc"
|
|
245
|
-
}),
|
|
246
|
-
/*#__PURE__*/ _jsx(MenuItem, {
|
|
247
|
-
value: "alphabetical-ci-asc",
|
|
248
|
-
children: "Alphabetical, case-insensitive, asc"
|
|
249
|
-
}),
|
|
250
|
-
/*#__PURE__*/ _jsx(MenuItem, {
|
|
251
|
-
value: "alphabetical-ci-desc",
|
|
252
|
-
children: "Alphabetical, case-insensitive, desc"
|
|
253
|
-
})
|
|
254
|
-
]
|
|
238
|
+
children: Object.keys(SORT_METHODS).map((key)=>{
|
|
239
|
+
if (!SORT_METHODS[key]) return null;
|
|
240
|
+
const { label } = SORT_METHODS[key];
|
|
241
|
+
return /*#__PURE__*/ _jsx(MenuItem, {
|
|
242
|
+
value: key,
|
|
243
|
+
children: label
|
|
244
|
+
}, key);
|
|
245
|
+
})
|
|
255
246
|
})
|
|
256
247
|
})
|
|
257
248
|
})
|