mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Moving active entities sync to helper function
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
68c684dc1c
commit
5e8142685d
@ -19,9 +19,7 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { reaction, when } from "mobx";
|
import { navigate } from "../../renderer/navigation";
|
||||||
import { catalogEntityRegistry } from "../../renderer/api/catalog-entity-registry";
|
|
||||||
import { isActiveRoute, navigate, navigation } from "../../renderer/navigation";
|
|
||||||
import { CatalogCategory, CatalogEntity, CatalogEntityMetadata, CatalogEntitySpec, CatalogEntityStatus } from "../catalog";
|
import { CatalogCategory, CatalogEntity, CatalogEntityMetadata, CatalogEntitySpec, CatalogEntityStatus } from "../catalog";
|
||||||
import { catalogCategoryRegistry } from "../catalog/catalog-category-registry";
|
import { catalogCategoryRegistry } from "../catalog/catalog-category-registry";
|
||||||
|
|
||||||
@ -73,23 +71,6 @@ export class GeneralCategory extends CatalogCategory {
|
|||||||
kind: "General"
|
kind: "General"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
reaction(() => navigation.location, () => this.setEntityOnRouteMatch(), { fireImmediately: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
async setEntityOnRouteMatch() {
|
|
||||||
await when(() => catalogEntityRegistry.entities.size > 0);
|
|
||||||
|
|
||||||
const entities = catalogEntityRegistry.getItemsForCategory(this);
|
|
||||||
const activeEntity = entities.find(entity => isActiveRoute(entity.spec.path));
|
|
||||||
|
|
||||||
if (activeEntity) {
|
|
||||||
catalogEntityRegistry.activeEntity = activeEntity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
catalogCategoryRegistry.add(new GeneralCategory());
|
catalogCategoryRegistry.add(new GeneralCategory());
|
||||||
|
|||||||
@ -76,6 +76,10 @@ export class CatalogCategoryRegistry {
|
|||||||
|
|
||||||
return this.getForGroupKind(group, data.kind);
|
return this.getForGroupKind(group, data.kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getByName(name: string) {
|
||||||
|
return this.items.find(category => category.metadata?.name == name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const catalogCategoryRegistry = new CatalogCategoryRegistry();
|
export const catalogCategoryRegistry = new CatalogCategoryRegistry();
|
||||||
|
|||||||
36
src/main/catalog-sources/helpers/general-active-sync.ts
Normal file
36
src/main/catalog-sources/helpers/general-active-sync.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* 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 { when } from "mobx";
|
||||||
|
import { catalogCategoryRegistry } from "../../../common/catalog";
|
||||||
|
import { catalogEntityRegistry } from "../../../renderer/api/catalog-entity-registry";
|
||||||
|
import { isActiveRoute } from "../../../renderer/navigation";
|
||||||
|
|
||||||
|
export async function setEntityOnRouteMatch() {
|
||||||
|
await when(() => catalogEntityRegistry.entities.size > 0);
|
||||||
|
|
||||||
|
const entities = catalogEntityRegistry.getItemsForCategory(catalogCategoryRegistry.getByName("General"));
|
||||||
|
const activeEntity = entities.find(entity => isActiveRoute(entity.spec.path));
|
||||||
|
|
||||||
|
if (activeEntity) {
|
||||||
|
catalogEntityRegistry.activeEntity = activeEntity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -44,7 +44,6 @@ 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 { RenderDelay } from "../render-delay/render-delay";
|
||||||
import { TopBar } from "../layout/topbar";
|
import { TopBar } from "../layout/topbar";
|
||||||
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
|
|
||||||
|
|
||||||
export const previousActiveTab = createAppStorage("catalog-previous-active-tab", "");
|
export const previousActiveTab = createAppStorage("catalog-previous-active-tab", "");
|
||||||
|
|
||||||
@ -105,11 +104,6 @@ export class Catalog extends React.Component<Props> {
|
|||||||
}, {fireImmediately: true}),
|
}, {fireImmediately: true}),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeActiveEntity() {
|
|
||||||
catalogEntityRegistry.activeEntity = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
addToHotbar(item: CatalogEntityItem<CatalogEntity>): void {
|
addToHotbar(item: CatalogEntityItem<CatalogEntity>): void {
|
||||||
HotbarStore.getInstance().addToHotbar(item.entity);
|
HotbarStore.getInstance().addToHotbar(item.entity);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import "./cluster-manager.scss";
|
|||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Redirect, Route, Switch } from "react-router";
|
import { Redirect, Route, Switch } from "react-router";
|
||||||
import { observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { BottomBar } from "./bottom-bar";
|
import { BottomBar } from "./bottom-bar";
|
||||||
import { Catalog } from "../+catalog";
|
import { Catalog } from "../+catalog";
|
||||||
import { Preferences } from "../+preferences";
|
import { Preferences } from "../+preferences";
|
||||||
@ -35,9 +35,18 @@ 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 * as routes from "../../../common/routes";
|
import * as routes from "../../../common/routes";
|
||||||
|
import { reaction } from "mobx";
|
||||||
|
import { navigation } from "../../navigation";
|
||||||
|
import { setEntityOnRouteMatch } from "../../../main/catalog-sources/helpers/general-active-sync";
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class ClusterManager extends React.Component {
|
export class ClusterManager extends React.Component {
|
||||||
|
componentDidMount() {
|
||||||
|
disposeOnUnmount(this, [
|
||||||
|
reaction(() => navigation.location, () => setEntityOnRouteMatch(), { fireImmediately: true })
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="ClusterManager">
|
<div className="ClusterManager">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user