mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
flatten file heirarchy
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
4c1489c3d5
commit
9746309949
@ -12,7 +12,7 @@ import { helmChartStore } from "./helm-chart.store";
|
||||
import type { HelmChart } from "../../../common/k8s-api/endpoints/helm-charts.api";
|
||||
import { HelmChartDetails } from "./helm-chart-details";
|
||||
import { navigation } from "../../navigation";
|
||||
import { ItemListLayout } from "../item-object-list/item-list-layout";
|
||||
import { ItemListLayout } from "../item-object-list/list-layout";
|
||||
import { helmChartsURL } from "../../../common/routes";
|
||||
import type { HelmChartsRouteParams } from "../../../common/routes";
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ import "./port-forwards.scss";
|
||||
import React from "react";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import type { RouteComponentProps } from "react-router-dom";
|
||||
import { ItemListLayout } from "../item-object-list/item-list-layout";
|
||||
import { ItemListLayout } from "../item-object-list/list-layout";
|
||||
import type { PortForwardItem, PortForwardStore } from "../../port-forward";
|
||||
import { PortForwardMenu } from "./port-forward-menu";
|
||||
import { PortForwardsRouteParams, portForwardsURL } from "../../../common/routes";
|
||||
|
||||
@ -3,24 +3,24 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import "../item-list-layout.scss";
|
||||
import "./item-list-layout.scss";
|
||||
|
||||
import React, { ReactNode } from "react";
|
||||
import { computed, makeObservable } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import { ConfirmDialog, ConfirmDialogParams } from "../../confirm-dialog";
|
||||
import { Table, TableCell, TableCellProps, TableHead, TableProps, TableRow, TableRowProps, TableSortCallbacks } from "../../table";
|
||||
import { boundMethod, cssNames, IClassName, isReactNode, prevDefault, stopPropagation } from "../../../utils";
|
||||
import { AddRemoveButtons, AddRemoveButtonsProps } from "../../add-remove-buttons";
|
||||
import { NoItems } from "../../no-items";
|
||||
import { Spinner } from "../../spinner";
|
||||
import type { ItemObject, ItemStore } from "../../../../common/item.store";
|
||||
import { Filter, pageFilters } from "../page-filters.store";
|
||||
import { ThemeStore } from "../../../theme.store";
|
||||
import { MenuActions } from "../../menu/menu-actions";
|
||||
import { MenuItem } from "../../menu";
|
||||
import { Checkbox } from "../../checkbox";
|
||||
import { UserStore } from "../../../../common/user-store";
|
||||
import { ConfirmDialog, ConfirmDialogParams } from "../confirm-dialog";
|
||||
import { Table, TableCell, TableCellProps, TableHead, TableProps, TableRow, TableRowProps, TableSortCallbacks } from "../table";
|
||||
import { boundMethod, cssNames, IClassName, isReactNode, prevDefault, stopPropagation } from "../../utils";
|
||||
import { AddRemoveButtons, AddRemoveButtonsProps } from "../add-remove-buttons";
|
||||
import { NoItems } from "../no-items";
|
||||
import { Spinner } from "../spinner";
|
||||
import type { ItemObject, ItemStore } from "../../../common/item.store";
|
||||
import { Filter, pageFilters } from "./page-filters.store";
|
||||
import { ThemeStore } from "../../theme.store";
|
||||
import { MenuActions } from "../menu/menu-actions";
|
||||
import { MenuItem } from "../menu";
|
||||
import { Checkbox } from "../checkbox";
|
||||
import { UserStore } from "../../../common/user-store";
|
||||
|
||||
interface ItemListLayoutContentProps<I extends ItemObject> {
|
||||
getFilters: () => Filter[]
|
||||
29
src/renderer/components/item-object-list/filters.tsx
Normal file
29
src/renderer/components/item-object-list/filters.tsx
Normal file
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import "./item-list-layout.scss";
|
||||
|
||||
import React from "react";
|
||||
import { PageFiltersList } from "./page-filters-list";
|
||||
import { observer } from "mobx-react";
|
||||
import type { Filter } from "./page-filters.store";
|
||||
|
||||
export interface ItemListLayoutFilterProps {
|
||||
getIsReady: () => boolean
|
||||
getFilters: () => Filter[]
|
||||
getFiltersAreShown: () => boolean
|
||||
hideFilters: boolean
|
||||
}
|
||||
|
||||
export const ItemListLayoutFilters = observer(({ getFilters, getFiltersAreShown, getIsReady, hideFilters }: ItemListLayoutFilterProps) => {
|
||||
const filters = getFilters();
|
||||
|
||||
if (!getIsReady() || !filters.length || hideFilters || !getFiltersAreShown()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <PageFiltersList filters={filters} />;
|
||||
});
|
||||
|
||||
17
src/renderer/components/item-object-list/header-filters.tsx
Normal file
17
src/renderer/components/item-object-list/header-filters.tsx
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { observer } from "mobx-react";
|
||||
import React from "react";
|
||||
import type { HeaderPlaceholders } from "./list-layout";
|
||||
|
||||
export interface ItemListLayoutHeaderFiltersProps {
|
||||
headerPlaceholders: HeaderPlaceholders
|
||||
}
|
||||
|
||||
export const ItemListLayoutHeaderFilters = observer(({ headerPlaceholders }: ItemListLayoutHeaderFiltersProps) => (
|
||||
<>
|
||||
{headerPlaceholders.filters}
|
||||
</>
|
||||
));
|
||||
54
src/renderer/components/item-object-list/header-info.tsx
Normal file
54
src/renderer/components/item-object-list/header-info.tsx
Normal file
@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import type { ItemObject, ItemStore } from "../../../common/item.store";
|
||||
import type { Filter } from "./page-filters.store";
|
||||
import type { HeaderPlaceholders } from "./list-layout";
|
||||
|
||||
interface ItemListLayoutHeaderInfoProps<I extends ItemObject> {
|
||||
headerPlaceholders: HeaderPlaceholders;
|
||||
getItems: () => I[];
|
||||
store: ItemStore<I>;
|
||||
getFilters: () => Filter[]
|
||||
toggleFilters: () => void
|
||||
}
|
||||
|
||||
export const ItemListLayoutHeaderInfo = observer(<I extends ItemObject>({
|
||||
headerPlaceholders,
|
||||
getItems,
|
||||
getFilters,
|
||||
store,
|
||||
toggleFilters,
|
||||
}: ItemListLayoutHeaderInfoProps<I>) => {
|
||||
const renderInfo = () => {
|
||||
const allItemsCount = store.getTotalCount();
|
||||
const itemsCount = getItems().length;
|
||||
|
||||
if (getFilters().length > 0) {
|
||||
return (
|
||||
<>
|
||||
<a onClick={toggleFilters}>Filtered</a>: {itemsCount} / {allItemsCount}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return allItemsCount === 1
|
||||
? `${allItemsCount} item`
|
||||
: `${allItemsCount} items`;
|
||||
};
|
||||
|
||||
const info = headerPlaceholders.info ?? renderInfo();
|
||||
|
||||
if (!info) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="info-panel box grow">
|
||||
{info}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
27
src/renderer/components/item-object-list/header-search.tsx
Normal file
27
src/renderer/components/item-object-list/header-search.tsx
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { observer } from "mobx-react";
|
||||
import type { ItemObject } from "../../../common/item.store";
|
||||
import { SearchInputUrl } from "../input";
|
||||
import React from "react";
|
||||
import type { HeaderPlaceholders, SearchFilter } from "./list-layout";
|
||||
|
||||
interface ItemListLayoutHeaderSearchProps<I extends ItemObject> {
|
||||
searchFilters: SearchFilter<I>[];
|
||||
headerPlaceholders: HeaderPlaceholders;
|
||||
}
|
||||
|
||||
export const ItemListLayoutHeaderSearch = observer(<I extends ItemObject>({
|
||||
searchFilters,
|
||||
headerPlaceholders = {},
|
||||
}: ItemListLayoutHeaderSearchProps<I>) => {
|
||||
const { searchProps } = headerPlaceholders;
|
||||
|
||||
if (searchFilters.length === 0 || !searchProps) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <SearchInputUrl {...searchProps} />;
|
||||
});
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { observer } from "mobx-react";
|
||||
import React from "react";
|
||||
import type { HeaderPlaceholders } from "../../item-list-layout";
|
||||
import type { HeaderPlaceholders } from "./list-layout";
|
||||
|
||||
interface ItemListLayoutHeaderTitleProps {
|
||||
renderHeaderTitle: React.ReactNode | (() => React.ReactNode);
|
||||
@ -3,20 +3,20 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import "../item-list-layout.scss";
|
||||
import "./item-list-layout.scss";
|
||||
|
||||
import React, { ReactNode } from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import { cssNames, IClassName } from "../../../utils";
|
||||
import type { ItemObject, ItemStore } from "../../../../common/item.store";
|
||||
import type { Filter } from "../page-filters.store";
|
||||
import { ItemListLayoutHeaderTitle } from "./item-list-layout-header-title/item-list-layout-header-title";
|
||||
import { ItemListLayoutHeaderInfo } from "./item-list-layout-header-info/item-list-layout-header-info";
|
||||
import { ItemListLayoutHeaderFilters } from "./item-list-layout-header-filters/item-list-layout-header-filters";
|
||||
import { ItemListLayoutHeaderSearch } from "./item-list-layout-header-search/item-list-layout-header-search";
|
||||
import type { HeaderCustomizer, SearchFilter } from "../item-list-layout";
|
||||
import { cssNames, IClassName } from "../../utils";
|
||||
import type { ItemObject, ItemStore } from "../../../common/item.store";
|
||||
import type { Filter } from "./page-filters.store";
|
||||
import { ItemListLayoutHeaderTitle } from "./header-title";
|
||||
import { ItemListLayoutHeaderInfo } from "./header-info";
|
||||
import { ItemListLayoutHeaderFilters } from "./header-filters";
|
||||
import { ItemListLayoutHeaderSearch } from "./header-search";
|
||||
import type { HeaderCustomizer, SearchFilter } from "./list-layout";
|
||||
|
||||
interface ItemListLayoutHeaderProps<I extends ItemObject> {
|
||||
export interface ItemListLayoutHeaderProps<I extends ItemObject> {
|
||||
getItems: () => I[];
|
||||
getFilters: () => Filter[];
|
||||
toggleFilters: () => void;
|
||||
@ -44,6 +44,10 @@ export class ItemListLayoutHeader<I extends ItemObject> extends React.Component<
|
||||
renderHeaderTitle,
|
||||
headerClassName,
|
||||
searchFilters,
|
||||
getItems,
|
||||
store,
|
||||
getFilters,
|
||||
toggleFilters,
|
||||
} = this.props;
|
||||
|
||||
if (!showHeader) {
|
||||
@ -69,10 +73,10 @@ export class ItemListLayoutHeader<I extends ItemObject> extends React.Component<
|
||||
|
||||
<ItemListLayoutHeaderInfo
|
||||
headerPlaceholders={headerPlaceholders}
|
||||
getItems={this.props.getItems}
|
||||
store={this.props.store}
|
||||
getFilters={this.props.getFilters}
|
||||
toggleFilters={this.props.toggleFilters}
|
||||
getItems={getItems}
|
||||
store={store}
|
||||
getFilters={getFilters}
|
||||
toggleFilters={toggleFilters}
|
||||
/>
|
||||
|
||||
<ItemListLayoutHeaderFilters headerPlaceholders={headerPlaceholders} />
|
||||
@ -3,4 +3,4 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
export * from "./item-list-layout";
|
||||
export * from "./list-layout";
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import "../item-list-layout.scss";
|
||||
|
||||
import React from "react";
|
||||
import { PageFiltersList } from "../page-filters-list";
|
||||
import { observer } from "mobx-react";
|
||||
import type { Filter } from "../page-filters.store";
|
||||
|
||||
interface ItemListLayoutFilterProps {
|
||||
getIsReady: () => boolean
|
||||
getFilters: () => Filter[]
|
||||
getFiltersAreShown: () => boolean
|
||||
hideFilters: boolean
|
||||
}
|
||||
|
||||
@observer
|
||||
export class ItemListLayoutFilters extends React.Component<ItemListLayoutFilterProps> {
|
||||
render() {
|
||||
const filters = this.props.getFilters();
|
||||
|
||||
if (!this.props.getIsReady() || !filters.length || this.props.hideFilters || !this.props.getFiltersAreShown()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <PageFiltersList filters={filters} />;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { observer } from "mobx-react";
|
||||
import React from "react";
|
||||
import type { HeaderPlaceholders } from "../../item-list-layout";
|
||||
|
||||
interface ItemListLayoutHeaderFiltersProps {
|
||||
headerPlaceholders: HeaderPlaceholders
|
||||
}
|
||||
|
||||
export const ItemListLayoutHeaderFilters = observer(
|
||||
({ headerPlaceholders }: ItemListLayoutHeaderFiltersProps) => (
|
||||
<>{headerPlaceholders.filters}</>
|
||||
),
|
||||
);
|
||||
@ -1,53 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import React from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import type { ItemObject, ItemStore } from "../../../../../common/item.store";
|
||||
import type { Filter } from "../../page-filters.store";
|
||||
import type { HeaderPlaceholders } from "../../item-list-layout";
|
||||
|
||||
interface ItemListLayoutHeaderInfoProps<I extends ItemObject> {
|
||||
headerPlaceholders: HeaderPlaceholders;
|
||||
getItems: () => I[];
|
||||
store: ItemStore<I>;
|
||||
getFilters: () => Filter[]
|
||||
toggleFilters: () => void
|
||||
}
|
||||
|
||||
export const ItemListLayoutHeaderInfo = observer(
|
||||
<I extends ItemObject>(props: ItemListLayoutHeaderInfoProps<I>) => {
|
||||
const { headerPlaceholders, getItems, getFilters, store, toggleFilters } =
|
||||
props;
|
||||
|
||||
const renderInfo = () => {
|
||||
const allItemsCount = store.getTotalCount();
|
||||
const itemsCount = getItems().length;
|
||||
|
||||
if (getFilters().length > 0) {
|
||||
return (
|
||||
<>
|
||||
<a onClick={toggleFilters}>Filtered</a>: {itemsCount} /{" "}
|
||||
{allItemsCount}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return allItemsCount === 1
|
||||
? `${allItemsCount} item`
|
||||
: `${allItemsCount} items`;
|
||||
};
|
||||
|
||||
const info =
|
||||
headerPlaceholders.info === undefined
|
||||
? renderInfo()
|
||||
: headerPlaceholders.info;
|
||||
|
||||
if (!info) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <div className="info-panel box grow">{info}</div>;
|
||||
},
|
||||
);
|
||||
@ -1,32 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { observer } from "mobx-react";
|
||||
import type { ItemObject } from "../../../../../common/item.store";
|
||||
import { SearchInputUrl } from "../../../input";
|
||||
import React from "react";
|
||||
import type { HeaderPlaceholders, SearchFilter } from "../../item-list-layout";
|
||||
|
||||
interface ItemListLayoutHeaderSearchProps<I extends ItemObject> {
|
||||
searchFilters: SearchFilter<I>[];
|
||||
headerPlaceholders: HeaderPlaceholders;
|
||||
}
|
||||
|
||||
export const ItemListLayoutHeaderSearch = observer(
|
||||
<I extends ItemObject>({
|
||||
searchFilters,
|
||||
headerPlaceholders,
|
||||
}: ItemListLayoutHeaderSearchProps<I>) => {
|
||||
const searchProps =
|
||||
headerPlaceholders.searchProps !== undefined
|
||||
? headerPlaceholders.searchProps
|
||||
: {};
|
||||
|
||||
if (searchFilters.length === 0 || !searchProps) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <SearchInputUrl {...searchProps} />;
|
||||
},
|
||||
);
|
||||
@ -32,11 +32,11 @@ import type { NamespaceStore } from "../+namespaces/namespace-store/namespace.st
|
||||
import namespaceStoreInjectable from "../+namespaces/namespace-store/namespace-store.injectable";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import itemListLayoutStorageInjectable
|
||||
from "./item-list-layout-storage/item-list-layout-storage.injectable";
|
||||
import { ItemListLayoutContent } from "./item-list-layout-content/item-list-layout-content";
|
||||
import { ItemListLayoutHeader } from "./item-list-layout-header/item-list-layout-header";
|
||||
from "./storage.injectable";
|
||||
import { ItemListLayoutContent } from "./content";
|
||||
import { ItemListLayoutHeader } from "./header";
|
||||
import groupBy from "lodash/groupBy";
|
||||
import { ItemListLayoutFilters } from "./item-list-layout-filters/item-list-layout-filters";
|
||||
import { ItemListLayoutFilters } from "./filters";
|
||||
import { observer } from "mobx-react";
|
||||
|
||||
export type SearchFilter<I extends ItemObject> = (item: I) => string | number | (string | number)[];
|
||||
@ -286,38 +286,28 @@ class NonInjectedItemListLayout<I extends ItemObject> extends React.Component<It
|
||||
failedToLoadMessage={this.props.failedToLoadMessage}
|
||||
/>
|
||||
|
||||
{this.props.renderFooter && this.props.renderFooter(this)}
|
||||
{this.props.renderFooter?.(this)}
|
||||
</div>
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
export function ItemListLayout<I extends ItemObject>(
|
||||
props: ItemListLayoutProps<I>,
|
||||
) {
|
||||
const InjectedItemListLayout = withInjectables<
|
||||
Dependencies,
|
||||
ItemListLayoutProps<I>
|
||||
>(
|
||||
NonInjectedItemListLayout,
|
||||
|
||||
{
|
||||
getProps: (di, props) => ({
|
||||
namespaceStore: di.inject(namespaceStoreInjectable),
|
||||
itemListLayoutStorage: di.inject(itemListLayoutStorageInjectable),
|
||||
...props,
|
||||
}),
|
||||
},
|
||||
);
|
||||
const InjectedItemListLayout = withInjectables<Dependencies, ItemListLayoutProps<ItemObject>>(NonInjectedItemListLayout, {
|
||||
getProps: (di, props) => ({
|
||||
namespaceStore: di.inject(namespaceStoreInjectable),
|
||||
itemListLayoutStorage: di.inject(itemListLayoutStorageInjectable),
|
||||
...props,
|
||||
}),
|
||||
});
|
||||
|
||||
export function ItemListLayout<I extends ItemObject>(props: ItemListLayoutProps<I>) {
|
||||
return <InjectedItemListLayout {...props} />;
|
||||
}
|
||||
|
||||
const applyFilters = <I extends ItemObject>(
|
||||
filters: ItemsFilter<I>[],
|
||||
items: I[],
|
||||
): I[] => {
|
||||
if (!filters || !filters.length) return items;
|
||||
function applyFilters<I extends ItemObject>(filters: ItemsFilter<I>[], items: I[]): I[] {
|
||||
if (!filters || !filters.length) {
|
||||
return items;
|
||||
}
|
||||
|
||||
return filters.reduce((items, filter) => filter(items), items);
|
||||
};
|
||||
}
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import createStorageInjectable from "../../../utils/create-storage/create-storage.injectable";
|
||||
import createStorageInjectable from "../../utils/create-storage/create-storage.injectable";
|
||||
|
||||
const itemListLayoutStorageInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
@ -10,7 +10,7 @@ import { computed, makeObservable, observable, reaction } from "mobx";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import { cssNames, Disposer } from "../../utils";
|
||||
import type { KubeObject } from "../../../common/k8s-api/kube-object";
|
||||
import { ItemListLayout, ItemListLayoutProps } from "../item-object-list/item-list-layout";
|
||||
import { ItemListLayout, ItemListLayoutProps } from "../item-object-list/list-layout";
|
||||
import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
||||
import { KubeObjectMenu } from "../kube-object-menu";
|
||||
import { NamespaceSelectFilter } from "../+namespaces/namespace-select-filter";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user