From a3073cc99b1cdd85eb693d65bae99b2f7df4842d Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Mon, 31 May 2021 08:28:15 -0400 Subject: [PATCH] Switch to I, remove type parameter default Signed-off-by: Sebastian Malton --- src/renderer/api/kube-object.ts | 2 +- .../item-object-list/item-list-layout.tsx | 50 +++++++++---------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/renderer/api/kube-object.ts b/src/renderer/api/kube-object.ts index ffba489651..b14fd3d993 100644 --- a/src/renderer/api/kube-object.ts +++ b/src/renderer/api/kube-object.ts @@ -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 = (new (data: KubeJsonApiData | any) => K) & { +export type IKubeObjectConstructor = (new (data: KubeJsonApiData | any) => K) & { kind?: string; namespaced?: boolean; apiBase?: string; diff --git a/src/renderer/components/item-object-list/item-list-layout.tsx b/src/renderer/components/item-object-list/item-list-layout.tsx index 76aa78315b..a9333ae50f 100644 --- a/src/renderer/components/item-object-list/item-list-layout.tsx +++ b/src/renderer/components/item-object-list/item-list-layout.tsx @@ -46,10 +46,10 @@ import { NamespaceSelectFilter } from "../+namespaces/namespace-select-filter"; // todo: refactor, split to small re-usable components -export type SearchFilter = (item: Item) => string | number | (string | number)[]; -export type SearchFilters = Record>; -export type ItemsFilter = (items: Item[]) => Item[]; -export type ItemsFilters = Record>; +export type SearchFilter = (item: I) => string | number | (string | number)[]; +export type SearchFilters = Record>; +export type ItemsFilter = (items: I[]) => I[]; +export type ItemsFilters = Record>; export interface IHeaderPlaceholders { title: ReactNode; @@ -58,22 +58,22 @@ export interface IHeaderPlaceholders { info: ReactNode; } -export interface ItemListLayoutProps { +export interface ItemListLayoutProps { tableId?: string; className: IClassName; - items?: Item[]; - store: ItemStore; + items?: I[]; + store: ItemStore; dependentStores?: ItemStore[]; preloadStores?: boolean; hideFilters?: boolean; - searchFilters?: SearchFilter[]; + searchFilters?: SearchFilter[]; /** @deprecated */ - filterItems?: ItemsFilter[]; + filterItems?: ItemsFilter[]; // header (title, filtering, searching, etc.) showHeader?: boolean; headerClassName?: IClassName; - renderHeaderTitle?: ReactNode | ((parent: ItemListLayout) => ReactNode); + renderHeaderTitle?: ReactNode | ((parent: ItemListLayout) => ReactNode); customizeHeader?: (placeholders: IHeaderPlaceholders, content: ReactNode) => Partial | ReactNode; // items list configuration @@ -82,25 +82,25 @@ export interface ItemListLayoutProps { isSearchable?: boolean; // apply search-filter & add search-input isConfigurable?: boolean; copyClassNameFromHeadCells?: boolean; - sortingCallbacks?: TableSortCallbacks; - tableProps?: Partial>; // low-level table configuration + sortingCallbacks?: TableSortCallbacks; + tableProps?: Partial>; // low-level table configuration renderTableHeader: TableCellProps[] | null; - renderTableContents: (item: Item) => (ReactNode | TableCellProps)[]; - renderItemMenu?: (item: Item, store: ItemStore) => ReactNode; - customizeTableRowProps?: (item: Item) => Partial; + renderTableContents: (item: I) => (ReactNode | TableCellProps)[]; + renderItemMenu?: (item: I, store: ItemStore) => ReactNode; + customizeTableRowProps?: (item: I) => Partial; addRemoveButtons?: Partial; virtual?: boolean; // item details view hasDetailsView?: boolean; - detailsItem?: Item; - onDetails?: (item: Item) => void; + detailsItem?: I; + onDetails?: (item: I) => void; // other - customizeRemoveDialog?: (selectedItems: Item[]) => Partial; - renderFooter?: (parent: ItemListLayout) => React.ReactNode; + customizeRemoveDialog?: (selectedItems: I[]) => Partial; + renderFooter?: (parent: ItemListLayout) => React.ReactNode; - filterCallbacks?: ItemsFilters; + filterCallbacks?: ItemsFilters; } const defaultProps: Partial> = { @@ -119,14 +119,14 @@ const defaultProps: Partial> = { }; @observer -export class ItemListLayout extends React.Component> { +export class ItemListLayout extends React.Component> { static defaultProps = defaultProps as object; private storage = createStorage("item_list_layout", { showFilters: false, // setup defaults }); - constructor(props: ItemListLayoutProps) { + constructor(props: ItemListLayoutProps) { super(props); makeObservable(this); } @@ -162,7 +162,7 @@ export class ItemListLayout extends React.Component store.loadAll(namespaceStore.contextNamespaces)); } - private filterCallbacks: ItemsFilters = { + private filterCallbacks: ItemsFilters = { [FilterType.SEARCH]: items => { const { searchFilters, isSearchable } = this.props; const search = pageFilters.getValues(FilterType.SEARCH)[0] || ""; @@ -203,7 +203,7 @@ export class ItemListLayout extends React.Component[], items: Item[]): Item[] { + applyFilters(filters: ItemsFilter[], items: I[]): I[] { if (!filters || !filters.length) return items; return filters.reduce((items, filter) => filter(items), items); @@ -213,7 +213,7 @@ export class ItemListLayout extends React.Component(filters, ({ type }) => type); - const filterItems: ItemsFilter[] = []; + const filterItems: ItemsFilter[] = []; Object.entries(filterGroups).forEach(([type, filtersGroup]) => { const filterCallback = filterCallbacks[type] ?? props.filterCallbacks?.[type];