mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE): Add omit utility and refactor clearTabActions to use
it
This commit is contained in:
@@ -305,3 +305,17 @@ export function transformConstants(
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function omit<T extends Record<string, unknown>, K extends keyof T>(
|
||||
obj: T,
|
||||
keys: K | K[]
|
||||
): Omit<T, K> {
|
||||
const keysArray = Array.isArray(keys) ? keys : [keys];
|
||||
const result = { ...obj };
|
||||
|
||||
keysArray.forEach((key) => {
|
||||
delete result[key];
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { TabActionsSlice } from '@/stores/tab-actions/tab-actions.store';
|
||||
import { omit } from '@/lib/helper';
|
||||
import { StateCreator } from 'zustand';
|
||||
|
||||
export const createTabActionsSlice: StateCreator<
|
||||
@@ -20,10 +21,9 @@ export const createTabActionsSlice: StateCreator<
|
||||
})),
|
||||
|
||||
clearTabActions: (tabId) =>
|
||||
set((state) => {
|
||||
const { [tabId]: _, ...rest } = state.tabActions;
|
||||
return { tabActions: rest };
|
||||
}),
|
||||
set((state) => ({
|
||||
tabActions: omit(state.tabActions, tabId),
|
||||
})),
|
||||
|
||||
clearAllTabActions: () => set({ tabActions: {} }),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user