mirror of https://github.com/portainer/portainer
refactor(ui/tables): remove temp type
parent
92dd6ed7bc
commit
1e2dbd7778
|
@ -100,18 +100,3 @@ export function createPersistedStore<T extends BasicTableSettings>(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** this class is just a dummy class to get return type of createPersistedStore
|
|
||||||
* can be fixed after upgrade to ts 4.7+
|
|
||||||
* https://stackoverflow.com/a/64919133
|
|
||||||
*/
|
|
||||||
class Wrapper<T extends BasicTableSettings> {
|
|
||||||
// eslint-disable-next-line class-methods-use-this
|
|
||||||
wrapped() {
|
|
||||||
return createPersistedStore<T>('', '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CreatePersistedStoreReturn<
|
|
||||||
T extends BasicTableSettings = BasicTableSettings
|
|
||||||
> = ReturnType<Wrapper<T>['wrapped']>;
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { useMemo, useState } from 'react';
|
||||||
import { useStore } from 'zustand';
|
import { useStore } from 'zustand';
|
||||||
|
|
||||||
import { useSearchBarState } from './SearchBar';
|
import { useSearchBarState } from './SearchBar';
|
||||||
import { BasicTableSettings, CreatePersistedStoreReturn } from './types';
|
import { BasicTableSettings, createPersistedStore } from './types';
|
||||||
|
|
||||||
export type TableState<TSettings extends BasicTableSettings> = TSettings & {
|
export type TableState<TSettings extends BasicTableSettings> = TSettings & {
|
||||||
setSearch: (search: string) => void;
|
setSearch: (search: string) => void;
|
||||||
|
@ -11,7 +11,10 @@ export type TableState<TSettings extends BasicTableSettings> = TSettings & {
|
||||||
|
|
||||||
export function useTableState<
|
export function useTableState<
|
||||||
TSettings extends BasicTableSettings = BasicTableSettings
|
TSettings extends BasicTableSettings = BasicTableSettings
|
||||||
>(store: CreatePersistedStoreReturn<TSettings>, storageKey: string) {
|
>(
|
||||||
|
store: ReturnType<typeof createPersistedStore<TSettings>>,
|
||||||
|
storageKey: string
|
||||||
|
) {
|
||||||
const settings = useStore(store);
|
const settings = useStore(store);
|
||||||
|
|
||||||
const [search, setSearch] = useSearchBarState(storageKey);
|
const [search, setSearch] = useSearchBarState(storageKey);
|
||||||
|
|
Loading…
Reference in New Issue