-
Notifications
You must be signed in to change notification settings - Fork 9
1042 relation data path formatter #1447
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
base: 1.x
Are you sure you want to change the base?
Changes from all commits
ed9d685
11f89a1
93bee9f
7a853d9
8f74ac1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,9 @@ import type { DragAndDropInfo } from '@Pimcore/components/drag-and-drop/context- | |
import { useAlertModal } from '@Pimcore/components/modal/alert-modal/hooks/use-alert-modal' | ||
import { useTranslation } from 'react-i18next' | ||
import { type Asset } from '@Pimcore/modules/asset/asset-api-slice-enhanced' | ||
import { useEffect } from 'react' | ||
import { useDataObjectHelper } from '@Pimcore/modules/data-object/hooks/use-data-object-helper' | ||
import { useDataObject } from '@Pimcore/modules/data-object/hooks/use-data-object' | ||
|
||
export interface ManyToManyRelationValueItem { | ||
id: number | ||
|
@@ -33,22 +36,51 @@ interface UseValueReturn { | |
addItems: (items: ManyToManyRelationValueItem[]) => void | ||
addAssets: (assets: Asset[]) => Promise<void> | ||
maxRemainingItems?: number | ||
pathFormatterClass?: string | null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently we have the loading spinner + the triggered |
||
} | ||
|
||
export const useValue = ( | ||
value: ManyToManyRelationValue | null, | ||
setValue: (value: ManyToManyRelationValue | null) => void, | ||
displayedValue: ManyToManyRelationValue | null, | ||
setDisplayedValue: (value: ManyToManyRelationValue | null) => void, | ||
setIsLoading: (isLoading: boolean) => void, | ||
maxItems: number | null, | ||
allowMultipleAssignments?: boolean | ||
id: string | undefined, | ||
allowMultipleAssignments?: boolean, | ||
pathFormatterClass?: string | null | ||
): UseValueReturn => { | ||
const { id: dataObjectId } = useDataObject() | ||
const { formatPath } = useDataObjectHelper() | ||
const modal = useAlertModal() | ||
|
||
const { t } = useTranslation() | ||
const itemIsInValue = (id: number, type: string): boolean => { | ||
return value?.some(item => item.id === id && item.type === type) ?? false | ||
} | ||
|
||
useEffect(() => { | ||
console.log(pathFormatterClass, value, dataObjectId, id) | ||
if (pathFormatterClass !== null && value !== null && dataObjectId !== undefined && id !== undefined) { | ||
setIsLoading(true) | ||
|
||
formatPath(value, id, dataObjectId).then((data) => { | ||
if (data === undefined) { | ||
return | ||
} | ||
|
||
const newValue = value.map((item) => ({ | ||
...item, | ||
fullPath: data.items.find(i => i.objectReference === `object_${item.id}`)?.formatedPath ?? item.fullPath | ||
})) | ||
|
||
console.log('newValue', newValue) | ||
setDisplayedValue(newValue) | ||
setIsLoading(false) | ||
}).catch(error => { console.error(error) }) | ||
} | ||
}, [value]) | ||
|
||
const addItems = (items: ManyToManyRelationValueItem[]): void => { | ||
const newItems = allowMultipleAssignments !== true | ||
? items.filter(item => !itemIsInValue(item.id, item.type)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ export interface ManyToManyRelationClassDefinitionProps { | |
} | ||
|
||
export interface ManyToManyRelationProps extends IRelationAllowedTypesDataComponent, ManyToManyRelationClassDefinitionProps { | ||
id?: string | ||
disabled?: boolean | ||
inherited?: boolean | ||
value?: ManyToManyRelationValue | null | ||
|
@@ -64,7 +65,8 @@ export interface ManyToManyRelationProps extends IRelationAllowedTypesDataCompon | |
export const ManyToManyRelation = (props: ManyToManyRelationProps): React.JSX.Element => { | ||
const [value, setValue] = useState<ManyToManyRelationValue | null>(props.value ?? null) | ||
const [displayedValue, setDisplayedValue] = useState<ManyToManyRelationValue | null>(props.value ?? null) | ||
const { onDrop, deleteItem, onSearch, addAssets, addItems, maxRemainingItems } = useValue(value, setValue, displayedValue, setDisplayedValue, props.maxItems, props.allowMultipleAssignments) | ||
const [isLoading, setIsLoading] = useState<boolean>(props.pathFormatterClass !== null) | ||
const { onDrop, deleteItem, onSearch, addAssets, addItems, maxRemainingItems } = useValue(value, setValue, displayedValue, setDisplayedValue, setIsLoading, props.maxItems, props.id, props.allowMultipleAssignments, props.pathFormatterClass) | ||
|
||
useEffect(() => { | ||
if (!isEqual(value, props.value ?? null)) { | ||
|
@@ -79,7 +81,7 @@ export const ManyToManyRelation = (props: ManyToManyRelationProps): React.JSX.El | |
} | ||
}, [JSON.stringify(props.value)]) | ||
|
||
if (props.isLoading === true) { | ||
if (isLoading || props.isLoading === true) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The loading state here seemed to be a good idea, but it's a bit annoying that the full data type has a loading state - especially when a new item is added via the tree. The grid data type itself also provides a loading prop. Maybe it's better to just set the grid itself to loading instead of everything? Not sure how easy it's possible but in a perfect world we would see the loading spinner directly on row level for newly added items (and only for the initial load we use the global one). |
||
return ( | ||
<Content | ||
loading | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"entrypoints": { | ||
"vendor": { | ||
"js": [ | ||
"/bundles/pimcorestudioui/build/6cba8b67-a6fe-4ac6-aa10-d3d8a0f49ea9/vendor.js" | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"bundles/pimcorestudioui/build/6cba8b67-a6fe-4ac6-aa10-d3d8a0f49ea9/vendor.js": "/bundles/pimcorestudioui/build/6cba8b67-a6fe-4ac6-aa10-d3d8a0f49ea9/vendor.js" | ||
} |
This file was deleted.
This file was deleted.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"entrypoints": { | ||
"core-dll": { | ||
"css": [ | ||
"/bundles/pimcorestudioui/build/a561e8d7-38c1-4bcf-976a-dfd64956d437/core-dll.css" | ||
], | ||
"js": [ | ||
"/bundles/pimcorestudioui/build/a561e8d7-38c1-4bcf-976a-dfd64956d437/core-dll.js" | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"bundles/pimcorestudioui/a561e8d7-38c1-4bcf-976a-dfd64956d437/core-dll.css": "/bundles/pimcorestudioui/build/a561e8d7-38c1-4bcf-976a-dfd64956d437/core-dll.css", | ||
"bundles/pimcorestudioui/a561e8d7-38c1-4bcf-976a-dfd64956d437/core-dll.js": "/bundles/pimcorestudioui/build/a561e8d7-38c1-4bcf-976a-dfd64956d437/core-dll.js", | ||
"bundles/pimcorestudioui/a561e8d7-38c1-4bcf-976a-dfd64956d437/105.js": "/bundles/pimcorestudioui/build/a561e8d7-38c1-4bcf-976a-dfd64956d437/105.js", | ||
"bundles/pimcorestudioui/a561e8d7-38c1-4bcf-976a-dfd64956d437/fonts/Lato-Light.ttf": "/bundles/pimcorestudioui/build/a561e8d7-38c1-4bcf-976a-dfd64956d437/fonts/Lato-Light.c7400fca.ttf", | ||
"bundles/pimcorestudioui/a561e8d7-38c1-4bcf-976a-dfd64956d437/fonts/Lato-Regular.ttf": "/bundles/pimcorestudioui/build/a561e8d7-38c1-4bcf-976a-dfd64956d437/fonts/Lato-Regular.9d883d54.ttf", | ||
"bundles/pimcorestudioui/a561e8d7-38c1-4bcf-976a-dfd64956d437/fonts/Lato-Bold.ttf": "/bundles/pimcorestudioui/build/a561e8d7-38c1-4bcf-976a-dfd64956d437/fonts/Lato-Bold.636be8de.ttf", | ||
"bundles/pimcorestudioui/a561e8d7-38c1-4bcf-976a-dfd64956d437/images/spritesheet.svg": "/bundles/pimcorestudioui/build/a561e8d7-38c1-4bcf-976a-dfd64956d437/images/spritesheet.a4e0eb7a.svg", | ||
"bundles/pimcorestudioui/a561e8d7-38c1-4bcf-976a-dfd64956d437/images/spritesheet-2x.png": "/bundles/pimcorestudioui/build/a561e8d7-38c1-4bcf-976a-dfd64956d437/images/spritesheet-2x.7ea3a6d4.png", | ||
"bundles/pimcorestudioui/a561e8d7-38c1-4bcf-976a-dfd64956d437/images/spritesheet.png": "/bundles/pimcorestudioui/build/a561e8d7-38c1-4bcf-976a-dfd64956d437/images/spritesheet.ef32ea2b.png", | ||
"bundles/pimcorestudioui/a561e8d7-38c1-4bcf-976a-dfd64956d437/images/marker-icon.png": "/bundles/pimcorestudioui/build/a561e8d7-38c1-4bcf-976a-dfd64956d437/images/marker-icon.2b3e1faf.png", | ||
"bundles/pimcorestudioui/a561e8d7-38c1-4bcf-976a-dfd64956d437/images/layers-2x.png": "/bundles/pimcorestudioui/build/a561e8d7-38c1-4bcf-976a-dfd64956d437/images/layers-2x.8f2c4d11.png", | ||
"bundles/pimcorestudioui/a561e8d7-38c1-4bcf-976a-dfd64956d437/images/layers.png": "/bundles/pimcorestudioui/build/a561e8d7-38c1-4bcf-976a-dfd64956d437/images/layers.416d9136.png" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"entrypoints": { | ||
"main": { | ||
"js": [ | ||
"/bundles/pimcorestudioui/build/f1523252-b7f0-4ed2-9cb3-85d97b02c6ca/main.js" | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"bundles/pimcorestudioui/build/f1523252-b7f0-4ed2-9cb3-85d97b02c6ca/main.js": "/bundles/pimcorestudioui/build/f1523252-b7f0-4ed2-9cb3-85d97b02c6ca/main.js" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be a bit tricky but we need to somehow find a way to respect the different possible context cases:
https://github.com/pimcore/studio-backend-bundle/blob/75ac539df3485d772261d8645d50765710ac0647/src/DataObject/Legacy/PathFormatterHelper.php#L46