mirror of
https://github.com/directus/directus.git
synced 2026-01-30 04:38:13 -05:00
Fix relational interfaces to return null when the array is empty after deselecting item(s) (#11765)
* Fix relational interfaces to return null on delete * add fix to m2a * fix treeview not clearing displayed list
This commit is contained in:
@@ -165,7 +165,7 @@ export default defineComponent({
|
||||
required: true,
|
||||
},
|
||||
value: {
|
||||
type: Array as PropType<any[]>,
|
||||
type: Array as PropType<any[] | null>,
|
||||
default: null,
|
||||
},
|
||||
disabled: {
|
||||
@@ -529,10 +529,13 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
function deselect(item: any) {
|
||||
emit(
|
||||
'input',
|
||||
(props.value || []).filter((current) => current !== item)
|
||||
);
|
||||
const newValue = (props.value || []).filter((current) => current !== item);
|
||||
|
||||
if (newValue.length === 0) {
|
||||
emit('input', null);
|
||||
} else {
|
||||
emit('input', newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,12 @@ export default function useActions(
|
||||
|
||||
return isEqual(item, deletingItem) === false;
|
||||
});
|
||||
emit(newValue);
|
||||
|
||||
if (newValue.length === 0) {
|
||||
emit(null);
|
||||
} else {
|
||||
emit(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -218,15 +218,20 @@ export default defineComponent({
|
||||
return result;
|
||||
}
|
||||
|
||||
function emitValue(value: Record<string, any>[]) {
|
||||
stagedValues.value = value;
|
||||
function emitValue(value: Record<string, any>[] | null) {
|
||||
if (!value || value.length === 0) {
|
||||
stagedValues.value = [];
|
||||
emit('input', null);
|
||||
} else {
|
||||
stagedValues.value = value;
|
||||
|
||||
if (relation.value.meta?.sort_field) {
|
||||
return emit('input', addSort(value));
|
||||
if (relation.value.meta?.sort_field) {
|
||||
return emit('input', addSort(value));
|
||||
}
|
||||
|
||||
emit('input', value);
|
||||
}
|
||||
|
||||
emit('input', value);
|
||||
|
||||
function addSort(value: Record<string, any>[]): Record<string, any>[] {
|
||||
return (value || []).map((item, index) => {
|
||||
return {
|
||||
@@ -315,7 +320,7 @@ export default defineComponent({
|
||||
|
||||
const newVal = [...response.data.data, ...stagedValues.value];
|
||||
|
||||
if (newVal.length === 0) emitValue([]);
|
||||
if (newVal.length === 0) emitValue(null);
|
||||
else emitValue(newVal);
|
||||
|
||||
loading.value = false;
|
||||
|
||||
@@ -259,16 +259,19 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
const id = item[relatedPrimKey];
|
||||
emit(
|
||||
'input',
|
||||
props.value.filter((item) => {
|
||||
if (typeof item === 'number' || typeof item === 'string') return item !== id;
|
||||
if (typeof item === 'object' && relatedPrimKey in item) {
|
||||
return item[relatedPrimKey] !== id;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
);
|
||||
const newValue = props.value.filter((item) => {
|
||||
if (typeof item === 'number' || typeof item === 'string') return item !== id;
|
||||
if (typeof item === 'object' && relatedPrimKey in item) {
|
||||
return item[relatedPrimKey] !== id;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (newValue.length === 0) {
|
||||
emit('input', null);
|
||||
} else {
|
||||
emit('input', newValue);
|
||||
}
|
||||
}
|
||||
|
||||
function useSort() {
|
||||
|
||||
Reference in New Issue
Block a user