Skip to content

Commit

Permalink
Batch edit types (#732)
Browse files Browse the repository at this point in the history
* first plugging in of dynamic types text

* update to include fallback

* add dynamic text area dynamic type

* Apply eslint-fixer changes

* Automatic frontend build

---------

Co-authored-by: xIrusux <[email protected]>
  • Loading branch information
xIrusux and xIrusux authored Nov 25, 2024
1 parent 55b58a5 commit d8a52a4
Show file tree
Hide file tree
Showing 34 changed files with 2,378 additions and 50 deletions.
30 changes: 26 additions & 4 deletions assets/js/src/core/app/config/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,27 @@ import { DynamicTypeObjectDataGeoPolygon } from '@Pimcore/modules/element/dynami
import { DynamicTypeObjectDataGeoPolyLine } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-geopolyline'
import { DynamicTypeObjectDataBlock } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-block'
import { DynamicTypeObjectDataLocalizedFields } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-localized-fields'
import { DynamicTypeGridCellAsset } from '@Pimcore/modules/element/dynamic-types/defintinitions/grid-cell/types/asset/dynamic-type-grid-cell-asset'
import { DynamicTypeGridCellObject } from '@Pimcore/modules/element/dynamic-types/defintinitions/grid-cell/types/object/dynamic-type-grid-cell-object'
import { DynamicTypeGridCellDocument } from '@Pimcore/modules/element/dynamic-types/defintinitions/grid-cell/types/document/dynamic-type-grid-cell-document'
import { DynamicTypeGridCellLanguageSelect } from '@Pimcore/modules/element/dynamic-types/defintinitions/grid-cell/types/language-select/dynamic-type-grid-cell-language-select'
import {
DynamicTypeBatchEditRegistry
} from '@Pimcore/modules/element/dynamic-types/defintinitions/batch-edits/dynamic-type-batch-edit-registry'
import {
DynamicTypeBatchEditText
} from '@Pimcore/modules/element/dynamic-types/defintinitions/batch-edits/types/text/dynamic-type-batch-edit-text'
import {
DynamicTypeBatchEditTextArea
} from '@Pimcore/modules/element/dynamic-types/defintinitions/batch-edits/types/text/dynamic-type-batch-edit-text-area'
import {
DynamicTypeGridCellAsset
} from '@Pimcore/modules/element/dynamic-types/defintinitions/grid-cell/types/asset/dynamic-type-grid-cell-asset'
import {
DynamicTypeGridCellObject
} from '@Pimcore/modules/element/dynamic-types/defintinitions/grid-cell/types/object/dynamic-type-grid-cell-object'
import {
DynamicTypeGridCellDocument
} from '@Pimcore/modules/element/dynamic-types/defintinitions/grid-cell/types/document/dynamic-type-grid-cell-document'
import {
DynamicTypeGridCellLanguageSelect
} from '@Pimcore/modules/element/dynamic-types/defintinitions/grid-cell/types/language-select/dynamic-type-grid-cell-language-select'

// Widget manager
container.bind(serviceIds.widgetManager).to(WidgetRegistry).inSingletonScope()
Expand Down Expand Up @@ -139,6 +156,11 @@ container.bind(serviceIds['DynamicTypes/FieldFilter/Number']).to(DynamicTypeFiel
container.bind(serviceIds['DynamicTypes/FieldFilter/Select']).to(DynamicTypeFieldFilterSelect).inSingletonScope()
container.bind(serviceIds['DynamicTypes/FieldFilter/Datetime']).to(DynamicTypeFieldFilterDatetime).inSingletonScope()

// dynamic types batch edit
container.bind(serviceIds['DynamicTypes/BatchEditRegistry']).to(DynamicTypeBatchEditRegistry).inSingletonScope()
container.bind(serviceIds['DynamicTypes/BatchEdit/Text']).to(DynamicTypeBatchEditText).inSingletonScope()
container.bind(serviceIds['DynamicTypes/BatchEdit/TextArea']).to(DynamicTypeBatchEditTextArea).inSingletonScope()

// dynamic types grid cells
container.bind(serviceIds['DynamicTypes/GridCellRegistry']).to(DynamicTypeGridCellRegistry).inSingletonScope()
container.bind(serviceIds['DynamicTypes/GridCell/Text']).to(DynamicTypeGridCellText).inSingletonScope()
Expand Down
4 changes: 4 additions & 0 deletions assets/js/src/core/app/config/services/service-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

export const dynamicTypeRegistriesServiceIds = {
'DynamicTypes/FieldFilterRegistry': 'DynamicTypes/FieldFilterRegistry',
'DynamicTypes/BatchEditRegistry': 'DynamicTypes/BatchEditRegistry',
'DynamicTypes/GridCellRegistry': 'DynamicTypes/GridCellRegistry',
'DynamicTypes/ListingRegistry': 'DynamicTypes/ListingRegistry',
'DynamicTypes/MetadataRegistry': 'DynamicTypes/MetadataRegistry',
Expand Down Expand Up @@ -55,6 +56,9 @@ export const serviceIds = {
'DynamicTypes/FieldFilter/Select': 'DynamicTypes/FieldFilter/Select',
'DynamicTypes/FieldFilter/Datetime': 'DynamicTypes/FieldFilter/Datetime',

'DynamicTypes/BatchEdit/Text': 'DynamicTypes/BatchEdit/Text',
'DynamicTypes/BatchEdit/TextArea': 'DynamicTypes/BatchEdit/TextArea',

'DynamicTypes/GridCell/Text': 'DynamicTypes/GridCell/Text',
'DynamicTypes/GridCell/Textarea': 'DynamicTypes/GridCell/Textarea',
'DynamicTypes/GridCell/Select': 'DynamicTypes/GridCell/Select',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
import React from 'react'
import { ListContainerInner } from './list-container-inner'
import { ListProvider } from './list-provider'
import { DynamicTypeRegistryProvider } from '@Pimcore/modules/element/dynamic-types/registry/provider/dynamic-type-registry-provider'
import {
DynamicTypeRegistryProvider
} from '@Pimcore/modules/element/dynamic-types/registry/provider/dynamic-type-registry-provider'

const ListContainer = (): React.JSX.Element => {
return (
<ListProvider>
<DynamicTypeRegistryProvider serviceIds={ [
'DynamicTypes/MetadataRegistry',
'DynamicTypes/ListingRegistry'
'DynamicTypes/ListingRegistry',
'DynamicTypes/BatchEditRegistry'
] }
>
<ListContainerInner />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface DefaultFilterProps {

export const DefaultFilter = ({ column }: DefaultFilterProps): React.JSX.Element => {
const { frontendType, type } = column

const { getComponentRenderer } = useDynamicTypeResolver()
const { ComponentRenderer } = getComponentRenderer({ target: 'FIELD_FILTER', dynamicTypeIds: [type, frontendType!] })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const BatchEditModal = ({ batchEditModalOpen, setBatchEditModalOpen }: Ba

const onColumnClick = (column: GridColumnConfiguration): void => {
const locale = column.locale ?? null
addOrUpdateBatchEdit(column.key, column.type, locale, column.localizable, '')
addOrUpdateBatchEdit(column.key, column.type, column.frontendType, locale, column.localizable, '')
}

const applyChanges = (): void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import React, { useState, createContext, useMemo } from 'react'
export interface BatchEdit {
key: string
type: string
frontendType: string | undefined
locale: string | null
localizable: boolean
value: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,29 @@
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL
*/

import React, { useMemo, type ComponentType, useState, useEffect } from 'react'
import React from 'react'
import {
type BatchEdit
} from '@Pimcore/modules/asset/editor/types/folder/tab-manager/tabs/list/toolbar/tools/batch-edit-modal/batch-edit-provider'
import { Input } from 'antd'
import {
useBatchEdit
} from '@Pimcore/modules/asset/editor/types/folder/tab-manager/tabs/list/toolbar/tools/batch-edit-modal/hooks/use-batch-edit'
import { useDynamicTypeResolver } from '@Pimcore/modules/element/dynamic-types/resolver/hooks/use-dynamic-type-resolver'

export interface DefaultBatchEditProps {
batchEdit: BatchEdit
}

export const DefaultBatchEdit = ({ batchEdit }: DefaultBatchEditProps): React.JSX.Element => {
const { key, type, locale, localizable, value: batchEditValue } = batchEdit
const { addOrUpdateBatchEdit } = useBatchEdit()

const TextFilter = (): React.JSX.Element => {
const [_value, setValue] = useState(batchEditValue)

useEffect(() => {
setValue(batchEditValue)
}, [batchEditValue])
const { frontendType, type } = batchEdit

const onBlur = (): void => {
addOrUpdateBatchEdit(key, type, locale, localizable, _value)
}
const { getComponentRenderer } = useDynamicTypeResolver()
const { ComponentRenderer } = getComponentRenderer({ dynamicTypeIds: [type, frontendType!], target: 'BATCH_EDIT' })

return (
<Input
onBlur={ onBlur }
onChange={ (event) => { setValue(event.target.value) } }
type='text'
value={ _value }
/>
)
if (ComponentRenderer === null) {
return <>Dynamic Field Filter not supported</>
}

const getComponent = (): ComponentType<DefaultBatchEditProps> => {
switch (type) {
case 'text':
return TextFilter
default:
return TextFilter
}
}

const Component = useMemo(() => {
return getComponent()
}, [])

return (
<Component batchEdit={ batchEdit } />
<>
{ ComponentRenderer({ batchEdit }) }
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { type AssetPatchByIdApiArg, type PatchCustomMetadata } from '@Pimcore/mo
import { useListSelectedRows } from '@Pimcore/modules/asset/editor/types/folder/tab-manager/tabs/list/hooks/use-list'

interface UseBatchEditHookReturn extends BatchContext {
addOrUpdateBatchEdit: (key: string, type: string, locale: string | null, localizable: boolean, value: string) => void
addOrUpdateBatchEdit: (key: string, type: string, frontendType: string | undefined, locale: string | null, localizable: boolean, value: string) => void
updateLocale: (key: string, locale: string | null) => void
resetBatchEdits: () => void
removeBatchEdit: (key: string) => void
Expand Down Expand Up @@ -78,10 +78,11 @@ export const useBatchEdit = (): UseBatchEditHookReturn => {
setBatchEdits(updatedEdits)
}

const addOrUpdateBatchEdit = (key: string, type: string, locale: string, localizable: boolean, value: string): void => {
const addOrUpdateBatchEdit = (key: string, type: string, frontendType: string, locale: string, localizable: boolean, value: string): void => {
const newEdit: BatchEdit = {
key,
type,
frontendType,
locale,
localizable,
value
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Pimcore
*
* This source file is available under two different licenses:
* - Pimcore Open Core License (POCL)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL
*/

import { type ReactElement } from 'react'
import { type DynamicTypeAbstract } from '../../registry/dynamic-type-registry-abstract'
import {
type BatchEdit
} from '@Pimcore/modules/asset/editor/types/folder/tab-manager/tabs/list/toolbar/tools/batch-edit-modal/batch-edit-provider'

export interface AbstractBatchEditDefinition {
batchEdit: BatchEdit
}

export abstract class DynamicTypeBatchEditAbstract implements DynamicTypeAbstract {
abstract readonly id: string
abstract getBatchEditComponent (props: AbstractBatchEditDefinition): ReactElement<AbstractBatchEditDefinition>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Pimcore
*
* This source file is available under two different licenses:
* - Pimcore Open Core License (POCL)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL
*/

import { type ReactElement } from 'react'
import { injectable } from 'inversify'
import { DynamicTypeRegistryAbstract } from '../../registry/dynamic-type-registry-abstract'
import {
type AbstractBatchEditDefinition,
type DynamicTypeBatchEditAbstract
} from '@Pimcore/modules/element/dynamic-types/defintinitions/batch-edits/dynamic-type-batch-edit-abstract'

@injectable()
export class DynamicTypeBatchEditRegistry extends DynamicTypeRegistryAbstract<DynamicTypeBatchEditAbstract> {
getComponent (id: string, props: AbstractBatchEditDefinition): ReactElement<AbstractBatchEditDefinition> {
return this.getDynamicType(id).getBatchEditComponent(props)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Pimcore
*
* This source file is available under two different licenses:
* - Pimcore Open Core License (POCL)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL
*/

import React, { useEffect, useState } from 'react'
import {
type AbstractBatchEditDefinition
} from '@Pimcore/modules/element/dynamic-types/defintinitions/batch-edits/dynamic-type-batch-edit-abstract'
import {
useBatchEdit
} from '@Pimcore/modules/asset/editor/types/folder/tab-manager/tabs/list/toolbar/tools/batch-edit-modal/hooks/use-batch-edit'
import TextArea from 'antd/es/input/TextArea'
export interface DynamicTypeBatchEditTextAreaProps extends AbstractBatchEditDefinition {}

export const DynamicTypeBatchEditTextAreaComponent = ({ batchEdit }: DynamicTypeBatchEditTextAreaProps): React.JSX.Element => {
const { addOrUpdateBatchEdit } = useBatchEdit()
const { key, type, frontendType, locale, localizable, value: batchEditValue } = batchEdit
const [_value, setValue] = useState(batchEditValue)

useEffect(() => {
setValue(batchEditValue)
}, [batchEditValue])

const onBlur = (): void => {
addOrUpdateBatchEdit(key, type, frontendType, locale, localizable, _value)
}

return (
<TextArea
autoSize={ { minRows: 2 } }
onBlur={ onBlur }
onChange={ (event) => { setValue(event.target.value) } }
value={ _value }
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Pimcore
*
* This source file is available under two different licenses:
* - Pimcore Open Core License (POCL)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL
*/

import React, { useEffect, useState } from 'react'
import { Input } from 'antd'
import {
type AbstractBatchEditDefinition
} from '@Pimcore/modules/element/dynamic-types/defintinitions/batch-edits/dynamic-type-batch-edit-abstract'
import {
useBatchEdit
} from '@Pimcore/modules/asset/editor/types/folder/tab-manager/tabs/list/toolbar/tools/batch-edit-modal/hooks/use-batch-edit'
export interface DynamicTypeBatchEditTextProps extends AbstractBatchEditDefinition {}

export const DynamicTypeBatchEditTextComponent = ({ batchEdit }: DynamicTypeBatchEditTextProps): React.JSX.Element => {
const { addOrUpdateBatchEdit } = useBatchEdit()
const { key, type, frontendType, locale, localizable, value: batchEditValue } = batchEdit
const [_value, setValue] = useState(batchEditValue)

useEffect(() => {
setValue(batchEditValue)
}, [batchEditValue])

const onBlur = (): void => {
addOrUpdateBatchEdit(key, type, frontendType, locale, localizable, _value)
}

return (
<Input
onBlur={ onBlur }
onChange={ (event) => { setValue(event.target.value) } }
type='text'
value={ _value }
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Pimcore
*
* This source file is available under two different licenses:
* - Pimcore Open Core License (POCL)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL
*/

import React, { type ReactElement } from 'react'
import { injectable } from 'inversify'
import {
type DynamicTypeBatchEditAbstract
} from '@Pimcore/modules/element/dynamic-types/defintinitions/batch-edits/dynamic-type-batch-edit-abstract'
import {
DynamicTypeBatchEditTextAreaComponent,
type DynamicTypeBatchEditTextAreaProps
} from '@Pimcore/modules/element/dynamic-types/defintinitions/batch-edits/types/components/dynamic-type-batch-edit-text-area-component'

@injectable()
export class DynamicTypeBatchEditTextArea implements DynamicTypeBatchEditAbstract {
id = 'textarea'

getBatchEditComponent (props: DynamicTypeBatchEditTextAreaProps): ReactElement<DynamicTypeBatchEditTextAreaProps> {
return (
<DynamicTypeBatchEditTextAreaComponent { ...props } />
)
}
}
Loading

0 comments on commit d8a52a4

Please sign in to comment.