@perses-dev/plugin-system 0.52.0 → 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.
Files changed (85) hide show
  1. package/dist/cjs/components/{DatasourceSelect.js → DatasourceSelect/DatasourceSelect.js} +2 -2
  2. package/dist/cjs/components/DatasourceSelect/index.js +30 -0
  3. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +25 -34
  4. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +33 -19
  5. package/dist/cjs/components/Variables/VariableEditorForm/index.js +1 -0
  6. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +47 -0
  7. package/dist/cjs/components/Variables/variable-model.js +3 -3
  8. package/dist/cjs/components/index.js +0 -1
  9. package/dist/cjs/context/index.js +0 -1
  10. package/dist/cjs/remote/remotePluginLoader.js +19 -4
  11. package/dist/cjs/runtime/UsageMetricsProvider.js +4 -3
  12. package/dist/cjs/runtime/time-series-queries.js +4 -4
  13. package/dist/cjs/test/mock-data.js +158 -0
  14. package/dist/components/{DatasourceSelect.d.ts → DatasourceSelect/DatasourceSelect.d.ts} +1 -1
  15. package/dist/components/DatasourceSelect/DatasourceSelect.d.ts.map +1 -0
  16. package/dist/components/{DatasourceSelect.js → DatasourceSelect/DatasourceSelect.js} +2 -2
  17. package/dist/components/DatasourceSelect/DatasourceSelect.js.map +1 -0
  18. package/dist/components/DatasourceSelect/index.d.ts +2 -0
  19. package/dist/components/DatasourceSelect/index.d.ts.map +1 -0
  20. package/dist/components/DatasourceSelect/index.js +15 -0
  21. package/dist/components/DatasourceSelect/index.js.map +1 -0
  22. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  23. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +25 -34
  24. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  25. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +2 -0
  26. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -1
  27. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +33 -19
  28. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
  29. package/dist/components/Variables/VariableEditorForm/index.d.ts +1 -0
  30. package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -1
  31. package/dist/components/Variables/VariableEditorForm/index.js +1 -0
  32. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -1
  33. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +6 -0
  34. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
  35. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +44 -0
  36. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  37. package/dist/components/Variables/variable-model.js +3 -3
  38. package/dist/components/Variables/variable-model.js.map +1 -1
  39. package/dist/components/index.d.ts +0 -1
  40. package/dist/components/index.d.ts.map +1 -1
  41. package/dist/components/index.js +0 -1
  42. package/dist/components/index.js.map +1 -1
  43. package/dist/context/index.d.ts +0 -1
  44. package/dist/context/index.d.ts.map +1 -1
  45. package/dist/context/index.js +0 -1
  46. package/dist/context/index.js.map +1 -1
  47. package/dist/model/time-series-queries.d.ts +1 -1
  48. package/dist/model/time-series-queries.d.ts.map +1 -1
  49. package/dist/model/time-series-queries.js.map +1 -1
  50. package/dist/model/variables.d.ts +1 -1
  51. package/dist/model/variables.d.ts.map +1 -1
  52. package/dist/model/variables.js.map +1 -1
  53. package/dist/remote/remotePluginLoader.d.ts +18 -1
  54. package/dist/remote/remotePluginLoader.d.ts.map +1 -1
  55. package/dist/remote/remotePluginLoader.js +22 -4
  56. package/dist/remote/remotePluginLoader.js.map +1 -1
  57. package/dist/runtime/UsageMetricsProvider.d.ts +3 -1
  58. package/dist/runtime/UsageMetricsProvider.d.ts.map +1 -1
  59. package/dist/runtime/UsageMetricsProvider.js +4 -3
  60. package/dist/runtime/UsageMetricsProvider.js.map +1 -1
  61. package/dist/runtime/time-series-queries.d.ts.map +1 -1
  62. package/dist/runtime/time-series-queries.js +4 -4
  63. package/dist/runtime/time-series-queries.js.map +1 -1
  64. package/dist/test/mock-data.d.ts +134 -0
  65. package/dist/test/mock-data.d.ts.map +1 -1
  66. package/dist/test/mock-data.js +135 -0
  67. package/dist/test/mock-data.js.map +1 -1
  68. package/package.json +3 -3
  69. package/dist/cjs/components/ProjectSelect.js +0 -96
  70. package/dist/cjs/context/ProjectStoreProvider.js +0 -81
  71. package/dist/cjs/context/query-params.js +0 -49
  72. package/dist/components/DatasourceSelect.d.ts.map +0 -1
  73. package/dist/components/DatasourceSelect.js.map +0 -1
  74. package/dist/components/ProjectSelect.d.ts +0 -15
  75. package/dist/components/ProjectSelect.d.ts.map +0 -1
  76. package/dist/components/ProjectSelect.js +0 -91
  77. package/dist/components/ProjectSelect.js.map +0 -1
  78. package/dist/context/ProjectStoreProvider.d.ts +0 -16
  79. package/dist/context/ProjectStoreProvider.d.ts.map +0 -1
  80. package/dist/context/ProjectStoreProvider.js +0 -59
  81. package/dist/context/ProjectStoreProvider.js.map +0 -1
  82. package/dist/context/query-params.d.ts +0 -5
  83. package/dist/context/query-params.d.ts.map +0 -1
  84. package/dist/context/query-params.js +0 -41
  85. package/dist/context/query-params.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/DatasourceSelect/DatasourceSelect.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 OpenInNewIcon from 'mdi-material-ui/OpenInNew';\nimport {\n Stack,\n ListItemText,\n Chip,\n IconButton,\n Box,\n OutlinedSelectProps,\n BaseSelectProps,\n Autocomplete,\n TextField,\n} from '@mui/material';\nimport { DatasourceSelector, VariableName } from '@perses-dev/core';\nimport { ReactElement, useMemo } from 'react';\nimport {\n DatasourceSelectItem,\n DatasourceSelectItemGroup,\n DatasourceSelectItemSelector,\n useListDatasourceSelectItems,\n useVariableValues,\n VariableStateMap,\n} from '../../runtime';\nimport { parseVariables } from '../../utils';\n\nconst DATASOURCE_VARIABLE_VALUE_PREFIX = '__DATASOURCE_VARIABLE_VALUE__';\nconst VARIABLE_IDENTIFIER = '$';\n// Props on MUI Select that we don't want people to pass because we're either redefining them or providing them in\n// this component\ntype OmittedMuiProps = 'children' | 'value' | 'onChange';\n\ntype DataSourceOption = {\n groupEditLink?: string;\n groupLabel?: string;\n value: string;\n} & Omit<DatasourceSelectItem, 'selector'> &\n Omit<DatasourceSelectItem['selector'], 'kind'>;\n\nconst emptyDatasourceOption: DataSourceOption = { name: '', value: '' };\n\nexport type DatasourceSelectValue<T = DatasourceSelector> = T | VariableName;\n\nexport interface DatasourceSelectProps extends Omit<OutlinedSelectProps & BaseSelectProps<string>, OmittedMuiProps> {\n value: DatasourceSelectValue;\n onChange: (next: DatasourceSelectValue) => void;\n datasourcePluginKind: string;\n project?: string;\n}\n\n/**\n * Displays a MUI input for selecting a Datasource of a particular kind. Note: The 'value' and `onChange` handler for\n * the input deal with a `DatasourceSelector`.\n */\nexport function DatasourceSelect(props: DatasourceSelectProps): ReactElement {\n const { datasourcePluginKind, value, project, readOnly, onChange, ...others } = props;\n const { data, isLoading } = useListDatasourceSelectItems(datasourcePluginKind, project);\n const variables = useVariableValues();\n\n const defaultValue = useMemo<VariableName | DatasourceSelectItemSelector>(() => {\n if (isVariableDatasource(value)) {\n return value;\n }\n\n const group = (data ?? [])\n .flatMap((itemGroup) => itemGroup.items)\n .find((item) => {\n return value.kind === item.selector.kind && value.name === item.selector.name && !item.overridden;\n })?.selector.group;\n return { ...value, group };\n }, [value, data]);\n\n const options = useMemo<DataSourceOption[]>(() => {\n const datasourceOptions = (data || []).flatMap<DataSourceOption>((itemGroup) =>\n itemGroup.items.map<DataSourceOption>((item) => ({\n groupLabel: itemGroup.group,\n groupEditLink: itemGroup.editLink,\n name: item.name,\n overriding: item.overriding,\n overridden: item.overridden,\n saved: item.saved ?? true,\n group: item.selector.group,\n value: selectorToOptionValue(item.selector),\n }))\n );\n\n const datasourceOptionsMap = new Map(datasourceOptions.map((option) => [option.name, option]));\n\n const variableOptions = Object.entries(variables).flatMap<DataSourceOption>(([name, variable]) => {\n if (Array.isArray(variable.value)) return [];\n\n const associatedDatasource = datasourceOptionsMap.get(variable.value ?? '');\n if (!associatedDatasource) return [];\n\n return {\n groupLabel: 'Variables',\n name: `${VARIABLE_IDENTIFIER}${name}`,\n saved: true,\n value: `${DATASOURCE_VARIABLE_VALUE_PREFIX}${VARIABLE_IDENTIFIER}${name}`,\n };\n });\n\n return [...datasourceOptions, ...variableOptions];\n }, [data, variables]);\n\n // While loading available values, just use an empty datasource option so MUI select doesn't warn about values out of range\n const optionValue = isLoading\n ? emptyDatasourceOption\n : options.find((option) => option.value === selectorToOptionValue(defaultValue));\n\n // When the user makes a selection, convert the string option value back to a DatasourceSelector\n const handleChange = (selectedOption: DataSourceOption | null): void => {\n if (selectedOption) {\n const next = optionValueToSelector(selectedOption?.value || '');\n onChange(next);\n } else {\n onChange({ kind: datasourcePluginKind });\n }\n };\n\n // We use a fake action event when we click on the action of the chip (hijack the \"delete\" feature).\n // This is because the href link action is on the `deleteIcon` property already, but the `onDelete` property\n // controls its visibility.\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const fakeActionEvent = (): void => {};\n\n return (\n <Autocomplete<DataSourceOption>\n readOnly={readOnly}\n options={options}\n renderInput={(params) => <TextField {...params} label={others.label} placeholder=\"\" />}\n groupBy={(option) => option.groupLabel || 'No group'}\n getOptionLabel={(option) => {\n return option.name;\n }}\n onChange={(_, v) => handleChange(v)}\n value={optionValue}\n renderOption={(props, option) => {\n return (\n <li {...props} key={option.value}>\n <Stack direction=\"row\" alignItems=\"center\" justifyContent=\"space-between\" width=\"100%\">\n <ListItemText>\n <DatasourceName name={option.name} overridden={option.overridden} overriding={option.overriding} />\n </ListItemText>\n {!option.saved && <ListItemText>Save the dashboard to enable this datasource</ListItemText>}\n <ListItemText style={{ textAlign: 'right' }}>\n {option.groupLabel && option.groupLabel.length > 0 && (\n <Chip\n disabled={false}\n label={option.groupLabel}\n size=\"small\"\n onDelete={option.groupEditLink ? fakeActionEvent : undefined}\n deleteIcon={\n option.groupEditLink ? (\n <IconButton href={option.groupEditLink} target=\"_blank\">\n <OpenInNewIcon fontSize=\"small\" />\n </IconButton>\n ) : undefined\n }\n />\n )}\n </ListItemText>\n </Stack>\n </li>\n );\n }}\n />\n );\n}\n\nexport function DatasourceName(props: { name: string; overridden?: boolean; overriding?: boolean }): ReactElement {\n const { name, overridden, overriding } = props;\n return (\n <>\n {`${name} `}\n {!overridden && overriding && (\n <Box display=\"inline\" fontWeight=\"normal\" color={(theme) => theme.palette.primary.main}>\n (overriding)\n </Box>\n )}\n {overridden && '(overridden)'}\n </>\n );\n}\n\n// Delimiter used to stringify/parse option values\nconst OPTION_VALUE_DELIMITER = '_____';\n\n/**\n * Given a DatasourceSelectItemSelector,\n * returns a string value like `{kind}_____{group}_____{name}` that can be used as a Select input value.\n * @param selector\n */\nexport function selectorToOptionValue(selector: DatasourceSelectItemSelector | VariableName): string {\n if (isVariableDatasource(selector)) {\n return `${DATASOURCE_VARIABLE_VALUE_PREFIX}${selector}`;\n }\n return [selector.kind, selector.group ?? '', selector.name ?? ''].join(OPTION_VALUE_DELIMITER);\n}\n\n/**\n * Given an option value name like `{kind}_____{group}_____{name}`,\n * returns a DatasourceSelector to be used by the query data model.\n * @param optionValue\n */\nexport function optionValueToSelector(optionValue: string): DatasourceSelectValue {\n if (optionValue.startsWith(DATASOURCE_VARIABLE_VALUE_PREFIX)) {\n return optionValue.split(DATASOURCE_VARIABLE_VALUE_PREFIX)[1]!;\n }\n\n const words = optionValue.split(OPTION_VALUE_DELIMITER);\n const kind = words[0];\n const name = words[2];\n if (kind === undefined || name === undefined) {\n throw new Error('Invalid optionValue string');\n }\n return {\n kind,\n name: name === '' ? undefined : name,\n };\n}\n\nexport function isVariableDatasource(value: DatasourceSelectValue | undefined): value is VariableName {\n return typeof value === 'string' && value.startsWith(VARIABLE_IDENTIFIER);\n}\n\nexport const datasourceSelectValueToSelector = (\n value: DatasourceSelectValue | undefined,\n variables: VariableStateMap,\n datasourceSelectItemGroups: DatasourceSelectItemGroup[] | undefined\n): DatasourceSelector | undefined => {\n if (!isVariableDatasource(value)) {\n return value;\n }\n\n const [variableName] = parseVariables(value);\n const variable = variables[variableName ?? ''];\n\n // If the variable is not defined or if its value is an array, we cannot determine a selector and return undefined\n if (!variable || Array.isArray(variable.value)) {\n return undefined;\n }\n\n const associatedDatasource = (datasourceSelectItemGroups || [])\n .flatMap((itemGroup) => itemGroup.items)\n .find((datasource) => datasource.name === variable.value);\n\n // If the variable value is not a datasource, we cannot determine a selector and return undefined\n if (associatedDatasource === undefined) {\n return undefined;\n }\n\n const datasourceSelector: DatasourceSelector = {\n kind: associatedDatasource.selector.kind,\n name: associatedDatasource.selector.name,\n };\n\n return datasourceSelector;\n};\n\nexport const useDatasourceSelectValueToSelector = (\n value: DatasourceSelectValue,\n datasourcePluginKind: string\n): DatasourceSelector => {\n const { data } = useListDatasourceSelectItems(datasourcePluginKind);\n const variables = useVariableValues();\n if (!isVariableDatasource(value)) {\n return value;\n }\n\n return datasourceSelectValueToSelector(value, variables, data) ?? { kind: datasourcePluginKind };\n};\n"],"names":["OpenInNewIcon","Stack","ListItemText","Chip","IconButton","Box","Autocomplete","TextField","useMemo","useListDatasourceSelectItems","useVariableValues","parseVariables","DATASOURCE_VARIABLE_VALUE_PREFIX","VARIABLE_IDENTIFIER","emptyDatasourceOption","name","value","DatasourceSelect","props","datasourcePluginKind","project","readOnly","onChange","others","data","isLoading","variables","defaultValue","isVariableDatasource","group","flatMap","itemGroup","items","find","item","kind","selector","overridden","options","datasourceOptions","map","groupLabel","groupEditLink","editLink","overriding","saved","selectorToOptionValue","datasourceOptionsMap","Map","option","variableOptions","Object","entries","variable","Array","isArray","associatedDatasource","get","optionValue","handleChange","selectedOption","next","optionValueToSelector","fakeActionEvent","renderInput","params","label","placeholder","groupBy","getOptionLabel","_","v","renderOption","li","key","direction","alignItems","justifyContent","width","DatasourceName","style","textAlign","length","disabled","size","onDelete","undefined","deleteIcon","href","target","fontSize","display","fontWeight","color","theme","palette","primary","main","OPTION_VALUE_DELIMITER","join","startsWith","split","words","Error","datasourceSelectValueToSelector","datasourceSelectItemGroups","variableName","datasource","datasourceSelector","useDatasourceSelectValueToSelector"],"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,mBAAmB,4BAA4B;AACtD,SACEC,KAAK,EACLC,YAAY,EACZC,IAAI,EACJC,UAAU,EACVC,GAAG,EAGHC,YAAY,EACZC,SAAS,QACJ,gBAAgB;AAEvB,SAAuBC,OAAO,QAAQ,QAAQ;AAC9C,SAIEC,4BAA4B,EAC5BC,iBAAiB,QAEZ,gBAAgB;AACvB,SAASC,cAAc,QAAQ,cAAc;AAE7C,MAAMC,mCAAmC;AACzC,MAAMC,sBAAsB;AAY5B,MAAMC,wBAA0C;IAAEC,MAAM;IAAIC,OAAO;AAAG;AAWtE;;;CAGC,GACD,OAAO,SAASC,iBAAiBC,KAA4B;IAC3D,MAAM,EAAEC,oBAAoB,EAAEH,KAAK,EAAEI,OAAO,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGC,QAAQ,GAAGL;IAChF,MAAM,EAAEM,IAAI,EAAE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YhB;IAClB,IAAI,CAACkB,qBAAqBZ,QAAQ;QAChC,OAAOA;IACT;IAEA,OAAOwF,gCAAgCxF,OAAOU,WAAWF,SAAS;QAAEW,MAAMhB;IAAqB;AACjG,EAAE"}
