Skip to content

Commit 66213be

Browse files
authored
Introduce grouping for simple fields (#3642)
* Introduce grouping for simple fields * Automatic frontend build --------- Co-authored-by: vin0401 <26813978+vin0401@users.noreply.github.com>
1 parent 1fb7264 commit 66213be

747 files changed

Lines changed: 30542 additions & 5 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

assets/js/src/core/modules/element/dynamic-types/definitions/pipelines/grid/source-fields/components/simple-field/simple-field.tsx

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,83 @@
1111
import { Form } from '@Pimcore/components/form/form'
1212
import { usePipelineConfig } from '@Pimcore/components/pipeline/provider/pipeline-config/use-pipeline-config'
1313
import { Select } from '@Pimcore/components/select/select'
14-
import React from 'react'
14+
import React, { useContext, useMemo } from 'react'
1515
import { useTranslation } from 'react-i18next'
16+
import { AvailableColumnsContext } from '@Pimcore/modules/element/listing/decorators/utils/column-configuration/context-layer/provider/available-columns/available-columns-provider'
17+
18+
interface SimpleFieldOption {
19+
label: string
20+
value: string
21+
}
22+
23+
const resolveGroupLabel = (group: unknown, translate: (key: string) => string): string | undefined => {
24+
if (group === undefined || group === null) {
25+
return undefined
26+
}
27+
28+
let parts: string[] = []
29+
30+
if (typeof group === 'string') {
31+
parts = group.split('.')
32+
} else if (Array.isArray(group)) {
33+
if (group.length === 0) {
34+
return undefined
35+
}
36+
37+
const firstPath = Array.isArray(group[0]) ? group[0] : group
38+
parts = (firstPath as unknown[]).map(part => String(part))
39+
} else {
40+
return undefined
41+
}
42+
43+
const labeledParts = parts.filter(part => part !== '').map(part => translate(part))
44+
45+
return labeledParts.length > 0 ? labeledParts.join(' / ') : undefined
46+
}
1647

1748
export const DynamicTypePipelineGridSourceFieldsSimpleFieldComponent = (): React.JSX.Element => {
1849
const { config } = usePipelineConfig()
1950
const { t } = useTranslation()
51+
const availableColumnsContext = useContext(AvailableColumnsContext)
2052

2153
const sourceFieldConfig = config?.simpleField
2254
if (sourceFieldConfig === undefined) {
2355
throw new Error('Source field configuration is missing')
2456
}
2557

26-
const sourceFieldOptions = sourceFieldConfig.map(configOption => ({
27-
label: configOption.name,
28-
value: configOption.key
29-
}))
58+
const sourceFieldOptions = useMemo(() => {
59+
const groupByKey = new Map<string, string | undefined>()
60+
for (const column of availableColumnsContext?.availableColumns ?? []) {
61+
groupByKey.set(String(column.key), resolveGroupLabel(column.group, t))
62+
}
63+
64+
const groups = new Map<string, SimpleFieldOption[]>()
65+
const ungrouped: SimpleFieldOption[] = []
66+
67+
for (const configOption of sourceFieldConfig) {
68+
const key = String(configOption.key)
69+
const option: SimpleFieldOption = {
70+
label: String(configOption.name),
71+
value: key
72+
}
73+
const groupLabel = groupByKey.get(key)
74+
75+
if (groupLabel === undefined) {
76+
ungrouped.push(option)
77+
continue
78+
}
79+
80+
const bucket = groups.get(groupLabel) ?? []
81+
bucket.push(option)
82+
groups.set(groupLabel, bucket)
83+
}
84+
85+
const groupedOptions = [...groups.entries()]
86+
.sort(([a], [b]) => a.localeCompare(b))
87+
.map(([label, options]) => ({ label, options }))
88+
89+
return [...groupedOptions, ...ungrouped]
90+
}, [sourceFieldConfig, availableColumnsContext?.availableColumns, t])
3091

3192
return (
3293
<Form.Item

public/build/86eb8896-37c5-4570-8f1e-8cc90e9d35bf/documentEditorIframe.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/86eb8896-37c5-4570-8f1e-8cc90e9d35bf/entrypoints.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/86eb8896-37c5-4570-8f1e-8cc90e9d35bf/exposeRemote.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/86eb8896-37c5-4570-8f1e-8cc90e9d35bf/main.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/86eb8896-37c5-4570-8f1e-8cc90e9d35bf/manifest.json

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/86eb8896-37c5-4570-8f1e-8cc90e9d35bf/mf-manifest.json

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/86eb8896-37c5-4570-8f1e-8cc90e9d35bf/mf-stats.json

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)