Refactor alias selection logic in AliasFilterSelect component
Publish telemt-api gateway Docker image / test (push) Successful in 26s
Publish telemt-api gateway Docker image / build-and-push (push) Successful in 2m11s

- Simplified the internal state management for alias selection, ensuring the selected value is consistent with available aliases.
- Updated the effect handling to directly modify the `value` prop based on alias availability, improving responsiveness.
- Streamlined the binding in the Select component to enhance the alias selection process.
This commit is contained in:
Denozordec
2026-03-30 23:08:37 +07:00
parent 4be07fc242
commit ce2a7ed43e
@@ -13,26 +13,21 @@
allLabel?: string; allLabel?: string;
} = $props(); } = $props();
let internalValue = $state(value ?? "all");
$effect(() => { $effect(() => {
const next = value ?? "all"; if ((value ?? "all") !== "all" && !availableAliases.includes(value ?? "all")) {
if (internalValue !== next) internalValue = next; value = "all";
}); }
if (!value) {
$effect(() => { value = "all";
if (internalValue !== "all" && !availableAliases.includes(internalValue)) {
internalValue = "all";
} }
if (value !== internalValue) value = internalValue;
}); });
let selectedLabel = $derived(internalValue === "all" ? allLabel : internalValue); let selectedLabel = $derived((value ?? "all") === "all" ? allLabel : (value ?? "all"));
</script> </script>
<label class="text-xs text-muted-foreground"> <label class="text-xs text-muted-foreground">
{label} {label}
<Select.Root type="single" bind:value={internalValue}> <Select.Root type="single" bind:value>
<Select.Trigger class="mt-1 w-[220px]"> <Select.Trigger class="mt-1 w-[220px]">
{selectedLabel} {selectedLabel}
</Select.Trigger> </Select.Trigger>