From 28080687c286d8fe3f55a409bdf3b7a8d2720a0f Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 27 Sep 2022 12:43:37 +0200 Subject: [PATCH] remove property editor alias from config response --- src/Umbraco.Web.UI.Client/schemas/api/api.yml | 3 --- .../schemas/generated-schema.ts | 1 - .../property-editor-config.store.ts | 22 +++++++++++++------ .../mocks/domains/property-editor.handlers.ts | 8 ++----- .../temp-schema-generator/property-editors.ts | 4 +--- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/schemas/api/api.yml b/src/Umbraco.Web.UI.Client/schemas/api/api.yml index 3f954a9547..c3e9670ea8 100644 --- a/src/Umbraco.Web.UI.Client/schemas/api/api.yml +++ b/src/Umbraco.Web.UI.Client/schemas/api/api.yml @@ -962,8 +962,6 @@ components: PropertyEditorConfigResponse: type: object properties: - propertyEditorAlias: - type: string properties: type: array items: @@ -971,7 +969,6 @@ components: defaultConfig: type: object required: - - propertyEditorAlias - properties ServerStatus: type: string diff --git a/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts b/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts index efbe58b664..82d2240c70 100644 --- a/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts +++ b/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts @@ -322,7 +322,6 @@ export interface components { config?: components["schemas"]["PropertyEditorConfig"]; }; PropertyEditorConfigResponse: { - propertyEditorAlias: string; properties: components["schemas"]["PropertyEditorConfigProperty"][]; defaultConfig?: { [key: string]: unknown }; }; diff --git a/src/Umbraco.Web.UI.Client/src/core/stores/property-editor-config/property-editor-config.store.ts b/src/Umbraco.Web.UI.Client/src/core/stores/property-editor-config/property-editor-config.store.ts index 3c535a25eb..53932e2819 100644 --- a/src/Umbraco.Web.UI.Client/src/core/stores/property-editor-config/property-editor-config.store.ts +++ b/src/Umbraco.Web.UI.Client/src/core/stores/property-editor-config/property-editor-config.store.ts @@ -2,15 +2,23 @@ import { BehaviorSubject, map, Observable } from 'rxjs'; import { getPropertyEditorConfig } from '../../api/fetcher'; import type { PropertyEditorConfig } from '../../models'; -export class UmbPropertyEditorConfigStore { - private _items: BehaviorSubject> = new BehaviorSubject(>[]); - public readonly items: Observable> = this._items.asObservable(); +export interface PropertyEditorConfigRef { + propertyEditorAlias: string; + config: PropertyEditorConfig; +} - getByAlias(alias: string): Observable { +export class UmbPropertyEditorConfigStore { + private _items: BehaviorSubject> = new BehaviorSubject( + >[] + ); + public readonly items: Observable> = this._items.asObservable(); + + getByAlias(alias: string): Observable { // TODO: only fetch if the data type is not in the store? getPropertyEditorConfig({ propertyEditorAlias: alias }) .then((res) => { - this.update([res.data]); + const propertyEditorConfigRef: PropertyEditorConfigRef = { propertyEditorAlias: alias, config: res.data }; + this.update([propertyEditorConfigRef]); }) .catch((err) => { console.log(err); @@ -19,9 +27,9 @@ export class UmbPropertyEditorConfigStore { return this.items.pipe(map((items) => items.find((item) => item.propertyEditorAlias === alias))); } - public update(updatedItems: Array) { + public update(updatedItems: Array) { const storedItems = this._items.getValue(); - const updated: PropertyEditorConfig[] = [...storedItems]; + const updated: PropertyEditorConfigRef[] = [...storedItems]; updatedItems.forEach((updatedItem) => { const index = storedItems diff --git a/src/Umbraco.Web.UI.Client/src/mocks/domains/property-editor.handlers.ts b/src/Umbraco.Web.UI.Client/src/mocks/domains/property-editor.handlers.ts index f39f0caa34..b7410401f0 100644 --- a/src/Umbraco.Web.UI.Client/src/mocks/domains/property-editor.handlers.ts +++ b/src/Umbraco.Web.UI.Client/src/mocks/domains/property-editor.handlers.ts @@ -37,12 +37,8 @@ export const handlers = [ if (!alias) return; const config = umbPropertyEditorData.getConfig(alias); + if (!config) return; - const response = { - propertyEditorAlias: alias, - config: config, - }; - - return res(ctx.status(200), ctx.json(response)); + return res(ctx.status(200), ctx.json(config)); }), ]; diff --git a/src/Umbraco.Web.UI.Client/temp-schema-generator/property-editors.ts b/src/Umbraco.Web.UI.Client/temp-schema-generator/property-editors.ts index 2eb7682a57..0fb5fa3384 100644 --- a/src/Umbraco.Web.UI.Client/temp-schema-generator/property-editors.ts +++ b/src/Umbraco.Web.UI.Client/temp-schema-generator/property-editors.ts @@ -50,9 +50,7 @@ export interface PropertyEditorsListResponse { export interface PropertyEditorResponse extends PropertyEditor {} -export interface PropertyEditorConfigResponse extends PropertyEditorConfig { - propertyEditorAlias: string; -} +export interface PropertyEditorConfigResponse extends PropertyEditorConfig {} export interface PropertyEditor { alias: string;