Skip to content

Commit

Permalink
merged changes from the main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeriaMaltseva committed Dec 12, 2024
2 parents 6d0ea35 + c8ba422 commit 9b456e6
Show file tree
Hide file tree
Showing 105 changed files with 7,546 additions and 2,296 deletions.
3 changes: 3 additions & 0 deletions assets/build/api/openapi-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ const config: ConfigFile = {
},
'../../js/src/core/modules/data-object/unit-slice.gen.ts': {
filterEndpoints: pathMatcher(/\/unit\//i)
},
'../../js/src/core/modules/document/sites-slice.gen.ts': {
filterEndpoints: pathMatcher(/\/documents\/sites\//i)
}
},
exportName: 'api',
Expand Down
17 changes: 12 additions & 5 deletions assets/js/src/core/app/api/pimcore/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

import { type ElementType } from 'types/element-type.d'
import trackError, { GeneralError } from '@Pimcore/modules/app/error-handler'

export type Tag = string | {
type: string
Expand All @@ -34,7 +35,9 @@ export const tagNames = {
PROPERTIES: 'PROPERTIES',
SCHEDULES: 'SCHEDULES',
DEPENDENCIES: 'DEPENDENCIES',
NOTES_AND_EVENTS: 'NOTES_AND_EVENTS'
NOTES_AND_EVENTS: 'NOTES_AND_EVENTS',
AVAILABLE_TAGS: 'AVAILABLE_TAGS',
ELEMENT_TAGS: 'ELEMENT_TAGS'
}

export const providingTags = {
Expand Down Expand Up @@ -69,7 +72,9 @@ export const providingTags = {
ELEMENT_WORKFLOW: (elementType: ElementType, id: number) => [getElementDetailTag(elementType, id), tagNames.WORKFLOW],
VERSIONS_DETAIL: (id: number) => [{ type: tagNames.VERSIONS, id }, tagNames.VERSIONS],
ELEMENT_NOTES_AND_EVENTS: (elementType: ElementType, id: number) => [getElementDetailTag(elementType, id), tagNames.NOTES_AND_EVENTS],
NOTES_AND_EVENTS_ID: (id: number) => [tagNames.NOTES_AND_EVENTS, { type: tagNames.NOTES_AND_EVENTS, id }]
NOTES_AND_EVENTS_ID: (id: number) => [tagNames.NOTES_AND_EVENTS, { type: tagNames.NOTES_AND_EVENTS, id }],
ELEMENT_TAGS: (elementType: ElementType, id: number) => [getElementDetailTag(elementType, id), { type: tagNames.ELEMENT_TAGS, id }],
AVAILABLE_TAGS: () => [tagNames.AVAILABLE_TAGS]
}

export const invalidatingTags = {
Expand All @@ -94,16 +99,18 @@ export const invalidatingTags = {
ELEMENT_WORKFLOW: (elementType: ElementType, id: number) => [getElementDetailTag(elementType, id)],
NOTES_AND_EVENTS_ID: (id: number) => [{ type: tagNames.NOTES_AND_EVENTS, id }],
VERSIONS_DETAIL: (id: number) => [{ type: tagNames.VERSIONS, id }],
ELEMENT_NOTES_AND_EVENTS: (elementType: ElementType, id: number) => [getElementDetailTag(elementType, id), tagNames.NOTES_AND_EVENTS]
ELEMENT_NOTES_AND_EVENTS: (elementType: ElementType, id: number) => [tagNames.NOTES_AND_EVENTS],
ELEMENT_TAGS: (elementType: ElementType, id: number) => [{ type: tagNames.ELEMENT_TAGS, id }],
AVAILABLE_TAGS: () => [tagNames.AVAILABLE_TAGS]
}

const getElementDetailTag = (elementType: ElementType, id: number): Tag => {
const getElementDetailTag = (elementType: ElementType, id: number): Tag | undefined => {
switch (elementType) {
case 'asset':
return { type: tagNames.ASSET_DETAIL, id }
case 'data-object':
return { type: tagNames.DATA_OBJECT_DETAIL, id }
}

throw new Error(`Unknown element type: ${elementType}`)
trackError(new GeneralError(`Unknown element type: ${elementType}`))
}
4 changes: 4 additions & 0 deletions assets/js/src/core/app/config/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ import { DynamicTypeObjectDataLastname } from '@Pimcore/modules/element/dynamic-
import { DynamicTypeObjectDataEmail } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-email'
import { DynamicTypeObjectDataGender } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-gender'
import { DynamicTypeObjectDataRgbaColor } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-rgba-color'
import { DynamicTypeObjectDataCheckbox } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-checkbox'
import { DynamicTypeObjectDataUrlSlug } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-url-slug'
import { DynamicTypeObjectDataDate } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-date'
import { DynamicTypeObjectDataDatetime } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-datetime'
import { DynamicTypeObjectDataDateRange } from '@Pimcore/modules/element/dynamic-types/defintinitions/objects/data-related/types/dynamic-type-object-data-date-range'
Expand Down Expand Up @@ -243,6 +245,8 @@ container.bind(serviceIds['DynamicTypes/ObjectData/Lastname']).to(DynamicTypeObj
container.bind(serviceIds['DynamicTypes/ObjectData/Email']).to(DynamicTypeObjectDataEmail).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/Gender']).to(DynamicTypeObjectDataGender).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/RgbaColor']).to(DynamicTypeObjectDataRgbaColor).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/Checkbox']).to(DynamicTypeObjectDataCheckbox).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/UrlSlug']).to(DynamicTypeObjectDataUrlSlug).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/Date']).to(DynamicTypeObjectDataDate).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/Datetime']).to(DynamicTypeObjectDataDatetime).inSingletonScope()
container.bind(serviceIds['DynamicTypes/ObjectData/DateRange']).to(DynamicTypeObjectDataDateRange).inSingletonScope()
Expand Down
2 changes: 2 additions & 0 deletions assets/js/src/core/app/config/services/service-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export const serviceIds = {
'DynamicTypes/ObjectData/Email': 'DynamicTypes/ObjectData/Email',
'DynamicTypes/ObjectData/Gender': 'DynamicTypes/ObjectData/Gender',
'DynamicTypes/ObjectData/RgbaColor': 'DynamicTypes/ObjectData/RgbaColor',
'DynamicTypes/ObjectData/Checkbox': 'DynamicTypes/ObjectData/Checkbox',
'DynamicTypes/ObjectData/UrlSlug': 'DynamicTypes/ObjectData/UrlSlug',
'DynamicTypes/ObjectData/Date': 'DynamicTypes/ObjectData/Date',
'DynamicTypes/ObjectData/Datetime': 'DynamicTypes/ObjectData/Datetime',
'DynamicTypes/ObjectData/DateRange': 'DynamicTypes/ObjectData/DateRange',
Expand Down
79 changes: 79 additions & 0 deletions assets/js/src/core/components/collapse/collapse.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* 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 type { Meta, StoryObj } from '@storybook/react'
import { Collapse, type CollapseProps } from './collapse'
import { Extra as CollapseItemDefault } from './item/collapse-item.stories'

const config: Meta = {
title: 'Components/Layout/Collapse/Collapse',
component: Collapse,
tags: ['autodocs']
}

export default config

export const _default: StoryObj<CollapseProps> = {
args: {
items: [
{
key: '1',
...CollapseItemDefault.args
},

{
key: '2',
...CollapseItemDefault.args
},

{
key: '3',
...CollapseItemDefault.args
}
]
}
}

export const Accordion: StoryObj<CollapseProps> = {
args: {
..._default.args,
accordion: true
}
}

export const HandleUniqueItems: StoryObj<CollapseProps> = {
args: {
..._default.args,
items: [
{
key: '1',
...CollapseItemDefault.args
},

{
key: '2',
...CollapseItemDefault.args,
bordered: false,
theme: 'primary',
hasContentSeparator: false
},

{
key: '3',
...CollapseItemDefault.args
}
],
bordered: true,
theme: 'success'
}
}
96 changes: 96 additions & 0 deletions assets/js/src/core/components/collapse/collapse.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* 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, useState } from 'react'
import { CollapseItem, type CollapseItemProps, type CollapseStyleProps } from './item/collapse-item'
import { Space, type SpaceProps } from '../space/space'
import cn from 'classnames'

