From 1814b6ec8657f3d7f542e65d4ee78361f5628b54 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Mon, 19 Jul 2021 10:22:23 +0300 Subject: [PATCH] Moving slow parts to Signed-off-by: Alex Andreev --- .../+catalog/catalog-tree.module.css | 5 + src/renderer/components/+catalog/catalog.tsx | 138 +++++++----------- src/renderer/components/menu/menu-actions.tsx | 51 ++++--- .../components/render-delay/render-delay.tsx | 61 ++++++++ types/dom.d.ts | 5 + 5 files changed, 153 insertions(+), 107 deletions(-) create mode 100644 src/renderer/components/render-delay/render-delay.tsx diff --git a/src/renderer/components/+catalog/catalog-tree.module.css b/src/renderer/components/+catalog/catalog-tree.module.css index 4787fd71b8..0b16983dbc 100644 --- a/src/renderer/components/+catalog/catalog-tree.module.css +++ b/src/renderer/components/+catalog/catalog-tree.module.css @@ -46,6 +46,11 @@ border-radius: 2px; } +.content:active { + color: white; + background-color: var(--blue); +} + .group { margin-left: 0px; } diff --git a/src/renderer/components/+catalog/catalog.tsx b/src/renderer/components/+catalog/catalog.tsx index 76339e79a3..207f3cb80b 100644 --- a/src/renderer/components/+catalog/catalog.tsx +++ b/src/renderer/components/+catalog/catalog.tsx @@ -42,6 +42,8 @@ import { CatalogEntityDetails } from "./catalog-entity-details"; import { catalogURL, CatalogViewRouteParam } from "../../../common/routes"; import { CatalogMenu } from "./catalog-menu"; import { HotbarIcon } from "../hotbar/hotbar-icon"; +import { RenderDelay } from "../render-delay/render-delay"; +import { CatalogTopbar } from "../cluster-manager/catalog-topbar"; export const previousActiveTab = createAppStorage("catalog-previous-active-tab", ""); @@ -144,7 +146,11 @@ export class Catalog extends React.Component { }; renderNavigation() { - return ; + return ( + + + + ); } renderItemMenu = (item: CatalogEntityItem) => { @@ -172,69 +178,37 @@ export class Catalog extends React.Component { renderIcon(item: CatalogEntityItem) { return ( - + + + ); } - renderSingleCategoryList() { + renderList() { + const { activeCategory } = this.catalogEntityStore; + + const tableId = activeCategory ? `catalog-items-${activeCategory?.metadata.name.replace(" ", "")}` : "catalog-items"; + + if (this.activeTab === undefined) { + return null; + } + return ( ) => item.name, - [sortBy.source]: (item: CatalogEntityItem) => item.source, - [sortBy.status]: (item: CatalogEntityItem) => item.phase, - }} - searchFilters={[ - (entity: CatalogEntityItem) => entity.searchFields, - ]} - renderTableHeader={[ - { title: "", className: css.iconCell, id: "icon" }, - { title: "Name", className: css.nameCell, sortBy: sortBy.name, id: "name" }, - { title: "Source", className: css.sourceCell, sortBy: sortBy.source, id: "source" }, - { title: "Labels", className: css.labelsCell, id: "labels" }, - { title: "Status", className: css.statusCell, sortBy: sortBy.status, id: "status" }, - ]} - customizeTableRowProps={(item: CatalogEntityItem) => ({ - disabled: !item.enabled, - })} - renderTableContents={(item: CatalogEntityItem) => [ - this.renderIcon(item), - item.name, - item.source, - item.getLabelBadges(), - { title: item.phase, className: cssNames(css[item.phase]) } - ]} - onDetails={this.onDetails} - renderItemMenu={this.renderItemMenu} - /> - ); - } - - renderAllCategoriesList() { - return ( - ) => item.name, [sortBy.kind]: (item: CatalogEntityItem) => item.kind, @@ -247,58 +221,56 @@ export class Catalog extends React.Component { renderTableHeader={[ { title: "", className: css.iconCell, id: "icon" }, { title: "Name", className: css.nameCell, sortBy: sortBy.name, id: "name" }, - { title: "Kind", className: css.kindCell, sortBy: sortBy.kind, id: "kind" }, + !activeCategory && { title: "Kind", className: css.kindCell, sortBy: sortBy.kind, id: "kind" }, { title: "Source", className: css.sourceCell, sortBy: sortBy.source, id: "source" }, { title: "Labels", className: css.labelsCell, id: "labels" }, { title: "Status", className: css.statusCell, sortBy: sortBy.status, id: "status" }, - ]} + ].filter(Boolean)} customizeTableRowProps={(item: CatalogEntityItem) => ({ disabled: !item.enabled, })} renderTableContents={(item: CatalogEntityItem) => [ this.renderIcon(item), item.name, - item.kind, + !activeCategory && item.kind, item.source, item.getLabelBadges(), { title: item.phase, className: cssNames(css[item.phase]) } - ]} - detailsItem={this.catalogEntityStore.selectedItem} + ].filter(Boolean)} onDetails={this.onDetails} renderItemMenu={this.renderItemMenu} /> ); } - renderCategoryList() { - if (this.activeTab === undefined) { - return null; - } - - return this.catalogEntityStore.activeCategory ? this.renderSingleCategoryList() : this.renderAllCategoriesList(); - } - render() { if (!this.catalogEntityStore) { return null; } return ( - -
- { this.renderCategoryList() } -
- { - this.catalogEntityStore.selectedItem - ? this.catalogEntityStore.selectedItemId = null} - /> - : - } -
+ <> + + +
+ { this.renderList() } +
+ { + this.catalogEntityStore.selectedItem + ? this.catalogEntityStore.selectedItemId = null} + /> + : ( + + + + ) + } +
+ ); } } diff --git a/src/renderer/components/menu/menu-actions.tsx b/src/renderer/components/menu/menu-actions.tsx index a69f226e5e..28747fec99 100644 --- a/src/renderer/components/menu/menu-actions.tsx +++ b/src/renderer/components/menu/menu-actions.tsx @@ -30,6 +30,7 @@ import { Icon, IconProps } from "../icon"; import { Menu, MenuItem, MenuProps } from "../menu"; import uniqueId from "lodash/uniqueId"; import isString from "lodash/isString"; +import { RenderDelay } from "../render-delay/render-delay"; export interface MenuActionsProps extends Partial { className?: string; @@ -124,30 +125,32 @@ export class MenuActions extends React.Component { return ( <> {this.renderTriggerIcon()} - - {children} - {updateAction && ( - - - Edit - - )} - {removeAction && ( - - - Remove - - )} - + + + {children} + {updateAction && ( + + + Edit + + )} + {removeAction && ( + + + Remove + + )} + + ); } diff --git a/src/renderer/components/render-delay/render-delay.tsx b/src/renderer/components/render-delay/render-delay.tsx new file mode 100644 index 0000000000..1127841477 --- /dev/null +++ b/src/renderer/components/render-delay/render-delay.tsx @@ -0,0 +1,61 @@ +/** + * Copyright (c) 2021 OpenLens Authors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +import React from "react"; +import { makeObservable, observable } from "mobx"; +import { observer } from "mobx-react"; +import { boundMethod } from "../../utils"; + +interface Props { + placeholder?: React.ReactNode; + children: unknown; +} + +@observer +export class RenderDelay extends React.Component { + @observable isVisible = false; + + constructor(props: Props) { + super(props); + makeObservable(this); + } + + componentDidMount() { + window.requestIdleCallback(this.showContents); + } + + componentWillUnmount() { + window.cancelIdleCallback(this.showContents); + } + + @boundMethod + showContents() { + this.isVisible = true; + } + + render() { + if (!this.isVisible) { + return this.props.placeholder || null; + } + + return this.props.children; + } +} diff --git a/types/dom.d.ts b/types/dom.d.ts index bb829706f0..7e8fde45cd 100644 --- a/types/dom.d.ts +++ b/types/dom.d.ts @@ -24,4 +24,9 @@ declare global { interface Element { scrollIntoViewIfNeeded(opt_center?: boolean): void; } + + interface Window { + requestIdleCallback(callback: () => void); + cancelIdleCallback(callback: () => void); + } }