diff --git a/src/renderer/components/+catalog/catalog.test.tsx b/src/renderer/components/+catalog/catalog.test.tsx index 218bb60feb..5c221bb457 100644 --- a/src/renderer/components/+catalog/catalog.test.tsx +++ b/src/renderer/components/+catalog/catalog.test.tsx @@ -25,6 +25,8 @@ import { UserStore } from "../../../common/user-store"; import mockFs from "mock-fs"; import directoryForUserDataInjectable from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable"; +import type { AppEvent } from "../../../common/app-event-bus/event-bus"; +import appEventBusInjectable from "../../../common/app-event-bus/app-event-bus.injectable"; mockWindow(); jest.mock("electron", () => ({ @@ -102,6 +104,7 @@ describe("", () => { let di: DiContainer; let catalogEntityStore: CatalogEntityStore; let catalogEntityRegistry: CatalogEntityRegistry; + let emitEvent: (event: AppEvent) => void; let render: DiRender; beforeEach(async () => { @@ -125,6 +128,12 @@ describe("", () => { di.override(catalogEntityRegistryInjectable, () => catalogEntityRegistry); + emitEvent = jest.fn(); + + di.override(appEventBusInjectable, () => ({ + emit: emitEvent, + })); + catalogEntityStore = di.inject(catalogEntityStoreInjectable); }); @@ -320,4 +329,39 @@ describe("", () => { userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon")); }); + + it("emits catalog open AppEvent", () => { + render( + , + ); + + expect(emitEvent).toHaveBeenCalledWith( { + action: "open", + name: "catalog", + }); + }); + + it("emits catalog change AppEvent when changing the category", () => { + render( + , + ); + + userEvent.click(screen.getByText("Web Links")); + + expect(emitEvent).toHaveBeenLastCalledWith({ + action: "change-category", + name: "catalog", + params: { + category: "Web Links", + }, + }); + }); }); diff --git a/src/renderer/components/+catalog/catalog.tsx b/src/renderer/components/+catalog/catalog.tsx index 359e538ac5..e8738f135a 100644 --- a/src/renderer/components/+catalog/catalog.tsx +++ b/src/renderer/components/+catalog/catalog.tsx @@ -36,6 +36,8 @@ import getCategoryColumnsInjectable from "./get-category-columns.injectable"; import type { RegisteredCustomCategoryViewDecl } from "./custom-views.injectable"; import customCategoryViewsInjectable from "./custom-views.injectable"; import type { CustomCategoryViewComponents } from "./custom-views"; +import type { AppEvent } from "../../../common/app-event-bus/event-bus"; +import appEventBusInjectable from "../../../common/app-event-bus/app-event-bus.injectable"; export interface CatalogProps extends RouteComponentProps {} @@ -44,6 +46,7 @@ interface Dependencies { catalogEntityStore: CatalogEntityStore; getCategoryColumns: (params: GetCategoryColumnsParams) => CategoryColumns; customCategoryViews: IComputedValue>>; + emitEvent: (event: AppEvent) => void; } @observer @@ -104,6 +107,11 @@ class NonInjectedCatalog extends React.Component { }); } })); + + this.props.emitEvent({ + name: "catalog", + action: "open", + }); } addToHotbar(entity: CatalogEntity): void { @@ -146,6 +154,14 @@ class NonInjectedCatalog extends React.Component { onTabChange = action((tabId: string | null) => { const activeCategory = this.categories.find(category => category.getId() === tabId); + this.props.emitEvent({ + name: "catalog", + action: "change-category", + params: { + category: activeCategory ? activeCategory?.metadata?.name : "Browse", + }, + }); + if (activeCategory) { navigate(catalogURL({ params: { group: activeCategory.spec.group, kind: activeCategory.spec.names.kind }})); } else { @@ -311,6 +327,7 @@ export const Catalog = withInjectables( NonInjectedC catalogPreviousActiveTabStorage: di.inject(catalogPreviousActiveTabStorageInjectable), getCategoryColumns: di.inject(getCategoryColumnsInjectable), customCategoryViews: di.inject(customCategoryViewsInjectable), + emitEvent: di.inject(appEventBusInjectable).emit, ...props, }), });