Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,27 @@
* @license Pimcore Open Core License (POCL)
*/

import React from 'react'
import { isNil, isNull } from 'lodash'
import { type MenuProps } from 'antd'
import { useTranslation } from 'react-i18next'
import { useInjection } from '@Pimcore/app/depency-injection'
import { Dropdown, type DropdownProps } from '@Pimcore/components/dropdown/dropdown'
import { Dropdown } from '@Pimcore/components/dropdown/dropdown'
import { useNumberedList } from '@Pimcore/components/form/controls/numbered-list/provider/numbered-list/use-numbered-list'
import { type DynamicTypePipelineRegistry } from '@Pimcore/modules/element/dynamic-types/definitions/pipelines/dynamic-type-pipeline-registry'
import React from 'react'
import { usePipelineConfig } from '../../provider/pipeline-config/use-pipeline-config'
import { type DynamicTypePipelineAbstract } from '@Pimcore/modules/element/dynamic-types/definitions/pipelines/dynamic-type-pipeline-abstract'
import { useTranslation } from 'react-i18next'

export interface DynamicGroupDropdownProps {
children: React.ReactNode
dynamicTypeRegistryId: string
}

interface IGroupedTree {
dynamicTypes?: DynamicTypePipelineAbstract[]
[groupKey: string]: any
}

export const DynamicGroupDropdown = ({ children, dynamicTypeRegistryId }: DynamicGroupDropdownProps): React.JSX.Element => {
const registry = useInjection<DynamicTypePipelineRegistry>(dynamicTypeRegistryId)
const { operations } = useNumberedList()
Expand All @@ -32,22 +39,65 @@ export const DynamicGroupDropdown = ({ children, dynamicTypeRegistryId }: Dynami
return dynamicType.isAvailableForSelection(config)
})

