From 626e057e55587c5071e6054c973be0e61a9e9f3a Mon Sep 17 00:00:00 2001 From: Sergej-Vlasov Date: Tue, 24 Dec 2024 15:16:28 +0000 Subject: [PATCH] use correct option property for variable options sorting --- .../src/variables/variants/query/utils.ts | 57 +++++++++---------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/packages/scenes/src/variables/variants/query/utils.ts b/packages/scenes/src/variables/variants/query/utils.ts index 28f40c58b..eb48a0b51 100644 --- a/packages/scenes/src/variables/variants/query/utils.ts +++ b/packages/scenes/src/variables/variants/query/utils.ts @@ -74,40 +74,11 @@ const getAllMatches = (str: string, regex: RegExp): RegExpExecArray[] => { return results; }; -export const sortVariableValues = (options: any[], sortOrder: VariableSort) => { +export const sortVariableValues = (options: VariableValueOption[], sortOrder: VariableSort) => { if (sortOrder === VariableSort.disabled) { return options; } - // @ts-ignore - const sortByNumeric = (opt) => { - if (!opt.text) { - return -1; - } - const matches = opt.text.match(/.*?(\d+).*/); - if (!matches || matches.length < 2) { - return -1; - } else { - return parseInt(matches[1], 10); - } - }; - - // @ts-ignore - const sortByNaturalSort = (options) => { - //@ts-ignore - return options.sort((a, b) => { - if (!a.text) { - return -1; - } - - if (!b.text) { - return 1; - } - - return a.text.localeCompare(b.text, undefined, { numeric: true }); - }); - }; - switch (sortOrder) { case VariableSort.alphabeticalAsc: options = sortBy(options, 'label'); @@ -146,3 +117,29 @@ export const sortVariableValues = (options: any[], sortOrder: VariableSort) => { } return options; }; + +function sortByNumeric(opt: VariableValueOption) { + if (!opt.label) { + return -1; + } + const matches = opt.label.match(/.*?(\d+).*/); + if (!matches || matches.length < 2) { + return -1; + } else { + return parseInt(matches[1], 10); + } +} + +function sortByNaturalSort(options: VariableValueOption[]) { + return options.sort((a, b) => { + if (!a.label) { + return -1; + } + + if (!b.label) { + return 1; + } + + return a.label.localeCompare(b.label, undefined, { numeric: true }); + }); +}