You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/kubernetes/datatables/default-kube-datatable-stor...

37 lines
975 B

import { useState } from 'react';
import {
refreshableSettings,
createPersistedStore,
ZustandSetFunc,
} from '@@/datatables/types';
import { useTableState } from '@@/datatables/useTableState';
import { TableSettings } from './DefaultDatatableSettings';
import { systemResourcesSettings } from './SystemResourcesSettings';
export function createStore<T extends TableSettings>(
storageKey: string,
initialSortBy?: string | { id: string; desc: boolean },
create: (set: ZustandSetFunc<T>) => Omit<T, keyof TableSettings> = () =>
({}) as T
) {
return createPersistedStore<T>(
storageKey,
initialSortBy,
(set) =>
({
...refreshableSettings(set),
...systemResourcesSettings(set),
...create(set),
}) as T
);
}
export function useKubeStore<T extends TableSettings>(
...args: Parameters<typeof createStore<T>>
) {
const [store] = useState(() => createStore(...args));
return useTableState(store, args[0]);
}