-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add advanced many to many relation data object type (#914)
- Loading branch information
1 parent
21ef8c1
commit 6ef0c84
Showing
31 changed files
with
1,872 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
...data-related/components/advanced-many-to-many-relation/advanced-many-to-many-relation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ns/objects/data-related/types/dynamic-type-object-data-advanced-many-to-many-relation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } /> | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
public/build/72032273-18f6-4afd-a10c-8d9fa4ba3376/entrypoints.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
public/build/72032273-18f6-4afd-a10c-8d9fa4ba3376/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.