export interface ICollapseItem extends Omit<CollapseItemProps, 'active'> {
key: string
}

export interface CollapseProps extends CollapseStyleProps {
defaultActiveKeys?: string[]
activeKeys?: string[]
onChange?: CollapseItemProps['onChange']
items: ICollapseItem[]
space?: SpaceProps
accordion?: boolean
className?: string
}

export const Collapse = ({ className, items, accordion, space, activeKeys, defaultActiveKeys, onChange, ...props }: CollapseProps): React.JSX.Element => {
const [internalActiveKeys, setInternalActiveKeys] = useState<string[]>(activeKeys ?? defaultActiveKeys ?? [])

useEffect(() => {
if (activeKeys !== undefined) {
setInternalActiveKeys(activeKeys)
}
}, [activeKeys])

const onItemChange = (item: ICollapseItem, keys: string[]): void => {
const isItemActive = keys.includes('0')
let newActiveKeys: string[] = []

if (accordion === true && isItemActive) {
newActiveKeys = [item.key]
} else if (isItemActive) {
newActiveKeys = [...internalActiveKeys, item.key]
} else {
newActiveKeys = internalActiveKeys.filter((key) => key !== item.key)
}

if (activeKeys === undefined) {
setInternalActiveKeys(newActiveKeys)
}

if (onChange !== undefined) {
onChange(newActiveKeys)
}
}

const preparedItems = items.map((item, index) => {
return {
...props,
...item
}
})

const classnames = cn(
'collapse',
className,
'w-full'
)

return (
<Space
className={ classnames }
direction="vertical"
{ ...space }
>
{preparedItems.map((item) => {
const { key, ...preparedItem } = item

return (
<CollapseItem
key={ key }
{ ...preparedItem }
active={ internalActiveKeys.includes(item.key) }
onChange={ (keys) => { onItemChange(item, keys) } }
/>
)
})}
</Space>
)
}
13 changes: 8 additions & 5 deletions assets/js/src/core/components/collapse/item/collapse-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,24 @@ import { Box, type BoxProps } from '@Pimcore/components/box/box'

