mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-03 16:20:27 +00:00
fix multiple selector bugs
This commit is contained in:
parent
63406747df
commit
f8140ac60e
3 changed files with 45 additions and 28 deletions
|
@ -45,6 +45,10 @@
|
||||||
type: String,
|
type: String,
|
||||||
default: "",
|
default: "",
|
||||||
},
|
},
|
||||||
|
compareKey: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const selectedIdx = ref(-1);
|
const selectedIdx = ref(-1);
|
||||||
|
@ -52,36 +56,34 @@
|
||||||
const internalSelected = useVModel(props, "modelValue", emit);
|
const internalSelected = useVModel(props, "modelValue", emit);
|
||||||
const internalValue = useVModel(props, "value", emit);
|
const internalValue = useVModel(props, "value", emit);
|
||||||
|
|
||||||
watch(selectedIdx, newVal => {
|
|
||||||
internalSelected.value = props.items[newVal];
|
|
||||||
});
|
|
||||||
|
|
||||||
watch(selectedIdx, newVal => {
|
|
||||||
if (props.valueKey) {
|
|
||||||
internalValue.value = props.items[newVal][props.valueKey];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
internalSelected,
|
selectedIdx,
|
||||||
() => {
|
newVal => {
|
||||||
const idx = props.items.findIndex(item => compare(item, internalSelected.value));
|
if (newVal === -1) {
|
||||||
selectedIdx.value = idx;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (props.value) {
|
||||||
|
internalValue.value = props.items[newVal][props.valueKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
internalSelected.value = props.items[newVal];
|
||||||
},
|
},
|
||||||
{
|
{ immediate: true }
|
||||||
immediate: true,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
internalValue,
|
[internalSelected, () => props.value],
|
||||||
() => {
|
() => {
|
||||||
const idx = props.items.findIndex(item => compare(item[props.valueKey], internalValue.value));
|
if (props.valueKey) {
|
||||||
|
const idx = props.items.findIndex(item => compare(item, internalValue.value));
|
||||||
|
selectedIdx.value = idx;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const idx = props.items.findIndex(item => compare(item, internalSelected.value));
|
||||||
selectedIdx.value = idx;
|
selectedIdx.value = idx;
|
||||||
},
|
},
|
||||||
{
|
{ immediate: true }
|
||||||
immediate: true,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
@ -90,8 +92,13 @@
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!a || !b) {
|
if (props.valueKey) {
|
||||||
return false;
|
return a[props.valueKey] === b;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try compare key
|
||||||
|
if (props.compareKey && a && b) {
|
||||||
|
return a[props.compareKey] === b[props.compareKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON.stringify(a) === JSON.stringify(b);
|
return JSON.stringify(a) === JSON.stringify(b);
|
||||||
|
|
|
@ -49,6 +49,7 @@ export interface ItemCreate {
|
||||||
/** Edges */
|
/** Edges */
|
||||||
locationId: string;
|
locationId: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
parentId: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ItemField {
|
export interface ItemField {
|
||||||
|
@ -63,10 +64,9 @@ export interface ItemField {
|
||||||
|
|
||||||
export interface ItemOut {
|
export interface ItemOut {
|
||||||
attachments: ItemAttachment[];
|
attachments: ItemAttachment[];
|
||||||
|
children: ItemSummary[];
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
description: string;
|
description: string;
|
||||||
|
|
||||||
/** Future */
|
|
||||||
fields: ItemField[];
|
fields: ItemField[];
|
||||||
id: string;
|
id: string;
|
||||||
insured: boolean;
|
insured: boolean;
|
||||||
|
@ -83,6 +83,7 @@ export interface ItemOut {
|
||||||
|
|
||||||
/** Extras */
|
/** Extras */
|
||||||
notes: string;
|
notes: string;
|
||||||
|
parent: ItemSummary | null;
|
||||||
purchaseFrom: string;
|
purchaseFrom: string;
|
||||||
|
|
||||||
/** @example 0 */
|
/** @example 0 */
|
||||||
|
@ -137,6 +138,7 @@ export interface ItemUpdate {
|
||||||
|
|
||||||
/** Extras */
|
/** Extras */
|
||||||
notes: string;
|
notes: string;
|
||||||
|
parentId: string | null;
|
||||||
purchaseFrom: string;
|
purchaseFrom: string;
|
||||||
|
|
||||||
/** @example 0 */
|
/** @example 0 */
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
refresh();
|
refresh();
|
||||||
});
|
});
|
||||||
|
@ -48,6 +49,7 @@
|
||||||
...item.value,
|
...item.value,
|
||||||
locationId: item.value.location?.id,
|
locationId: item.value.location?.id,
|
||||||
labelIds: item.value.labels.map(l => l.id),
|
labelIds: item.value.labels.map(l => l.id),
|
||||||
|
parentId: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { error } = await api.items.update(itemId.value, payload);
|
const { error } = await api.items.update(itemId.value, payload);
|
||||||
|
@ -314,8 +316,8 @@
|
||||||
<template #title> Attachment Edit </template>
|
<template #title> Attachment Edit </template>
|
||||||
|
|
||||||
<FormTextField v-model="editState.title" label="Attachment Title" />
|
<FormTextField v-model="editState.title" label="Attachment Title" />
|
||||||
|
{{ editState.type }}
|
||||||
<FormSelect
|
<FormSelect
|
||||||
v-model="editState.obj"
|
|
||||||
v-model:value="editState.type"
|
v-model:value="editState.type"
|
||||||
label="Attachment Type"
|
label="Attachment Type"
|
||||||
value-key="value"
|
value-key="value"
|
||||||
|
@ -354,7 +356,13 @@
|
||||||
</template>
|
</template>
|
||||||
</BaseSectionHeader>
|
</BaseSectionHeader>
|
||||||
<div class="px-5 mb-6 grid md:grid-cols-2 gap-4">
|
<div class="px-5 mb-6 grid md:grid-cols-2 gap-4">
|
||||||
<FormSelect v-if="item" v-model="item.location" label="Location" :items="locations ?? []" />
|
<FormSelect
|
||||||
|
v-if="item"
|
||||||
|
v-model="item.location"
|
||||||
|
label="Location"
|
||||||
|
:items="locations ?? []"
|
||||||
|
compare-key="id"
|
||||||
|
/>
|
||||||
<FormMultiselect v-model="item.labels" label="Labels" :items="labels ?? []" />
|
<FormMultiselect v-model="item.labels" label="Labels" :items="labels ?? []" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue