Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding table package with injection tokens #7818

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
007a017
Add table and add-remove buttons injection tokens
aleksfront Jun 1, 2023
471a515
Add table package.json
aleksfront Jun 1, 2023
6e6e540
Add table package tsconfig and webpack.config
aleksfront Jun 1, 2023
547722f
Add simple README
aleksfront Jun 1, 2023
a2cd784
Bump @ogre-tools/injectable version
aleksfront Jun 1, 2023
f9978f3
Use table from injection token
aleksfront Jun 1, 2023
c48b88e
Using AddOrRemoveButtons component from injection token
aleksfront Jun 1, 2023
60c4391
Creating tableComponentInjectable in open-lens
aleksfront Jun 1, 2023
c7f4d1c
Adding addRemoveButtonsInjectable
aleksfront Jun 1, 2023
9aae3ff
Adding @k8slens/table as dependencies to core and open-lens
aleksfront Jun 1, 2023
1855b2a
Create injectables in test-env also
aleksfront Jun 1, 2023
4173225
Remove "dev" command
aleksfront Jun 1, 2023
0f41556
Linter fixes
aleksfront Jun 1, 2023
2a629ff
Adding createTableStateInjectionToken
aleksfront Jun 2, 2023
365cf5c
Update package-lock.json
aleksfront Jun 2, 2023
71ebf6e
Add linkable command to core package
aleksfront Jun 2, 2023
da3946b
Adding tableStateInjectable and context
aleksfront Jun 2, 2023
4fa2cce
Using tableStateInjectable in content.tsx
aleksfront Jun 2, 2023
e4c4f54
Adding createTableStateInjectable
aleksfront Jun 2, 2023
0ac0157
Linter fixes
aleksfront Jun 2, 2023
c57c236
Merge branch 'master' into add-table-package
aleksfront Jun 2, 2023
d4edddf
Merge remote-tracking branch 'origin/master' into add-table-package
ixrock Jun 5, 2023
fc22241
Remove unused dev dependency from core
aleksfront Jun 6, 2023
3b17490
Changing paths for test-env injectables
aleksfront Jun 6, 2023
ddc1048
Adding TableDataColumn and TableDataRow types
aleksfront Jun 6, 2023
67370c1
Adding create-table-state.injectable.ts into test-env folder
aleksfront Jun 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions open-lens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
"@k8slens/routing": "^1.0.0",
"@k8slens/run-many": "^1.0.0",
"@k8slens/startable-stoppable": "^1.0.0",
"@k8slens/table": "6.5.0",
"@k8slens/tooltip": "^1.0.0",
"@k8slens/utilities": "^1.0.0",
"@kubernetes/client-node": "^0.18.1",
Expand Down
11 changes: 11 additions & 0 deletions open-lens/src/renderer/add-remove-buttons.injectable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getInjectable } from "@ogre-tools/injectable";
import { AddRemoveButtons } from "@k8slens/core/renderer";
import { addOrRemoveButtonsInjectionToken } from "@k8slens/table";

const addRemoveButtonsInjectable = getInjectable({
id: "add-remove-buttons-component",
instantiate: () => ({ Component: AddRemoveButtons }),
injectionToken: addOrRemoveButtonsInjectionToken,
});

export default addRemoveButtonsInjectable
10 changes: 10 additions & 0 deletions open-lens/src/renderer/create-table-state.injectable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createTableStateInjectionToken } from "@k8slens/table";
import { getInjectable } from "@ogre-tools/injectable";

const createTableStateInjectable = getInjectable({
id: "open-lens-table-state",
instantiate: () => () => {},
injectionToken: createTableStateInjectionToken,
});

export default createTableStateInjectable
11 changes: 11 additions & 0 deletions open-lens/src/renderer/table.injectable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { tableComponentInjectionToken } from "@k8slens/table";
import { getInjectable } from "@ogre-tools/injectable";
import { Table } from "@k8slens/core/renderer";

const tableComponentInjectable = getInjectable({
id: "table-component",
instantiate: () => ({ Component: Table }),
injectionToken: tableComponentInjectionToken,
});

