Refactor alias selection logic in AliasFilterSelect component
- 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:
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user