1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix returning to specific catalog tab and removing a hotbar item (#5201)

* Fix removing hot bar item

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>

* Fix navigating back to tab in catalog from hotbar

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-04-12 07:34:44 +03:00 committed by GitHub
parent c66f9ad407
commit 68a605ded9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View File

@ -45,7 +45,7 @@ import hotbarStoreInjectable from "../../../common/hotbar-store.injectable";
import type { HotbarStore } from "../../../common/hotbar-store"; import type { HotbarStore } from "../../../common/hotbar-store";
interface Dependencies { interface Dependencies {
catalogPreviousActiveTabStorage: { set: (value: string ) => void }; catalogPreviousActiveTabStorage: { set: (value: string ) => void; get: () => string };
catalogEntityStore: CatalogEntityStore; catalogEntityStore: CatalogEntityStore;
getCategoryColumns: (params: GetCategoryColumnsParams) => CategoryColumns; getCategoryColumns: (params: GetCategoryColumnsParams) => CategoryColumns;
customCategoryViews: IComputedValue<Map<string, Map<string, RegisteredCustomCategoryViewDecl>>>; customCategoryViews: IComputedValue<Map<string, Map<string, RegisteredCustomCategoryViewDecl>>>;
@ -81,6 +81,12 @@ class NonInjectedCatalog extends React.Component<Dependencies> {
return `${dereferencedGroup}/${dereferencedKind}`; return `${dereferencedGroup}/${dereferencedKind}`;
} }
const previousTab = this.props.catalogPreviousActiveTabStorage.get();
if (previousTab) {
return previousTab;
}
return browseCatalogTab; return browseCatalogTab;
} }
@ -92,8 +98,6 @@ class NonInjectedCatalog extends React.Component<Dependencies> {
disposeOnUnmount(this, [ disposeOnUnmount(this, [
this.props.catalogEntityStore.watch(), this.props.catalogEntityStore.watch(),
reaction(() => this.routeActiveTab, async (routeTab) => { reaction(() => this.routeActiveTab, async (routeTab) => {
this.props.catalogPreviousActiveTabStorage.set(this.routeActiveTab);
try { try {
await when(() => (routeTab === browseCatalogTab || !!catalogCategoryRegistry.filteredItems.find(i => i.getId() === routeTab)), { timeout: 5_000 }); // we need to wait because extensions might take a while to load await when(() => (routeTab === browseCatalogTab || !!catalogCategoryRegistry.filteredItems.find(i => i.getId() === routeTab)), { timeout: 5_000 }); // we need to wait because extensions might take a while to load
const item = catalogCategoryRegistry.filteredItems.find(i => i.getId() === routeTab); const item = catalogCategoryRegistry.filteredItems.find(i => i.getId() === routeTab);
@ -178,9 +182,10 @@ class NonInjectedCatalog extends React.Component<Dependencies> {
}); });
if (activeCategory) { if (activeCategory) {
this.props.catalogPreviousActiveTabStorage.set(`${activeCategory.spec.group}/${activeCategory.spec.names.kind}`);
this.props.navigateToCatalog({ group: activeCategory.spec.group, kind: activeCategory.spec.names.kind }); this.props.navigateToCatalog({ group: activeCategory.spec.group, kind: activeCategory.spec.names.kind });
} else { } else {
this.props.catalogPreviousActiveTabStorage.set(null);
this.props.navigateToCatalog({ group: browseCatalogTab }); this.props.navigateToCatalog({ group: browseCatalogTab });
} }
}); });

View File

@ -75,17 +75,17 @@ class NonInjectedHotbarMenu extends React.Component<Dependencies & HotbarMenuPro
this.props.hotbarStore.restackItems(from, to); this.props.hotbarStore.restackItems(from, to);
} }
removeItem(uid: string) { removeItem = (uid: string) => {
const hotbar = this.props.hotbarStore; const hotbar = this.props.hotbarStore;
hotbar.removeFromHotbar(uid); hotbar.removeFromHotbar(uid);
} };
addItem(entity: CatalogEntity, index = -1) { addItem = (entity: CatalogEntity, index = -1) => {
const hotbar = this.props.hotbarStore; const hotbar = this.props.hotbarStore;
hotbar.addToHotbar(entity, index); hotbar.addToHotbar(entity, index);
} };
getMoveAwayDirection(entityId: string, cellIndex: number) { getMoveAwayDirection(entityId: string, cellIndex: number) {
const draggableItemIndex = this.hotbar.items.findIndex(item => item?.entity.uid == entityId); const draggableItemIndex = this.hotbar.items.findIndex(item => item?.entity.uid == entityId);