Skip to content

Added support for custom column width #1477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
fe5c980
implemented dynamic cell type
Corepex May 7, 2025
455f35b
added logic to fetch subtype of `dataobject.adapter`
Corepex May 7, 2025
57b98bd
adjust several column types
Corepex May 7, 2025
debf154
adjust column width for several cells
Corepex May 8, 2025
77fcadb
moved `dynType.getDefaultGridColumnWidth` to subclass
Corepex May 9, 2025
13deb7d
cleanup
Corepex May 9, 2025
50daa8f
added several custom column widths
Corepex May 9, 2025
a00e225
cleanup
Corepex May 9, 2025
c389076
Automatic frontend build
Corepex May 9, 2025
a8b14ce
Merge remote-tracking branch 'origin/1430-data-object-grid-default-wi…
Corepex May 9, 2025
fa60ba3
added with to relation table
Corepex May 12, 2025
48ec8c3
added translations
Corepex May 12, 2025
9b3adf2
adjust column size in edit modal
Corepex May 12, 2025
f76f55c
Merge branch '1.x' into 1430-data-object-grid-default-width-of-column…
Corepex May 13, 2025
e63be5e
Automatic frontend build
Corepex May 13, 2025
c9a4e68
fixed width overwrite issue
Corepex May 14, 2025
96e8ad8
moved column default with to helper
Corepex May 14, 2025
2b62f8e
cleanup
Corepex May 14, 2025
6fea6aa
fixed double const
Corepex May 14, 2025
9529331
Merge remote-tracking branch 'origin/1430-data-object-grid-default-wi…
Corepex May 14, 2025
fabc535
Automatic frontend build
Corepex May 14, 2025
acf057a
Merge branch '1.x' into 1430-data-object-grid-default-width-of-column…
Corepex May 15, 2025
6cdac29
Merge remote-tracking branch 'origin/1430-data-object-grid-default-wi…
Corepex May 15, 2025
edf2be9
Automatic frontend build
Corepex May 15, 2025
3a5b491
fixed double translation bug
Corepex May 15, 2025
e2f736c
Automatic frontend build
Corepex May 15, 2025
a4eaab0
Don't overwrite already defined column sizes
markus-moser May 15, 2025
811357a
Automatic frontend build
markus-moser May 15, 2025
35fadb1
fixed smaller bugs
Corepex May 16, 2025
98185e4
fixed `undefined` check
Corepex May 16, 2025
29ff6c8
added with to link type
Corepex May 16, 2025
f8a2906
added more customized with
Corepex May 16, 2025
c58471a
added more customized width
Corepex May 16, 2025
e243d82
fixed typo
Corepex May 16, 2025
f1d2f9d
Apply eslint-fixer changes
Corepex May 16, 2025
53b0e84
Automatic frontend build
Corepex May 16, 2025
68e447c
removed `size`
Corepex May 16, 2025
6cc4b14
made linter happy
Corepex May 16, 2025
375381b
made linter even happier
Corepex May 16, 2025
7cda054
Merge branch '1.x' into 1430-data-object-grid-default-width-of-column…
Corepex May 16, 2025
1326b00
Apply eslint-fixer changes
Corepex May 16, 2025
6c8ed31
Automatic frontend build
Corepex May 16, 2025
d7cb9a9
Adjust default widths for various data object types
markus-moser May 16, 2025
bfbe846
Pass field definition instead of ColumnMeta to data object dynamic ty…
markus-moser May 16, 2025
9764cba
Merge branch '1430-data-object-grid-default-width-of-columns-based-on…
markus-moser May 16, 2025
a69af00
avoid code duplication
Corepex May 19, 2025
b1df9e7
redesigned column helper function, removed duplicate code
Corepex May 19, 2025
692d368
Automatic frontend build
markus-moser May 19, 2025
18ea7a1
Merge remote-tracking branch 'origin/1430-data-object-grid-default-wi…
Corepex May 19, 2025
31c039a
renamed function, cleanup
Corepex May 19, 2025
4368d5c
fixed merge bugs
Corepex May 19, 2025
23291ff
adjust system column width
Corepex May 19, 2025
2e6f83b
Merge remote-tracking branch 'origin/1430-data-object-grid-default-wi…
Corepex May 19, 2025
47fe517
Automatic frontend build
Corepex May 19, 2025
5d67153
adjust type to gain more type safty
Corepex May 19, 2025
9c180e9
Automatic frontend build
Corepex May 19, 2025
2de3923
removed `console.log`
Corepex May 19, 2025
92010ca
Automatic frontend build
Corepex May 19, 2025
fb7a8fd
Merge branch '1.x' into 1430-data-object-grid-default-width-of-column…
markus-moser Jun 2, 2025
82541e0
Automatic frontend build
markus-moser Jun 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 38 additions & 21 deletions assets/js/src/core/components/grid/grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@

