-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #814 from pimcore/753-missing-asset-context-menu-a…
…ctions-rename * added manual cache update * created simple-to-use hook for manual cache updates * renamed `updateCache` to `update` * cleanup * Automatic frontend build * Automatic frontend build * simplified `updateFieldValue` function * Automatic frontend build --------- Co-authored-by: Corepex <[email protected]>
- Loading branch information
Showing
33 changed files
with
2,068 additions
and
1,962 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
assets/js/src/core/modules/element/hooks/use-cache-update.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* 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 { store, useAppDispatch } from '@Pimcore/app/store' | ||
import { api as assetApi } from '@Pimcore/modules/asset/asset-api-slice-enhanced' | ||
import { api as dataObjectApi } from '@Pimcore/modules/data-object/data-object-api-slice-enhanced' | ||
import { type TagDescription } from '@reduxjs/toolkit/query' | ||
import { type ElementType } from '../../../../../types/element-type.d' | ||
import { type Element } from '../element-helper' | ||
|
||
interface UseCacheUpdateHookReturn { | ||
update: (props: UpdateCacheProps) => void | ||
updateFieldValue: (id: number, field: string, value: any) => void | ||
} | ||
|
||
interface UpdateCacheProps { | ||
updateFn: (draft: any) => void | ||
} | ||
|
||
export const useCacheUpdate = (elementType: ElementType, tags: ReadonlyArray<TagDescription<string>>): UseCacheUpdateHookReturn => { | ||
const dispatch = useAppDispatch() | ||
const api = getElementTypeDependantApi() | ||
const cacheEntries = getCacheEntries(tags) | ||
|
||
function getCacheEntries (tags: ReadonlyArray<TagDescription<string>>): Array<{ | ||
endpointName: string | ||
originalArgs: any | ||
queryCacheKey: string | ||
}> { | ||
return api.util.selectInvalidatedBy( | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
store.getState() as any, | ||
tags | ||
) | ||
} | ||
|
||
function getElementTypeDependantApi (): typeof assetApi | typeof dataObjectApi { | ||
if (elementType === 'asset') { | ||
return assetApi | ||
} | ||
|
||
if (elementType === 'data-object') { | ||
return dataObjectApi | ||
} | ||
|
||
throw new Error('Unknown element type') | ||
} | ||
|
||
const update = ({ updateFn }: UpdateCacheProps): void => { | ||
cacheEntries.forEach((cacheEntry) => { | ||
// @ts-expect-error not compatible with the current type definitions | ||
dispatch(api.util.updateQueryData( | ||
cacheEntry.endpointName, | ||
cacheEntry.originalArgs, | ||
updateFn | ||
)) | ||
}) | ||
} | ||
|
||
const updateFieldValue = (id: number, field: string, value: any): void => { | ||
update({ | ||
updateFn: (draft: any) => { | ||
if ('items' in draft && typeof draft.items === 'object') { | ||
const entries = draft.items as Element[] | ||
const indexToUpdate = entries.findIndex((entry) => entry.id === id) | ||
|
||
if (indexToUpdate !== -1 && field in draft.items![indexToUpdate]) { | ||
draft.items![indexToUpdate][field] = value | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
|
||
return { | ||
update, | ||
updateFieldValue | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
public/build/65ed0e96-b0cb-49f1-b16f-3e333f8fefee/entrypoints.json
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
public/build/65ed0e96-b0cb-49f1-b16f-3e333f8fefee/manifest.json
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...-08c4-43f3-9f28-876514532044/core-dll.css → ...-392b-4411-b632-60ddee170740/core-dll.css
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
public/build/85fbfe37-392b-4411-b632-60ddee170740/core-dll.js
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
public/build/85fbfe37-392b-4411-b632-60ddee170740/entrypoints.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"entrypoints": { | ||
"core-dll": { | ||
"css": [ | ||
"/bundles/pimcorestudioui/build/85fbfe37-392b-4411-b632-60ddee170740/core-dll.css" | ||
], | ||
"js": [ | ||
"/bundles/pimcorestudioui/build/85fbfe37-392b-4411-b632-60ddee170740/core-dll.js" | ||
] | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.