Skip to content

Commit

Permalink
fix: editorInterface methods do not reset custom editor extension (#181)
Browse files Browse the repository at this point in the history
* fix: editorInterface methods do not reset custom editor extension

* Addressed PR comments
  • Loading branch information
Alexander Suevalov authored and Khaledgarbaya committed May 2, 2019
1 parent 0abfeb3 commit e93634a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
28 changes: 19 additions & 9 deletions src/lib/entities/content-type.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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
}
}

Expand Down
16 changes: 12 additions & 4 deletions src/lib/interfaces/content-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -67,5 +74,6 @@ export {
APIEditorInterfaces,
APIEditorInterfaceControl,
APIEditorInterfaceSettings,
APIEditorInterfaceSidebar
APIEditorInterfaceSidebar,
APIEditorIntefaceEditor
}
3 changes: 2 additions & 1 deletion test/unit/lib/offline-api/build-payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const buildPayloads = async function (runMigration, contentTypes: APIContentType
version: 1
},
controls: [],
sidebar: undefined
sidebar: undefined,
editor: undefined
})
const editorInterfacesByContentType: Map<String, EditorInterfaces> = new Map()

Expand Down

0 comments on commit e93634a

Please sign in to comment.