mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Switch to I, remove type parameter default
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
defb0ea0dd
commit
a3073cc99b
@ -30,7 +30,7 @@ import type { JsonApiParams } from "./json-api";
|
|||||||
import { resourceApplierApi } from "./endpoints/resource-applier.api";
|
import { resourceApplierApi } from "./endpoints/resource-applier.api";
|
||||||
import { hasOptionalProperty, hasTypedProperty, isObject, isString, bindPredicate, isTypedArray, isRecord } from "../../common/utils/type-narrowing";
|
import { hasOptionalProperty, hasTypedProperty, isObject, isString, bindPredicate, isTypedArray, isRecord } from "../../common/utils/type-narrowing";
|
||||||
|
|
||||||
export type IKubeObjectConstructor<K extends KubeObject = KubeObject> = (new (data: KubeJsonApiData | any) => K) & {
|
export type IKubeObjectConstructor<K extends KubeObject> = (new (data: KubeJsonApiData | any) => K) & {
|
||||||
kind?: string;
|
kind?: string;
|
||||||
namespaced?: boolean;
|
namespaced?: boolean;
|
||||||
apiBase?: string;
|
apiBase?: string;
|
||||||
|
|||||||
@ -46,10 +46,10 @@ import { NamespaceSelectFilter } from "../+namespaces/namespace-select-filter";
|
|||||||
|
|
||||||
// todo: refactor, split to small re-usable components
|
// todo: refactor, split to small re-usable components
|
||||||
|
|
||||||
export type SearchFilter<Item extends ItemObject> = (item: Item) => string | number | (string | number)[];
|
export type SearchFilter<I extends ItemObject> = (item: I) => string | number | (string | number)[];
|
||||||
export type SearchFilters<Item extends ItemObject> = Record<string, SearchFilter<Item>>;
|
export type SearchFilters<I extends ItemObject> = Record<string, SearchFilter<I>>;
|
||||||
export type ItemsFilter<Item extends ItemObject> = (items: Item[]) => Item[];
|
export type ItemsFilter<I extends ItemObject> = (items: I[]) => I[];
|
||||||
export type ItemsFilters<Item extends ItemObject> = Record<string, ItemsFilter<Item>>;
|
export type ItemsFilters<I extends ItemObject> = Record<string, ItemsFilter<I>>;
|
||||||
|
|
||||||
export interface IHeaderPlaceholders {
|
export interface IHeaderPlaceholders {
|
||||||
title: ReactNode;
|
title: ReactNode;
|
||||||
@ -58,22 +58,22 @@ export interface IHeaderPlaceholders {
|
|||||||
info: ReactNode;
|
info: ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ItemListLayoutProps<Item extends ItemObject> {
|
export interface ItemListLayoutProps<I extends ItemObject> {
|
||||||
tableId?: string;
|
tableId?: string;
|
||||||
className: IClassName;
|
className: IClassName;
|
||||||
items?: Item[];
|
items?: I[];
|
||||||
store: ItemStore<Item>;
|
store: ItemStore<I>;
|
||||||
dependentStores?: ItemStore<ItemObject>[];
|
dependentStores?: ItemStore<ItemObject>[];
|
||||||
preloadStores?: boolean;
|
preloadStores?: boolean;
|
||||||
hideFilters?: boolean;
|
hideFilters?: boolean;
|
||||||
searchFilters?: SearchFilter<Item>[];
|
searchFilters?: SearchFilter<I>[];
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
filterItems?: ItemsFilter<Item>[];
|
filterItems?: ItemsFilter<I>[];
|
||||||
|
|
||||||
// header (title, filtering, searching, etc.)
|
// header (title, filtering, searching, etc.)
|
||||||
showHeader?: boolean;
|
showHeader?: boolean;
|
||||||
headerClassName?: IClassName;
|
headerClassName?: IClassName;
|
||||||
renderHeaderTitle?: ReactNode | ((parent: ItemListLayout<Item>) => ReactNode);
|
renderHeaderTitle?: ReactNode | ((parent: ItemListLayout<I>) => ReactNode);
|
||||||
customizeHeader?: (placeholders: IHeaderPlaceholders, content: ReactNode) => Partial<IHeaderPlaceholders> | ReactNode;
|
customizeHeader?: (placeholders: IHeaderPlaceholders, content: ReactNode) => Partial<IHeaderPlaceholders> | ReactNode;
|
||||||
|
|
||||||
// items list configuration
|
// items list configuration
|
||||||
@ -82,25 +82,25 @@ export interface ItemListLayoutProps<Item extends ItemObject> {
|
|||||||
isSearchable?: boolean; // apply search-filter & add search-input
|
isSearchable?: boolean; // apply search-filter & add search-input
|
||||||
isConfigurable?: boolean;
|
isConfigurable?: boolean;
|
||||||
copyClassNameFromHeadCells?: boolean;
|
copyClassNameFromHeadCells?: boolean;
|
||||||
sortingCallbacks?: TableSortCallbacks<Item>;
|
sortingCallbacks?: TableSortCallbacks<I>;
|
||||||
tableProps?: Partial<TableProps<Item>>; // low-level table configuration
|
tableProps?: Partial<TableProps<I>>; // low-level table configuration
|
||||||
renderTableHeader: TableCellProps[] | null;
|
renderTableHeader: TableCellProps[] | null;
|
||||||
renderTableContents: (item: Item) => (ReactNode | TableCellProps)[];
|
renderTableContents: (item: I) => (ReactNode | TableCellProps)[];
|
||||||
renderItemMenu?: (item: Item, store: ItemStore<Item>) => ReactNode;
|
renderItemMenu?: (item: I, store: ItemStore<I>) => ReactNode;
|
||||||
customizeTableRowProps?: (item: Item) => Partial<TableRowProps>;
|
customizeTableRowProps?: (item: I) => Partial<TableRowProps>;
|
||||||
addRemoveButtons?: Partial<AddRemoveButtonsProps>;
|
addRemoveButtons?: Partial<AddRemoveButtonsProps>;
|
||||||
virtual?: boolean;
|
virtual?: boolean;
|
||||||
|
|
||||||
// item details view
|
// item details view
|
||||||
hasDetailsView?: boolean;
|
hasDetailsView?: boolean;
|
||||||
detailsItem?: Item;
|
detailsItem?: I;
|
||||||
onDetails?: (item: Item) => void;
|
onDetails?: (item: I) => void;
|
||||||
|
|
||||||
// other
|
// other
|
||||||
customizeRemoveDialog?: (selectedItems: Item[]) => Partial<ConfirmDialogParams>;
|
customizeRemoveDialog?: (selectedItems: I[]) => Partial<ConfirmDialogParams>;
|
||||||
renderFooter?: (parent: ItemListLayout<Item>) => React.ReactNode;
|
renderFooter?: (parent: ItemListLayout<I>) => React.ReactNode;
|
||||||
|
|
||||||
filterCallbacks?: ItemsFilters<Item>;
|
filterCallbacks?: ItemsFilters<I>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultProps: Partial<ItemListLayoutProps<ItemObject>> = {
|
const defaultProps: Partial<ItemListLayoutProps<ItemObject>> = {
|
||||||
@ -119,14 +119,14 @@ const defaultProps: Partial<ItemListLayoutProps<ItemObject>> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class ItemListLayout<Item extends ItemObject> extends React.Component<ItemListLayoutProps<Item>> {
|
export class ItemListLayout<I extends ItemObject> extends React.Component<ItemListLayoutProps<I>> {
|
||||||
static defaultProps = defaultProps as object;
|
static defaultProps = defaultProps as object;
|
||||||
|
|
||||||
private storage = createStorage("item_list_layout", {
|
private storage = createStorage("item_list_layout", {
|
||||||
showFilters: false, // setup defaults
|
showFilters: false, // setup defaults
|
||||||
});
|
});
|
||||||
|
|
||||||
constructor(props: ItemListLayoutProps<Item>) {
|
constructor(props: ItemListLayoutProps<I>) {
|
||||||
super(props);
|
super(props);
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
}
|
}
|
||||||
@ -162,7 +162,7 @@ export class ItemListLayout<Item extends ItemObject> extends React.Component<Ite
|
|||||||
stores.forEach(store => store.loadAll(namespaceStore.contextNamespaces));
|
stores.forEach(store => store.loadAll(namespaceStore.contextNamespaces));
|
||||||
}
|
}
|
||||||
|
|
||||||
private filterCallbacks: ItemsFilters<Item> = {
|
private filterCallbacks: ItemsFilters<I> = {
|
||||||
[FilterType.SEARCH]: items => {
|
[FilterType.SEARCH]: items => {
|
||||||
const { searchFilters, isSearchable } = this.props;
|
const { searchFilters, isSearchable } = this.props;
|
||||||
const search = pageFilters.getValues(FilterType.SEARCH)[0] || "";
|
const search = pageFilters.getValues(FilterType.SEARCH)[0] || "";
|
||||||
@ -203,7 +203,7 @@ export class ItemListLayout<Item extends ItemObject> extends React.Component<Ite
|
|||||||
return activeFilters;
|
return activeFilters;
|
||||||
}
|
}
|
||||||
|
|
||||||
applyFilters(filters: ItemsFilter<Item>[], items: Item[]): Item[] {
|
applyFilters(filters: ItemsFilter<I>[], items: I[]): I[] {
|
||||||
if (!filters || !filters.length) return items;
|
if (!filters || !filters.length) return items;
|
||||||
|
|
||||||
return filters.reduce((items, filter) => filter(items), items);
|
return filters.reduce((items, filter) => filter(items), items);
|
||||||
@ -213,7 +213,7 @@ export class ItemListLayout<Item extends ItemObject> extends React.Component<Ite
|
|||||||
const { filters, filterCallbacks, props } = this;
|
const { filters, filterCallbacks, props } = this;
|
||||||
const filterGroups = groupBy<Filter>(filters, ({ type }) => type);
|
const filterGroups = groupBy<Filter>(filters, ({ type }) => type);
|
||||||
|
|
||||||
const filterItems: ItemsFilter<Item>[] = [];
|
const filterItems: ItemsFilter<I>[] = [];
|
||||||
|
|
||||||
Object.entries(filterGroups).forEach(([type, filtersGroup]) => {
|
Object.entries(filterGroups).forEach(([type, filtersGroup]) => {
|
||||||
const filterCallback = filterCallbacks[type] ?? props.filterCallbacks?.[type];
|
const filterCallback = filterCallbacks[type] ?? props.filterCallbacks?.[type];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user