Skip to content
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

Added cache clear to asset view tab #884

Open
wants to merge 2 commits into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 15 additions & 2 deletions assets/js/src/core/modules/asset/asset-api-slice-enhanced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL
*/

import { invalidatingTags, providingTags, tagNames } from '@Pimcore/app/api/pimcore/tags'
import { invalidatingTags, providingTags, type Tag, tagNames } from '@Pimcore/app/api/pimcore/tags'
import { api as baseApi } from './asset-api-slice.gen'

const api = baseApi.enhanceEndpoints({
Expand All @@ -38,7 +38,20 @@ const api = baseApi.enhanceEndpoints({
},

assetGetTree: {
providesTags: (result, error, args) => args.parentId !== undefined ? providingTags.ASSET_TREE_ID(args.parentId) : providingTags.ASSET_TREE()
providesTags: (result, error, args) => {
let providingTagsForTree: Tag[] = []
if (result !== undefined) {
providingTagsForTree = result?.items.flatMap((item) => providingTags.ASSET_DETAIL_ID(item.id))
}

providingTagsForTree = [
...providingTagsForTree,
...providingTags.ASSET_TREE(),
...args.parentId !== undefined ? providingTags.ASSET_TREE_ID(args.parentId) : []
]

return providingTagsForTree
}
},

assetUpdateById: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ import {
} from '@Pimcore/modules/asset/editor/types/folder/tab-manager/tabs/preview/flex-container-view'
import { PreviewCard } from '@Pimcore/components/preview-card/preview-card'
import { useAssetHelper } from '@Pimcore/modules/asset/hooks/use-asset-helper'
import { type AssetGetTreeApiResponse } from '@Pimcore/modules/asset/asset-api-slice-enhanced'
import { api as assetApi, type AssetGetTreeApiResponse } from '@Pimcore/modules/asset/asset-api-slice-enhanced'
import { type DropdownProps } from '@Pimcore/components/dropdown/dropdown'
import { Icon } from '@Pimcore/components/icon/icon'
import { useRename } from '@Pimcore/modules/element/actions/rename/use-rename'
import { useDelete } from '@Pimcore/modules/element/actions/delete/use-delete'
import { useDownload } from '@Pimcore/modules/asset/actions/download/use-download'
import { useUploadNewVersion } from '@Pimcore/modules/asset/actions/upload-new-version/upload-new-version'
import { useOpen } from '@Pimcore/modules/element/actions/open/open'
import { useAppDispatch } from '@Pimcore/app/store'
import { invalidatingTags } from '@Pimcore/app/api/pimcore/tags'

interface FlexContainerProps {
assets: AssetGetTreeApiResponse
Expand All @@ -40,6 +42,7 @@ const FlexContainer = (props: FlexContainerProps): React.JSX.Element => {
const { downloadContextMenuItem } = useDownload()
const { uploadNewVersionContextMenuItem } = useUploadNewVersion()
const { openContextMenuItem } = useOpen('asset')
const dispatch = useAppDispatch()

const cards: ReactNode[] = []
assets.items.forEach((asset) => {
Expand All @@ -51,6 +54,14 @@ const FlexContainer = (props: FlexContainerProps): React.JSX.Element => {
})
}

const clearCache = (): void => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we do this somewhere inside of the action so that the cache clears in all cases when the asset gets deleted? And in addition to that shouldn't we use our new useElementRefresh then?

dispatch(
assetApi.util.invalidateTags(
invalidatingTags.ASSET_DETAIL_ID(asset.id)
)
)
}

const dropdownItems: DropdownProps['menu']['items'] = [
openContextMenuItem(asset),
{
Expand All @@ -68,7 +79,7 @@ const FlexContainer = (props: FlexContainerProps): React.JSX.Element => {
renameContextMenuItem(asset),
uploadNewVersionContextMenuItem(asset),
downloadContextMenuItem(asset),
deleteContextMenuItem(asset)
deleteContextMenuItem(asset, clearCache)
]

if ('imageThumbnailPath' in asset && asset.imageThumbnailPath !== undefined && asset.imageThumbnailPath !== null) {
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/build/09434365-d3c3-4f58-b654-9c28e80a2845/entrypoints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"entrypoints": {
"core-dll": {
"css": [
"/bundles/pimcorestudioui/build/09434365-d3c3-4f58-b654-9c28e80a2845/core-dll.css"
],
"js": [
"/bundles/pimcorestudioui/build/09434365-d3c3-4f58-b654-9c28e80a2845/core-dll.js"
]
}
}
}

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions public/build/3dc417f0-e327-4bc2-aaf8-77d1ea6f2ddf/entrypoints.json

This file was deleted.

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": {
"main": {
"js": [
"/bundles/pimcorestudioui/build/df05d724-6117-4fa6-972b-867b28a7a0d5/main.js"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"bundles/pimcorestudioui/build/df05d724-6117-4fa6-972b-867b28a7a0d5/main.js": "/bundles/pimcorestudioui/build/df05d724-6117-4fa6-972b-867b28a7a0d5/main.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"entrypoints": {
"vendor": {
"js": [
"/bundles/pimcorestudioui/build/f35b9ca7-3624-488d-84f5-369e9570e93f/vendor.js"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"bundles/pimcorestudioui/build/f35b9ca7-3624-488d-84f5-369e9570e93f/vendor.js": "/bundles/pimcorestudioui/build/f35b9ca7-3624-488d-84f5-369e9570e93f/vendor.js"
}