Skip to content

[Asset Preview] Persist folder preview image size (#3745) - #3897

Open
xIrusux wants to merge 6 commits into
2026.xfrom
feature/3745-persist-asset-preview-image-size-2026x
Open

[Asset Preview] Persist folder preview image size (#3745)#3897
xIrusux wants to merge 6 commits into
2026.xfrom
feature/3745-persist-asset-preview-image-size-2026x

Conversation

@xIrusux

@xIrusux xIrusux commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

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 useState that reset on every remount.

Approach

Client-side only, per review feedback on the companion backend PR (pimcore/studio-backend-bundle#1953):

@fashxp: we also could consider storing it in local storage client side - similar to the opened tabs? wdyt?

@martineiber: Agreed — unless we need it to sync across browsers/machines, local storage (like we do for the opened tabs) is the cleanest option here. The database approach would be a bit overkill then.

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 a folderId -> size map in one local storage entry per user, keyed pimcore_studio_asset_folder_preview_image_size_<userId>.
    • Reuses the existing getLocalStorageItem / removeLocalStorageItem utils and loadReduxState, and follows the same key convention as the persisted widget-manager tab layout (getWidgetManagerStorageKey), including the userId !== 0 guard for "user not loaded yet".
    • Values are validated against SizeTypes on read, so a hand-edited or future-format entry can never reach the Segmented control; unparseable JSON falls back to the default with a console.warn.
    • Only folders deviating from the default (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.tsxuseState replaced by the hook; onChange is a single local call again. setCardSize added to the memo dependency list.
  • folder-preview-setting-api-slice.ts — deleted.
  • preview-card.types.ts (new) — SizeTypes extracted out of preview-card.tsx, which imports antd/es/card/Meta and therefore cannot be loaded under the jest transform. preview-card.tsx re-exports it, so all existing consumers and the @sdk/components barrel 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 — clean
  • npm run lint — clean
  • npm run test — 235 passed / 17 suites
  • Manual: toggle to Large, switch tabs, reload, log out and back in — size sticks; a different folder is unaffected; back to Small removes the entry and eventually the key; no preview-setting request is fired.

🤖 Generated with Claude Code

xIrusux and others added 3 commits July 16, 2026 09:00
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@xIrusux xIrusux linked an issue Jul 16, 2026 that may be closed by this pull request
@xIrusux xIrusux added this to the 2026.3.0 milestone Jul 16, 2026
@xIrusux xIrusux self-assigned this Jul 16, 2026
xIrusux and others added 2 commits July 27, 2026 12:59
…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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 SizeTypes compatibility 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.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Asset Preview] - save image size settings

2 participants