const items: DropdownProps['menu']['items'] = availableDynamicTypes.map((dynamicType) => ({
key: dynamicType.id,
label: t(`grid.advanced-column.advancedColumns.${dynamicType.id}`),
onClick: () => {
operations.add({
key: dynamicType.id
const groupedTree: IGroupedTree = {}

availableDynamicTypes.forEach(dynamicType => {
let groupId: string[] = []

if (!isNull(dynamicType.group)) {
if (Array.isArray(dynamicType.group)) {
groupId = dynamicType.group
} else {
groupId = [dynamicType.group]
}
}

let currentLevel = groupedTree

groupId.forEach(groupKey => {
if (isNil(currentLevel[groupKey])) {
currentLevel[groupKey] = {}
}

currentLevel = currentLevel[groupKey]
})

if (isNil(currentLevel.dynamicTypes)) {
currentLevel.dynamicTypes = []
}

currentLevel.dynamicTypes.push(dynamicType)
})

const buildMenuItemsFromTree = (group: IGroupedTree): NonNullable<MenuProps['items']> => {
const items: NonNullable<MenuProps['items']> = []

if (!isNil(group.dynamicTypes)) {
group.dynamicTypes.forEach(dynamicType => {
items.push({
key: dynamicType.id,
label: t(`grid.advanced-column.advancedColumns.${dynamicType.id}`),
onClick: () => { operations.add({ key: dynamicType.id }) }
})
})
}
}))

Object.entries(group).forEach(([groupKey, childNode]) => {
if (groupKey === 'dynamicTypes') return
items.push({
key: `${groupKey}-group`,
label: t(`grid.advanced-column.advancedColumns.group.${groupKey}`),
children: buildMenuItemsFromTree(childNode as IGroupedTree)
})
})

return items
}

const items = buildMenuItemsFromTree(groupedTree)

return (
<Dropdown
menu={ {
items
} }
>
<Dropdown menu={ { items } }>
{children}
</Dropdown>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { type ReactElement } from 'react'
@injectable()
export abstract class DynamicTypePipelineAbstract implements DynamicTypeAbstract {
abstract readonly id: string
readonly group: string | string[] | null = null

abstract getComponent (): ReactElement

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export const DynamicTypePipelineGridSourceFieldsSimpleFieldComponent = (): React
label={ t('field') }
name={ 'field' }
>
<Select options={ sourceFieldOptions } />
<Select
options={ sourceFieldOptions }
showSearch
/>
</Form.Item>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DynamicTypePipelineGridTransformersAnonymizerComponent } from '@Pimcore
@injectable()
export class DynamicTypePipelineGridTransformersAnonymizer extends DynamicTypePipelineAbstract {
readonly id = 'anonymizer'
readonly group = 'string'

getComponent (): ReactElement {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DynamicTypePipelineGridTransformersBlurComponent } from '@Pimcore/modul
@injectable()
export class DynamicTypePipelineGridTransformersBlur extends DynamicTypePipelineAbstract {
readonly id = 'blur'
readonly group = 'string'

getComponent (): ReactElement {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DynamicTypePipelineGridTransformersBooleanFormatterComponent } from '@P
@injectable()
export class DynamicTypePipelineGridTransformersBooleanFormatter extends DynamicTypePipelineAbstract {
readonly id = 'booleanFormatter'
readonly group = 'boolean'

getComponent (): ReactElement {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { injectable } from 'inversify'
@injectable()
export class DynamicTypePipelineGridTransformersChangeCase extends DynamicTypePipelineAbstract {
readonly id = 'caseChange'
readonly group = 'string'

getComponent (): ReactElement {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DynamicTypePipelineGridTransformersCombineComponent } from '../../compo
@injectable()
export class DynamicTypePipelineGridTransformersCombine extends DynamicTypePipelineAbstract {
readonly id = 'combine'
readonly group = 'string'

getComponent (): ReactElement {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DynamicTypePipelineGridTransformersDateFormatterComponent } from '@Pimc
@injectable()
export class DynamicTypePipelineGridTransformersDateFormatter extends DynamicTypePipelineAbstract {
readonly id = 'dateFormatter'
readonly group = 'date'

getComponent (): ReactElement {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { DynamicTypePipelineAbstract } from '../../../../dynamic-type-pipeline-a
@injectable()
export class DynamicTypePipelineGridTransformersElementCounter extends DynamicTypePipelineAbstract {
readonly id = 'elementCounter'
readonly group = 'other'

getComponent (): ReactElement {
return <></>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DynamicTypePipelineGridTransformersExplodeComponent } from '@Pimcore/mo
@injectable()
export class DynamicTypePipelineGridTransformersExplode extends DynamicTypePipelineAbstract {
readonly id = 'explode'
readonly group = 'string'

getComponent (): ReactElement {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DynamicTypePipelineGridTransformersStringReplaceComponent } from '@Pimc
@injectable()
export class DynamicTypePipelineGridTransformersStringReplace extends DynamicTypePipelineAbstract {
readonly id = 'stringReplace'
readonly group = 'string'

getComponent (): ReactElement {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DynamicTypePipelineGridTransformersSubstringComponent } from '@Pimcore/
@injectable()
export class DynamicTypePipelineGridTransformersSubstring extends DynamicTypePipelineAbstract {
readonly id = 'substring'
readonly group = 'string'

getComponent (): ReactElement {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DynamicTypePipelineGridTransformersTrimComponent } from '@Pimcore/modul
@injectable()
export class DynamicTypePipelineGridTransformersTrim extends DynamicTypePipelineAbstract {
readonly id = 'trim'
readonly group = 'string'

getComponent (): ReactElement {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DynamicTypePipelineGridTransformersTwigOperatorComponent } from '@Pimco
@injectable()
export class DynamicTypePipelineGridTransformersTwigOperator extends DynamicTypePipelineAbstract {
readonly id = 'twigOperator'
readonly group = 'other'

getComponent (): ReactElement {
return (
Expand Down
23 changes: 23 additions & 0 deletions public/build/176d4d2d-e74f-4e82-bf64-9f35acf3a038/entrypoints.json

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

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

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

Loading