Skip to content

Commit

Permalink
Add advanced many to many relation data object type (#914)
Browse files Browse the repository at this point in the history
  • Loading branch information
markus-moser authored Jan 23, 2025
1 parent 21ef8c1 commit 6ef0c84
Show file tree
Hide file tree
Showing 31 changed files with 1,872 additions and 4 deletions.
2 changes: 2 additions & 0 deletions assets/js/src/core/app/config/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ import { DynamicTypeObjectDataGeoPolyLine } from '@Pimcore/modules/element/dynam
import { DynamicTypeObjectDataManyToOneRelation } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-many-to-one-relation'
import { DynamicTypeObjectDataManyToManyRelation } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-many-to-many-relation'
import { DynamicTypeObjectDataManyToManyObjectRelation } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-many-to-many-object-relation'
import { DynamicTypeObjectDataAdvancedManyToManyRelation } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-advanced-many-to-many-relation'
import { DynamicTypeObjectDataAdvancedManyToManyObjectRelation } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-advanced-many-to-many-object-relation'
import { DynamicTypeObjectDataReverseObjectRelation } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-reverse-object-relation'
import { DynamicTypeObjectDataStructuredTable } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-structured-table'
Expand Down Expand Up @@ -277,6 +278,7 @@ container.bind(serviceIds['DynamicTypes/ObjectData/GeoPolyLine']).to(DynamicType
container.bind(serviceIds['DynamicTypes/ObjectData/ManyToOneRelation']).to(DynamicTypeObjectDataManyToOneRelation).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/ManyToManyRelation']).to(DynamicTypeObjectDataManyToManyRelation).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/ManyToManyObjectRelation']).to(DynamicTypeObjectDataManyToManyObjectRelation).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/AdvancedManyToManyRelation']).to(DynamicTypeObjectDataAdvancedManyToManyRelation).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/AdvancedManyToManyObjectRelation']).to(DynamicTypeObjectDataAdvancedManyToManyObjectRelation).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/ReverseObjectRelation']).to(DynamicTypeObjectDataReverseObjectRelation).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/Table']).to(DynamicTypeObjectDataTable).inSingletonScope()
Expand Down
1 change: 1 addition & 0 deletions assets/js/src/core/app/config/services/service-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export const serviceIds = {
'DynamicTypes/ObjectData/ManyToOneRelation': 'DynamicTypes/ObjectData/ManyToOneRelation',
'DynamicTypes/ObjectData/ManyToManyRelation': 'DynamicTypes/ObjectData/ManyToManyRelation',
'DynamicTypes/ObjectData/ManyToManyObjectRelation': 'DynamicTypes/ObjectData/ManyToManyObjectRelation',
'DynamicTypes/ObjectData/AdvancedManyToManyRelation': 'DynamicTypes/ObjectData/AdvancedManyToManyRelation',
'DynamicTypes/ObjectData/AdvancedManyToManyObjectRelation': 'DynamicTypes/ObjectData/AdvancedManyToManyObjectRelation',
'DynamicTypes/ObjectData/ReverseObjectRelation': 'DynamicTypes/ObjectData/ReverseObjectRelation',
'DynamicTypes/ObjectData/Table': 'DynamicTypes/ObjectData/Table',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { getElementActionCacheKey } from '@Pimcore/modules/element/element-helpe
export const ListGridContextMenu = (props: ListGridContextMenuProps): React.JSX.Element => {
const { row } = props
const { openGridContextMenuItem } = useOpen('asset')
const { renameGridContextMenuItem } = useRename('asset', getElementActionCacheKey('asset', 'rename', row.id))
const { deleteGridContextMenuItem } = useDelete('asset', getElementActionCacheKey('asset', 'delete', row.id))
const { renameGridContextMenuItem } = useRename('asset', getElementActionCacheKey('asset', 'rename', Number(row.id)))
const { deleteGridContextMenuItem } = useDelete('asset', getElementActionCacheKey('asset', 'delete', Number(row.id)))
const { downloadGridContextMenuItem } = useDownload()

const items = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* 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 } from 'react'
import type {
ManyToManyRelationValue,
ManyToManyRelationValueItem
} from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/components/many-to-many-relation/hooks/use-value'
import {
type AdvancedManyToManyRelationValue
} from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/helpers/relations/types/advanced-many-to-many-relation'
import {
useConvertRelationEditableColumns
} from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/helpers/relations/hooks/use-convert-relation-editable-columns'
import {
ManyToManyRelation
} from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/components/many-to-many-relation/many-to-many-relation'
import type {
IRelationAllowedTypesDataComponent
} from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/helpers/relations/allowed-types'
import { type ColumnDef, createColumnHelper } from '@tanstack/react-table'
import { useTranslation } from 'react-i18next'

export interface AdvancedManyToManyRelationClassDefinitionProps {
allowToClearRelation: boolean
allowMultipleAssignments: boolean
maxItems: number | null
pathFormatterClass: string | null
width: number | string | null
height: number | string | null
columns?: RelationColumnDefinition[] | null
name: string[]
}

export interface RelationColumnDefinition {
type?: string
position: number
key: string
label?: string
width?: number
value?: string
}

export interface AdvancedManyToManyRelationProps extends IRelationAllowedTypesDataComponent, AdvancedManyToManyRelationClassDefinitionProps {
disabled?: boolean
value?: AdvancedManyToManyRelationValue | null
onChange?: (value?: AdvancedManyToManyRelationValue | null) => void
enrichRowData?: (row: ManyToManyRelationValueItem) => ManyToManyRelationValueItem & Record<string, any>
}

export const AdvancedManyToManyRelation = (props: AdvancedManyToManyRelationProps): React.JSX.Element => {
const fieldName = props.name[props.name.length - 1]
const { columnDefinition, onUpdateCellData, convertToManyToManyRelationValue, convertToAdvancedManyToManyRelationValue } = useConvertRelationEditableColumns(props.columns ?? [], fieldName, props.value, props.onChange)
const { t } = useTranslation()

useEffect(() => {
}, [props.value])

const onChange = (value?: ManyToManyRelationValue | null): void => {
props.onChange?.(convertToAdvancedManyToManyRelationValue(value))
}

const addNotEditableColumns = (columnDefinition: Array<ColumnDef<any>>): Array<ColumnDef<any>> => {
const columnHelper = createColumnHelper()
return [
columnHelper.accessor('id', {
header: t('relations.id'),
size: 80
}),
columnHelper.accessor('fullPath', {
header: t('relations.reference'),
meta: {
autoWidth: true
},
size: 200
}),
...columnDefinition,
columnHelper.accessor('type', {
header: t('relations.type'),
meta: {
type: 'translate'
},
size: 150
}),
columnHelper.accessor('subtype', {
header: t('relations.subtype'),
meta: {
type: 'translate'
},
size: 150
})
]
}

return (
<ManyToManyRelation
{ ...props }
columnDefinition={ addNotEditableColumns(columnDefinition) }
dataObjectsAllowed
onChange={ onChange }
onUpdateCellData={ onUpdateCellData }
value={ convertToManyToManyRelationValue(props.value) }
/>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface UseConvertRelationEditableColumnsResult {
const EDITABLE_COLUMN_PREFIX = 'edit::'

const mapColumnType = (type: string, value?: string): ColumnMeta<any, any> => {
if (type === 'bool') {
if (type === 'bool' || type === 'columnbool') {
return {
type: 'checkbox',
editable: true
Expand Down Expand Up @@ -129,7 +129,7 @@ export const useConvertRelationEditableColumns = (
for (const key in value.data) {
const column = columns.find(col => col.key === key)
if (column?.type === 'multiselect') {
editableData[EDITABLE_COLUMN_PREFIX + key] = _.compact(String(value.data[key]).split(','))
editableData[EDITABLE_COLUMN_PREFIX + key] = _.isEmpty(value.data[key]) ? [] : _.compact(String(value.data[key]).split(','))
} else {
editableData[EDITABLE_COLUMN_PREFIX + key] = value.data[key]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* 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 from 'react'
import {
type AbstractObjectDataDefinition, DynamicTypeObjectDataAbstract
} from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/dynamic-type-object-data-abstract'
import type { FormItemProps } from 'antd/es/form/FormItem'
import {
ManyToManyRelationLabel
} from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/helpers/relations/components/label/label'
import {
AdvancedManyToManyRelation, type AdvancedManyToManyRelationClassDefinitionProps
} from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/components/advanced-many-to-many-relation/advanced-many-to-many-relation'
import {
convertAllowedTypes,
type IRelationAllowedTypesClassDefinition
} from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/helpers/relations/allowed-types'

export type AdvancedManyToManyRelationObjectDataDefinition = AbstractObjectDataDefinition & IRelationAllowedTypesClassDefinition & AdvancedManyToManyRelationClassDefinitionProps

export class DynamicTypeObjectDataAdvancedManyToManyRelation extends DynamicTypeObjectDataAbstract {
id: string = 'advancedManyToManyRelation'

getObjectDataComponent (props: AdvancedManyToManyRelationObjectDataDefinition): React.ReactElement<AbstractObjectDataDefinition> {
return (
<AdvancedManyToManyRelation
{ ...props }
{ ... convertAllowedTypes(props) }
disabled={ props.noteditable === true }
/>
)
}

getObjectDataFormItemProps (props: AdvancedManyToManyRelationObjectDataDefinition): FormItemProps {
return {
...super.getObjectDataFormItemProps(props),
label: <ManyToManyRelationLabel label={ props.title } />
}
}
}
2 changes: 2 additions & 0 deletions assets/js/src/core/modules/element/dynamic-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import { type DynamicTypeObjectDataGeoPolyLine } from '@Pimcore/modules/element/
import { type DynamicTypeObjectDataManyToOneRelation } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-many-to-one-relation'
import { type DynamicTypeObjectDataManyToManyRelation } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-many-to-many-relation'
import { type DynamicTypeObjectDataManyToManyObjectRelation } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-many-to-many-object-relation'
import { type DynamicTypeObjectDataAdvancedManyToManyRelation } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-advanced-many-to-many-relation'
import { type DynamicTypeObjectDataAdvancedManyToManyObjectRelation } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-advanced-many-to-many-object-relation'
import { type DynamicTypeObjectDataReverseObjectRelation } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-reverse-object-relation'
import { type DynamicTypeObjectDataTable } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-table'
Expand Down Expand Up @@ -246,6 +247,7 @@ moduleSystem.registerModule({
objectDataRegistry.registerDynamicType(container.get<DynamicTypeObjectDataManyToManyRelation>(serviceIds['DynamicTypes/ObjectData/ManyToManyRelation']))
objectDataRegistry.registerDynamicType(container.get<DynamicTypeObjectDataManyToManyObjectRelation>(serviceIds['DynamicTypes/ObjectData/ManyToManyObjectRelation']))
objectDataRegistry.registerDynamicType(container.get<DynamicTypeObjectDataAdvancedManyToManyObjectRelation>(serviceIds['DynamicTypes/ObjectData/AdvancedManyToManyObjectRelation']))
objectDataRegistry.registerDynamicType(container.get<DynamicTypeObjectDataAdvancedManyToManyRelation>(serviceIds['DynamicTypes/ObjectData/AdvancedManyToManyRelation']))
objectDataRegistry.registerDynamicType(container.get<DynamicTypeObjectDataReverseObjectRelation>(serviceIds['DynamicTypes/ObjectData/ReverseObjectRelation']))
objectDataRegistry.registerDynamicType(container.get<DynamicTypeObjectDataTable>(serviceIds['DynamicTypes/ObjectData/Table']))
objectDataRegistry.registerDynamicType(container.get<DynamicTypeObjectDataStructuredTable>(serviceIds['DynamicTypes/ObjectData/StructuredTable']))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"entrypoints": {
"vendor": {
"js": [
"/bundles/pimcorestudioui/build/72032273-18f6-4afd-a10c-8d9fa4ba3376/vendor.js"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"bundles/pimcorestudioui/build/72032273-18f6-4afd-a10c-8d9fa4ba3376/vendor.js": "/bundles/pimcorestudioui/build/72032273-18f6-4afd-a10c-8d9fa4ba3376/vendor.js"
}
2 changes: 2 additions & 0 deletions public/build/72032273-18f6-4afd-a10c-8d9fa4ba3376/vendor.js

Large diffs are not rendered by default.

Loading

0 comments on commit 6ef0c84

Please sign in to comment.