1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/packages/table/index.ts
Alex Andreev 2a629ff8b7 Adding createTableStateInjectionToken
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
2023-06-02 11:15:37 +03:00

61 lines
1.8 KiB
TypeScript

/**
* 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 {
BaseKubeObjectListLayoutColumn,
GeneralKubeObjectListLayoutColumn,
SpecificKubeListLayoutColumn,
} from "@k8slens/list-layout";
import { getInjectionToken } from "@ogre-tools/injectable";
import type { IComputedValue, IObservableValue } from "mobx";
type Column = (
| BaseKubeObjectListLayoutColumn<KubeObject>
| SpecificKubeListLayoutColumn<KubeObject>
| GeneralKubeObjectListLayoutColumn
);
export interface TableComponentProps {
tableId?: string;
columns?: Column[];
save?: (state: object) => void;
load?: (tableId: string) => object;
}
export interface TableComponent {
Component: React.ComponentType<TableComponentProps & { state: any }>;
}
export interface AddRemoveButtonsProps extends React.HTMLAttributes<any> {
onAdd?: () => void;
onRemove?: () => void;
addTooltip?: React.ReactNode;
removeTooltip?: React.ReactNode;
}
export interface AddOrRemoveButtons {
Component: React.ComponentType<AddRemoveButtonsProps>;
}
export type CreateTableState = (params: {
dataItems: IComputedValue<any[]>;
headingColumns: object[];
customizeRows?: (row: object) => object;
getRowId?: (dataItem: any) => string | number | symbol;
searchBox?: IComputedValue<string> | IObservableValue<string>;
}) => any;
export const tableComponentInjectionToken = getInjectionToken<TableComponent>({
id: "table-component-injection-token",
});
export const addOrRemoveButtonsInjectionToken = getInjectionToken<AddOrRemoveButtons>({
id: "add-or-remove-buttons-injection-token",
});
export const createTableStateInjectionToken = getInjectionToken<CreateTableState>({
id: "create-table-state-injection-token",
})