fix(webui): ordering of attributes in Selector

fix/notes-editor
Tomáš Mládek 2024-01-28 15:24:37 +01:00
parent b78d1be240
commit de9f808b7a
1 changed files with 9 additions and 2 deletions

View File

@ -232,12 +232,13 @@
}
if (types.includes('Attribute')) {
let selectorOptions: SelectorOption[] = [];
const allAttributes = await api.fetchAllAttributes({ abortController });
const attributes = attributeOptions
? allAttributes.filter((attr) => attributeOptions!.includes(attr.name))
: allAttributes;
if (emptyOptions === undefined || query.length > 0) {
result.push(
selectorOptions.push(
...attributes
.filter(
(attr) =>
@ -254,6 +255,10 @@
);
}
selectorOptions = matchSorter(selectorOptions, inputValue, {
keys: [(i) => (i.t === 'Attribute' && i.labels) || [], 'name']
});
const attributeToCreate = query.toUpperCase().replaceAll(/[^A-Z0-9]/g, '_');
if (
!attributeOptions &&
@ -261,12 +266,14 @@
!allAttributes.map((attr) => attr.name).includes(attributeToCreate) &&
types.includes('NewAttribute')
) {
result.push({
selectorOptions.push({
t: 'NewAttribute',
name: attributeToCreate,
label: query
});
}
result.push(...selectorOptions);
}
} catch (e: unknown) {
if (e && (e as Error).name !== 'AbortError') {