Skip to content

Commit

Permalink
👽 Replace deprecated changeEditorInterface method
Browse files Browse the repository at this point in the history
  • Loading branch information
OriginalEXE authored and deluan committed Mar 10, 2020
1 parent 868ae2b commit 9962b74
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions lib/bootstrap/__tests__/jsonToScript.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const expect = require('expect.js')
const {
removeNullValues,
rejectEmptyObjects,
createChangeEditorInterface,
createChangeFieldControl,
restructureFields,
restructureContentTypeJson,
jsonToScript
Expand Down Expand Up @@ -74,26 +74,26 @@ describe('rejectEmptyObjects', () => {
})
})

describe('createChangeEditorInterface', () => {
it('creates changeEditorInterface without settings', () => {
describe('createChangeFieldControl', () => {
it('creates changeFieldControl without settings', () => {
const itemId = 'myModel'
const field = { fieldId: 'unicornDestroyer', widgetId: 'number' }

const changeEditorInterface = createChangeEditorInterface(itemId, field)
const expected = 'myModel.changeEditorInterface("unicornDestroyer", "number");'
expect(changeEditorInterface).to.equal(expected)
const changeFieldControl = createChangeFieldControl(itemId, field)
const expected = 'myModel.changeFieldControl("unicornDestroyer", "builtin", "number");'
expect(changeFieldControl).to.equal(expected)
})

it('creates changeEditorInterface with settings', () => {
it('creates changeFieldControl with settings', () => {
const itemId = 'myModel'
const field = {
fieldId: 'pegasusLauncher',
widgetId: 'radio',
settings: { parts: 'button' }
}
const changeEditorInterface = createChangeEditorInterface(itemId, field)
const expected = 'myModel.changeEditorInterface("pegasusLauncher", "radio", {"parts":"button"});'
expect(changeEditorInterface).to.equal(expected)
const changeFieldControl = createChangeFieldControl(itemId, field)
const expected = 'myModel.changeFieldControl("pegasusLauncher", "builtin", "radio", {"parts":"button"});'
expect(changeFieldControl).to.equal(expected)
})
})

Expand Down
8 changes: 4 additions & 4 deletions lib/bootstrap/jsonToScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ const createField = (itemId, field) => `
${itemId}.createField("${field.id}")${''.concat(...Object.entries(field.props).filter(rejectEmptyObjects).map(createProp))};
`

const createChangeEditorInterface = (itemId, field) => {
const createChangeFieldControl = (itemId, field) => {
const { fieldId, widgetId, settings } = field
const baseString = `${itemId}.changeEditorInterface("${fieldId}", "${widgetId}"`
const baseString = `${itemId}.changeFieldControl("${fieldId}", "builtin", "${widgetId}"`
return settings ? `${baseString}, ${JSON.stringify(settings)});` : `${baseString});`
}

const createContentType = (item, editorInterface) => `
const ${item.id} = migration.createContentType('${item.id}')${''.concat(...Object.entries(item.props).map(createProp))};
${''.concat(...item.fields.map(field => createField(item.id, field)))}
${editorInterface.map(field => createChangeEditorInterface(item.id, field)).join('\n')}
${editorInterface.map(field => createChangeFieldControl(item.id, field)).join('\n')}
`

const createScript = (item, editorInterface) => `module.exports.description = "Create content model for ${item.props.name}";
Expand Down Expand Up @@ -77,7 +77,7 @@ const jsonToScript = (contentTypeJson, editorInterface) => {
module.exports = {
removeNullValues,
rejectEmptyObjects,
createChangeEditorInterface,
createChangeFieldControl,
restructureFields,
restructureContentTypeJson,
jsonToScript
Expand Down

0 comments on commit 9962b74

Please sign in to comment.