Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions keep-ui/entities/presets/model/usePresetActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ export function usePresetActions() {
);
const revalidateMultiple = useRevalidateMultiple();
const mutatePresetsList = useCallback(
() => revalidateMultiple(["/preset", "/preset?"]),
() => {
// Use exact match for /preset (list without filters) and prefix match only
// for /preset? (filtered queries like /preset?filters=...).
// Do NOT use a broad /preset prefix — that would accidentally match
// /preset/{id}/column-config and wipe the user's column configuration.
revalidateMultiple(["/preset"], { isExact: true });
revalidateMultiple(["/preset?"]);
},
[revalidateMultiple]
);
const mutateTags = useCallback(
Expand Down Expand Up @@ -88,7 +95,7 @@ export function usePresetActions() {
return;
}
try {
const response = await api.delete(`/preset/${presetId}`);
await api.delete(`/preset/${presetId}`);
showSuccessToast(`Preset ${presetName} deleted!`);
mutatePresetsList();
setLocalDynamicPresets((oldOrder) =>
Expand Down
7 changes: 2 additions & 5 deletions keep-ui/entities/presets/model/usePresetColumnConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useApi } from "@/shared/lib/hooks/useApi";
import { useCallback } from "react";
import { showErrorToast, showSuccessToast } from "@/shared/ui";
import { ColumnConfiguration } from "./types";
import { useRevalidateMultiple } from "@/shared/lib/state-utils";

type UsePresetColumnConfigOptions = {
presetId?: string;
Expand All @@ -24,7 +23,6 @@ export const usePresetColumnConfig = ({
...options
}: UsePresetColumnConfigOptions = {}) => {
const api = useApi();
const revalidateMultiple = useRevalidateMultiple();

const {
data: columnConfig = DEFAULT_COLUMN_CONFIG,
Expand Down Expand Up @@ -82,16 +80,15 @@ export const usePresetColumnConfig = ({
config
);
showSuccessToast("Column configuration saved!");
// mutate() already revalidates /preset/${presetId}/column-config
mutate();
// Also revalidate preset list to update any cached data
revalidateMultiple(["/preset", "/preset?"]);
return response;
} catch (error) {
showErrorToast(error, "Failed to save column configuration");
throw error;
}
},
[api, presetId, mutate, revalidateMultiple]
[api, presetId, mutate]
);

return {
Expand Down
37 changes: 19 additions & 18 deletions keep-ui/entities/presets/model/usePresetColumnState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,19 @@ export const usePresetColumnState = ({
columnListFormats?: Record<string, ListFormatOption>;
}) => {
if (shouldUseBackend && !error) {
// Batch all updates into a single API call
const batchedUpdate: Partial<ColumnConfiguration> = {};

if (updates.columnVisibility !== undefined) {
batchedUpdate.column_visibility = updates.columnVisibility;
}
if (updates.columnOrder !== undefined) {
batchedUpdate.column_order = updates.columnOrder;
}
if (updates.columnRenameMapping !== undefined) {
batchedUpdate.column_rename_mapping = updates.columnRenameMapping;
}
if (updates.columnTimeFormats !== undefined) {
batchedUpdate.column_time_formats = updates.columnTimeFormats;
}
if (updates.columnListFormats !== undefined) {
batchedUpdate.column_list_formats = updates.columnListFormats;
}
// Always send the FULL current config to the backend.
// The backend PUT replaces the entire config object, so sending only
// a partial update (e.g. just column_rename_mapping) would wipe out
// all other fields (column_visibility, column_order, etc.) causing
// custom columns to disappear after a rename or format change.
const batchedUpdate: ColumnConfiguration = {
column_visibility: updates.columnVisibility ?? columnVisibility,
column_order: updates.columnOrder ?? columnOrder,
column_rename_mapping:
updates.columnRenameMapping ?? columnRenameMapping,
column_time_formats: updates.columnTimeFormats ?? columnTimeFormats,
column_list_formats: updates.columnListFormats ?? columnListFormats,
};

try {
return await updateColumnConfig(batchedUpdate);
Expand Down Expand Up @@ -209,6 +204,12 @@ export const usePresetColumnState = ({
setLocalColumnTimeFormats,
setLocalColumnListFormats,
error,
// Current state values needed as baseline for full-config PUT
columnVisibility,
columnOrder,
columnRenameMapping,
columnTimeFormats,
columnListFormats,
]
);

Expand Down
Loading