Skip to content

Commit

Permalink
Merge master into editor-layout-draft branch (#1048)
Browse files Browse the repository at this point in the history
* build(deps-dev): bump eslint-plugin-promise from 5.1.0 to 6.0.0

Bumps [eslint-plugin-promise](https://github.com/xjamundx/eslint-plugin-promise) from 5.1.0 to 6.0.0.
- [Release notes](https://github.com/xjamundx/eslint-plugin-promise/releases)
- [Changelog](https://github.com/xjamundx/eslint-plugin-promise/blob/development/CHANGELOG.md)
- [Commits](https://github.com/xjamundx/eslint-plugin-promise/commits)

---
updated-dependencies:
- dependency-name: eslint-plugin-promise
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* fix(config): Fix missing uuid dependency when using the built package (#984)

* Fix README.md in the editField section

The function description says that the `id` parameter will be used to identify the field to be deleted.

* feat: replace listr with listr2 (#982)

* fix(dependencies): bump ts + contentful-management (#1019)

* build(deps-dev): bump @types/node from 14.14.19 to 17.0.14 (#1020)

* build(deps): bump follow-redirects from 1.14.3 to 1.14.8 (#1022)

* build(deps-dev): bump ts-node from 10.3.0 to 10.5.0 (#1023)

* build(deps-dev): bump source-map-support from 0.5.20 to 0.5.21 (#976)

* build(deps-dev): bump @types/mocha from 9.0.0 to 9.1.0 (#1026)

* feat(options): Expose retryLimit parameter

* chore(lint): Configure prettier

* fix: add retryLimit to RunMigrationConfig type

* build(deps-dev): bump @types/lodash from 4.14.174 to 4.14.179 (#1037)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Marco Montalbano <[email protected]>
Co-authored-by: Andreas Egger <[email protected]>
Co-authored-by: João Melo <[email protected]>
Co-authored-by: Patrick Edqvist <[email protected]>
Co-authored-by: Janko Marklein <[email protected]>
Co-authored-by: Andreas Egger <[email protected]>
Co-authored-by: Meike Pollakowski <[email protected]>
Co-authored-by: Meike P <[email protected]>
  • Loading branch information
10 people authored Apr 4, 2022
1 parent 42cc328 commit 7cf8fc3
Show file tree
Hide file tree
Showing 8 changed files with 451 additions and 319 deletions.
192 changes: 122 additions & 70 deletions index.d.ts

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

146 changes: 93 additions & 53 deletions src/lib/entities/content-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,29 @@ import {
APIEditorInterfaceSettings,
APIEditorInterfaceSidebar,
APIEditorIntefaceEditor,
APIEditorInterfaceEditorLayout,
APISidebarWidgetNamespace,
APIControlWidgetNamespace,
APIEditorInterfaceEditorLayout,
APIEditorLayoutFieldGroupItem
} from '../interfaces/content-type'
import { SidebarWidgetNamespace, DEFAULT_SIDEBAR_LIST } from '../action/sidebarwidget'
import { findFieldGroup, isFieldGroupItem, find as findEditorLayoutItem, isFieldItem, FieldGroupItem, FieldItem } from '../utils/editor-layout'
import {
findFieldGroup,
isFieldGroupItem,
find as findEditorLayoutItem,
isFieldItem,
FieldGroupItem,
FieldItem
} from '../utils/editor-layout'
import { EditorLayoutItem } from 'contentful-management/dist/typings/export-types'

export type EditorLayoutFieldMovementDirection = 'afterField' | 'beforeField' | 'afterFieldGroup' | 'beforeFieldGroup' | 'toTheTopOfFieldGroup' | 'toTheBottomOfFieldGroup'
export type EditorLayoutFieldMovementDirection =
| 'afterField'
| 'beforeField'
| 'afterFieldGroup'
| 'beforeFieldGroup'
| 'toTheTopOfFieldGroup'
| 'toTheBottomOfFieldGroup'

class Fields {
private _fields: Field[]
Expand Down Expand Up @@ -285,17 +298,19 @@ class EditorInterfaces {
this._editors = editors
}

createEditorLayout (fields: Field[]) {
createEditorLayout(fields: Field[]) {
// A newly created editor layout doesn’t have the correct shape. This is corrected when adding the first group.
this._editorLayout = fields.map(field => ({ fieldId: field.id })) as unknown as APIEditorInterfaceEditorLayout
this._editorLayout = fields.map((field) => ({
fieldId: field.id
})) as unknown as APIEditorInterfaceEditorLayout
}

deleteEditorLayout () {
deleteEditorLayout() {
delete this._groupControls
delete this._editorLayout
}

createEditorLayoutFieldGroup (fieldGroupId: string, parentFieldGroupId?: string) {
createEditorLayoutFieldGroup(fieldGroupId: string, parentFieldGroupId?: string) {
if (parentFieldGroupId) {
// create field set
const parent = findFieldGroup(this._editorLayout, parentFieldGroupId)
Expand All @@ -305,22 +320,24 @@ class EditorInterfaces {
})
} else {
// create tab
const hasFieldGroup = this._editorLayout.some(item => isFieldGroupItem(item))
const hasFieldGroup = this._editorLayout.some((item) => isFieldGroupItem(item))
if (hasFieldGroup) {
this._editorLayout.push({
groupId: fieldGroupId,
items: []
})
} else {
this._editorLayout = [{
groupId: fieldGroupId,
items: [...this._editorLayout]
}]
this._editorLayout = [
{
groupId: fieldGroupId,
items: [...this._editorLayout]
}
]
}
}
}

deleteEditorLayoutFieldGroup (fieldGroupId: string) {
deleteEditorLayoutFieldGroup(fieldGroupId: string) {
const fieldGroup = findFieldGroup(this._editorLayout, fieldGroupId)
if (!fieldGroup) {
return
Expand All @@ -330,7 +347,7 @@ class EditorInterfaces {
const groupIndex = fieldGroup.path[fieldGroup.path.length - 1] as number

if (parentPath.length === 0) {
this._editorLayout = this._editorLayout.filter(item => item.groupId !== fieldGroupId)
this._editorLayout = this._editorLayout.filter((item) => item.groupId !== fieldGroupId)
this._editorLayout[0].items = [...this._editorLayout[0].items, ...fieldGroup.item.items]

return
Expand All @@ -343,39 +360,49 @@ class EditorInterfaces {
})
}

changeFieldGroupId (fieldGroupId: string, newFieldGroupId: string) {
changeFieldGroupId(fieldGroupId: string, newFieldGroupId: string) {
const fieldGroup = findFieldGroup(this._editorLayout, fieldGroupId)

if (fieldGroup?.item) {
fieldGroup.item.groupId = newFieldGroupId
}

const existingGroupControl = this._groupControls.find(control => control.groupId === fieldGroupId)
const existingGroupControl = this._groupControls.find(
(control) => control.groupId === fieldGroupId
)
if (existingGroupControl) {
existingGroupControl.groupId = newFieldGroupId
}
}

updateEditorLayoutFieldGroup (fieldGroupId: string, props: Pick<APIEditorLayoutFieldGroupItem, 'name'>) {
updateEditorLayoutFieldGroup(
fieldGroupId: string,
props: Pick<APIEditorLayoutFieldGroupItem, 'name'>
) {
const fieldGroup = findFieldGroup(this._editorLayout, fieldGroupId)

Object.assign(fieldGroup.item, pick(props, ['name']))
}

createGroupControls () {
createGroupControls() {
this._groupControls = []
}

createTabGroupControl (fieldGroupId: string) {
createTabGroupControl(fieldGroupId: string) {
this._groupControls.push({
groupId: fieldGroupId,
widgetId: 'topLevelTab',
widgetNamespace: 'builtin'
})
}

updateGroupControl (fieldGroupId: string, groupControl: Omit<APIEditorInterfaceGroupControl, 'groupId'>) {
const existingGroupControl = this._groupControls.find(control => control.groupId === fieldGroupId)
updateGroupControl(
fieldGroupId: string,
groupControl: Omit<APIEditorInterfaceGroupControl, 'groupId'>
) {
const existingGroupControl = this._groupControls.find(
(control) => control.groupId === fieldGroupId
)
if (existingGroupControl) {
existingGroupControl.widgetId = groupControl.widgetId
existingGroupControl.widgetNamespace = groupControl.widgetNamespace
Expand All @@ -387,30 +414,35 @@ class EditorInterfaces {
groupId: fieldGroupId,
widgetId: groupControl.widgetId,
widgetNamespace: groupControl.widgetNamespace,
settings: (groupControl.settings ?? {})
settings: groupControl.settings ?? {}
})
}
}

deleteGroupControl (fieldGroupId: string) {
this._groupControls = this._groupControls.filter(control => control.groupId !== fieldGroupId)
deleteGroupControl(fieldGroupId: string) {
this._groupControls = this._groupControls.filter((control) => control.groupId !== fieldGroupId)
}

moveFieldInEditorLayout (
moveFieldInEditorLayout(
fieldId: string,
direction: EditorLayoutFieldMovementDirection,
pivot?: string) {

pivot?: string
) {
// find the field and its parent (sourceGroup) within editorLayout
let fieldItem: FieldItem
const { item: sourceGroupItem } = findEditorLayoutItem(this._editorLayout, (item) =>
isFieldGroupItem(item) && Boolean(item.items.find((item) => {
if (isTargetFieldItem(item, fieldId)) {
fieldItem = item
return true
}
return false
}))
const { item: sourceGroupItem } = findEditorLayoutItem(
this._editorLayout,
(item) =>
isFieldGroupItem(item) &&
Boolean(
item.items.find((item) => {
if (isTargetFieldItem(item, fieldId)) {
fieldItem = item
return true
}
return false
})
)
) as { item: FieldGroupItem | undefined }

// remove field item from original group
Expand All @@ -424,9 +456,8 @@ class EditorInterfaces {
let destinationGroupItem: FieldGroupItem = sourceGroupItem

const findGroupItem = (groupId) => {
const { item } = findEditorLayoutItem(
this._editorLayout,
(item) => isTargetGroupItem(item, groupId)
const { item } = findEditorLayoutItem(this._editorLayout, (item) =>
isTargetGroupItem(item, groupId)
) as { item: FieldGroupItem | undefined }

return item
Expand All @@ -444,10 +475,13 @@ class EditorInterfaces {
}
pivotIndex = destinationGroupItem.items.length
} else {
const movementConfigMap: Record<string, {
isTargetPivot: (EditorLayoutItem) => boolean,
pivotIndexOffset: number
}> = {
const movementConfigMap: Record<
string,
{
isTargetPivot: (EditorLayoutItem) => boolean
pivotIndexOffset: number
}
> = {
afterField: {
isTargetPivot: (item) => isTargetFieldItem(item, pivot),
pivotIndexOffset: 1
Expand All @@ -468,15 +502,19 @@ class EditorInterfaces {
const movementConfig = movementConfigMap[direction]

// find the parent group of target pivot
const { item: pivotParent } = findEditorLayoutItem(this._editorLayout, (item) =>
isFieldGroupItem(item)
&& Boolean(item.items.find((childItem, childItemIndex) => {
if (movementConfig.isTargetPivot(childItem)) {
pivotIndex = childItemIndex + movementConfig.pivotIndexOffset
return true
}
return false
}))
const { item: pivotParent } = findEditorLayoutItem(
this._editorLayout,
(item) =>
isFieldGroupItem(item) &&
Boolean(
item.items.find((childItem, childItemIndex) => {
if (movementConfig.isTargetPivot(childItem)) {
pivotIndex = childItemIndex + movementConfig.pivotIndexOffset
return true
}
return false
})
)
) as { item: FieldGroupItem | undefined }

destinationGroupItem = pivotParent
Expand Down Expand Up @@ -609,7 +647,9 @@ class ContentType {
}
}

const isTargetFieldItem = (item, fieldId): item is FieldItem => isFieldItem(item) && item.fieldId === fieldId
const isTargetGroupItem = (item, groupId): item is FieldGroupItem => isFieldGroupItem(item) && item.groupId === groupId
const isTargetFieldItem = (item, fieldId): item is FieldItem =>
isFieldItem(item) && item.fieldId === fieldId
const isTargetGroupItem = (item, groupId): item is FieldGroupItem =>
isFieldGroupItem(item) && item.groupId === groupId

export { ContentType as default, ContentType, Fields, Field, EditorInterfaces }
4 changes: 2 additions & 2 deletions src/lib/interfaces/content-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ interface APIEditorInterfaceControl {

interface APIEditorInterfaceGroupControl {
groupId: string
widgetId?: string,
widgetNamespace?: string,
widgetId?: string
widgetNamespace?: string
settings?: APIEditorInterfaceSettings
}

Expand Down
1 change: 0 additions & 1 deletion src/lib/migration-chunks/validation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function validateIntents(
editorInterfaces: Map<string, EditorInterfaces>,
tags: Tag[]
): ValidationError[] | InvalidActionError[] {

const intents: Intent[] = intentList.getIntents()
const ctErrors = contentTypeValidations(intents, contentTypes)
if (ctErrors.length > 0) {
Expand Down
Loading

0 comments on commit 7cf8fc3

Please sign in to comment.