style(webui): reorder options in selector

refactor/sveltekit
Tomáš Mládek 2023-11-26 22:52:57 +01:00
parent 2c75a76446
commit 1890b29624
1 changed files with 43 additions and 43 deletions

View File

@ -146,49 +146,6 @@
return;
}
if (types.includes("Attribute")) {
const allAttributes = await api.fetchAllAttributes();
const attributes = attributeOptions
? allAttributes.filter((attr) => attributeOptions.includes(attr.name))
: allAttributes;
if (emptyOptions === undefined || query.length > 0) {
options.push(
...attributes
.filter(
(attr) =>
attr.name.toLowerCase().includes(query.toLowerCase()) ||
attr.labels.some((label) =>
label.toLowerCase().includes(query.toLowerCase()),
),
)
.map(
(attribute) =>
({
t: "Attribute",
...attribute,
}) as SelectorOption,
),
);
}
const attributeToCreate = query
.toUpperCase()
.replaceAll(/[^A-Z0-9]/g, "_");
if (
!attributeOptions &&
query &&
!allAttributes.map((attr) => attr.name).includes(attributeToCreate) &&
types.includes("NewAttribute")
) {
options.push({
t: "NewAttribute",
name: attributeToCreate,
label: query,
});
}
options = options;
}
if (types.includes("Number")) {
const number = parseFloat(query);
if (!Number.isNaN(number)) {
@ -255,6 +212,49 @@
);
}
if (types.includes("Attribute")) {
const allAttributes = await api.fetchAllAttributes();
const attributes = attributeOptions
? allAttributes.filter((attr) => attributeOptions.includes(attr.name))
: allAttributes;
if (emptyOptions === undefined || query.length > 0) {
options.push(
...attributes
.filter(
(attr) =>
attr.name.toLowerCase().includes(query.toLowerCase()) ||
attr.labels.some((label) =>
label.toLowerCase().includes(query.toLowerCase()),
),
)
.map(
(attribute) =>
({
t: "Attribute",
...attribute,
}) as SelectorOption,
),
);
}
const attributeToCreate = query
.toUpperCase()
.replaceAll(/[^A-Z0-9]/g, "_");
if (
!attributeOptions &&
query &&
!allAttributes.map((attr) => attr.name).includes(attributeToCreate) &&
types.includes("NewAttribute")
) {
options.push({
t: "NewAttribute",
name: attributeToCreate,
label: query,
});
}
options = options;
}
options = options;
}, 200);