1
0
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:
Sebastian Malton 2023-04-27 10:35:15 -04:00
parent 1bf24db797
commit 721c3b17ff
7 changed files with 56 additions and 20 deletions

View File

@ -1 +1,4 @@
export * from "./kube-object-list-layout-column-injection-token"; export * from "./src/list-layout-column";
export * from "./src/general-kube-column-token";
export * from "./src/kube-list-layout-column";
export * from "./src/pod-list-layout-token";

View File

@ -32,6 +32,7 @@
"lint:fix": "lens-lint --fix" "lint:fix": "lens-lint --fix"
}, },
"peerDependencies": { "peerDependencies": {
"@k8slens/kube-object": "^1.0.0-alpha.1",
"@ogre-tools/injectable": "^15.1.2", "@ogre-tools/injectable": "^15.1.2",
"react": "^17.0.2" "react": "^17.0.2"
}, },

View File

@ -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",
});

View File

@ -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> {}

View File

@ -2,13 +2,13 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { ReactNode } from "react"; import type { ReactNode } from "react";
import type { SingleOrMany } from "@k8slens/utilities"; import type { SingleOrMany } from "@k8slens/utilities";
import { getInjectionToken } from "@ogre-tools/injectable";
export interface ItemObject { export interface ItemObject {
getId(): string; getId: () => string;
getName(): string; getName: () => string;
} }
export type TableSortBy = string; export type TableSortBy = string;
@ -80,18 +80,3 @@ export interface TableCellProps extends React.DOMAttributes<HTMLDivElement> {
*/ */
_nowrap?: boolean; _nowrap?: boolean;
} }
export interface KubeObjectListLayoutColumn<Item extends ItemObject> {
id: string;
kind: string;
apiVersion: string;
priority: number;
sortingCallBack?: TableSortCallback<Item>;
searchFilter?: SearchFilter<Item>;
header: TableCellProps | undefined | null;
content: (item: Item) => ReactNode | TableCellProps;
}
export const kubeObjectListLayoutColumnInjectionToken = getInjectionToken<KubeObjectListLayoutColumn<any>>({
id: "kube-object-list-layout-column",
});

View File

@ -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",
});

View File

@ -1 +1 @@
module.exports = require("@k8slens/webpack").configForReact; module.exports = require("@k8slens/webpack").configForNode;