export default tableComponentInjectable
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"test:unit": "jest --testPathIgnorePatterns integration",
"test:watch": "func() { jest ${1} --watch --testPathIgnorePatterns integration; }; func",
"lint": "PROD=true eslint --ext js,ts,tsx --max-warnings=0 .",
"lint:fix": "npm run lint -- --fix"
"lint:fix": "npm run lint -- --fix",
"postinstall": "linkable"
},
"config": {
"k8sProxyVersion": "0.3.0",
Expand Down Expand Up @@ -238,6 +239,7 @@
"@k8slens/run-many": "^1.0.0-alpha.1",
"@k8slens/spinner": "^1.0.0",
"@k8slens/startable-stoppable": "^1.0.0-alpha.1",
"@k8slens/table": "6.5.0",
"@k8slens/tooltip": "^1.0.0-alpha.5",
"@k8slens/utilities": "^1.0.0-alpha.1",
"@kubernetes/client-node": "^0.18.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import { computed, makeObservable } from "mobx";
import { Observer, observer } from "mobx-react";
import type { ConfirmDialogParams } from "../confirm-dialog";
import type { TableProps, TableRowProps, TableSortCallbacks } from "../table";
import { Table, TableCell, TableHead, TableRow } from "../table";
import { TableCell, TableHead, TableRow } from "../table";
import type { IClassName, StrictReactNode } from "@k8slens/utilities";
import { cssNames, isDefined, isReactNode, noop, prevDefault, stopPropagation } from "@k8slens/utilities";
import type { AddRemoveButtonsProps } from "../add-remove-buttons";
import { AddRemoveButtons } from "../add-remove-buttons";
import { NoItems } from "../no-items";
import { Spinner } from "@k8slens/spinner";
import type { ItemObject, TableCellProps } from "@k8slens/list-layout";
import type { GeneralKubeObjectListLayoutColumn, ItemObject, TableCellProps } from "@k8slens/list-layout";
import type { Filter, PageFiltersStore } from "./page-filters/store";
import type { LensTheme } from "../../themes/lens-theme";
import { MenuActions } from "../menu/menu-actions";
Expand All @@ -35,6 +33,9 @@ import type { ToggleTableColumnVisibility } from "../../../features/user-prefere
import toggleTableColumnVisibilityInjectable from "../../../features/user-preferences/common/toggle-table-column-visibility.injectable";
import type { IsTableColumnHidden } from "../../../features/user-preferences/common/is-table-column-hidden.injectable";
import isTableColumnHiddenInjectable from "../../../features/user-preferences/common/is-table-column-hidden.injectable";
import type { AddOrRemoveButtons, AddRemoveButtonsProps, TableComponent } from "@k8slens/table";
import { addOrRemoveButtonsInjectionToken, tableComponentInjectionToken } from "@k8slens/table";
import { tableStateInjectable } from "../table/table-state.injectable";

export interface ItemListLayoutContentProps<Item extends ItemObject, PreLoadStores extends boolean> {
getFilters: () => Filter[];
Expand All @@ -54,6 +55,7 @@ export interface ItemListLayoutContentProps<Item extends ItemObject, PreLoadStor
customizeTableRowProps?: (item: Item) => Partial<TableRowProps<Item>>;
addRemoveButtons?: Partial<AddRemoveButtonsProps>;
virtual?: boolean;
columns?: GeneralKubeObjectListLayoutColumn[];

// item details view
hasDetailsView?: boolean;
Expand All @@ -79,6 +81,9 @@ interface Dependencies {
openConfirmDialog: OpenConfirmDialog;
toggleTableColumnVisibility: ToggleTableColumnVisibility;
isTableColumnHidden: IsTableColumnHidden;
table: TableComponent;
addOrRemoveButtons: AddOrRemoveButtons;
tableState: object;
}

@observer
Expand Down Expand Up @@ -299,6 +304,7 @@ class NonInjectedItemListLayoutContent<
const {
store, hasDetailsView, addRemoveButtons = {}, virtual, sortingCallbacks,
detailsItem, className, tableProps = {}, tableId, getItems, activeTheme,
table, addOrRemoveButtons, tableState,
} = this.props;
const selectedItemId = detailsItem && detailsItem.getId();
const classNames = cssNames(className, "box", "grow", activeTheme.get().type);
Expand All @@ -307,7 +313,7 @@ class NonInjectedItemListLayoutContent<

return (
<div className="items box grow flex column">
<Table
<table.Component
tableId={tableId}
virtual={virtual}
selectable={hasDetailsView}
Expand All @@ -318,15 +324,16 @@ class NonInjectedItemListLayoutContent<
selectedItemId={selectedItemId}
noItems={this.renderNoItems()}
className={classNames}
state={tableState}
{...tableProps}
>
{this.renderTableHeader()}
{this.renderItems()}
</Table>
</table.Component>

<Observer>
{() => (
<AddRemoveButtons
<addOrRemoveButtons.Component
onRemove={
(store.removeItems || store.removeSelectedItems) && selectedItems.length > 0
? () => this.removeItemsDialog(selectedItems)
Expand Down Expand Up @@ -385,5 +392,8 @@ export const ItemListLayoutContent = withInjectables<Dependencies, ItemListLayou
openConfirmDialog: di.inject(openConfirmDialogInjectable),
toggleTableColumnVisibility: di.inject(toggleTableColumnVisibilityInjectable),
isTableColumnHidden: di.inject(isTableColumnHiddenInjectable),
table: di.inject(tableComponentInjectionToken),
addOrRemoveButtons: di.inject(addOrRemoveButtonsInjectionToken),
tableState: di.inject(tableStateInjectable, props),
}),
}) as <Item extends ItemObject, PreLoadStores extends boolean>(props: ItemListLayoutContentProps<Item, PreLoadStores>) => React.ReactElement;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { TableProps, TableRowProps, TableSortCallbacks } from "../table";
import type { IClassName, StrictReactNode, SingleOrMany } from "@k8slens/utilities";
import { cssNames, noop } from "@k8slens/utilities";
import type { AddRemoveButtonsProps } from "../add-remove-buttons";
import type { ItemObject, TableCellProps } from "@k8slens/list-layout";
import type { ItemObject, TableCellProps, GeneralKubeObjectListLayoutColumn } from "@k8slens/list-layout";
import type { SearchInputUrlProps } from "../input";
import type { PageFiltersStore } from "./page-filters/store";
import { FilterType } from "./page-filters/store";
Expand Down Expand Up @@ -98,6 +98,7 @@ export type ItemListLayoutProps<Item extends ItemObject, PreLoadStores extends b
headerClassName?: IClassName;
renderHeaderTitle?: RenderHeaderTitle<Item, PreLoadStores>;
customizeHeader?: HeaderCustomizer | HeaderCustomizer[];
columns?: GeneralKubeObjectListLayoutColumn[];

// items list configuration
isReady?: boolean; // show loading indicator while not ready
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface KubeObjectListLayoutProps<
// eslint-disable-next-line unused-imports/no-unused-vars-ts, @typescript-eslint/no-unused-vars
A extends KubeApi<K, D>,
D extends KubeJsonApiDataFor<K>,
> extends Omit<ItemListLayoutProps<K, false>, "getItems" | "dependentStores" | "preloadStores"> {
> extends Omit<ItemListLayoutProps<K, false>, "getItems" | "dependentStores" | "preloadStores" | "columns"> {
items?: K[];
getItems?: () => K[];
store: KubeItemListStore<K>;
Expand Down Expand Up @@ -193,6 +193,7 @@ class NonInjectedKubeObjectListLayout<
getItems={() => this.props.items || store.contextItems}
preloadStores={false} // loading handled in kubeWatchApi.subscribeStores()
detailsItem={this.selectedItem}
columns={targetColumns as GeneralKubeObjectListLayoutColumn[]}
customizeHeader={[
({ filters, searchProps, info, ...headerPlaceHolders }) => ({
filters: (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/

import React from "react";
import type { KubeObject } from "@k8slens/kube-object";
import type {
BaseKubeObjectListLayoutColumn,
GeneralKubeObjectListLayoutColumn,
SpecificKubeListLayoutColumn,
} from "@k8slens/list-layout";
import type { ItemListLayoutContentProps } from "../item-object-list/content";

export type TableContextRequiredDataFromComponentsLayerAbove<
K extends KubeObject,
> = Pick<
ItemListLayoutContentProps<K, any>,
| "tableId"
| "getFilters"
| "renderItemMenu"
| "store"
| "onDetails"
| "hasDetailsView"
| "getItems"
| "renderTableHeader"
| "renderTableContents"
| "sortingCallbacks"
| "isSelectable"
>;

export interface TableDataContextValue<K extends KubeObject>
extends TableContextRequiredDataFromComponentsLayerAbove<K> {
columns?: (
| BaseKubeObjectListLayoutColumn<K>
| SpecificKubeListLayoutColumn<K>
| GeneralKubeObjectListLayoutColumn
)[];
}

export const TableDataContext = React.createContext<
TableDataContextValue<KubeObject>
>({} as any);
Loading