Skip to content

Commit 168e03d

Browse files
authored
[Grid] update tag selection in grid after deleting an item (#3464)
* update tag selection in grid after deleting an item * fix lint error * Automatic frontend build * use Number.parseInt instead of just parseInt * Automatic frontend build
1 parent 27f2b19 commit 168e03d

749 files changed

Lines changed: 30090 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

assets/js/src/core/app/api/pimcore/tags.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export const invalidatingTags = {
230230
ELEMENT_TAGS: (elementType: ElementType, id: number) => [getElementSpecificTag(tagNames.ELEMENT_TAGS, elementType, id)],
231231
ROLE: () => [tagNames.ROLE],
232232
PREDEFINED_ASSET_METADATA: () => [tagNames.PREDEFINED_ASSET_METADATA],
233-
ELEMENT_DETAIL: (elementType: ElementType, id: number) => [getElementDetailTag(elementType, id)],
233+
ELEMENT_DETAIL: (elementType: ElementType, id: number) => [getElementDetailTag(elementType, id), getElementGridTag(elementType)],
234234
EMAIL_BLOCKLIST: () => [tagNames.EMAIL_BLOCKLIST],
235235
EMAIL_BLOCKLIST_DETAIL: (id: string) => [{ type: tagNames.EMAIL_BLOCKLIST_DETAIL, id }],
236236
APPLICATION_LOGGER: () => [tagNames.APPLICATION_LOGGER],
@@ -278,3 +278,14 @@ const getElementDetailTag = (elementType: ElementType, id: number): Tag => {
278278
return { type: tagNames.DOCUMENT_DETAIL, id }
279279
}
280280
}
281+
282+
const getElementGridTag = (elementType: ElementType): Tag => {
283+
switch (elementType) {
284+
case 'asset':
285+
return tagNames.ASSET_GRID
286+
case 'data-object':
287+
return tagNames.DATA_OBJECT_GRID
288+
case 'document':
289+
return tagNames.DOCUMENT
290+
}
291+
}

assets/js/src/core/modules/element/element-api-slice-enhanced.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { invalidatingTags, tagNames } from '@Pimcore/app/api/pimcore/tags'
1717
import { type DocumentPermissions } from '../document/document-api-slice.gen'
1818

1919
const api = baseApi.enhanceEndpoints({
20-
addTagTypes: [tagNames.DATA_OBJECT_DETAIL, tagNames.ASSET_DETAIL],
20+
addTagTypes: [tagNames.DATA_OBJECT_DETAIL, tagNames.ASSET_DETAIL, tagNames.ASSET_GRID, tagNames.DATA_OBJECT_GRID],
2121
endpoints: {
2222
elementDelete: {
2323
invalidatesTags: (result, error, args) => invalidatingTags.ELEMENT_DETAIL(args.elementType, args.id)

assets/js/src/core/modules/element/listing/decorators/row-selection/view-layer/components/grid/hooks/use-grid-options/with-row-selection.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,32 @@ export const WithRowSelection = (useBaseHook: IRowSelectionDecoratorProps['useGr
2323
const { selectedRows, setSelectedRows, selectedRowsData, setSelectedRowsData } = useRowSelection()
2424
const { availableColumns } = useAvailableColumns()
2525

26+
useEffect(() => {
27+
if (data?.items === undefined) {
28+
return
29+
}
30+
31+
const items = data.items as Array<{ columns: Array<{ key: string, value: unknown }> }>
32+
const dataItemIds = new Set(
33+
items.map(item => item.columns.find(column => column.key === 'id')?.value).filter(Boolean)
34+
)
35+
36+
const prunedSelectedRows: Record<string, boolean> = {}
37+
let selectionChanged = false
38+
39+
for (const key in selectedRows) {
40+
if (dataItemIds.has(Number.parseInt(key))) {
41+
prunedSelectedRows[key] = selectedRows[key]
42+
} else {
43+
selectionChanged = true
44+
}
45+
}
46+
47+
if (selectionChanged) {
48+
setSelectedRows(prunedSelectedRows)
49+
}
50+
}, [data?.items])
51+
2652
useEffect(() => {
2753
const newSelectedRowsData: RowSelectionData['selectedRowsData'] = {}
2854
const systemColumns = availableColumns.filter(column => Array.isArray(column.group) && column.group.includes('system'))

public/build/17bd6268-3b5a-438b-a622-17d09f6ee3cb/documentEditorIframe.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/17bd6268-3b5a-438b-a622-17d09f6ee3cb/entrypoints.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/17bd6268-3b5a-438b-a622-17d09f6ee3cb/exposeRemote.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/17bd6268-3b5a-438b-a622-17d09f6ee3cb/main.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/17bd6268-3b5a-438b-a622-17d09f6ee3cb/manifest.json

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/17bd6268-3b5a-438b-a622-17d09f6ee3cb/mf-manifest.json

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/17bd6268-3b5a-438b-a622-17d09f6ee3cb/mf-stats.json

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)