[Asset Preview] Persist folder preview image size (#3745) - #3897
Open
xIrusux wants to merge 6 commits into
Open
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…t-asset-preview-image-size-2026x # Conflicts: # build-dist/build-9e3f09e47269.zip # build-dist/build-d10f72a05090.zip # build-dist/build-f2a33d8e6d16.zip
Replaces the server-backed approach with client-side persistence, per review feedback on pimcore/studio-backend-bundle#1953: the setting does not need to sync across browsers or machines, so a database table and two API endpoints are overkill. - Remove the hand-injected folder-preview-setting-api-slice. - Add useFolderPreviewImageSize, which stores a folder -> size map under a user namespaced local storage key, following the same conventions as the persisted widget-manager tab layout. Only folders deviating from the default are kept, and the key is removed once the map is empty. - Extract SizeTypes into preview-card.types so it can be consumed without pulling in the antd based component; preview-card re-exports it, so the SDK surface is unchanged. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Verdict: LGTM. The PR fixes the ephemeral folder preview size by persisting it per folder and user in local storage (use-folder-preview-image-size.ts:75-99).
Changes:
- Replaces component-local state with the persistence hook (
preview-container.tsx:33-35). - Validates, restores, prunes, and namespaces stored values (
use-folder-preview-image-size.ts:26-62). - Preserves
SizeTypescompatibility through re-export and adds focused regression tests (preview-card.tsx:23-26,use-folder-preview-image-size.test.ts:42-140).
The fix addresses the root cause at the owning hook boundary. Existing enum consumers remain compatible, and malformed or obsolete storage values safely fall back to the default. Remaining browser-local behavior is intentional (use-folder-preview-image-size.ts:70-73).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
preview-container.tsx |
Uses persisted preview sizing. |
hooks/use-folder-preview-image-size.ts |
Implements per-user, per-folder persistence. |
hooks/use-folder-preview-image-size.test.ts |
Covers persistence and edge cases. |
preview-card.types.ts |
Extracts the size enum. |
preview-card.tsx |
Re-exports the enum for compatibility. |
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What
Closes #3745. Persist the asset folder Preview tab "Image display" size (Small/Large) so it is remembered per folder and survives remount, reload and re-login. Previously it was ephemeral
useStatethat reset on every remount.Approach
Client-side only, per review feedback on the companion backend PR (pimcore/studio-backend-bundle#1953):
The setting is intentionally browser-local — it does not sync across browsers or machines. The backend PR #1953 is being closed; no API, entity, table or migration is involved.
Changes
hooks/use-folder-preview-image-size.ts(new) — stores afolderId -> sizemap in one local storage entry per user, keyedpimcore_studio_asset_folder_preview_image_size_<userId>.getLocalStorageItem/removeLocalStorageItemutils andloadReduxState, and follows the same key convention as the persisted widget-manager tab layout (getWidgetManagerStorageKey), including theuserId !== 0guard for "user not loaded yet".SizeTypeson read, so a hand-edited or future-format entry can never reach theSegmentedcontrol; unparseable JSON falls back to the default with aconsole.warn.small) are stored, and the whole key is removed once the map is empty — the payload stays bounded no matter how many folders are visited.preview-container.tsx—useStatereplaced by the hook;onChangeis a single local call again.setCardSizeadded to the memo dependency list.folder-preview-setting-api-slice.ts— deleted.preview-card.types.ts(new) —SizeTypesextracted out ofpreview-card.tsx, which importsantd/es/card/Metaand therefore cannot be loaded under the jest transform.preview-card.tsxre-exports it, so all existing consumers and the@sdk/componentsbarrel are unchanged.Tests
9 new jest tests covering the default, restore, per-folder isolation, pruning on return to default, key removal, corrupt JSON, unknown enum values, per-user namespacing and the unloaded-user key.
Verification
npm run check-types— cleannpm run lint— cleannpm run test— 235 passed / 17 suitespreview-settingrequest is fired.🤖 Generated with Claude Code