fix(ui): repair settings editing and workflow diagnostics
This commit is contained in:
1 parent
3229de9b3b
commit
41cd938748
46 files changed
+708
-240
No files matched your search
@@ -14,50 +14,57 @@ const props = defineProps<{ id?: string; disabled?: boolean; units?: DurationUni
|
||||
const model = defineModel<string>({ required: true });
|
||||
|
||||
const units = computed(() => props.units ?? DURATION_UNITS);
|
||||
const amount = ref(0);
|
||||
const amount = ref<string | number>(0);
|
||||
const invalid = computed(() => amount.value !== "" && (!Number.isFinite(Number(amount.value)) || Number(amount.value) < 0));
|
||||
const unit = ref<DurationUnit>("s");
|
||||
|
||||
watch(
|
||||
model,
|
||||
(text) => {
|
||||
const ms = parseGoDuration(text ?? "");
|
||||
if (ms === null) return;
|
||||
if (joinDuration(amount.value, unit.value) === ms) return;
|
||||
if (ms === null) { amount.value = text ?? ""; return; }
|
||||
if (amount.value !== "" && !invalid.value && joinDuration(Number(amount.value), unit.value) === ms) return;
|
||||
const split = splitDuration(ms);
|
||||
amount.value = split.value;
|
||||
unit.value = units.value.includes(split.unit) ? split.unit : "ms";
|
||||
unit.value = units.value.includes(split.unit) ? split.unit : (units.value[0] ?? "s");
|
||||
amount.value = ms / joinDuration(1, unit.value);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
function emitChange() {
|
||||
if (!Number.isFinite(amount.value) || amount.value < 0) return;
|
||||
model.value = formatGoDuration(joinDuration(amount.value, unit.value));
|
||||
if (amount.value === "" || invalid.value) {
|
||||
model.value = String(amount.value);
|
||||
return;
|
||||
}
|
||||
model.value = formatGoDuration(joinDuration(Number(amount.value), unit.value));
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<InputGroup class="w-48">
|
||||
<InputGroupInput
|
||||
:id="id"
|
||||
v-model.number="amount"
|
||||
type="number"
|
||||
min="0"
|
||||
inputmode="decimal"
|
||||
class="font-mono"
|
||||
:disabled="disabled"
|
||||
@change="emitChange"
|
||||
/>
|
||||
<InputGroupAddon align="inline-end">
|
||||
<select
|
||||
v-model="unit"
|
||||
aria-label="Unit"
|
||||
class="bg-transparent font-mono text-xs text-muted-foreground outline-none"
|
||||
<div class="w-48">
|
||||
<InputGroup>
|
||||
<InputGroupInput
|
||||
:id="id"
|
||||
:model-value="amount"
|
||||
type="text"
|
||||
:aria-invalid="invalid ? true : undefined"
|
||||
@update:model-value="(value: string | number) => { amount = value; emitChange(); }"
|
||||
inputmode="decimal"
|
||||
class="font-mono"
|
||||
:disabled="disabled"
|
||||
@change="emitChange"
|
||||
>
|
||||
<option v-for="u in units" :key="u" :value="u">{{ u }}</option>
|
||||
</select>
|
||||
</InputGroupAddon>
|
||||
</InputGroup>
|
||||
/>
|
||||
<InputGroupAddon align="inline-end">
|
||||
<select
|
||||
v-model="unit"
|
||||
aria-label="Unit"
|
||||
class="bg-transparent font-mono text-xs text-muted-foreground outline-none"
|
||||
:disabled="disabled"
|
||||
@change="emitChange"
|
||||
>
|
||||
<option v-for="u in units" :key="u" :value="u">{{ u }}</option>
|
||||
</select>
|
||||
</InputGroupAddon>
|
||||
</InputGroup>
|
||||
<p v-if="invalid" role="alert" class="mt-1 text-xs text-danger">Enter a number zero or greater.</p>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user