/* eslint-disable max-lines */

import { serviceIds } from '@Pimcore/app/config/services/service-ids'
import { useInjection } from '@Pimcore/app/depency-injection'
import { useCssComponentHash } from '@Pimcore/modules/ant-design/hooks/use-css-component-hash'
import trackError, { GeneralError } from '@Pimcore/modules/app/error-handler'
import type { AssetGetGridApiResponse } from '@Pimcore/modules/asset/asset-api-slice.gen'
import { type DynamicTypeGridCellRegistry } from '@Pimcore/modules/element/dynamic-types/definitions/grid-cell/dynamic-type-grid-cell-registry'
import { type GridProps } from '@Pimcore/types/components/types'
import {
type CellContext,
type Column,
Expand All @@ -27,19 +33,16 @@ import {
type TableOptions,
useReactTable
} from '@tanstack/react-table'
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { isEmpty } from 'lodash'
import { Checkbox, Skeleton } from 'antd'
import cn from 'classnames'
import { useStyles } from './grid.styles'
import { Resizer } from './resizer/resizer'
import { DefaultCell } from './columns/default-cell'
import { isEmpty } from 'lodash'
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Checkbox, Skeleton } from 'antd'
import { GridRow } from './grid-cell/grid-row'
import { SortButton, type SortDirection, SortDirections } from '../sort-button/sort-button'
import { type GridProps } from '@Pimcore/types/components/types'
import trackError, { GeneralError } from '@Pimcore/modules/app/error-handler'
import type { AssetGetGridApiResponse } from '@Pimcore/modules/asset/asset-api-slice.gen'
import { DefaultCell } from './columns/default-cell'
import { GridRow } from './grid-cell/grid-row'
import { useStyles } from './grid.styles'
import { Resizer } from './resizer/resizer'

