From e93634af41633f788c542ff8029a9ae9305a0efc Mon Sep 17 00:00:00 2001 From: Alexander Suevalov Date: Thu, 2 May 2019 10:50:37 +0200 Subject: [PATCH] fix: editorInterface methods do not reset custom editor extension (#181) * fix: editorInterface methods do not reset custom editor extension * Addressed PR comments --- src/lib/entities/content-type.ts | 28 ++++++++++++++------- src/lib/interfaces/content-type.ts | 16 +++++++++--- test/unit/lib/offline-api/build-payloads.ts | 3 ++- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/lib/entities/content-type.ts b/src/lib/entities/content-type.ts index 1c3ef3ef0..2005becb6 100644 --- a/src/lib/entities/content-type.ts +++ b/src/lib/entities/content-type.ts @@ -1,4 +1,4 @@ -import { APIContentType, Field, APIEditorInterfaceControl, APIEditorInterfaces, APIEditorInterfaceSettings, APIEditorInterfaceSidebar } from '../interfaces/content-type' +import { APIContentType, Field, APIEditorInterfaceControl, APIEditorInterfaces, APIEditorInterfaceSettings, APIEditorInterfaceSidebar, APIEditorIntefaceEditor } from '../interfaces/content-type' import { cloneDeep, find, filter, findIndex, pull, forEach } from 'lodash' class Fields { @@ -82,11 +82,13 @@ class EditorInterfaces { private _version: number private _controls: APIEditorInterfaceControl[] private _sidebar?: APIEditorInterfaceSidebar[] + private _editor?: APIEditorIntefaceEditor constructor (apiEditorInterfaces: APIEditorInterfaces) { this._version = apiEditorInterfaces.sys.version this._controls = apiEditorInterfaces.controls this._sidebar = apiEditorInterfaces.sidebar || undefined + this._editor = apiEditorInterfaces.editor || undefined } get version () { @@ -140,23 +142,31 @@ class EditorInterfaces { } toAPI (): object { - let result: APIEditorInterfaceControl[] = [] + let controls: APIEditorInterfaceControl[] = [] forEach(this._controls, (c) => { - result.push({ + controls.push({ fieldId: c.fieldId, widgetId: c.widgetId, settings: c.settings }) }) + + const result: { + controls: APIEditorInterfaceControl[], + sidebar?: APIEditorInterfaceSidebar[], + editor?: APIEditorIntefaceEditor + } = { + controls + } + if (this._sidebar) { - return { - controls: result, - sidebar: this._sidebar - } + result.sidebar = this._sidebar } - return { - controls: result + if (this._editor) { + result.editor = this._editor } + + return result } } diff --git a/src/lib/interfaces/content-type.ts b/src/lib/interfaces/content-type.ts index 65648e4f7..2c893548c 100644 --- a/src/lib/interfaces/content-type.ts +++ b/src/lib/interfaces/content-type.ts @@ -52,12 +52,19 @@ interface APIEditorInterfaceSidebar { settings?: { [key: string]: any } } +interface APIEditorIntefaceEditor { + widgetId: string, + widgetNamespace: 'builtin' | 'extension', + settings?: { [key: string]: any } +} + interface APIEditorInterfaces { sys: { version: number - } - controls: APIEditorInterfaceControl[] - sidebar?: APIEditorInterfaceSidebar[] + }, + controls: APIEditorInterfaceControl[], + sidebar?: APIEditorInterfaceSidebar[], + editor?: APIEditorIntefaceEditor } export { @@ -67,5 +74,6 @@ export { APIEditorInterfaces, APIEditorInterfaceControl, APIEditorInterfaceSettings, - APIEditorInterfaceSidebar + APIEditorInterfaceSidebar, + APIEditorIntefaceEditor } diff --git a/test/unit/lib/offline-api/build-payloads.ts b/test/unit/lib/offline-api/build-payloads.ts index 3c98f8a06..052d75b8b 100644 --- a/test/unit/lib/offline-api/build-payloads.ts +++ b/test/unit/lib/offline-api/build-payloads.ts @@ -17,7 +17,8 @@ const buildPayloads = async function (runMigration, contentTypes: APIContentType version: 1 }, controls: [], - sidebar: undefined + sidebar: undefined, + editor: undefined }) const editorInterfacesByContentType: Map = new Map()