1
0
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:
Sebastian Malton 2021-05-31 08:28:15 -04:00
parent defb0ea0dd
commit a3073cc99b
2 changed files with 26 additions and 26 deletions

View File

@ -30,7 +30,7 @@ import type { JsonApiParams } from "./json-api";
import { resourceApplierApi } from "./endpoints/resource-applier.api";
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;
namespaced?: boolean;
apiBase?: string;

View File

@ -46,10 +46,10 @@ import { NamespaceSelectFilter } from "../+namespaces/namespace-select-filter";
// todo: refactor, split to small re-usable components
export type SearchFilter<Item extends ItemObject> = (item: Item) => string | number | (string | number)[];
export type SearchFilters<Item extends ItemObject> = Record<string, SearchFilter<Item>>;
export type ItemsFilter<Item extends ItemObject> = (items: Item[]) => Item[];
export type ItemsFilters<Item extends ItemObject> = Record<string, ItemsFilter<Item>>;
export type SearchFilter<I extends ItemObject> = (item: I) => string | number | (string | number)[];
export type SearchFilters<I extends ItemObject> = Record<string, SearchFilter<I>>;
export type ItemsFilter<I extends ItemObject> = (items: I[]) => I[];
export type ItemsFilters<I extends ItemObject> = Record<string, ItemsFilter<I>>;
export interface IHeaderPlaceholders {
title: ReactNode;
@ -58,22 +58,22 @@ export interface IHeaderPlaceholders {
info: ReactNode;
}
export interface ItemListLayoutProps<Item extends ItemObject> {
export interface ItemListLayoutProps<I extends ItemObject> {
tableId?: string;
className: IClassName;
items?: Item[];
store: ItemStore<Item>;
items?: I[];
store: ItemStore<I>;
dependentStores?: ItemStore<ItemObject>[];
preloadStores?: boolean;
hideFilters?: boolean;
searchFilters?: SearchFilter<Item>[];
searchFilters?: SearchFilter<I>[];
/** @deprecated */
filterItems?: ItemsFilter<Item>[];
filterItems?: ItemsFilter<I>[];
// header (title, filtering, searching, etc.)
showHeader?: boolean;
headerClassName?: IClassName;
renderHeaderTitle?: ReactNode | ((parent: ItemListLayout<Item>) => ReactNode);
renderHeaderTitle?: ReactNode | ((parent: ItemListLayout<I>) => ReactNode);
customizeHeader?: (placeholders: IHeaderPlaceholders, content: ReactNode) => Partial<IHeaderPlaceholders> | ReactNode;
// items list configuration
@ -82,25 +82,25 @@ export interface ItemListLayoutProps<Item extends ItemObject> {
isSearchable?: boolean; // apply search-filter & add search-input
isConfigurable?: boolean;
copyClassNameFromHeadCells?: boolean;
sortingCallbacks?: TableSortCallbacks<Item>;
tableProps?: Partial<TableProps<Item>>; // low-level table configuration
sortingCallbacks?: TableSortCallbacks<I>;
tableProps?: Partial<TableProps<I>>; // low-level table configuration
renderTableHeader: TableCellProps[] | null;
renderTableContents: (item: Item) => (ReactNode | TableCellProps)[];
renderItemMenu?: (item: Item, store: ItemStore<Item>) => ReactNode;
customizeTableRowProps?: (item: Item) => Partial<TableRowProps>;
renderTableContents: (item: I) => (ReactNode | TableCellProps)[];
renderItemMenu?: (item: I, store: ItemStore<I>) => ReactNode;
customizeTableRowProps?: (item: I) => Partial<TableRowProps>;
addRemoveButtons?: Partial<AddRemoveButtonsProps>;
virtual?: boolean;
// item details view
hasDetailsView?: boolean;
detailsItem?: Item;
onDetails?: (item: Item) => void;
detailsItem?: I;
onDetails?: (item: I) => void;
// other
customizeRemoveDialog?: (selectedItems: Item[]) => Partial<ConfirmDialogParams>;
renderFooter?: (parent: ItemListLayout<Item>) => React.ReactNode;
customizeRemoveDialog?: (selectedItems: I[]) => Partial<ConfirmDialogParams>;
renderFooter?: (parent: ItemListLayout<I>) => React.ReactNode;
filterCallbacks?: ItemsFilters<Item>;
filterCallbacks?: ItemsFilters<I>;
}
const defaultProps: Partial<ItemListLayoutProps<ItemObject>> = {
@ -119,14 +119,14 @@ const defaultProps: Partial<ItemListLayoutProps<ItemObject>> = {
};
@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;
private storage = createStorage("item_list_layout", {
showFilters: false, // setup defaults
});
constructor(props: ItemListLayoutProps<Item>) {
constructor(props: ItemListLayoutProps<I>) {
super(props);
makeObservable(this);
}
@ -162,7 +162,7 @@ export class ItemListLayout<Item extends ItemObject> extends React.Component<Ite
stores.forEach(store => store.loadAll(namespaceStore.contextNamespaces));
}
private filterCallbacks: ItemsFilters<Item> = {
private filterCallbacks: ItemsFilters<I> = {
[FilterType.SEARCH]: items => {
const { searchFilters, isSearchable } = this.props;
const search = pageFilters.getValues(FilterType.SEARCH)[0] || "";
@ -203,7 +203,7 @@ export class ItemListLayout<Item extends ItemObject> extends React.Component<Ite
return activeFilters;
}
applyFilters(filters: ItemsFilter<Item>[], items: Item[]): Item[] {
applyFilters(filters: ItemsFilter<I>[], items: I[]): I[] {
if (!filters || !filters.length) return 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 filterGroups = groupBy<Filter>(filters, ({ type }) => type);
const filterItems: ItemsFilter<Item>[] = [];
const filterItems: ItemsFilter<I>[] = [];
Object.entries(filterGroups).forEach(([type, filtersGroup]) => {
const filterCallback = filterCallbacks[type] ?? props.filterCallbacks?.[type];