mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix!: Improve typing of columns for kube object list layout
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
1bf24db797
commit
721c3b17ff
7 files changed
+56
-20
No files matched your search
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { GeneralKubeObjectListLayoutColumn } from "./kube-list-layout-column";
|
||||
|
||||
export const kubeObjectListLayoutColumnInjectionToken = getInjectionToken<GeneralKubeObjectListLayoutColumn>({
|
||||
id: "kube-object-list-layout-column",
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { KubeObject } from "@k8slens/kube-object";
|
||||
import type { ReactNode } from "react";
|
||||
import type { TableSortCallback, SearchFilter, TableCellProps } from "./list-layout-column";
|
||||
|
||||
export interface BaseKubeObjectListLayoutColumn<K extends KubeObject> {
|
||||
id: string;
|
||||
priority: number;
|
||||
sortingCallBack?: TableSortCallback<K>;
|
||||
searchFilter?: SearchFilter<K>;
|
||||
header: TableCellProps | undefined | null;
|
||||
content: (item: K) => ReactNode | TableCellProps;
|
||||
}
|
||||
|
||||
export interface GeneralKubeObjectListLayoutColumn extends BaseKubeObjectListLayoutColumn<KubeObject> {
|
||||
kind: string;
|
||||
apiVersion: string | string[];
|
||||
}
|
||||
|
||||
export interface SpecificKubeListLayoutColumn<K extends KubeObject> extends BaseKubeObjectListLayoutColumn<K> {}
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
import type { SingleOrMany } from "@k8slens/utilities";
|
||||
|
||||
export interface ItemObject {
|
||||
getId: () => string;
|
||||
getName: () => string;
|
||||
}
|
||||
|
||||
export type TableSortBy = string;
|
||||
export type TableOrderBy = "asc" | "desc";
|
||||
export interface TableSortParams {
|
||||
sortBy: TableSortBy;
|
||||
orderBy: TableOrderBy;
|
||||
}
|
||||
|
||||
export type TableSortCallback<Item> = (data: Item) => undefined | string | number | (string | number)[];
|
||||
export type TableSortCallbacks<Item> = Record<string, TableSortCallback<Item>>;
|
||||
|
||||
export type SearchFilter<I extends ItemObject> = (item: I) => SingleOrMany<string | number | undefined | null>;
|
||||
|
||||
export interface TableCellProps extends React.DOMAttributes<HTMLDivElement> {
|
||||
/**
|
||||
* used for configuration visibility of columns
|
||||
*/
|
||||
id?: string;
|
||||
|
||||
/**
|
||||
* Any css class names for this table cell. Only used if `title` is a "simple" react node
|
||||
*/
|
||||
className?: string;
|
||||
|
||||
/**
|
||||
* The actual value of the cell
|
||||
*/
|
||||
title?: ReactNode;
|
||||
|
||||
/**
|
||||
* content inside could be scrolled
|
||||
*/
|
||||
scrollable?: boolean;
|
||||
|
||||
/**
|
||||
* render cell with a checkbox
|
||||
*/
|
||||
checkbox?: boolean;
|
||||
|
||||
/**
|
||||
* mark checkbox as checked or not
|
||||
*/
|
||||
isChecked?: boolean;
|
||||
|
||||
/**
|
||||
* column name, must be same as key in sortable object <Table sortable={}/>
|
||||
*/
|
||||
sortBy?: TableSortBy;
|
||||
|
||||
/**
|
||||
* id of the column which follow same visibility rules
|
||||
*/
|
||||
showWithColumn?: string;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
_sorting?: Partial<TableSortParams>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
_sort?(sortBy: TableSortBy): void;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* indicator, might come from parent <TableHead>, don't use this prop outside (!)
|
||||
*/
|
||||
_nowrap?: boolean;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { Pod } from "@k8slens/kube-object";
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { SpecificKubeListLayoutColumn } from "./kube-list-layout-column";
|
||||
|
||||
export const podListLayoutColumnInjectionToken = getInjectionToken<SpecificKubeListLayoutColumn<Pod>>({
|
||||
id: "kube-object-list-layout-column",
|
||||
});
|
||||
Reference in new issue
Block a user