@@ -0,0 +1,2 @@
1
+ export * from './DatasourceSelect';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/DatasourceSelect/index.ts"],"names":[],"mappings":"AAaA,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,15 @@
1
+ // Copyright 2023 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
+ export * from './DatasourceSelect';
14
+
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/DatasourceSelect/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './DatasourceSelect';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,qBAAqB"}
@@ -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;AAwTtF,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"}
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
- kind ? /*#__PURE__*/ _jsx(Box, {
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__*/ _jsxs(TextField, {
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
- /*#__PURE__*/ _jsx(MenuItem, {
227
- value: "none",
228
- children: "None"
229
- }),
230
- /*#__PURE__*/ _jsx(MenuItem, {
231
- value: "alphabetical-asc",
232
- children: "Alphabetical, asc"
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
  })
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Variables/VariableEditorForm/VariableEditorForm.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 { DispatchWithoutAction, ReactElement, useState } from 'react';\nimport { Box, Typography, Switch, TextField, Grid, FormControlLabel, MenuItem, Stack, Divider } from '@mui/material';\nimport { VariableDefinition, ListVariableDefinition, Action } from '@perses-dev/core';\nimport { DiscardChangesConfirmationDialog, ErrorAlert, ErrorBoundary, FormActions } from '@perses-dev/components';\nimport { Control, Controller, FormProvider, SubmitHandler, useForm, useFormContext, useWatch } from 'react-hook-form';\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport { getSubmitText, getTitleAction } from '../../../utils';\nimport { PluginEditor } from '../../PluginEditor';\nimport { useValidationSchemas } from '../../../context';\nimport { VARIABLE_TYPES } from '../variable-model';\nimport { useTimeRange } from '../../../runtime';\nimport { VariableListPreview, VariablePreview } from './VariablePreview';\n\nfunction FallbackPreview(): ReactElement {\n return <div>Error previewing values</div>;\n}\n\ninterface KindVariableEditorFormProps {\n action: Action;\n control: Control<VariableDefinition>;\n}\n\nfunction TextVariableEditorForm({ action, control }: KindVariableEditorFormProps): ReactElement {\n return (\n <>\n <Typography py={1} variant=\"subtitle1\">\n Text Options\n </Typography>\n <Stack spacing={2}>\n <Controller\n control={control}\n name=\"spec.value\"\n render={({ field, fieldState }) => (\n <>\n <Box>\n <VariablePreview values={[field.value]} />\n </Box>\n <TextField\n {...field}\n label=\"Value\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n </>\n )}\n />\n <Controller\n control={control}\n name=\"spec.constant\"\n render={({ field }) => (\n <FormControlLabel\n label=\"Constant\"\n control={\n <Switch\n {...field}\n checked={!!field.value}\n readOnly={action === 'read'}\n value={field.value ?? false}\n onChange={(event) => {\n if (action === 'read') return; // ReadOnly prop is not blocking user interaction...\n field.onChange(event);\n }}\n />\n }\n />\n )}\n />\n </Stack>\n </>\n );\n}\n\nfunction ListVariableEditorForm({ action, control }: KindVariableEditorFormProps): ReactElement {\n const form = useFormContext<VariableDefinition>();\n /** We use `previewSpec` to know when to explicitly update the\n * spec that will be used for preview. The reason why we do this is to avoid\n * having to re-fetch the values when the user is still editing the spec.\n */\n const previewSpec = form.getValues() as ListVariableDefinition;\n\n const plugin = useWatch<VariableDefinition, 'spec.plugin'>({ control, name: 'spec.plugin' });\n const kind = plugin?.kind;\n const pluginSpec = plugin?.spec;\n\n const _allowAllValue = useWatch<VariableDefinition, 'spec.allowAllValue'>({\n control: control,\n name: 'spec.allowAllValue',\n });\n\n // When variable kind is selected we need to provide default values\n // TODO: check if react-hook-form has a better way to do this\n const values = form.getValues() as ListVariableDefinition;\n if (values.spec.allowAllValue === undefined) {\n form.setValue('spec.allowAllValue', false);\n }\n\n if (values.spec.allowMultiple === undefined) {\n form.setValue('spec.allowMultiple', false);\n }\n\n const { refresh } = useTimeRange();\n\n return (\n <>\n <Typography py={1} variant=\"subtitle1\">\n List Options\n </Typography>\n <Stack spacing={2} mb={2}>\n {kind ? (\n <Box>\n <ErrorBoundary FallbackComponent={FallbackPreview} resetKeys={[previewSpec]}>\n <VariableListPreview definition={previewSpec} />\n </ErrorBoundary>\n </Box>\n ) : (\n <VariablePreview isLoading={true} />\n )}\n\n <Stack>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <Controller\n control={control}\n name=\"spec.plugin\"\n render={({ field }) => {\n return (\n <PluginEditor\n postExecuteRunQuery={refresh}\n withRunQueryButton\n width=\"100%\"\n pluginTypes={['Variable']}\n pluginKindLabel=\"Source\"\n value={{\n selection: {\n type: 'Variable',\n kind: kind ?? 'StaticListVariable',\n },\n spec: pluginSpec ?? {},\n }}\n isReadonly={action === 'read'}\n onChange={(v) => {\n field.onChange({ kind: v.selection.kind, spec: v.spec });\n }}\n />\n );\n }}\n />\n </ErrorBoundary>\n </Stack>\n\n <Stack>\n <Controller\n control={control}\n name=\"spec.capturingRegexp\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n label=\"Capturing Regexp Filter\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n value={field.value ?? ''}\n onChange={(event) => {\n if (event.target.value === '') {\n field.onChange(undefined);\n } else {\n field.onChange(event);\n }\n }}\n helperText={\n fieldState.error?.message\n ? fieldState.error.message\n : 'Optional, if you want to filter on captured result.'\n }\n />\n )}\n />\n </Stack>\n\n <Stack>\n <Controller\n control={control}\n name=\"spec.sort\"\n render={({ field, fieldState }) => (\n <TextField\n select\n {...field}\n fullWidth\n label=\"Sort\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? 'none'}\n onChange={(event) => {\n field.onChange(event);\n }}\n >\n <MenuItem value=\"none\">None</MenuItem>\n <MenuItem value=\"alphabetical-asc\">Alphabetical, asc</MenuItem>\n <MenuItem value=\"alphabetical-desc\">Alphabetical, desc</MenuItem>\n <MenuItem value=\"numerical-asc\">Numerical, asc</MenuItem>\n <MenuItem value=\"numerical-desc\">Numerical, desc</MenuItem>\n <MenuItem value=\"alphabetical-ci-asc\">Alphabetical, case-insensitive, asc</MenuItem>\n <MenuItem value=\"alphabetical-ci-desc\">Alphabetical, case-insensitive, desc</MenuItem>\n </TextField>\n )}\n />\n </Stack>\n </Stack>\n\n <Divider />\n\n <Typography py={1} variant=\"subtitle1\">\n Dropdown Options\n </Typography>\n <Stack spacing=\"2\">\n <Stack>\n <Controller\n control={control}\n name=\"spec.allowMultiple\"\n render={({ field }) => (\n <FormControlLabel\n label=\"Allow Multiple Values\"\n control={\n <Switch\n {...field}\n checked={!!field.value}\n readOnly={action === 'read'}\n value={field.value ?? false}\n onChange={(event) => {\n if (action === 'read') return; // ReadOnly prop is not blocking user interaction...\n field.onChange(event);\n }}\n />\n }\n />\n )}\n />\n <Typography variant=\"caption\">Enables multiple values to be selected at the same time</Typography>\n </Stack>\n <Stack>\n <Controller\n control={control}\n name=\"spec.allowAllValue\"\n render={({ field }) => (\n <FormControlLabel\n label=\"Allow All option\"\n control={\n <Switch\n {...field}\n checked={!!field.value}\n readOnly={action === 'read'}\n value={field.value ?? false}\n onChange={(event) => {\n if (action === 'read') return; // ReadOnly prop is not blocking user interaction...\n field.onChange(event);\n }}\n />\n }\n />\n )}\n />\n <Typography mb={1} variant=\"caption\">\n Enables an option to include all variable values\n </Typography>\n {_allowAllValue && (\n <Controller\n control={control}\n name=\"spec.customAllValue\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"Custom All Value\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={\n fieldState.error?.message\n ? fieldState.error.message\n : 'When All is selected, this value will be used'\n }\n value={field.value ?? ''}\n onChange={(event) => {\n if (event.target.value === '') {\n field.onChange(undefined);\n } else {\n field.onChange(event);\n }\n }}\n />\n )}\n />\n )}\n </Stack>\n </Stack>\n </>\n );\n}\n\ninterface VariableEditorFormProps {\n initialVariableDefinition: VariableDefinition;\n action: Action;\n isDraft: boolean;\n isReadonly?: boolean;\n onActionChange?: (action: Action) => void;\n onSave: (def: VariableDefinition) => void;\n onClose: () => void;\n onDelete?: DispatchWithoutAction;\n}\n\nexport function VariableEditorForm({\n initialVariableDefinition,\n action,\n isDraft,\n isReadonly,\n onActionChange,\n onSave,\n onClose,\n onDelete,\n}: VariableEditorFormProps): ReactElement {\n const [isDiscardDialogOpened, setDiscardDialogOpened] = useState<boolean>(false);\n const titleAction = getTitleAction(action, isDraft);\n const submitText = getSubmitText(action, isDraft);\n\n const { variableEditorSchema } = useValidationSchemas();\n const form = useForm<VariableDefinition>({\n resolver: zodResolver(variableEditorSchema),\n mode: 'onBlur',\n defaultValues: initialVariableDefinition,\n });\n\n const kind = useWatch({ control: form.control, name: 'kind' });\n\n function clearFormData(data: VariableDefinition): VariableDefinition {\n const result = { ...data };\n if (\n result.spec.display?.name === undefined &&\n result.spec.display?.description === undefined &&\n result.spec.display?.hidden === undefined\n ) {\n delete result.spec.display;\n }\n return result;\n }\n\n const processForm: SubmitHandler<VariableDefinition> = (data: VariableDefinition) => {\n // reset display attributes to undefined when empty, because we don't want to save empty strings\n onSave(clearFormData(data));\n };\n\n // When user click on cancel, several possibilities:\n // - create action: ask for discard approval\n // - update action: ask for discard approval if changed\n // - read action: don´t ask for discard approval\n function handleCancel(): void {\n if (JSON.stringify(initialVariableDefinition) !== JSON.stringify(clearFormData(form.getValues()))) {\n setDiscardDialogOpened(true);\n } else {\n onClose();\n }\n }\n\n return (\n <FormProvider {...form}>\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n padding: (theme) => theme.spacing(1, 2),\n borderBottom: (theme) => `1px solid ${theme.palette.divider}`,\n }}\n >\n <Typography variant=\"h2\">{titleAction} Variable</Typography>\n <FormActions\n action={action}\n submitText={submitText}\n isReadonly={isReadonly}\n isValid={form.formState.isValid}\n onActionChange={onActionChange}\n onSubmit={form.handleSubmit(processForm)}\n onDelete={onDelete}\n onCancel={handleCancel}\n />\n </Box>\n <Box padding={2} sx={{ overflowY: 'scroll' }}>\n <Grid container spacing={2} mb={2}>\n <Grid item xs={8}>\n <Controller\n control={form.control}\n name=\"spec.name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n required\n fullWidth\n label=\"Name\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n disabled: action === 'update' && !isDraft,\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={4}>\n <Controller\n control={form.control}\n name=\"spec.display.name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"Display Label\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={8}>\n <Controller\n control={form.control}\n name=\"spec.display.description\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"Description\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={4}>\n <Controller\n control={form.control}\n name=\"kind\"\n render={({ field, fieldState }) => (\n <TextField\n select\n {...field}\n fullWidth\n label=\"Type\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? 'TextVariable'}\n onChange={(event) => {\n field.onChange(event);\n }}\n >\n {VARIABLE_TYPES.map((v) => (\n <MenuItem key={v.kind} value={v.kind}>\n {v.label}\n </MenuItem>\n ))}\n </TextField>\n )}\n />\n </Grid>\n </Grid>\n\n <Divider />\n\n {kind === 'TextVariable' && (\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <TextVariableEditorForm action={action} control={form.control} />\n </ErrorBoundary>\n )}\n {kind === 'ListVariable' && (\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <ListVariableEditorForm action={action} control={form.control} />\n </ErrorBoundary>\n )}\n </Box>\n <DiscardChangesConfirmationDialog\n description=\"Are you sure you want to discard these changes? Changes cannot be recovered.\"\n isOpen={isDiscardDialogOpened}\n onCancel={() => {\n setDiscardDialogOpened(false);\n }}\n onDiscardChanges={() => {\n setDiscardDialogOpened(false);\n onClose();\n }}\n />\n </FormProvider>\n );\n}\n"],"names":["useState","Box","Typography","Switch","TextField","Grid","FormControlLabel","MenuItem","Stack","Divider","DiscardChangesConfirmationDialog","ErrorAlert","ErrorBoundary","FormActions","Controller","FormProvider","useForm","useFormContext","useWatch","zodResolver","getSubmitText","getTitleAction","PluginEditor","useValidationSchemas","VARIABLE_TYPES","useTimeRange","VariableListPreview","VariablePreview","FallbackPreview","div","TextVariableEditorForm","action","control","py","variant","spacing","name","render","field","fieldState","values","value","label","InputLabelProps","shrink","undefined","InputProps","readOnly","error","helperText","message","onChange","event","checked","ListVariableEditorForm","form","previewSpec","getValues","plugin","kind","pluginSpec","spec","_allowAllValue","allowAllValue","setValue","allowMultiple","refresh","mb","FallbackComponent","resetKeys","definition","isLoading","postExecuteRunQuery","withRunQueryButton","width","pluginTypes","pluginKindLabel","selection","type","isReadonly","v","target","select","fullWidth","VariableEditorForm","initialVariableDefinition","isDraft","onActionChange","onSave","onClose","onDelete","isDiscardDialogOpened","setDiscardDialogOpened","titleAction","submitText","variableEditorSchema","resolver","mode","defaultValues","clearFormData","data","result","display","description","hidden","processForm","handleCancel","JSON","stringify","sx","alignItems","padding","theme","borderBottom","palette","divider","isValid","formState","onSubmit","handleSubmit","onCancel","overflowY","container","item","xs","required","disabled","map","isOpen","onDiscardChanges"],"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,SAA8CA,QAAQ,QAAQ,QAAQ;AACtE,SAASC,GAAG,EAAEC,UAAU,EAAEC,MAAM,EAAEC,SAAS,EAAEC,IAAI,EAAEC,gBAAgB,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,OAAO,QAAQ,gBAAgB;AAErH,SAASC,gCAAgC,EAAEC,UAAU,EAAEC,aAAa,EAAEC,WAAW,QAAQ,yBAAyB;AAClH,SAAkBC,UAAU,EAAEC,YAAY,EAAiBC,OAAO,EAAEC,cAAc,EAAEC,QAAQ,QAAQ,kBAAkB;AACtH,SAASC,WAAW,QAAQ,0BAA0B;AACtD,SAASC,aAAa,EAAEC,cAAc,QAAQ,iBAAiB;AAC/D,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,oBAAoB,QAAQ,mBAAmB;AACxD,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,YAAY,QAAQ,mBAAmB;AAChD,SAASC,mBAAmB,EAAEC,eAAe,QAAQ,oBAAoB;AAEzE,SAASC;IACP,qBAAO,KAACC;kBAAI;;AACd;AAOA,SAASC,uBAAuB,EAAEC,MAAM,EAAEC,OAAO,EAA+B;IAC9E,qBACE;;0BACE,KAAC9B;gBAAW+B,IAAI;gBAAGC,SAAQ;0BAAY;;0BAGvC,MAAC1B;gBAAM2B,SAAS;;kCACd,KAACrB;wBACCkB,SAASA;wBACTI,MAAK;wBACLC,QAAQ,CAAC,EAAEC,KAAK,EAAEC,UAAU,E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AAO,CAAC,CAACT,WAAWS,KAAK;4CACzBC,YAAYV,WAAWS,KAAK,EAAEE;4CAC9BT,OAAOH,MAAMG,KAAK,IAAI;4CACtBU,UAAU,CAACC;gDACTd,MAAMa,QAAQ,CAACC;4CACjB;sDAEC5B,eAAeuG,GAAG,CAAC,CAAC/C,kBACnB,KAACzE;oDAAsBkC,OAAOuC,EAAErB,IAAI;8DACjCqB,EAAEtC,KAAK;mDADKsC,EAAErB,IAAI;;;;;;kCAUjC,KAAClD;oBAEAkD,SAAS,gCACR,KAAC/C;wBAAcwD,mBAAmBzD;kCAChC,cAAA,KAACmB;4BAAuBC,QAAQA;4BAAQC,SAASuB,KAAKvB,OAAO;;;oBAGhE2B,SAAS,gCACR,KAAC/C;wBAAcwD,mBAAmBzD;kCAChC,cAAA,KAAC2C;4BAAuBvB,QAAQA;4BAAQC,SAASuB,KAAKvB,OAAO;;;;;0BAInE,KAACtB;gBACC6F,aAAY;gBACZyB,QAAQrC;gBACR6B,UAAU;oBACR5B,uBAAuB;gBACzB;gBACAqC,kBAAkB;oBAChBrC,uBAAuB;oBACvBH;gBACF;;;;AAIR"}
1
+ {"version":3,"sources":["../../../../src/components/Variables/VariableEditorForm/VariableEditorForm.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 { DispatchWithoutAction, ReactElement, useState } from 'react';\nimport { Box, Typography, Switch, TextField, Grid, FormControlLabel, MenuItem, Stack, Divider } from '@mui/material';\nimport { VariableDefinition, ListVariableDefinition, Action } from '@perses-dev/core';\nimport { DiscardChangesConfirmationDialog, ErrorAlert, ErrorBoundary, FormActions } from '@perses-dev/components';\nimport { Control, Controller, FormProvider, SubmitHandler, useForm, useFormContext, useWatch } from 'react-hook-form';\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport { getSubmitText, getTitleAction } from '../../../utils';\nimport { PluginEditor } from '../../PluginEditor';\nimport { useValidationSchemas } from '../../../context';\nimport { VARIABLE_TYPES } from '../variable-model';\nimport { useTimeRange } from '../../../runtime';\nimport { VariableListPreview, VariablePreview } from './VariablePreview';\nimport { SORT_METHODS, SortMethodName } from './variable-editor-form-model';\n\nfunction FallbackPreview(): ReactElement {\n return <div>Error previewing values</div>;\n}\n\ninterface KindVariableEditorFormProps {\n action: Action;\n control: Control<VariableDefinition>;\n}\n\nfunction TextVariableEditorForm({ action, control }: KindVariableEditorFormProps): ReactElement {\n return (\n <>\n <Typography py={1} variant=\"subtitle1\">\n Text Options\n </Typography>\n <Stack spacing={2}>\n <Controller\n control={control}\n name=\"spec.value\"\n render={({ field, fieldState }) => (\n <>\n <Box>\n <VariablePreview values={[field.value]} />\n </Box>\n <TextField\n {...field}\n label=\"Value\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n </>\n )}\n />\n <Controller\n control={control}\n name=\"spec.constant\"\n render={({ field }) => (\n <FormControlLabel\n label=\"Constant\"\n control={\n <Switch\n {...field}\n checked={!!field.value}\n readOnly={action === 'read'}\n value={field.value ?? false}\n onChange={(event) => {\n if (action === 'read') return; // ReadOnly prop is not blocking user interaction...\n field.onChange(event);\n }}\n />\n }\n />\n )}\n />\n </Stack>\n </>\n );\n}\n\nfunction ListVariableEditorForm({ action, control }: KindVariableEditorFormProps): ReactElement {\n const form = useFormContext<VariableDefinition>();\n /** We use `previewSpec` to know when to explicitly update the\n * spec that will be used for preview. The reason why we do this is to avoid\n * having to re-fetch the values when the user is still editing the spec.\n */\n const previewSpec = form.getValues() as ListVariableDefinition;\n\n const plugin = useWatch<VariableDefinition, 'spec.plugin'>({ control, name: 'spec.plugin' });\n const kind = plugin?.kind;\n const pluginSpec = plugin?.spec;\n\n const _allowAllValue = useWatch<VariableDefinition, 'spec.allowAllValue'>({\n control: control,\n name: 'spec.allowAllValue',\n });\n\n const sortMethod = useWatch<VariableDefinition, 'spec.sort'>({\n control: control,\n name: 'spec.sort',\n }) as SortMethodName;\n\n // When variable kind is selected we need to provide default values\n // TODO: check if react-hook-form has a better way to do this\n const values = form.getValues() as ListVariableDefinition;\n if (values.spec.allowAllValue === undefined) {\n form.setValue('spec.allowAllValue', false);\n }\n\n if (values.spec.allowMultiple === undefined) {\n form.setValue('spec.allowMultiple', false);\n }\n\n if (!values.spec.plugin) {\n form.setValue('spec.plugin', { kind: 'StaticListVariable', spec: {} });\n }\n\n if (!values.spec.sort) {\n form.setValue('spec.sort', 'none');\n }\n\n const { refresh } = useTimeRange();\n\n return (\n <>\n <Typography py={1} variant=\"subtitle1\">\n List Options\n </Typography>\n <Stack spacing={2} mb={2}>\n <Box>\n <ErrorBoundary FallbackComponent={FallbackPreview} resetKeys={[previewSpec]}>\n <VariableListPreview sortMethod={sortMethod} definition={previewSpec} />\n </ErrorBoundary>\n </Box>\n <Stack>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <Controller\n control={control}\n name=\"spec.plugin\"\n render={({ field }) => {\n return (\n <PluginEditor\n postExecuteRunQuery={refresh}\n withRunQueryButton\n width=\"100%\"\n pluginTypes={['Variable']}\n pluginKindLabel=\"Source\"\n value={{\n selection: {\n type: 'Variable',\n kind: kind ?? 'StaticListVariable',\n },\n spec: pluginSpec ?? {},\n }}\n isReadonly={action === 'read'}\n onChange={(v) => {\n field.onChange({ kind: v.selection.kind, spec: v.spec });\n }}\n />\n );\n }}\n />\n </ErrorBoundary>\n </Stack>\n\n <Stack>\n <Controller\n control={control}\n name=\"spec.capturingRegexp\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n label=\"Capturing Regexp Filter\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n value={field.value ?? ''}\n onChange={(event) => {\n if (event.target.value === '') {\n field.onChange(undefined);\n } else {\n field.onChange(event);\n }\n }}\n helperText={\n fieldState.error?.message\n ? fieldState.error.message\n : 'Optional, if you want to filter on captured result.'\n }\n />\n )}\n />\n </Stack>\n\n <Stack>\n <Controller\n control={control}\n name=\"spec.sort\"\n render={({ field, fieldState }) => (\n <TextField\n select\n {...field}\n fullWidth\n label=\"Sort\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? 'none'}\n onChange={(event) => {\n field.onChange(event);\n }}\n >\n {Object.keys(SORT_METHODS).map((key) => {\n if (!SORT_METHODS[key as SortMethodName]) return null;\n const { label } = SORT_METHODS[key as SortMethodName];\n return (\n <MenuItem key={key} value={key}>\n {label}\n </MenuItem>\n );\n })}\n </TextField>\n )}\n />\n </Stack>\n </Stack>\n\n <Divider />\n\n <Typography py={1} variant=\"subtitle1\">\n Dropdown Options\n </Typography>\n <Stack spacing=\"2\">\n <Stack>\n <Controller\n control={control}\n name=\"spec.allowMultiple\"\n render={({ field }) => (\n <FormControlLabel\n label=\"Allow Multiple Values\"\n control={\n <Switch\n {...field}\n checked={!!field.value}\n readOnly={action === 'read'}\n value={field.value ?? false}\n onChange={(event) => {\n if (action === 'read') return; // ReadOnly prop is not blocking user interaction...\n field.onChange(event);\n }}\n />\n }\n />\n )}\n />\n <Typography variant=\"caption\">Enables multiple values to be selected at the same time</Typography>\n </Stack>\n <Stack>\n <Controller\n control={control}\n name=\"spec.allowAllValue\"\n render={({ field }) => (\n <FormControlLabel\n label=\"Allow All option\"\n control={\n <Switch\n {...field}\n checked={!!field.value}\n readOnly={action === 'read'}\n value={field.value ?? false}\n onChange={(event) => {\n if (action === 'read') return; // ReadOnly prop is not blocking user interaction...\n field.onChange(event);\n }}\n />\n }\n />\n )}\n />\n <Typography mb={1} variant=\"caption\">\n Enables an option to include all variable values\n </Typography>\n {_allowAllValue && (\n <Controller\n control={control}\n name=\"spec.customAllValue\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"Custom All Value\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={\n fieldState.error?.message\n ? fieldState.error.message\n : 'When All is selected, this value will be used'\n }\n value={field.value ?? ''}\n onChange={(event) => {\n if (event.target.value === '') {\n field.onChange(undefined);\n } else {\n field.onChange(event);\n }\n }}\n />\n )}\n />\n )}\n </Stack>\n </Stack>\n </>\n );\n}\n\ninterface VariableEditorFormProps {\n initialVariableDefinition: VariableDefinition;\n action: Action;\n isDraft: boolean;\n isReadonly?: boolean;\n onActionChange?: (action: Action) => void;\n onSave: (def: VariableDefinition) => void;\n onClose: () => void;\n onDelete?: DispatchWithoutAction;\n}\n\nexport function VariableEditorForm({\n initialVariableDefinition,\n action,\n isDraft,\n isReadonly,\n onActionChange,\n onSave,\n onClose,\n onDelete,\n}: VariableEditorFormProps): ReactElement {\n const [isDiscardDialogOpened, setDiscardDialogOpened] = useState<boolean>(false);\n const titleAction = getTitleAction(action, isDraft);\n const submitText = getSubmitText(action, isDraft);\n\n const { variableEditorSchema } = useValidationSchemas();\n const form = useForm<VariableDefinition>({\n resolver: zodResolver(variableEditorSchema),\n mode: 'onBlur',\n defaultValues: initialVariableDefinition,\n });\n\n const kind = useWatch({ control: form.control, name: 'kind' });\n\n function clearFormData(data: VariableDefinition): VariableDefinition {\n const result = { ...data };\n if (\n result.spec.display?.name === undefined &&\n result.spec.display?.description === undefined &&\n result.spec.display?.hidden === undefined\n ) {\n delete result.spec.display;\n }\n return result;\n }\n\n const processForm: SubmitHandler<VariableDefinition> = (data: VariableDefinition) => {\n // reset display attributes to undefined when empty, because we don't want to save empty strings\n onSave(clearFormData(data));\n };\n\n // When user click on cancel, several possibilities:\n // - create action: ask for discard approval\n // - update action: ask for discard approval if changed\n // - read action: don´t ask for discard approval\n function handleCancel(): void {\n if (JSON.stringify(initialVariableDefinition) !== JSON.stringify(clearFormData(form.getValues()))) {\n setDiscardDialogOpened(true);\n } else {\n onClose();\n }\n }\n\n return (\n <FormProvider {...form}>\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n padding: (theme) => theme.spacing(1, 2),\n borderBottom: (theme) => `1px solid ${theme.palette.divider}`,\n }}\n >\n <Typography variant=\"h2\">{titleAction} Variable</Typography>\n <FormActions\n action={action}\n submitText={submitText}\n isReadonly={isReadonly}\n isValid={form.formState.isValid}\n onActionChange={onActionChange}\n onSubmit={form.handleSubmit(processForm)}\n onDelete={onDelete}\n onCancel={handleCancel}\n />\n </Box>\n <Box padding={2} sx={{ overflowY: 'scroll' }}>\n <Grid container spacing={2} mb={2}>\n <Grid item xs={8}>\n <Controller\n control={form.control}\n name=\"spec.name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n required\n fullWidth\n label=\"Name\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n disabled: action === 'update' && !isDraft,\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={4}>\n <Controller\n control={form.control}\n name=\"spec.display.name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"Display Label\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={8}>\n <Controller\n control={form.control}\n name=\"spec.display.description\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"Description\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={4}>\n <Controller\n control={form.control}\n name=\"kind\"\n render={({ field, fieldState }) => (\n <TextField\n select\n {...field}\n fullWidth\n label=\"Type\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? 'TextVariable'}\n onChange={(event) => {\n field.onChange(event);\n }}\n >\n {VARIABLE_TYPES.map((v) => (\n <MenuItem key={v.kind} value={v.kind}>\n {v.label}\n </MenuItem>\n ))}\n </TextField>\n )}\n />\n </Grid>\n </Grid>\n\n <Divider />\n\n {kind === 'TextVariable' && (\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <TextVariableEditorForm action={action} control={form.control} />\n </ErrorBoundary>\n )}\n {kind === 'ListVariable' && (\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <ListVariableEditorForm action={action} control={form.control} />\n </ErrorBoundary>\n )}\n </Box>\n <DiscardChangesConfirmationDialog\n description=\"Are you sure you want to discard these changes? Changes cannot be recovered.\"\n isOpen={isDiscardDialogOpened}\n onCancel={() => {\n setDiscardDialogOpened(false);\n }}\n onDiscardChanges={() => {\n setDiscardDialogOpened(false);\n onClose();\n }}\n />\n </FormProvider>\n );\n}\n"],"names":["useState","Box","Typography","Switch","TextField","Grid","FormControlLabel","MenuItem","Stack","Divider","DiscardChangesConfirmationDialog","ErrorAlert","ErrorBoundary","FormActions","Controller","FormProvider","useForm","useFormContext","useWatch","zodResolver","getSubmitText","getTitleAction","PluginEditor","useValidationSchemas","VARIABLE_TYPES","useTimeRange","VariableListPreview","VariablePreview","SORT_METHODS","FallbackPreview","div","TextVariableEditorForm","action","control","py","variant","spacing","name","render","field","fieldState","values","value","label","InputLabelProps","shrink","undefined","InputProps","readOnly","error","helperText","message","onChange","event","checked","ListVariableEditorForm","form","previewSpec","getValues","plugin","kind","pluginSpec","spec","_allowAllValue","sortMethod","allowAllValue","setValue","allowMultiple","sort","refresh","mb","FallbackComponent","resetKeys","definition","postExecuteRunQuery","withRunQueryButton","width","pluginTypes","pluginKindLabel","selection","type","isReadonly","v","target","select","fullWidth","Object","keys","map","key","VariableEditorForm","initialVariableDefinition","isDraft","onActionChange","onSave","onClose","onDelete","isDiscardDialogOpened","setDiscardDialogOpened","titleAction","submitText","variableEditorSchema","resolver","mode","defaultValues","clearFormData","data","result","display","description","hidden","processForm","handleCancel","JSON","stringify","sx","alignItems","padding","theme","borderBottom","palette","divider","isValid","formState","onSubmit","handleSubmit","onCancel","overflowY","container","item","xs","required","disabled","isOpen","onDiscardChanges"],"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,SAA8CA,QAAQ,QAAQ,QAAQ;AACtE,SAASC,GAAG,EAAEC,UAAU,EAAEC,MAAM,EAAEC,SAAS,EAAEC,IAAI,EAAEC,gBAAgB,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,OAAO,QAAQ,gBAAgB;AAErH,SAASC,gCAAgC,EAAEC,UAAU,EAAEC,aAAa,EAAEC,WAAW,QAAQ,yBAAyB;AAClH,SAAkBC,UAAU,EAAEC,YAAY,EAAiBC,OAAO,EAAEC,cAAc,EAAEC,QAAQ,QAAQ,kBAAkB;AACtH,SAASC,WAAW,QAAQ,0BAA0B;AACtD,SAASC,aAAa,EAAEC,cAAc,QAAQ,iBAAiB;AAC/D,SAASC,YA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B,QAAQA;4BAAQC,SAASuB,KAAKvB,OAAO;;;;;0BAInE,KAACvB;gBACCmG,aAAY;gBACZwB,QAAQpC;gBACR6B,UAAU;oBACR5B,uBAAuB;gBACzB;gBACAoC,kBAAkB;oBAChBpC,uBAAuB;oBACvBH;gBACF;;;;AAIR"}
@@ -1,5 +1,6 @@
1
1
  import { ReactElement } from 'react';
2
2
  import { ListVariableDefinition } from '@perses-dev/core';
3
+ import { SORT_METHODS } from './variable-editor-form-model';
3
4
  interface VariablePreviewProps {
4
5
  values?: string[];
5
6
  isLoading?: boolean;
@@ -8,6 +9,7 @@ interface VariablePreviewProps {
8
9
  export declare function VariablePreview(props: VariablePreviewProps): ReactElement;
9
10
  interface VariableListPreviewProps {
10
11
  definition: ListVariableDefinition;
12
+ sortMethod?: keyof typeof SORT_METHODS;
11
13
  }
12
14
  export declare function VariableListPreview(props: VariableListPreviewProps): ReactElement;
13
15
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"VariablePreview.d.ts","sourceRoot":"","sources":["../../../../src/components/Variables/VariableEditorForm/VariablePreview.tsx"],"names":[],"mappings":"AAaA,OAAc,EAAE,YAAY,EAAqB,MAAM,OAAO,CAAC;AAI/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAM1D,UAAU,oBAAoB;IAC5B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CA8CzE;AAED,UAAU,wBAAwB;IAChC,UAAU,EAAE,sBAAsB,CAAC;CACpC;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,YAAY,CAWjF"}
1
+ {"version":3,"file":"VariablePreview.d.ts","sourceRoot":"","sources":["../../../../src/components/Variables/VariableEditorForm/VariablePreview.tsx"],"names":[],"mappings":"AAaA,OAAc,EAAE,YAAY,EAAqB,MAAM,OAAO,CAAC;AAI/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAI5D,UAAU,oBAAoB;IAC5B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CAuDzE;AAED,UAAU,wBAAwB;IAChC,UAAU,EAAE,sBAAsB,CAAC;IACnC,UAAU,CAAC,EAAE,MAAM,OAAO,YAAY,CAAC;CACxC;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,YAAY,CAmBjF"}
@@ -17,6 +17,7 @@ import { InfoTooltip, useSnackbar } from '@perses-dev/components';
17
17
  import Clipboard from 'mdi-material-ui/ClipboardOutline';
18
18
  import { TOOLTIP_TEXT } from '../../../constants';
19
19
  import { useListVariablePluginValues } from '../variable-model';
20
+ import { SORT_METHODS } from './variable-editor-form-model';
20
21
  const DEFAULT_MAX_PREVIEW_VALUES = 50;
21
22
  export function VariablePreview(props) {
22
23
  const { values, isLoading, error } = props;
@@ -29,6 +30,33 @@ export function VariablePreview(props) {
29
30
  if (values && values?.length > 0 && maxValues) {
30
31
  notShown = values.length - maxValues;
31
32
  }
33
+ const variablePreviewState = useMemo(()=>{
34
+ if (isLoading) {
35
+ return /*#__PURE__*/ _jsx(Stack, {
36
+ width: "100%",
37
+ sx: {
38
+ alignItems: 'center',
39
+ justifyContent: 'center'
40
+ },
41
+ children: /*#__PURE__*/ _jsx(CircularProgress, {})
42
+ });
43
+ } else if (error) {
44
+ return /*#__PURE__*/ _jsx(Alert, {
45
+ severity: "error",
46
+ children: error
47
+ });
48
+ } else if (!values?.length) {
49
+ return /*#__PURE__*/ _jsx(Alert, {
50
+ severity: "info",
51
+ children: "No results"
52
+ });
53
+ }
54
+ return null;
55
+ }, [
56
+ error,
57
+ isLoading,
58
+ values
59
+ ]);
32
60
  return /*#__PURE__*/ _jsxs(Box, {
33
61
  children: [
34
62
  /*#__PURE__*/ _jsxs(Stack, {
@@ -66,22 +94,7 @@ export function VariablePreview(props) {
66
94
  m: 2
67
95
  },
68
96
  children: [
69
- error && /*#__PURE__*/ _jsx(Alert, {
70
- severity: "error",
71
- children: error
72
- }),
73
- values?.length === 0 && /*#__PURE__*/ _jsx(Alert, {
74
- severity: "info",
75
- children: "No results"
76
- }),
77
- isLoading && /*#__PURE__*/ _jsx(Stack, {
78
- width: "100%",
79
- sx: {
80
- alignItems: 'center',
81
- justifyContent: 'center'
82
- },
83
- children: /*#__PURE__*/ _jsx(CircularProgress, {})
84
- }),
97
+ variablePreviewState,
85
98
  values?.slice(0, maxValues).map((val, index)=>/*#__PURE__*/ _jsx(Chip, {
86
99
  size: "small",
87
100
  label: val
@@ -99,17 +112,18 @@ export function VariablePreview(props) {
99
112
  });
100
113
  }
101
114
  export function VariableListPreview(props) {
102
- const { definition } = props;
115
+ const { definition, sortMethod } = props;
103
116
  const { data, isFetching, error } = useListVariablePluginValues(definition);
104
117
  const errorMessage = error?.message;
118
+ const result = !sortMethod || sortMethod === 'none' || !data ? data : SORT_METHODS[sortMethod].sort(data);
105
119
  const variablePreview = useMemo(()=>/*#__PURE__*/ _jsx(VariablePreview, {
106
- values: data?.map((val)=>val.value) || [],
120
+ values: result?.map((val)=>val.label || val.value),
107
121
  isLoading: isFetching,
108
122
  error: errorMessage
109
123
  }), [
110
124
  errorMessage,
111
125
  isFetching,
112
- data
126
+ result
113
127
  ]);
114
128
  return variablePreview;
115
129
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Variables/VariableEditorForm/VariablePreview.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 React, { ReactElement, useMemo, useState } from 'react';\nimport { Alert, Box, Card, Chip, CircularProgress, IconButton, Stack, Typography } from '@mui/material';\nimport { InfoTooltip, useSnackbar } from '@perses-dev/components';\nimport Clipboard from 'mdi-material-ui/ClipboardOutline';\nimport { ListVariableDefinition } from '@perses-dev/core';\nimport { TOOLTIP_TEXT } from '../../../constants';\nimport { useListVariablePluginValues } from '../variable-model';\n\nconst DEFAULT_MAX_PREVIEW_VALUES = 50;\n\ninterface VariablePreviewProps {\n values?: string[];\n isLoading?: boolean;\n error?: string;\n}\n\nexport function VariablePreview(props: VariablePreviewProps): ReactElement {\n const { values, isLoading, error } = props;\n const [maxValues, setMaxValues] = useState<number | undefined>(DEFAULT_MAX_PREVIEW_VALUES);\n const { infoSnackbar } = useSnackbar();\n const showAll = (): void => {\n setMaxValues(undefined);\n };\n let notShown = 0;\n\n if (values && values?.length > 0 && maxValues) {\n notShown = values.length - maxValues;\n }\n\n return (\n <Box>\n <Stack direction=\"row\" spacing={1} alignItems=\"center\" mb={1}>\n <Typography variant=\"h4\">Preview Values</Typography>\n <InfoTooltip description={TOOLTIP_TEXT.copyVariableValues}>\n <IconButton\n onClick={async () => {\n if (values?.length) {\n await navigator.clipboard.writeText(values.map((value) => value).join(', '));\n infoSnackbar('Preview values copied to clipboard!');\n }\n }}\n size=\"small\"\n >\n <Clipboard />\n </IconButton>\n </InfoTooltip>\n </Stack>\n <Card variant=\"outlined\">\n <Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 1, m: 2 }}>\n {error && <Alert severity=\"error\">{error}</Alert>}\n {values?.length === 0 && <Alert severity=\"info\">No results</Alert>}\n {isLoading && (\n <Stack width=\"100%\" sx={{ alignItems: 'center', justifyContent: 'center' }}>\n <CircularProgress />\n </Stack>\n )}\n {values?.slice(0, maxValues).map((val, index) => <Chip size=\"small\" key={index} label={val} />)}\n {notShown > 0 && <Chip onClick={showAll} variant=\"outlined\" size=\"small\" label={`+${notShown} more`} />}\n </Box>\n </Card>\n </Box>\n );\n}\n\ninterface VariableListPreviewProps {\n definition: ListVariableDefinition;\n}\n\nexport function VariableListPreview(props: VariableListPreviewProps): ReactElement {\n const { definition } = props;\n const { data, isFetching, error } = useListVariablePluginValues(definition);\n const errorMessage = (error as Error)?.message;\n\n const variablePreview = useMemo(\n () => <VariablePreview values={data?.map((val) => val.value) || []} isLoading={isFetching} error={errorMessage} />,\n [errorMessage, isFetching, data]\n );\n\n return variablePreview;\n}\n"],"names":["React","useMemo","useState","Alert","Box","Card","Chip","CircularProgress","IconButton","Stack","Typography","InfoTooltip","useSnackbar","Clipboard","TOOLTIP_TEXT","useListVariablePluginValues","DEFAULT_MAX_PREVIEW_VALUES","VariablePreview","props","values","isLoading","error","maxValues","setMaxValues","infoSnackbar","showAll","undefined","notShown","length","direction","spacing","alignItems","mb","variant","description","copyVariableValues","onClick","navigator","clipboard","writeText","map","value","join","size","sx","display","flexWrap","gap","m","severity","width","justifyContent","slice","val","index","label","VariableListPreview","definition","data","isFetching","errorMessage","message","variablePreview"],"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,SAAuBC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAC/D,SAASC,KAAK,EAAEC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,gBAAgB,EAAEC,UAAU,EAAEC,KAAK,EAAEC,UAAU,QAAQ,gBAAgB;AACxG,SAASC,WAAW,EAAEC,WA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,cAAA,KAAC5C;;wBAGJY,QAAQiC,MAAM,GAAG9B,WAAWkB,IAAI,CAACa,KAAKC,sBAAU,KAAChD;gCAAKqC,MAAK;gCAAoBY,OAAOF;+BAAdC;wBACxE3B,WAAW,mBAAK,KAACrB;4BAAK8B,SAASX;4BAASQ,SAAQ;4BAAWU,MAAK;4BAAQY,OAAO,CAAC,CAAC,EAAE5B,SAAS,KAAK,CAAC;;;;;;;AAK7G;AAMA,OAAO,SAAS6B,oBAAoBtC,KAA+B;IACjE,MAAM,EAAEuC,UAAU,EAAE,GAAGvC;IACvB,MAAM,EAAEwC,IAAI,EAAEC,UAAU,EAAEtC,KAAK,EAAE,GAAGN,4BAA4B0C;IAChE,MAAMG,eAAgBvC,OAAiBwC;IAEvC,MAAMC,kBAAkB7D,QACtB,kBAAM,KAACgB;YAAgBE,QAAQuC,MAAMlB,IAAI,CAACa,MAAQA,IAAIZ,KAAK,KAAK,EAAE;YAAErB,WAAWuC;YAAYtC,OAAOuC;YAClG;QAACA;QAAcD;QAAYD;KAAK;IAGlC,OAAOI;AACT"}
1
+ {"version":3,"sources":["../../../../src/components/Variables/VariableEditorForm/VariablePreview.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 React, { ReactElement, useMemo, useState } from 'react';\nimport { Alert, Box, Card, Chip, CircularProgress, IconButton, Stack, Typography } from '@mui/material';\nimport { InfoTooltip, useSnackbar } from '@perses-dev/components';\nimport Clipboard from 'mdi-material-ui/ClipboardOutline';\nimport { ListVariableDefinition } from '@perses-dev/core';\nimport { TOOLTIP_TEXT } from '../../../constants';\nimport { useListVariablePluginValues } from '../variable-model';\nimport { SORT_METHODS } from './variable-editor-form-model';\n\nconst DEFAULT_MAX_PREVIEW_VALUES = 50;\n\ninterface VariablePreviewProps {\n values?: string[];\n isLoading?: boolean;\n error?: string;\n}\n\nexport function VariablePreview(props: VariablePreviewProps): ReactElement {\n const { values, isLoading, error } = props;\n const [maxValues, setMaxValues] = useState<number | undefined>(DEFAULT_MAX_PREVIEW_VALUES);\n const { infoSnackbar } = useSnackbar();\n const showAll = (): void => {\n setMaxValues(undefined);\n };\n let notShown = 0;\n\n if (values && values?.length > 0 && maxValues) {\n notShown = values.length - maxValues;\n }\n\n const variablePreviewState = useMemo((): JSX.Element | null => {\n if (isLoading) {\n return (\n <Stack width=\"100%\" sx={{ alignItems: 'center', justifyContent: 'center' }}>\n <CircularProgress />\n </Stack>\n );\n } else if (error) {\n return <Alert severity=\"error\">{error}</Alert>;\n } else if (!values?.length) {\n return <Alert severity=\"info\">No results</Alert>;\n }\n return null;\n }, [error, isLoading, values]);\n\n return (\n <Box>\n <Stack direction=\"row\" spacing={1} alignItems=\"center\" mb={1}>\n <Typography variant=\"h4\">Preview Values</Typography>\n <InfoTooltip description={TOOLTIP_TEXT.copyVariableValues}>\n <IconButton\n onClick={async () => {\n if (values?.length) {\n await navigator.clipboard.writeText(values.map((value) => value).join(', '));\n infoSnackbar('Preview values copied to clipboard!');\n }\n }}\n size=\"small\"\n >\n <Clipboard />\n </IconButton>\n </InfoTooltip>\n </Stack>\n <Card variant=\"outlined\">\n <Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 1, m: 2 }}>\n {variablePreviewState}\n {values?.slice(0, maxValues).map((val, index) => <Chip size=\"small\" key={index} label={val} />)}\n {notShown > 0 && <Chip onClick={showAll} variant=\"outlined\" size=\"small\" label={`+${notShown} more`} />}\n </Box>\n </Card>\n </Box>\n );\n}\n\ninterface VariableListPreviewProps {\n definition: ListVariableDefinition;\n sortMethod?: keyof typeof SORT_METHODS;\n}\n\nexport function VariableListPreview(props: VariableListPreviewProps): ReactElement {\n const { definition, sortMethod } = props;\n const { data, isFetching, error } = useListVariablePluginValues(definition);\n const errorMessage = (error as Error)?.message;\n\n const result = !sortMethod || sortMethod === 'none' || !data ? data : SORT_METHODS[sortMethod].sort(data);\n\n const variablePreview = useMemo(\n () => (\n <VariablePreview\n values={result?.map((val) => val.label || val.value)}\n isLoading={isFetching}\n error={errorMessage}\n />\n ),\n [errorMessage, isFetching, result]\n );\n\n return variablePreview;\n}\n"],"names":["React","useMemo","useState","Alert","Box","Card","Chip","CircularProgress","IconButton","Stack","Typography","InfoTooltip","useSnackbar","Clipboard","TOOLTIP_TEXT","useListVariablePluginValues","SORT_METHODS","DEFAULT_MAX_PREVIEW_VALUES","VariablePreview","props","values","isLoading","error","maxValues","setMaxValues","infoSnackbar","showAll","undefined","notShown","length","variablePreviewState","width","sx","alignItems","justifyContent","severity","direction","spacing","mb","variant","description","copyVariableValues","onClick","navigator","clipboard","writeText","map","value","join","size","display","flexWrap","gap","m","slice","val","index","label","VariableListPreview","definition","sortMethod","data","isFetching","errorMessage","message","result","sort","variablePreview"],"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,SAAuBC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAC/D,SAASC,KAAK,EAAEC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,gBAAgB,EAAEC,UAAU,EAAEC,KAAK,EAAEC,UAAU,QAAQ,gBAAgB;AACxG,SAASC,WAAW,EAAEC,WAAW,QAAQ,yBAAyB;AAClE,OAAOC,eAAe,mCAAmC;AAEzD,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,2BAA2B,QAAQ,oBAAoB;AAChE,SAASC,YAAY,QAAQ,+BA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BAAQC,UAAU;wBAAQC,KAAK;wBAAGC,GAAG;oBAAE;;wBACxDvB;wBACAV,QAAQkC,MAAM,GAAG/B,WAAWuB,IAAI,CAACS,KAAKC,sBAAU,KAAClD;gCAAK2C,MAAK;gCAAoBQ,OAAOF;+BAAdC;wBACxE5B,WAAW,mBAAK,KAACtB;4BAAKoC,SAAShB;4BAASa,SAAQ;4BAAWU,MAAK;4BAAQQ,OAAO,CAAC,CAAC,EAAE7B,SAAS,KAAK,CAAC;;;;;;;AAK7G;AAOA,OAAO,SAAS8B,oBAAoBvC,KAA+B;IACjE,MAAM,EAAEwC,UAAU,EAAEC,UAAU,EAAE,GAAGzC;IACnC,MAAM,EAAE0C,IAAI,EAAEC,UAAU,EAAExC,KAAK,EAAE,GAAGP,4BAA4B4C;IAChE,MAAMI,eAAgBzC,OAAiB0C;IAEvC,MAAMC,SAAS,CAACL,cAAcA,eAAe,UAAU,CAACC,OAAOA,OAAO7C,YAAY,CAAC4C,WAAW,CAACM,IAAI,CAACL;IAEpG,MAAMM,kBAAkBlE,QACtB,kBACE,KAACiB;YACCE,QAAQ6C,QAAQnB,IAAI,CAACS,MAAQA,IAAIE,KAAK,IAAIF,IAAIR,KAAK;YACnD1B,WAAWyC;YACXxC,OAAOyC;YAGX;QAACA;QAAcD;QAAYG;KAAO;IAGpC,OAAOE;AACT"}
@@ -1,3 +1,4 @@
1
1
  export * from './VariableEditorForm';
2
2
  export * from './VariablePreview';
3
+ export * from './variable-editor-form-model';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Variables/VariableEditorForm/index.ts"],"names":[],"mappings":"AAaA,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Variables/VariableEditorForm/index.ts"],"names":[],"mappings":"AAaA,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC"}
@@ -12,5 +12,6 @@
12
12
  // limitations under the License.
13
13
  export * from './VariableEditorForm';
14
14
  export * from './VariablePreview';
15
+ export * from './variable-editor-form-model';
15
16
 
16
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/Variables/VariableEditorForm/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './VariableEditorForm';\nexport * from './VariablePreview';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,uBAAuB;AACrC,cAAc,oBAAoB"}
1
+ {"version":3,"sources":["../../../../src/components/Variables/VariableEditorForm/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './VariableEditorForm';\nexport * from './VariablePreview';\nexport * from './variable-editor-form-model';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,uBAAuB;AACrC,cAAc,oBAAoB;AAClC,cAAc,+BAA+B"}
@@ -1,4 +1,10 @@
1
1
  import { ListVariableSpec, TextVariableSpec, VariableDefinition } from '@perses-dev/core';
2
+ import { VariableOption } from '../../../model';
3
+ export type SortMethodName = 'none' | 'alphabetical-asc' | 'alphabetical-desc' | 'numerical-asc' | 'numerical-desc' | 'alphabetical-ci-asc' | 'alphabetical-ci-desc';
4
+ export declare const SORT_METHODS: Record<SortMethodName, {
5
+ label: string;
6
+ sort: (input: VariableOption[]) => VariableOption[];
7
+ }>;
2
8
  export type VariableEditorState = {
3
9
  name: string;
4
10
  title?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"variable-editor-form-model.d.ts","sourceRoot":"","sources":["../../../../src/components/Variables/VariableEditorForm/variable-editor-form-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAA0B,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAElH,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,cAAc,GAAG,cAAc,GAAG,iBAAiB,CAAC;IAC1D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAC/D,kBAAkB,EAAE,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CAChE,CAAC;AAEF,wBAAgB,eAAe,CAAC,yBAAyB,EAAE,kBAAkB,GAAG,mBAAmB,CAkClG;AAED,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,mBAAmB,GAAG,kBAAkB,CAgC7F"}
1
+ {"version":3,"file":"variable-editor-form-model.d.ts","sourceRoot":"","sources":["../../../../src/components/Variables/VariableEditorForm/variable-editor-form-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAA0B,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAClH,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,MAAM,cAAc,GACtB,MAAM,GACN,kBAAkB,GAClB,mBAAmB,GACnB,eAAe,GACf,gBAAgB,GAChB,qBAAqB,GACrB,sBAAsB,CAAC;AAE3B,eAAO,MAAM,YAAY,EAAE,MAAM,CAC/B,cAAc,EACd;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,CAAA;CAAE,CA4CvE,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,cAAc,GAAG,cAAc,GAAG,iBAAiB,CAAC;IAC1D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAC/D,kBAAkB,EAAE,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CAChE,CAAC;AAEF,wBAAgB,eAAe,CAAC,yBAAyB,EAAE,kBAAkB,GAAG,mBAAmB,CAkClG;AAED,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,mBAAmB,GAAG,kBAAkB,CAgC7F"}
@@ -10,6 +10,50 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
+ export const SORT_METHODS = {
14
+ none: {
15
+ label: 'None',
16
+ sort: (input)=>{
17
+ return input.slice();
18
+ }
19
+ },
20
+ 'alphabetical-asc': {
21
+ label: 'Alphabetical, asc',
22
+ sort: (input)=>{
23
+ return input.slice().sort((a, b)=>a.label > b.label ? 1 : -1);
24
+ }
25
+ },
26
+ 'alphabetical-desc': {
27
+ label: 'Alphabetical, desc',
28
+ sort: (input)=>{
29
+ return input.slice().sort((a, b)=>a.label > b.label ? -1 : 1);
30
+ }
31
+ },
32
+ 'numerical-asc': {
33
+ label: 'Numerical, asc',
34
+ sort: (input)=>{
35
+ return input.slice().sort((a, b)=>parseInt(a.label) > parseInt(b.label) ? 1 : -1);
36
+ }
37
+ },
38
+ 'numerical-desc': {
39
+ label: 'Numerical, desc',
40
+ sort: (input)=>{
41
+ return input.slice().sort((a, b)=>parseInt(a.label) < parseInt(b.label) ? 1 : -1);
42
+ }
43
+ },
44
+ 'alphabetical-ci-asc': {
45
+ label: 'Alphabetical, case-insensitive, asc',
46
+ sort: (input)=>{
47
+ return input.slice().sort((a, b)=>a.label.toLowerCase() > b.label.toLowerCase() ? 1 : -1);
48
+ }
49
+ },
50
+ 'alphabetical-ci-desc': {
51
+ label: 'Alphabetical, case-insensitive, desc',
52
+ sort: (input)=>{
53
+ return input.slice().sort((a, b)=>a.label.toLowerCase() > b.label.toLowerCase() ? -1 : 1);
54
+ }
55
+ }
56
+ };
13
57
  export function getInitialState(initialVariableDefinition) {
14
58
  const textVariableFields = {
15
59
  value: initialVariableDefinition.spec.value ?? '',