[6.x] Ability to save/reset changes to filter presets#13956
Conversation
jasonvarga
left a comment
There was a problem hiding this comment.
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:
- Use
selectedPresetfor delete/rename flow
When the dropdown is shown, the “current” preset is the one identified byselectedPreset, notactivePreset. Update:
-
deletePreset(): useselectedPreset.value(e.g.Statamic.$preferences.remove(\${preferencesKey.value}.${selectedPreset.value})`). -
renamePreset(): useselectedPresetPayload.value.displayfor the initial name (e.g.savingPresetName.value = selectedPresetPayload.value.display). -
saveExisting(): where you detect the preset to rename (key === activePreset.value), usekey === selectedPreset.value(and keep usingselectedPresetfor any follow-up likeselectPreset(savingPresetHandle.value)). -
presetPreferencesPayload: when used for renaming, the display fallback should come from the selected preset, e.g.activePresetPayload.value.display→selectedPresetPayload.value?.display ?? activePresetPayload.value?.display(or useselectedPresetPayloadwhen 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.
|
Just pushed some changes. I've updated I've also fixed the rename modal's "already exists" validation to filter by |
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
selectedPresetstate to track which preset the user selected (so it persists when the user adds/removes filters), separate from theactivePresetstate 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