diff --git a/src/renderer/components/+workloads-pods/pod-details-list.tsx b/src/renderer/components/+workloads-pods/pod-details-list.tsx index b3dbe80fe7..e7e603375c 100644 --- a/src/renderer/components/+workloads-pods/pod-details-list.tsx +++ b/src/renderer/components/+workloads-pods/pod-details-list.tsx @@ -51,26 +51,14 @@ interface Props extends OptionalProps { interface OptionalProps { maxCpu?: number; maxMemory?: number; - showTitle?: boolean; } @observer export class PodDetailsList extends React.Component { - static defaultProps: OptionalProps = { - showTitle: true - }; - private metricsWatcher = interval(120, () => { podsStore.loadKubeMetrics(this.props.owner.getNs()); }); - private sortingCallbacks = { - [sortBy.name]: (pod: Pod) => pod.getName(), - [sortBy.namespace]: (pod: Pod) => pod.getNs(), - [sortBy.cpu]: (pod: Pod) => podsStore.getPodKubeMetrics(pod).cpu, - [sortBy.memory]: (pod: Pod) => podsStore.getPodKubeMetrics(pod).memory, - }; - componentDidMount() { this.metricsWatcher.start(true); disposeOnUnmount(this, [ @@ -144,27 +132,43 @@ export class PodDetailsList extends React.Component { } render() { - const { pods, showTitle } = this.props; - const virtual = pods.length > 100; + const { pods } = this.props; - if (!pods.length && !podsStore.isLoaded) return ( -
- ); - if (!pods.length) return null; + if (!podsStore.isLoaded) { + return ( +
+ +
+ ); + } + + if (!pods.length) { + return null; + } + + const virtual = pods.length > 20; return (
- {showTitle && } + pod.getName(), + [sortBy.namespace]: pod => pod.getNs(), + [sortBy.cpu]: pod => podsStore.getPodKubeMetrics(pod).cpu, + [sortBy.memory]: pod => podsStore.getPodKubeMetrics(pod).memory, + }} sortByDefault={{ sortBy: sortBy.cpu, orderBy: "desc" }} sortSyncWithUrl={false} getTableRow={this.getTableRow} + renderRow={!virtual && (pod => this.getTableRow(pod.getId()))} className="box grow" > @@ -176,9 +180,6 @@ export class PodDetailsList extends React.Component { Memory Status - { - !virtual && pods.map(pod => this.getTableRow(pod.getId())) - }
); diff --git a/src/renderer/components/table/table.tsx b/src/renderer/components/table/table.tsx index 1d428c62be..6d71ba78a2 100644 --- a/src/renderer/components/table/table.tsx +++ b/src/renderer/components/table/table.tsx @@ -57,9 +57,26 @@ export interface TableProps extends React.DOMAttributes { onSort?: (params: TableSortParams) => void; // callback on sort change, default: global sync with url noItems?: React.ReactNode; // Show no items state table list is empty selectedItemId?: string; // Allows to scroll list to selected item - virtual?: boolean; // Use virtual list component to render only visible rows - rowPadding?: string; - rowLineHeight?: string; + + /** + * Use virtual list component to render only visible rows. By default uses a + * auto sizer to fill available height + */ + virtual?: boolean; + /** + * Only used when virtual is true. Sets the virtual list to be a fixed height. + * Needed when used in contexts that already have a parent component that + * is `overflow-y: scroll`, + */ + virtualHeight?: number; + /** + * Row padding in pixels + */ + rowPadding?: number; + /** + * Row line height in pixels + */ + rowLineHeight?: number; customRowHeights?: (item: Item, lineHeight: number, paddings: number) => number; getTableRow?: (uid: string) => React.ReactElement; renderRow?: (item: Item) => React.ReactElement; @@ -78,9 +95,10 @@ export class Table extends React.Component> { static defaultProps: TableProps = { scrollable: true, autoSize: true, - rowPadding: "8px", - rowLineHeight: "17px", + rowPadding: 8, + rowLineHeight: 17, sortSyncWithUrl: true, + customRowHeights: (item, lineHeight, paddings) => lineHeight + paddings, }; constructor(props: TableProps) { @@ -185,7 +203,10 @@ export class Table extends React.Component> { } renderRows() { - const { noItems, virtual, customRowHeights, rowLineHeight, rowPadding, items, getTableRow, selectedItemId, className } = this.props; + const { + noItems, virtual, customRowHeights, rowLineHeight, rowPadding, items, + getTableRow, selectedItemId, className, virtualHeight + } = this.props; const content = this.getContent(); let rows: React.ReactElement[] = content.filter(elem => elem.type === TableRow); let sortedItems = rows.length ? rows.map(row => row.props.sortItem) : [...items]; @@ -194,9 +215,7 @@ export class Table extends React.Component> { sortedItems = this.getSorted(sortedItems); if (rows.length) { - rows = sortedItems.map(item => rows.find(row => { - return item == row.props.sortItem; - })); + rows = sortedItems.map(item => rows.find(row => item == row.props.sortItem)); } } @@ -205,15 +224,7 @@ export class Table extends React.Component> { } if (virtual) { - const lineHeight = parseFloat(rowLineHeight); - const padding = parseFloat(rowPadding); - let rowHeights: number[] = Array(items.length).fill(lineHeight + padding * 2); - - if (customRowHeights) { - rowHeights = sortedItems.map(item => { - return customRowHeights(item, lineHeight, padding * 2); - }); - } + const rowHeights = sortedItems.map(item => customRowHeights(item, rowLineHeight, rowPadding * 2)); return ( extends React.Component> { getRow={getTableRow} selectedItemId={selectedItemId} className={className} + fixedHeight={virtualHeight} /> ); } diff --git a/src/renderer/components/virtual-list/virtual-list.tsx b/src/renderer/components/virtual-list/virtual-list.tsx index 36f62dff93..be3f2fae61 100644 --- a/src/renderer/components/virtual-list/virtual-list.tsx +++ b/src/renderer/components/virtual-list/virtual-list.tsx @@ -44,6 +44,12 @@ interface Props { getRow?: (uid: string | number) => React.ReactElement; onScroll?: (props: ListOnScrollProps) => void; outerRef?: React.Ref + + /** + * If specified then AutoSizer will not be used and instead a fixed height + * virtual list will be rendered + */ + fixedHeight?: number; } interface State { @@ -98,34 +104,45 @@ export class VirtualList extends Component { this.listRef.current?.scrollToItem(index, align); }; - render() { - const { width, className, items, getRow, onScroll, outerRef } = this.props; + renderList(height: number | undefined) { + const { width, items, getRow, onScroll, outerRef } = this.props; const { overscanCount } = this.state; - const rowData: RowData = { - items, - getRow - }; + + return ( + + {Row} + + ); + } + + render() { + const { className, fixedHeight } = this.props; return (
- - {({ height }) => ( - - {Row} - - )} - + { + typeof fixedHeight === "number" + ? this.renderList(fixedHeight) + : ( + + {({ height }) => this.renderList(height)} + + ) + }
); }