Skip to content

Commit

Permalink
fix: editorInterface methods do not reset custom sidebar anymore (#175)
Browse files Browse the repository at this point in the history
`editorInterface` payload can have custom sidebar configuration saved. Currently all related methods just override `sidebar` configuration. This PR fixes the behavior, so if `sidebar` configuration isn't overwritten if present in the initial payload.
  • Loading branch information
suevalov authored and Khaledgarbaya committed Mar 27, 2019
1 parent 2728f82 commit e2d5bb2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
10 changes: 9 additions & 1 deletion 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 } from '../interfaces/content-type'
import { APIContentType, Field, APIEditorInterfaceControl, APIEditorInterfaces, APIEditorInterfaceSettings, APIEditorInterfaceSidebar } from '../interfaces/content-type'
import { cloneDeep, find, filter, findIndex, pull, forEach } from 'lodash'

class Fields {
Expand Down Expand Up @@ -81,10 +81,12 @@ class Fields {
class EditorInterfaces {
private _version: number
private _controls: APIEditorInterfaceControl[]
private _sidebar?: APIEditorInterfaceSidebar[]

constructor (apiEditorInterfaces: APIEditorInterfaces) {
this._version = apiEditorInterfaces.sys.version
this._controls = apiEditorInterfaces.controls
this._sidebar = apiEditorInterfaces.sidebar || undefined
}

get version () {
Expand Down Expand Up @@ -146,6 +148,12 @@ class EditorInterfaces {
settings: c.settings
})
})
if (this._sidebar) {
return {
controls: result,
sidebar: this._sidebar
}
}
return {
controls: result
}
Expand Down
14 changes: 12 additions & 2 deletions src/lib/interfaces/content-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,24 @@ interface APIEditorInterfaceSettings {

interface APIEditorInterfaceControl {
fieldId: string,
widgetId: string,
widgetId?: string,
widgetNamespace?: 'builtin' | 'extension',
settings?: APIEditorInterfaceSettings
}

interface APIEditorInterfaceSidebar {
widgetId: string,
widgetNamespace: 'builtin' | 'extension',
disabled?: boolean,
settings?: { [key: string]: any }
}

interface APIEditorInterfaces {
sys: {
version: number
}
controls: APIEditorInterfaceControl[]
sidebar?: APIEditorInterfaceSidebar[]
}

export {
Expand All @@ -57,5 +66,6 @@ export {
Field,
APIEditorInterfaces,
APIEditorInterfaceControl,
APIEditorInterfaceSettings
APIEditorInterfaceSettings,
APIEditorInterfaceSidebar
}
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 @@ -16,7 +16,8 @@ const buildPayloads = async function (runMigration, contentTypes: APIContentType
sys: {
version: 1
},
controls: []
controls: [],
sidebar: undefined
})
const editorInterfacesByContentType: Map<String, EditorInterfaces> = new Map()

Expand Down

0 comments on commit e2d5bb2

Please sign in to comment.