From 47f05d96aa204a65ac7fbf87f515671226f25fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20M=C3=B8ller=20Jensen?= <26099018+JesmoDev@users.noreply.github.com> Date: Wed, 15 Mar 2023 21:09:14 +1300 Subject: [PATCH 1/2] entity mock save now accepts an item instead of an array --- .../src/core/mocks/data/entity.data.ts | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/core/mocks/data/entity.data.ts b/src/Umbraco.Web.UI.Client/src/core/mocks/data/entity.data.ts index 29d9fc8f09..58d730e6d4 100644 --- a/src/Umbraco.Web.UI.Client/src/core/mocks/data/entity.data.ts +++ b/src/Umbraco.Web.UI.Client/src/core/mocks/data/entity.data.ts @@ -10,7 +10,7 @@ export class UmbEntityData extends UmbData { getList(skip: number, take: number) { return this.data.slice(skip, skip + take); } - + getByKey(key: string) { return this.data.find((item) => item.key === key); } @@ -19,20 +19,18 @@ export class UmbEntityData extends UmbData { return this.data.filter((item) => keys.includes(item.key)); } - save(saveItems: Array) { - saveItems.forEach((saveItem) => { - const foundIndex = this.data.findIndex((item) => item.key === saveItem.key); - if (foundIndex !== -1) { - // update - this.data[foundIndex] = saveItem; - this.updateData(saveItem); - } else { - // new - this.data.push(saveItem); - } - }); + save(saveItem: T) { + const foundIndex = this.data.findIndex((item) => item.key === saveItem.key); + if (foundIndex !== -1) { + // update + this.data[foundIndex] = saveItem; + this.updateData(saveItem); + } else { + // new + this.data.push(saveItem); + } - return saveItems; + return saveItem; } move(keys: Array, destinationKey: string) { From 5793c4d4dad3b158e44d7d0230bf056977d78cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20M=C3=B8ller=20Jensen?= <26099018+JesmoDev@users.noreply.github.com> Date: Mon, 20 Mar 2023 16:13:27 +1300 Subject: [PATCH 2/2] mocks now saves a single item instead of array --- .../src/core/mocks/domains/dictionary.handlers.ts | 6 +++--- .../src/core/mocks/domains/document-type.handlers.ts | 4 ++-- .../src/core/mocks/domains/users.handlers.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/core/mocks/domains/dictionary.handlers.ts b/src/Umbraco.Web.UI.Client/src/core/mocks/domains/dictionary.handlers.ts index ba47b8ec0b..77a3a72942 100644 --- a/src/Umbraco.Web.UI.Client/src/core/mocks/domains/dictionary.handlers.ts +++ b/src/Umbraco.Web.UI.Client/src/core/mocks/domains/dictionary.handlers.ts @@ -92,7 +92,7 @@ export const handlers = [ }, ]; - const value = umbDictionaryData.save([data])[0]; + const value = umbDictionaryData.save(data); const createdResult = { value, @@ -110,7 +110,7 @@ export const handlers = [ if (!key) return; const dataToSave = JSON.parse(data[0].value); - const saved = umbDictionaryData.save([dataToSave]); + const saved = umbDictionaryData.save(dataToSave); return res(ctx.status(200), ctx.json(saved)); }), @@ -182,7 +182,7 @@ export const handlers = [ if (!file) return; importResponse.parentKey = req.url.searchParams.get('parentId') ?? null; - umbDictionaryData.save([importResponse]); + umbDictionaryData.save(importResponse); // build the path to the new item => reflects the expected server response const path = ['-1']; diff --git a/src/Umbraco.Web.UI.Client/src/core/mocks/domains/document-type.handlers.ts b/src/Umbraco.Web.UI.Client/src/core/mocks/domains/document-type.handlers.ts index 02fd203f22..2a35512574 100644 --- a/src/Umbraco.Web.UI.Client/src/core/mocks/domains/document-type.handlers.ts +++ b/src/Umbraco.Web.UI.Client/src/core/mocks/domains/document-type.handlers.ts @@ -4,7 +4,7 @@ import type { DocumentTypeResponseModel } from '@umbraco-cms/backend-api'; // TODO: add schema export const handlers = [ - rest.post('/umbraco/management/api/v1/document-type/:key', (req, res, ctx) => { + rest.post('/umbraco/management/api/v1/document-type/:key', (req, res, ctx) => { const data = req.body; if (!data) return; @@ -22,7 +22,7 @@ export const handlers = [ return res(ctx.status(200), ctx.json([document])); }), - rest.post('/umbraco/management/api/v1/document-type/details/save', (req, res, ctx) => { + rest.post('/umbraco/management/api/v1/document-type/details/save', (req, res, ctx) => { const data = req.body; if (!data) return; diff --git a/src/Umbraco.Web.UI.Client/src/core/mocks/domains/users.handlers.ts b/src/Umbraco.Web.UI.Client/src/core/mocks/domains/users.handlers.ts index e6b8cea1fc..52f405beb1 100644 --- a/src/Umbraco.Web.UI.Client/src/core/mocks/domains/users.handlers.ts +++ b/src/Umbraco.Web.UI.Client/src/core/mocks/domains/users.handlers.ts @@ -66,7 +66,7 @@ export const handlers = [ mediaStartNodes: [], }; - const invited = umbUsersData.save([newUser]); + const invited = umbUsersData.save(newUser); console.log('invited', invited);