1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Remove isClusterScoped from ItemListLayout (#2743)

* remove isClusterScoped from ItemListLayout

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Move <NamespaceSelectFilter> to KubeObjectListLayout

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* revert to simpler NamespaceSelectFilter fix

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-06-04 05:58:12 -04:00 committed by GitHub
parent 0d0c67f13f
commit deaf67b30b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 43 additions and 32 deletions

View File

@ -81,7 +81,6 @@ export class HelmCharts extends Component<Props> {
tableId="helm_charts" tableId="helm_charts"
className="HelmCharts" className="HelmCharts"
store={helmChartStore} store={helmChartStore}
isClusterScoped={true}
isSelectable={false} isSelectable={false}
sortingCallbacks={{ sortingCallbacks={{
[columnId.name]: (chart: HelmChart) => chart.getName(), [columnId.name]: (chart: HelmChart) => chart.getName(),

View File

@ -145,7 +145,7 @@ export class CRDDetails extends React.Component<Props> {
<> <>
<DrawerTitle title="Validation"/> <DrawerTitle title="Validation"/>
<AceEditor <AceEditor
mode="json" mode="yaml"
className="validation" className="validation"
value={validation} value={validation}
readOnly readOnly

View File

@ -90,7 +90,6 @@ export class CrdList extends React.Component {
isConfigurable isConfigurable
tableId="crd" tableId="crd"
className="CrdList" className="CrdList"
isClusterScoped={true}
store={crdStore} store={crdStore}
items={items} items={items}
sortingCallbacks={sortingCallbacks} sortingCallbacks={sortingCallbacks}

View File

@ -95,7 +95,6 @@ export class CrdResources extends React.Component<Props> {
isConfigurable isConfigurable
tableId="crd_resources" tableId="crd_resources"
className="CrdResources" className="CrdResources"
isClusterScoped={!isNamespaced}
store={store} store={store}
sortingCallbacks={sortingCallbacks} sortingCallbacks={sortingCallbacks}
searchFilters={[ searchFilters={[

View File

@ -47,7 +47,6 @@ export class Namespaces extends React.Component<Props> {
return ( return (
<TabLayout> <TabLayout>
<KubeObjectListLayout <KubeObjectListLayout
isClusterScoped
isConfigurable isConfigurable
tableId="namespaces" tableId="namespaces"
className="Namespaces" store={namespaceStore} className="Namespaces" store={namespaceStore}

View File

@ -166,7 +166,7 @@ export class Nodes extends React.Component<Props> {
isConfigurable isConfigurable
tableId="nodes" tableId="nodes"
className="Nodes" className="Nodes"
store={nodesStore} isClusterScoped store={nodesStore}
isReady={nodesStore.isLoaded} isReady={nodesStore.isLoaded}
dependentStores={[podsStore]} dependentStores={[podsStore]}
isSelectable={false} isSelectable={false}

View File

@ -43,7 +43,6 @@ export class PodSecurityPolicies extends React.Component {
isConfigurable isConfigurable
tableId="access_pod_security_policies" tableId="access_pod_security_policies"
className="PodSecurityPolicies" className="PodSecurityPolicies"
isClusterScoped={true}
store={podSecurityPoliciesStore} store={podSecurityPoliciesStore}
sortingCallbacks={{ sortingCallbacks={{
[columnId.name]: (item: PodSecurityPolicy) => item.getName(), [columnId.name]: (item: PodSecurityPolicy) => item.getName(),

View File

@ -49,7 +49,7 @@ export class StorageClasses extends React.Component<Props> {
isConfigurable isConfigurable
tableId="storage_classes" tableId="storage_classes"
className="StorageClasses" className="StorageClasses"
store={storageClassStore} isClusterScoped store={storageClassStore}
sortingCallbacks={{ sortingCallbacks={{
[columnId.name]: (item: StorageClass) => item.getName(), [columnId.name]: (item: StorageClass) => item.getName(),
[columnId.age]: (item: StorageClass) => item.getTimeDiffFromNow(), [columnId.age]: (item: StorageClass) => item.getTimeDiffFromNow(),

View File

@ -52,7 +52,7 @@ export class PersistentVolumes extends React.Component<Props> {
isConfigurable isConfigurable
tableId="storage_volumes" tableId="storage_volumes"
className="PersistentVolumes" className="PersistentVolumes"
store={volumesStore} isClusterScoped store={volumesStore}
sortingCallbacks={{ sortingCallbacks={{
[columnId.name]: (item: PersistentVolume) => item.getName(), [columnId.name]: (item: PersistentVolume) => item.getName(),
[columnId.storageClass]: (item: PersistentVolume) => item.getStorageClass(), [columnId.storageClass]: (item: PersistentVolume) => item.getStorageClass(),

View File

@ -24,7 +24,7 @@ import groupBy from "lodash/groupBy";
import React, { ReactNode } from "react"; import React, { ReactNode } from "react";
import { computed, makeObservable } from "mobx"; import { computed, makeObservable } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react"; import { observer } from "mobx-react";
import { ConfirmDialog, ConfirmDialogParams } from "../confirm-dialog"; import { ConfirmDialog, ConfirmDialogParams } from "../confirm-dialog";
import { Table, TableCell, TableCellProps, TableHead, TableProps, TableRow, TableRowProps, TableSortCallback } from "../table"; import { Table, TableCell, TableCellProps, TableHead, TableProps, TableRow, TableRowProps, TableSortCallback } from "../table";
import { boundMethod, createStorage, cssNames, IClassName, isReactNode, noop, ObservableToggleSet, prevDefault, stopPropagation } from "../../utils"; import { boundMethod, createStorage, cssNames, IClassName, isReactNode, noop, ObservableToggleSet, prevDefault, stopPropagation } from "../../utils";
@ -36,13 +36,14 @@ import { SearchInputUrl } from "../input";
import { Filter, FilterType, pageFilters } from "./page-filters.store"; import { Filter, FilterType, pageFilters } from "./page-filters.store";
import { PageFiltersList } from "./page-filters-list"; import { PageFiltersList } from "./page-filters-list";
import { PageFiltersSelect } from "./page-filters-select"; import { PageFiltersSelect } from "./page-filters-select";
import { NamespaceSelectFilter } from "../+namespaces/namespace-select-filter";
import { ThemeStore } from "../../theme.store"; import { ThemeStore } from "../../theme.store";
import { MenuActions } from "../menu/menu-actions"; import { MenuActions } from "../menu/menu-actions";
import { MenuItem } from "../menu"; import { MenuItem } from "../menu";
import { Checkbox } from "../checkbox"; import { Checkbox } from "../checkbox";
import { UserStore } from "../../../common/user-store"; import { UserStore } from "../../../common/user-store";
import { namespaceStore } from "../+namespaces/namespace.store"; import { namespaceStore } from "../+namespaces/namespace.store";
import { KubeObjectStore } from "../../kube-object.store";
import { NamespaceSelectFilter } from "../+namespaces/namespace-select-filter";
// todo: refactor, split to small re-usable components // todo: refactor, split to small re-usable components
@ -63,7 +64,6 @@ export interface ItemListLayoutProps<T extends ItemObject = ItemObject> {
store: ItemStore<T>; store: ItemStore<T>;
dependentStores?: ItemStore[]; dependentStores?: ItemStore[];
preloadStores?: boolean; preloadStores?: boolean;
isClusterScoped?: boolean;
hideFilters?: boolean; hideFilters?: boolean;
searchFilters?: SearchFilter<T>[]; searchFilters?: SearchFilter<T>[];
/** @deprecated */ /** @deprecated */
@ -137,7 +137,7 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
} }
async componentDidMount() { async componentDidMount() {
const { isClusterScoped, isConfigurable, tableId, preloadStores } = this.props; const { isConfigurable, tableId, preloadStores } = this.props;
if (isConfigurable && !tableId) { if (isConfigurable && !tableId) {
throw new Error("[ItemListLayout]: configurable list require props.tableId to be specified"); throw new Error("[ItemListLayout]: configurable list require props.tableId to be specified");
@ -149,12 +149,6 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
if (preloadStores) { if (preloadStores) {
this.loadStores(); this.loadStores();
if (!isClusterScoped) {
disposeOnUnmount(this, [
namespaceStore.onContextChange(() => this.loadStores())
]);
}
} }
} }
@ -162,7 +156,6 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
const { store, dependentStores } = this.props; const { store, dependentStores } = this.props;
const stores = Array.from(new Set([store, ...dependentStores])); const stores = Array.from(new Set([store, ...dependentStores]));
// load context namespaces by default (see also: `<NamespaceSelectFilter/>`)
stores.forEach(store => store.loadAll(namespaceStore.contextNamespaces)); stores.forEach(store => store.loadAll(namespaceStore.contextNamespaces));
} }
@ -224,7 +217,7 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
} }
@computed get items() { @computed get items() {
const {filters, filterCallbacks } = this; const { filters, filterCallbacks } = this;
const filterGroups = groupBy<Filter>(filters, ({ type }) => type); const filterGroups = groupBy<Filter>(filters, ({ type }) => type);
const filterItems: ItemsFilter[] = []; const filterItems: ItemsFilter[] = [];
@ -330,7 +323,7 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
return null; return null;
} }
return <PageFiltersList filters={filters}/>; return <PageFiltersList filters={filters} />;
} }
renderNoItems() { renderNoItems() {
@ -355,7 +348,7 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
); );
} }
return <NoItems/>; return <NoItems />;
} }
renderItems() { renderItems() {
@ -397,20 +390,26 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
} }
renderHeader() { renderHeader() {
const { showHeader, customizeHeader, renderHeaderTitle, headerClassName, isClusterScoped } = this.props; const { showHeader, customizeHeader, renderHeaderTitle, headerClassName } = this.props;
if (!showHeader) return null; if (!showHeader) {
return null;
}
const showNamespaceSelectFilter = this.props.store instanceof KubeObjectStore && this.props.store.api.isNamespaced;
const title = typeof renderHeaderTitle === "function" ? renderHeaderTitle(this) : renderHeaderTitle; const title = typeof renderHeaderTitle === "function" ? renderHeaderTitle(this) : renderHeaderTitle;
const placeholders: IHeaderPlaceholders = { const placeholders: IHeaderPlaceholders = {
title: <h5 className="title">{title}</h5>, title: <h5 className="title">{title}</h5>,
info: this.renderInfo(), info: this.renderInfo(),
filters: <> filters: (
{!isClusterScoped && <NamespaceSelectFilter/>} <>
<PageFiltersSelect allowEmpty disableFilters={{ {showNamespaceSelectFilter && <NamespaceSelectFilter />}
[FilterType.NAMESPACE]: true, // namespace-select used instead <PageFiltersSelect allowEmpty disableFilters={{
}}/> [FilterType.NAMESPACE]: true, // namespace-select used instead
</>, }} />
search: <SearchInputUrl/>, </>
),
search: <SearchInputUrl />,
}; };
let header = this.renderHeaderContent(placeholders); let header = this.renderHeaderContent(placeholders);

View File

@ -29,6 +29,19 @@ import { MainLayoutHeader } from "../main-layout-header";
import { Cluster } from "../../../../main/cluster"; import { Cluster } from "../../../../main/cluster";
import { ClusterStore } from "../../../../common/cluster-store"; import { ClusterStore } from "../../../../common/cluster-store";
import mockFs from "mock-fs"; import mockFs from "mock-fs";
import { ThemeStore } from "../../../theme.store";
import { UserStore } from "../../../../common/user-store";
jest.mock("electron", () => {
return {
app: {
getVersion: () => "99.99.99",
getPath: () => "tmp",
getLocale: () => "en",
setLoginItemSettings: jest.fn(),
},
};
});
describe("<MainLayoutHeader />", () => { describe("<MainLayoutHeader />", () => {
let cluster: Cluster; let cluster: Cluster;
@ -60,6 +73,8 @@ describe("<MainLayoutHeader />", () => {
mockFs(mockOpts); mockFs(mockOpts);
UserStore.createInstance();
ThemeStore.createInstance();
ClusterStore.createInstance(); ClusterStore.createInstance();
cluster = new Cluster({ cluster = new Cluster({
@ -71,6 +86,8 @@ describe("<MainLayoutHeader />", () => {
afterEach(() => { afterEach(() => {
ClusterStore.resetInstance(); ClusterStore.resetInstance();
ThemeStore.resetInstance();
UserStore.resetInstance();
mockFs.restore(); mockFs.restore();
}); });