mirror of
https://github.com/directus/directus.git
synced 2026-01-27 10:08:04 -05:00
This commit is contained in:
@@ -223,46 +223,6 @@ describe('test o2m relation', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
test('updating an item twice without $index', async () => {
|
||||
const wrapper = mount(TestComponent, {
|
||||
props: { relation: relationO2M, value: [], id: 1 },
|
||||
});
|
||||
|
||||
wrapper.vm.update({ id: 2, name: 'test2-edited' });
|
||||
wrapper.vm.update({ id: 2, name: 'test2-edited again' });
|
||||
|
||||
await flushPromises();
|
||||
|
||||
const changes = cloneDeep(workerData);
|
||||
changes.splice(1, 1, { id: 2, name: 'test2-edited again', facility: 1, $edits: 0, $type: 'updated', $index: 0 });
|
||||
|
||||
expect(wrapper.vm.displayItems).toEqual(changes);
|
||||
expect(wrapper.emitted()['update:value'][0]).toEqual([
|
||||
{
|
||||
create: [],
|
||||
update: [
|
||||
{
|
||||
id: 2,
|
||||
name: 'test2-edited',
|
||||
},
|
||||
],
|
||||
delete: [],
|
||||
},
|
||||
]);
|
||||
expect(wrapper.emitted()['update:value'][1]).toEqual([
|
||||
{
|
||||
create: [],
|
||||
update: [
|
||||
{
|
||||
id: 2,
|
||||
name: 'test2-edited again',
|
||||
},
|
||||
],
|
||||
delete: [],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('removing an item', async () => {
|
||||
const wrapper = mount(TestComponent, {
|
||||
props: { relation: relationO2M, value: [], id: 1 },
|
||||
|
||||
@@ -206,22 +206,7 @@ export function useRelationMultiple(
|
||||
function update(...items: DisplayItem[]) {
|
||||
if (!relation.value) return;
|
||||
|
||||
const targetPKField =
|
||||
relation.value.type === 'o2m'
|
||||
? relation.value.relatedPrimaryKeyField.field
|
||||
: relation.value.junctionPrimaryKeyField.field;
|
||||
|
||||
for (const item of items) {
|
||||
const editsIndex =
|
||||
item.$index ??
|
||||
target.value.update.findIndex(
|
||||
(edit: any) => typeof edit === 'object' && edit[targetPKField] === item[targetPKField]
|
||||
);
|
||||
if (item.$index === undefined && editsIndex !== -1) {
|
||||
item.$index = editsIndex;
|
||||
item.$type = 'updated';
|
||||
}
|
||||
|
||||
if (item.$type === undefined || item.$index === undefined) {
|
||||
target.value.update.push(cleanItem(item));
|
||||
} else if (item.$type === 'created') {
|
||||
|
||||
Reference in New Issue
Block a user