mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Catalog render optimizations (#3422)
This commit is contained in:
parent
86db8e5e2c
commit
4fe0a7d73e
32
__mocks__/windowMock.ts
Normal file
32
__mocks__/windowMock.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
Object.defineProperty(window, "requestIdleCallback", {
|
||||||
|
writable: true,
|
||||||
|
value: jest.fn().mockImplementation(callback => callback()),
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(window, "cancelIdleCallback", {
|
||||||
|
writable: true,
|
||||||
|
value: jest.fn(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default {};
|
||||||
@ -63,7 +63,8 @@
|
|||||||
},
|
},
|
||||||
"moduleNameMapper": {
|
"moduleNameMapper": {
|
||||||
"\\.(css|scss)$": "<rootDir>/__mocks__/styleMock.ts",
|
"\\.(css|scss)$": "<rootDir>/__mocks__/styleMock.ts",
|
||||||
"\\.(svg)$": "<rootDir>/__mocks__/imageMock.ts"
|
"\\.(svg)$": "<rootDir>/__mocks__/imageMock.ts",
|
||||||
|
"src/(.*)": "<rootDir>/__mocks__/windowMock.ts"
|
||||||
},
|
},
|
||||||
"modulePathIgnorePatterns": [
|
"modulePathIgnorePatterns": [
|
||||||
"<rootDir>/dist",
|
"<rootDir>/dist",
|
||||||
|
|||||||
@ -137,7 +137,11 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
|
|||||||
* Toggles the hidden configuration of a table's column
|
* Toggles the hidden configuration of a table's column
|
||||||
*/
|
*/
|
||||||
toggleTableColumnVisibility(tableId: string, columnId: string) {
|
toggleTableColumnVisibility(tableId: string, columnId: string) {
|
||||||
this.hiddenTableColumns.get(tableId)?.toggle(columnId);
|
if (!this.hiddenTableColumns.get(tableId)) {
|
||||||
|
this.hiddenTableColumns.set(tableId, new ObservableToggleSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.hiddenTableColumns.get(tableId).toggle(columnId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
|||||||
@ -46,6 +46,11 @@
|
|||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.content:active {
|
||||||
|
color: white;
|
||||||
|
background-color: var(--blue);
|
||||||
|
}
|
||||||
|
|
||||||
.group {
|
.group {
|
||||||
margin-left: 0px;
|
margin-left: 0px;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,6 +42,9 @@ import { CatalogEntityDetails } from "./catalog-entity-details";
|
|||||||
import { catalogURL, CatalogViewRouteParam } from "../../../common/routes";
|
import { catalogURL, CatalogViewRouteParam } from "../../../common/routes";
|
||||||
import { CatalogMenu } from "./catalog-menu";
|
import { CatalogMenu } from "./catalog-menu";
|
||||||
import { HotbarIcon } from "../hotbar/hotbar-icon";
|
import { HotbarIcon } from "../hotbar/hotbar-icon";
|
||||||
|
import { RenderDelay } from "../render-delay/render-delay";
|
||||||
|
import { CatalogTopbar } from "../cluster-manager/catalog-topbar";
|
||||||
|
import type { TableSortCallback } from "../table";
|
||||||
|
|
||||||
export const previousActiveTab = createAppStorage("catalog-previous-active-tab", "");
|
export const previousActiveTab = createAppStorage("catalog-previous-active-tab", "");
|
||||||
|
|
||||||
@ -144,7 +147,9 @@ export class Catalog extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
renderNavigation() {
|
renderNavigation() {
|
||||||
return <CatalogMenu activeItem={this.activeTab} onItemClick={this.onTabChange}/>;
|
return (
|
||||||
|
<CatalogMenu activeItem={this.activeTab} onItemClick={this.onTabChange}/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderItemMenu = (item: CatalogEntityItem<CatalogEntity>) => {
|
renderItemMenu = (item: CatalogEntityItem<CatalogEntity>) => {
|
||||||
@ -172,110 +177,73 @@ export class Catalog extends React.Component<Props> {
|
|||||||
|
|
||||||
renderIcon(item: CatalogEntityItem<CatalogEntity>) {
|
renderIcon(item: CatalogEntityItem<CatalogEntity>) {
|
||||||
return (
|
return (
|
||||||
<HotbarIcon
|
<RenderDelay>
|
||||||
uid={`catalog-icon-${item.getId()}`}
|
<HotbarIcon
|
||||||
title={item.getName()}
|
uid={`catalog-icon-${item.getId()}`}
|
||||||
source={item.source}
|
title={item.getName()}
|
||||||
src={item.entity.spec.icon?.src}
|
source={item.source}
|
||||||
material={item.entity.spec.icon?.material}
|
src={item.entity.spec.icon?.src}
|
||||||
background={item.entity.spec.icon?.background}
|
material={item.entity.spec.icon?.material}
|
||||||
size={24}
|
background={item.entity.spec.icon?.background}
|
||||||
/>
|
size={24}
|
||||||
|
/>
|
||||||
|
</RenderDelay>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderSingleCategoryList() {
|
renderList() {
|
||||||
return (
|
const { activeCategory } = this.catalogEntityStore;
|
||||||
<ItemListLayout
|
const tableId = activeCategory ? `catalog-items-${activeCategory.metadata.name.replace(" ", "")}` : "catalog-items";
|
||||||
key={this.catalogEntityStore.activeCategory.getId()}
|
let sortingCallbacks: { [sortBy: string]: TableSortCallback } = {
|
||||||
tableId={`catalog-items-${this.catalogEntityStore.activeCategory?.metadata.name.replace(" ", "")}`}
|
[sortBy.name]: (item: CatalogEntityItem<CatalogEntity>) => item.name,
|
||||||
renderHeaderTitle={this.catalogEntityStore.activeCategory?.metadata.name}
|
[sortBy.source]: (item: CatalogEntityItem<CatalogEntity>) => item.source,
|
||||||
isSelectable={false}
|
[sortBy.status]: (item: CatalogEntityItem<CatalogEntity>) => item.phase,
|
||||||
isConfigurable={true}
|
};
|
||||||
className="CatalogItemList"
|
|
||||||
store={this.catalogEntityStore}
|
|
||||||
sortingCallbacks={{
|
|
||||||
[sortBy.name]: (item: CatalogEntityItem<CatalogEntity>) => item.name,
|
|
||||||
[sortBy.source]: (item: CatalogEntityItem<CatalogEntity>) => item.source,
|
|
||||||
[sortBy.status]: (item: CatalogEntityItem<CatalogEntity>) => item.phase,
|
|
||||||
}}
|
|
||||||
searchFilters={[
|
|
||||||
(entity: CatalogEntityItem<CatalogEntity>) => 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<CatalogEntity>) => ({
|
|
||||||
disabled: !item.enabled,
|
|
||||||
})}
|
|
||||||
renderTableContents={(item: CatalogEntityItem<CatalogEntity>) => [
|
|
||||||
this.renderIcon(item),
|
|
||||||
item.name,
|
|
||||||
item.source,
|
|
||||||
item.getLabelBadges(),
|
|
||||||
{ title: item.phase, className: cssNames(css[item.phase]) }
|
|
||||||
]}
|
|
||||||
onDetails={this.onDetails}
|
|
||||||
renderItemMenu={this.renderItemMenu}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderAllCategoriesList() {
|
sortingCallbacks = activeCategory ? sortingCallbacks : {
|
||||||
return (
|
...sortingCallbacks,
|
||||||
<ItemListLayout
|
[sortBy.kind]: (item: CatalogEntityItem<CatalogEntity>) => item.kind,
|
||||||
key="all"
|
};
|
||||||
renderHeaderTitle={"Browse All"}
|
|
||||||
isSelectable={false}
|
|
||||||
isConfigurable={true}
|
|
||||||
className="CatalogItemList"
|
|
||||||
store={this.catalogEntityStore}
|
|
||||||
tableId="catalog-items"
|
|
||||||
sortingCallbacks={{
|
|
||||||
[sortBy.name]: (item: CatalogEntityItem<CatalogEntity>) => item.name,
|
|
||||||
[sortBy.kind]: (item: CatalogEntityItem<CatalogEntity>) => item.kind,
|
|
||||||
[sortBy.source]: (item: CatalogEntityItem<CatalogEntity>) => item.source,
|
|
||||||
[sortBy.status]: (item: CatalogEntityItem<CatalogEntity>) => item.phase,
|
|
||||||
}}
|
|
||||||
searchFilters={[
|
|
||||||
(entity: CatalogEntityItem<CatalogEntity>) => entity.searchFields,
|
|
||||||
]}
|
|
||||||
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" },
|
|
||||||
{ 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<CatalogEntity>) => ({
|
|
||||||
disabled: !item.enabled,
|
|
||||||
})}
|
|
||||||
renderTableContents={(item: CatalogEntityItem<CatalogEntity>) => [
|
|
||||||
this.renderIcon(item),
|
|
||||||
item.name,
|
|
||||||
item.kind,
|
|
||||||
item.source,
|
|
||||||
item.getLabelBadges(),
|
|
||||||
{ title: item.phase, className: cssNames(css[item.phase]) }
|
|
||||||
]}
|
|
||||||
detailsItem={this.catalogEntityStore.selectedItem}
|
|
||||||
onDetails={this.onDetails}
|
|
||||||
renderItemMenu={this.renderItemMenu}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderCategoryList() {
|
|
||||||
if (this.activeTab === undefined) {
|
if (this.activeTab === undefined) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.catalogEntityStore.activeCategory ? this.renderSingleCategoryList() : this.renderAllCategoriesList();
|
return (
|
||||||
|
<ItemListLayout
|
||||||
|
tableId={tableId}
|
||||||
|
renderHeaderTitle={activeCategory?.metadata.name || "Browse All"}
|
||||||
|
isSelectable={false}
|
||||||
|
isConfigurable={true}
|
||||||
|
className="CatalogItemList"
|
||||||
|
store={this.catalogEntityStore}
|
||||||
|
sortingCallbacks={sortingCallbacks}
|
||||||
|
searchFilters={[
|
||||||
|
(entity: CatalogEntityItem<CatalogEntity>) => entity.searchFields,
|
||||||
|
]}
|
||||||
|
renderTableHeader={[
|
||||||
|
{ title: "", className: css.iconCell, id: "icon" },
|
||||||
|
{ title: "Name", className: css.nameCell, sortBy: sortBy.name, id: "name" },
|
||||||
|
!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<CatalogEntity>) => ({
|
||||||
|
disabled: !item.enabled,
|
||||||
|
})}
|
||||||
|
renderTableContents={(item: CatalogEntityItem<CatalogEntity>) => [
|
||||||
|
this.renderIcon(item),
|
||||||
|
item.name,
|
||||||
|
!activeCategory && item.kind,
|
||||||
|
item.source,
|
||||||
|
item.getLabelBadges(),
|
||||||
|
{ title: item.phase, className: cssNames(css[item.phase]) }
|
||||||
|
].filter(Boolean)}
|
||||||
|
onDetails={this.onDetails}
|
||||||
|
renderItemMenu={this.renderItemMenu}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -284,21 +252,28 @@ export class Catalog extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MainLayout sidebar={this.renderNavigation()}>
|
<>
|
||||||
<div className="p-6 h-full">
|
<CatalogTopbar/>
|
||||||
{ this.renderCategoryList() }
|
<MainLayout sidebar={this.renderNavigation()}>
|
||||||
</div>
|
<div className="p-6 h-full">
|
||||||
{
|
{ this.renderList() }
|
||||||
this.catalogEntityStore.selectedItem
|
</div>
|
||||||
? <CatalogEntityDetails
|
{
|
||||||
item={this.catalogEntityStore.selectedItem}
|
this.catalogEntityStore.selectedItem
|
||||||
hideDetails={() => this.catalogEntityStore.selectedItemId = null}
|
? <CatalogEntityDetails
|
||||||
/>
|
item={this.catalogEntityStore.selectedItem}
|
||||||
: <CatalogAddButton
|
hideDetails={() => this.catalogEntityStore.selectedItemId = null}
|
||||||
category={this.catalogEntityStore.activeCategory}
|
/>
|
||||||
/>
|
: (
|
||||||
}
|
<RenderDelay>
|
||||||
</MainLayout>
|
<CatalogAddButton
|
||||||
|
category={this.catalogEntityStore.activeCategory}
|
||||||
|
/>
|
||||||
|
</RenderDelay>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</MainLayout>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,10 +35,6 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
> * {
|
|
||||||
z-index: 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.HotbarMenu {
|
.HotbarMenu {
|
||||||
@ -52,7 +48,7 @@
|
|||||||
#lens-views {
|
#lens-views {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
top: 0;
|
top: 40px; // Move below top bar
|
||||||
right: 0;
|
right: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@ -34,8 +34,6 @@ import { Extensions } from "../+extensions";
|
|||||||
import { HotbarMenu } from "../hotbar/hotbar-menu";
|
import { HotbarMenu } from "../hotbar/hotbar-menu";
|
||||||
import { EntitySettings } from "../+entity-settings";
|
import { EntitySettings } from "../+entity-settings";
|
||||||
import { Welcome } from "../+welcome";
|
import { Welcome } from "../+welcome";
|
||||||
import { ClusterTopbar } from "./cluster-topbar";
|
|
||||||
import { CatalogTopbar } from "./catalog-topbar";
|
|
||||||
import * as routes from "../../../common/routes";
|
import * as routes from "../../../common/routes";
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -43,8 +41,6 @@ export class ClusterManager extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="ClusterManager">
|
<div className="ClusterManager">
|
||||||
<Route component={CatalogTopbar} {...routes.catalogRoute} />
|
|
||||||
<Route component={ClusterTopbar} {...routes.clusterViewRoute} />
|
|
||||||
<main>
|
<main>
|
||||||
<div id="lens-views"/>
|
<div id="lens-views"/>
|
||||||
<Switch>
|
<Switch>
|
||||||
|
|||||||
@ -34,6 +34,7 @@ import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
|||||||
import { navigate } from "../../navigation";
|
import { navigate } from "../../navigation";
|
||||||
import { catalogURL, ClusterViewRouteParams } from "../../../common/routes";
|
import { catalogURL, ClusterViewRouteParams } from "../../../common/routes";
|
||||||
import { previousActiveTab } from "../+catalog";
|
import { previousActiveTab } from "../+catalog";
|
||||||
|
import { ClusterTopbar } from "./cluster-topbar";
|
||||||
|
|
||||||
interface Props extends RouteComponentProps<ClusterViewRouteParams> {
|
interface Props extends RouteComponentProps<ClusterViewRouteParams> {
|
||||||
}
|
}
|
||||||
@ -104,6 +105,7 @@ export class ClusterView extends React.Component<Props> {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="ClusterView flex column align-center">
|
<div className="ClusterView flex column align-center">
|
||||||
|
<ClusterTopbar {...this.props}/>
|
||||||
{this.renderStatus()}
|
{this.renderStatus()}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -61,7 +61,6 @@
|
|||||||
width: 0;
|
width: 0;
|
||||||
height: 2px;
|
height: 2px;
|
||||||
background: $primary;
|
background: $primary;
|
||||||
transition: width 250ms;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import { Icon, IconProps } from "../icon";
|
|||||||
import { Menu, MenuItem, MenuProps } from "../menu";
|
import { Menu, MenuItem, MenuProps } from "../menu";
|
||||||
import uniqueId from "lodash/uniqueId";
|
import uniqueId from "lodash/uniqueId";
|
||||||
import isString from "lodash/isString";
|
import isString from "lodash/isString";
|
||||||
|
import { RenderDelay } from "../render-delay/render-delay";
|
||||||
|
|
||||||
export interface MenuActionsProps extends Partial<MenuProps> {
|
export interface MenuActionsProps extends Partial<MenuProps> {
|
||||||
className?: string;
|
className?: string;
|
||||||
@ -124,30 +125,32 @@ export class MenuActions extends React.Component<MenuActionsProps> {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{this.renderTriggerIcon()}
|
{this.renderTriggerIcon()}
|
||||||
<Menu
|
<RenderDelay>
|
||||||
htmlFor={this.id}
|
<Menu
|
||||||
isOpen={this.isOpen} open={this.toggle} close={this.toggle}
|
htmlFor={this.id}
|
||||||
className={menuClassName}
|
isOpen={this.isOpen} open={this.toggle} close={this.toggle}
|
||||||
usePortal={autoClose}
|
className={menuClassName}
|
||||||
closeOnScroll={autoClose}
|
usePortal={autoClose}
|
||||||
closeOnClickItem={autoCloseOnSelect ?? autoClose }
|
closeOnScroll={autoClose}
|
||||||
closeOnClickOutside={autoClose}
|
closeOnClickItem={autoCloseOnSelect ?? autoClose }
|
||||||
{...menuProps}
|
closeOnClickOutside={autoClose}
|
||||||
>
|
{...menuProps}
|
||||||
{children}
|
>
|
||||||
{updateAction && (
|
{children}
|
||||||
<MenuItem onClick={updateAction}>
|
{updateAction && (
|
||||||
<Icon material="edit" interactive={toolbar} tooltip="Edit"/>
|
<MenuItem onClick={updateAction}>
|
||||||
<span className="title">Edit</span>
|
<Icon material="edit" interactive={toolbar} tooltip="Edit"/>
|
||||||
</MenuItem>
|
<span className="title">Edit</span>
|
||||||
)}
|
</MenuItem>
|
||||||
{removeAction && (
|
)}
|
||||||
<MenuItem onClick={this.remove}>
|
{removeAction && (
|
||||||
<Icon material="delete" interactive={toolbar} tooltip="Delete"/>
|
<MenuItem onClick={this.remove}>
|
||||||
<span className="title">Remove</span>
|
<Icon material="delete" interactive={toolbar} tooltip="Delete"/>
|
||||||
</MenuItem>
|
<span className="title">Remove</span>
|
||||||
)}
|
</MenuItem>
|
||||||
</Menu>
|
)}
|
||||||
|
</Menu>
|
||||||
|
</RenderDelay>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -260,6 +260,8 @@ export class Menu extends React.Component<MenuProps, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onBlur() {
|
onBlur() {
|
||||||
|
if (!this.isOpen) return; // Prevents triggering document.activeElement for each <Menu/> instance
|
||||||
|
|
||||||
if (document.activeElement?.tagName == "IFRAME") {
|
if (document.activeElement?.tagName == "IFRAME") {
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* 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 "@testing-library/jest-dom/extend-expect";
|
||||||
|
import { render } from "@testing-library/react";
|
||||||
|
import { RenderDelay } from "../render-delay";
|
||||||
|
|
||||||
|
describe("<RenderDelay/>", () => {
|
||||||
|
it("renders w/o errors", () => {
|
||||||
|
const { container } = render(<RenderDelay><button>My button</button></RenderDelay>);
|
||||||
|
|
||||||
|
expect(container).toBeInstanceOf(HTMLElement);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders it's child", () => {
|
||||||
|
const { getByText } = render(<RenderDelay><button>My button</button></RenderDelay>);
|
||||||
|
|
||||||
|
expect(getByText("My button")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
63
src/renderer/components/render-delay/render-delay.tsx
Normal file
63
src/renderer/components/render-delay/render-delay.tsx
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/**
|
||||||
|
* 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<Props> {
|
||||||
|
@observable isVisible = false;
|
||||||
|
|
||||||
|
constructor(props: Props) {
|
||||||
|
super(props);
|
||||||
|
makeObservable(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
const guaranteedFireTime = 1000;
|
||||||
|
|
||||||
|
window.requestIdleCallback(this.showContents, { timeout: guaranteedFireTime });
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
window.cancelIdleCallback(this.showContents);
|
||||||
|
}
|
||||||
|
|
||||||
|
@boundMethod
|
||||||
|
showContents() {
|
||||||
|
this.isVisible = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
if (!this.isVisible) {
|
||||||
|
return this.props.placeholder || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.props.children;
|
||||||
|
}
|
||||||
|
}
|
||||||
5
types/dom.d.ts
vendored
5
types/dom.d.ts
vendored
@ -24,4 +24,9 @@ declare global {
|
|||||||
interface Element {
|
interface Element {
|
||||||
scrollIntoViewIfNeeded(opt_center?: boolean): void;
|
scrollIntoViewIfNeeded(opt_center?: boolean): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Window {
|
||||||
|
requestIdleCallback(callback: () => void, options: { timeout: number });
|
||||||
|
cancelIdleCallback(callback: () => void);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user