Skip to content

Commit e2d5bb2

Browse files
suevalovKhaledgarbaya
authored andcommitted
fix: editorInterface methods do not reset custom sidebar anymore (#175)
`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.
1 parent 2728f82 commit e2d5bb2

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/lib/entities/content-type.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { APIContentType, Field, APIEditorInterfaceControl, APIEditorInterfaces, APIEditorInterfaceSettings } from '../interfaces/content-type'
1+
import { APIContentType, Field, APIEditorInterfaceControl, APIEditorInterfaces, APIEditorInterfaceSettings, APIEditorInterfaceSidebar } from '../interfaces/content-type'
22
import { cloneDeep, find, filter, findIndex, pull, forEach } from 'lodash'
33

44
class Fields {
@@ -81,10 +81,12 @@ class Fields {
8181
class EditorInterfaces {
8282
private _version: number
8383
private _controls: APIEditorInterfaceControl[]
84+
private _sidebar?: APIEditorInterfaceSidebar[]
8485

8586
constructor (apiEditorInterfaces: APIEditorInterfaces) {
8687
this._version = apiEditorInterfaces.sys.version
8788
this._controls = apiEditorInterfaces.controls
89+
this._sidebar = apiEditorInterfaces.sidebar || undefined
8890
}
8991

9092
get version () {
@@ -146,6 +148,12 @@ class EditorInterfaces {
146148
settings: c.settings
147149
})
148150
})
151+
if (this._sidebar) {
152+
return {
153+
controls: result,
154+
sidebar: this._sidebar
155+
}
156+
}
149157
return {
150158
controls: result
151159
}

src/lib/interfaces/content-type.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,24 @@ interface APIEditorInterfaceSettings {
4040

4141
interface APIEditorInterfaceControl {
4242
fieldId: string,
43-
widgetId: string,
43+
widgetId?: string,
44+
widgetNamespace?: 'builtin' | 'extension',
4445
settings?: APIEditorInterfaceSettings
4546
}
4647

48+
interface APIEditorInterfaceSidebar {
49+
widgetId: string,
50+
widgetNamespace: 'builtin' | 'extension',
51+
disabled?: boolean,
52+
settings?: { [key: string]: any }
53+
}
54+
4755
interface APIEditorInterfaces {
4856
sys: {
4957
version: number
5058
}
5159
controls: APIEditorInterfaceControl[]
60+
sidebar?: APIEditorInterfaceSidebar[]
5261
}
5362

5463
export {
@@ -57,5 +66,6 @@ export {
5766
Field,
5867
APIEditorInterfaces,
5968
APIEditorInterfaceControl,
60-
APIEditorInterfaceSettings
69+
APIEditorInterfaceSettings,
70+
APIEditorInterfaceSidebar
6171
}

test/unit/lib/offline-api/build-payloads.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const buildPayloads = async function (runMigration, contentTypes: APIContentType
1616
sys: {
1717
version: 1
1818
},
19-
controls: []
19+
controls: [],
20+
sidebar: undefined
2021
})
2122
const editorInterfacesByContentType: Map<String, EditorInterfaces> = new Map()
2223

0 commit comments

Comments
 (0)