type AntdCollapsePropsItem = Exclude<CollapseProps['items'], undefined>[number]

export interface CollapseItemProps extends Omit<AntdCollapsePropsItem, 'key' | 'onChange' | 'showArrow'> {
export interface CollapseStyleProps {
size?: CollapseProps['size']
bordered?: CollapseProps['bordered']
active?: boolean
defaultActive?: boolean
expandIcon?: CollapseProps['expandIcon']
expandIconPosition?: CollapseProps['expandIconPosition']
onChange?: CollapseProps['onChange']
subLabel?: React.ReactNode
extraPosition?: 'start' | 'end'
theme?: 'success' | 'primary' | 'simple' | 'default' | 'card-with-highlight' | 'fieldset'
contentPadding?: BoxProps['padding']
hasContentSeparator?: boolean
}

export interface CollapseItemProps extends Omit<AntdCollapsePropsItem, 'key' | 'onChange' | 'showArrow'>, CollapseStyleProps {
active?: boolean
defaultActive?: boolean
onChange?: CollapseProps['onChange']
subLabel?: React.ReactNode
}

export const ExpandIcon = ({ isActive }: { isActive: boolean }): React.ReactElement => {
return <Icon value={ isActive ? 'chevron-up' : 'chevron-down' } />
}
Expand Down
16 changes: 11 additions & 5 deletions assets/js/src/core/components/drag-and-drop/context-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

import React, { type MutableRefObject, createContext, useRef, type ReactNode, useMemo } from 'react'
import { DndContext, DragOverlay, MouseSensor, TouchSensor, useSensor, useSensors, type DragEndEvent, type DragStartEvent } from '@dnd-kit/core'
import { closestCorners, DndContext, DragOverlay, MouseSensor, TouchSensor, useSensor, useSensors, type DragEndEvent, type DragStartEvent } from '@dnd-kit/core'
import { type Callback, CallbackRegistry, type ICallbackRegistry } from './callback-registry'
import { DragOverlay as StyledDragOverlay } from './drag-overlay'
import { boundingRectIntersection } from './collision-detection/boundingRectIntersection'
Expand All @@ -22,6 +22,7 @@ export interface DragAndDropInfo {
icon: string
title: string
data: any
sortable?: any
}

const defaultInfo: DragAndDropInfo = { type: 'unknown', data: null, title: '', icon: 'widget-default' }
Expand All @@ -43,9 +44,11 @@ export const DragAndDropInfoContext = createContext<IDragAndDropInfoContext>({
export const DragAndDropContextProvider = ({ children }: { children: ReactNode }): React.JSX.Element => {
const [info, setInfo] = React.useState<DragAndDropInfo>(defaultInfo)
const callbackRegistry = useRef<ICallbackRegistry>(new CallbackRegistry())
const isSortableInfo = Object.keys(info).includes('sortable')
const collisionDetection = isSortableInfo ? closestCorners : boundingRectIntersection

const mouseSensor = useSensor(MouseSensor, { activationConstraint: { distance: 10 } })
const touchSensor = useSensor(TouchSensor, { activationConstraint: { distance: 10 } })
const mouseSensor = useSensor(MouseSensor, { activationConstraint: { distance: 5 } })
const touchSensor = useSensor(TouchSensor, { activationConstraint: { distance: 5 } })

const sensors = useSensors(mouseSensor, touchSensor)

Expand Down Expand Up @@ -84,22 +87,25 @@ export const DragAndDropContextProvider = ({ children }: { children: ReactNode }
return useMemo(() => (
<DndContext
autoScroll={ false }
collisionDetection={ boundingRectIntersection }
collisionDetection={ collisionDetection }
onDragCancel={ onDragCancel }
onDragEnd={ onDragEnd }
onDragStart={ onDragStart }
sensors={ sensors }
>
{ info.sortable === undefined && (
<DragOverlay
className='dnd-overlay'
dropAnimation={ null }
style={ { width: 'max-content' } }
>
<StyledDragOverlay info={ info } />
</DragOverlay>
)}

<DragAndDropInfoContext.Provider value={ { type: info.type, data: info.data, icon: info.icon, title: info.title, setInfo: setContext, removeInfo: removeContext, getInfo: getContext, callbackRegistry } }>
{children}
</DragAndDropInfoContext.Provider>
</DndContext>
), [info, children])
), [info, children, collisionDetection])
}
6 changes: 4 additions & 2 deletions assets/js/src/core/components/drag-and-drop/draggable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useDraggable } from '@dnd-kit/core'
import { type DragAndDropInfo } from './context-provider'
import { uuid } from '@Pimcore/utils/uuid'
import { GlobalStyle } from './draggable.styles'
import trackError, { GeneralError } from '@Pimcore/modules/app/error-handler'

interface DraggableProps {
children: React.ReactNode
Expand All @@ -32,7 +33,8 @@ function Draggable (props: DraggableProps): React.JSX.Element {
const Child = Children.only(props.children)

if (!isValidElement(Child)) {
throw new Error('Children must be a valid react component')
trackError(new GeneralError('Children must be a valid react component'))
throw new Error('Invalid React child element.')
}

const Component = Child.type
Expand All @@ -48,7 +50,7 @@ function Draggable (props: DraggableProps): React.JSX.Element {
{ ...Child.props }
/>
</div>
), [])
), [props.children])
}

const DraggableMemo = React.memo(Draggable)
Expand Down
Loading

0 comments on commit 9b456e6

Please sign in to comment.