Skip to content

[6.x] Ability to save/reset changes to filter presets#13956

Merged
jasonvarga merged 6 commits into6.xfrom
save-listing-preset
Mar 11, 2026
Merged

[6.x] Ability to save/reset changes to filter presets#13956
jasonvarga merged 6 commits into6.xfrom
save-listing-preset

Conversation

@duncanmcclean
Copy link
Copy Markdown
Member

This pull request brings back the ability to save/reset changes to listing filter presets, like you could in v5.

I've added a new selectedPreset state to track which preset the user selected (so it persists when the user adds/removes filters), separate from the activePreset state which tracks whether the current filters match any presets.

Filters are now cloned when selecting a preset to prevent mutation of saved preset data.

Closes #13754

Copy link
Copy Markdown
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

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

AI review:

Bug — Delete/Rename when dirty: When a preset is selected and the user changes filters, activePreset becomes null (filters no longer match). The dropdown (Rename/Delete) is still shown because it’s keyed by handle === selectedPreset. But deletePreset() uses activePreset.value (null), so it would remove the wrong preference key. renamePreset() uses activePresetPayload.value.display (i.e. presets.value[null]), which is undefined. saveExisting() uses activePreset.value in the key comparison, so the rename would not find the preset. These paths should use selectedPreset / selectedPresetPayload so Rename and Delete work when the view is dirty.

Suggested change:

  1. Use selectedPreset for delete/rename flow
    When the dropdown is shown, the “current” preset is the one identified by selectedPreset, not activePreset. Update:
  • deletePreset(): use selectedPreset.value (e.g. Statamic.$preferences.remove(\${preferencesKey.value}.${selectedPreset.value})`).
  • renamePreset(): use selectedPresetPayload.value.display for the initial name (e.g. savingPresetName.value = selectedPresetPayload.value.display).
  • saveExisting(): where you detect the preset to rename (key === activePreset.value), use key === selectedPreset.value (and keep using selectedPreset for any follow-up like selectPreset(savingPresetHandle.value)).
  • presetPreferencesPayload: when used for renaming, the display fallback should come from the selected preset, e.g. activePresetPayload.value.displayselectedPresetPayload.value?.display ?? activePresetPayload.value?.display (or use selectedPresetPayload when in rename context) so the modal has the right name when dirty.
  • Any other logic that means “the preset for this tab” in the dropdown context should use selectedPreset/selectedPresetPayload.

@duncanmcclean
Copy link
Copy Markdown
Member Author

Just pushed some changes.

I've updated deletePreset(), renamePreset(), saveExisting(), and presetPreferencesPayload to use selectedPreset/selectedPresetPayload instead of activePreset/activePresetPayload.

I've also fixed the rename modal's "already exists" validation to filter by selectedPreset.

@jasonvarga jasonvarga merged commit 453047e into 6.x Mar 11, 2026
17 checks passed
@jasonvarga jasonvarga deleted the save-listing-preset branch March 11, 2026 15:48
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.

Unable to save updates to custom views

2 participants