export interface ColumnMetaType {
editable?: boolean
Expand All @@ -52,6 +55,7 @@ export interface ColumnMetaType {
declare module '@tanstack/react-table' {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface ColumnMeta<TData extends RowData, TValue> extends ColumnMetaType {
size?: number
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -101,6 +105,7 @@ export const Grid = ({
const [internalSorting, setInternalSorting] = useState<SortingState>(sorting ?? [])
const memoModifiedCells = useMemo(() => { return modifiedCells ?? [] }, [JSON.stringify(modifiedCells)])
const autoColumnRef = useRef<HTMLTableCellElement>(null)
const gridCellRegistry = useInjection<DynamicTypeGridCellRegistry>(serviceIds['DynamicTypes/GridCellRegistry'])

useEffect(() => {
onActiveCellChange?.(activeCell)
Expand Down Expand Up @@ -137,6 +142,18 @@ export const Grid = ({
[props.isLoading, props.columns]
) as Array<ColumnDef<any>>

columns.forEach(column => {
if (column.meta?.type !== undefined) {
const dynamicType = gridCellRegistry.getDynamicType(column.meta.type, false)

if (dynamicType !== undefined) {
if (dynamicType?.getDefaultGridColumnWidth !== undefined) {
column.size = dynamicType.getDefaultGridColumnWidth(column.meta)
}
}
}
})

useMemo(() => {
updateRowSelectionColumn()
}, [columns, isRowSelectionEnabled, selectedRows])
Expand Down Expand Up @@ -250,7 +267,7 @@ export const Grid = ({
ref={ tableElement }
style={ { width: tableAutoWidth ? '100%' : calculateTableWidth(), minWidth: table.getCenterTotalSize() } }
>
{ !hideColumnHeaders && (
{!hideColumnHeaders && (
<thead className='ant-table-thead'>
{table.getHeaderGroups().map(headerGroup => (
<tr key={ headerGroup.id }>
Expand All @@ -260,16 +277,16 @@ export const Grid = ({
key={ header.id }
ref={ header.column.columnDef.meta?.autoWidth === true ? autoColumnRef : null }
style={
header.column.columnDef.meta?.autoWidth === true && !header.column.getIsResizing()
? {
width: 'auto',
minWidth: header.column.getSize()
}
: {
width: header.column.getSize(),
maxWidth: header.column.getSize()
}
}
header.column.columnDef.meta?.autoWidth === true && !header.column.getIsResizing()
? {
width: 'auto',
minWidth: header.column.getSize()
}
: {
width: header.column.getSize(),
maxWidth: header.column.getSize()
}
}
>
<div className='grid__cell-content'>
<span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { InheritanceLayer } from '../inheritance-layer'
import { Flex } from '@Pimcore/components/flex/flex'
import { useSelectedColumns } from '@Pimcore/modules/element/listing/abstract/configuration-layer/provider/selected-columns/use-selected-columns'
import { META_SUPPORTS_BATCH_APPEND_MODE } from '@Pimcore/modules/data-object/listing/batch-actions/batch-append-mode/batch-append-mode'
import { useTranslation } from 'react-i18next'

export interface EditModalModeCellProps {
objectCellDefinition: WithEditModalGridCellDefinition
Expand All @@ -31,6 +32,7 @@ export const EditModalCell = (props: EditModalModeCellProps): React.JSX.Element
const { decodeColumnIdentifier } = useSelectedColumns()
const { isInEditMode, fireOnUpdateCellDataEvent, disableEditMode } = useEditMode(props.cellProps)
const [form] = Form.useForm()
const { t } = useTranslation()

const onFormFinish = (values): void => {
fireOnUpdateCellDataEvent(values.value, {
Expand Down Expand Up @@ -62,15 +64,15 @@ export const EditModalCell = (props: EditModalModeCellProps): React.JSX.Element
{props.objectCellDefinition.previewComponent}
</InheritanceLayer>

{ isInEditMode && !isUndefined(props.objectCellDefinition.editModalSettings) && (
{isInEditMode && !isUndefined(props.objectCellDefinition.editModalSettings) && (
<WindowModal
cancelText='Discard'
okText='Apply Changes'
cancelText={ t('edit-modal.discard') }
okText={ t('edit-modal.apply-changes') }
onCancel={ onCancel }
onOk={ () => { form.submit() } }
open={ isInEditMode }
size={ props.objectCellDefinition.editModalSettings.modalSize }
title={ 'Inline edit' }
title={ t('edit-modal.inline-edit') }
>
<FieldWidthProvider>
<FieldCollectionProvider id={ props.cellProps.row.original.id }>
Expand All @@ -90,7 +92,7 @@ export const EditModalCell = (props: EditModalModeCellProps): React.JSX.Element
</FieldCollectionProvider>
</FieldWidthProvider>
</WindowModal>
) }
)}
</Flex>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@
* @license Pimcore Open Core License (POCL)
*/

import { type ReactElement } from 'react'
import { DynamicTypeAbstract } from '../../registry/dynamic-type-registry-abstract'
import { type DefaultCellProps } from '@Pimcore/components/grid/columns/default-cell'
import { type ColumnMeta } from '@tanstack/react-table'
import { injectable } from 'inversify'
import { type ReactElement } from 'react'
import { DynamicTypeAbstract } from '../../registry/dynamic-type-registry-abstract'

export interface AbstractGridCellDefinition extends DefaultCellProps {}
export interface AbstractGridCellDefinition extends DefaultCellProps { }

// @todo check for copy and paste handler implementation
@injectable()
export abstract class DynamicTypeGridCellAbstract extends DynamicTypeAbstract {
abstract readonly id: string
abstract getGridCellComponent (props: AbstractGridCellDefinition): ReactElement<AbstractGridCellDefinition>

getDefaultGridColumnWidth (props: ColumnMeta<any, any>): number | undefined {
return undefined
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ export class DynamicTypeGridCellAssetActions extends DynamicTypeGridCellAbstract
getGridCellComponent (props: AbstractGridCellDefinition): ReactElement<AbstractGridCellDefinition> {
return <AssetActionsCell { ...props } />
}

getDefaultGridColumnWidth (): number | undefined {
return 100
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ export class DynamicTypeGridCellAssetLink extends DynamicTypeGridCellAbstract {
getGridCellComponent (props: AbstractGridCellDefinition): ReactElement<AbstractGridCellDefinition> {
return <ElementCell { ...addColumnConfig(props, { allowedTypes: ['asset'] }) } />
}

getDefaultGridColumnWidth (): number | undefined {
return 350
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ export class DynamicTypeGridCellBoolean extends DynamicTypeGridCellAbstract {
getGridCellComponent (props: AbstractGridCellDefinition): ReactElement<AbstractGridCellDefinition> {
return <CheckboxCell { ...props } />
}

getDefaultGridColumnWidth (): number | undefined {
return 100
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ export class DynamicTypeGridCellCheckbox extends DynamicTypeGridCellAbstract {
getGridCellComponent (props: AbstractGridCellDefinition): ReactElement<AbstractGridCellDefinition> {
return <CheckboxCell { ...props } />
}

getDefaultGridColumnWidth (): number | undefined {
return 100
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ export class DynamicTypeGridCellDataObjectActions extends DynamicTypeGridCellAbs
getGridCellComponent (props: AbstractGridCellDefinition): ReactElement<AbstractGridCellDefinition> {
return <DataObjectActionsCell { ...props } />
}

getDefaultGridColumnWidth (): number | undefined {
return 100
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
* @license Pimcore Open Core License (POCL)
*/

import React, { type ReactElement } from 'react'
import { type AbstractGridCellDefinition, DynamicTypeGridCellAbstract } from '../../dynamic-type-grid-cell-abstract'
import { type ColumnMeta } from '@tanstack/react-table'
import { injectable } from 'inversify'
import React, { type ReactElement } from 'react'
import { DataObjectAdapterCell } from '../../components/data-object-adapter/data-object-adapter-cell'
import { type AbstractGridCellDefinition, DynamicTypeGridCellAbstract } from '../../dynamic-type-grid-cell-abstract'
import { useInjection } from '@Pimcore/app/depency-injection'
import { type DynamicTypeObjectDataRegistry } from '../../../objects/data-related/dynamic-type-object-data-registry'
import { serviceIds } from '@Pimcore/app/config/services/service-ids'

@injectable()
export class DynamicTypeGridCellDataObjectAdapter extends DynamicTypeGridCellAbstract {
Expand All @@ -20,4 +24,18 @@ export class DynamicTypeGridCellDataObjectAdapter extends DynamicTypeGridCellAbs
getGridCellComponent (props: AbstractGridCellDefinition): ReactElement<AbstractGridCellDefinition> {
return <DataObjectAdapterCell { ...props } />
}

getDefaultGridColumnWidth (props?: ColumnMeta<any, any>): number | undefined {
const objectDataRegistry = useInjection<DynamicTypeObjectDataRegistry>(serviceIds['DynamicTypes/ObjectDataRegistry'])
const type = props?.config?.dataObjectType as string | undefined

if (type !== undefined) {
const dynType = objectDataRegistry.getDynamicType(type)
if (dynType?.getDefaultGridColumnWidth !== undefined) {
return dynType.getDefaultGridColumnWidth(props)
}
}

return undefined
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
* @license Pimcore Open Core License (POCL)
*/

import React, { type ReactElement } from 'react'
import { type AbstractGridCellDefinition, DynamicTypeGridCellAbstract } from '../../dynamic-type-grid-cell-abstract'
import { serviceIds } from '@Pimcore/app/config/services/service-ids'
import { useInjection } from '@Pimcore/app/depency-injection'
import { type ColumnMeta } from '@tanstack/react-table'
import { injectable } from 'inversify'
import React, { type ReactElement } from 'react'
import { type DynamicTypeObjectDataRegistry } from 'src/sdk/modules/element'
import { DataObjectAdapterCell } from '../../components/data-object-adapter/data-object-adapter-cell'
import { type AbstractGridCellDefinition, DynamicTypeGridCellAbstract } from '../../dynamic-type-grid-cell-abstract'

@injectable()
export class DynamicTypeGridCellDataObjectObjectBrick extends DynamicTypeGridCellAbstract {
Expand All @@ -20,4 +24,18 @@ export class DynamicTypeGridCellDataObjectObjectBrick extends DynamicTypeGridCel
getGridCellComponent (props: AbstractGridCellDefinition): ReactElement<AbstractGridCellDefinition> {
return <DataObjectAdapterCell { ...props } />
}

getDefaultGridColumnWidth (props: ColumnMeta<any, any>): number | undefined {
const objectDataRegistry = useInjection<DynamicTypeObjectDataRegistry>(serviceIds['DynamicTypes/ObjectDataRegistry'])
const type = props.config?.dataObjectType as string

if (type !== undefined) {
const dynType = objectDataRegistry.getDynamicType(type)
if (dynType?.getDefaultGridColumnWidth !== undefined) {
return dynType.getDefaultGridColumnWidth(props)
}
}

return undefined
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ export class DynamicTypeGridCellText extends DynamicTypeGridCellAbstract {
getGridCellComponent (props: AbstractGridCellDefinition): ReactElement<AbstractGridCellDefinition> {
return <TextCell { ...props } />
}

getDefaultGridColumnWidth (): number | undefined {
return 350
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ export class DynamicTypeGridCellTextarea extends DynamicTypeGridCellAbstract {
getGridCellComponent (props: AbstractGridCellDefinition): ReactElement<AbstractGridCellDefinition> {
return <TextareaCell { ...props } />
}

getDefaultGridColumnWidth (): number | undefined {
return 400
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export const ManyToManyRelationGrid = forwardRef(function ManyToManyRelationGrid
]

columns.push(

columnHelper.accessor('actions', {
header: t('actions'),
size: 110,
Expand Down Expand Up @@ -240,7 +239,7 @@ export const ManyToManyRelationGrid = forwardRef(function ManyToManyRelationGrid
onUpdateCellData={ props.onUpdateCellData }
resizable
/>
{ props.hint }
{props.hint}
</div>
</Content>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
type IFormattedDataStructureData,
type IProcessVersionFieldDataProps
} from '@Pimcore/modules/data-object/editor/shared-tab-manager/tabs/versions/types'
import { type ColumnMeta } from '@tanstack/react-table'

export type EditMode = 'default' | 'edit-modal' | 'column-meta'
export interface EditModalSettings {
Expand Down Expand Up @@ -151,4 +152,8 @@ export abstract class DynamicTypeObjectDataAbstract implements DynamicTypeAbstra
handleDefaultValue (props: AbstractObjectDataDefinition, form: FormInstance, fieldName: NamePath): void {
// This method is intentionally left empty - can be implemented in subclasses
}

getDefaultGridColumnWidth (props?: ColumnMeta<any, any>): number | undefined {
return undefined
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export const useConvertRelationEditableColumns = (
const columnDefinition: Array<ColumnDef<any>> = []

for (const column of columns) {
console.log('flexxxxxxx', column)

columnDefinition.push(
columnHelper.accessor(EDITABLE_COLUMN_PREFIX + column.key, {
header: !_.isEmpty(column.label) ? t(String(column.label)) : undefined,
Expand Down
Loading