mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Emit AppEvent when opening Catalog and changing Catalog Category.
Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
parent
1a6c07c176
commit
5646282f7f
@ -25,6 +25,8 @@ import { UserStore } from "../../../common/user-store";
|
|||||||
import mockFs from "mock-fs";
|
import mockFs from "mock-fs";
|
||||||
import directoryForUserDataInjectable
|
import directoryForUserDataInjectable
|
||||||
from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
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();
|
mockWindow();
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
@ -102,6 +104,7 @@ describe("<Catalog />", () => {
|
|||||||
let di: DiContainer;
|
let di: DiContainer;
|
||||||
let catalogEntityStore: CatalogEntityStore;
|
let catalogEntityStore: CatalogEntityStore;
|
||||||
let catalogEntityRegistry: CatalogEntityRegistry;
|
let catalogEntityRegistry: CatalogEntityRegistry;
|
||||||
|
let emitEvent: (event: AppEvent) => void;
|
||||||
let render: DiRender;
|
let render: DiRender;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@ -125,6 +128,12 @@ describe("<Catalog />", () => {
|
|||||||
|
|
||||||
di.override(catalogEntityRegistryInjectable, () => catalogEntityRegistry);
|
di.override(catalogEntityRegistryInjectable, () => catalogEntityRegistry);
|
||||||
|
|
||||||
|
emitEvent = jest.fn();
|
||||||
|
|
||||||
|
di.override(appEventBusInjectable, () => ({
|
||||||
|
emit: emitEvent,
|
||||||
|
}));
|
||||||
|
|
||||||
catalogEntityStore = di.inject(catalogEntityStoreInjectable);
|
catalogEntityStore = di.inject(catalogEntityStoreInjectable);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -320,4 +329,39 @@ describe("<Catalog />", () => {
|
|||||||
|
|
||||||
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon"));
|
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("emits catalog open AppEvent", () => {
|
||||||
|
render(
|
||||||
|
<Catalog
|
||||||
|
history={history}
|
||||||
|
location={mockLocation}
|
||||||
|
match={mockMatch}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(emitEvent).toHaveBeenCalledWith( {
|
||||||
|
action: "open",
|
||||||
|
name: "catalog",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("emits catalog change AppEvent when changing the category", () => {
|
||||||
|
render(
|
||||||
|
<Catalog
|
||||||
|
history={history}
|
||||||
|
location={mockLocation}
|
||||||
|
match={mockMatch}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
userEvent.click(screen.getByText("Web Links"));
|
||||||
|
|
||||||
|
expect(emitEvent).toHaveBeenLastCalledWith({
|
||||||
|
action: "change-category",
|
||||||
|
name: "catalog",
|
||||||
|
params: {
|
||||||
|
category: "Web Links",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -36,6 +36,8 @@ import getCategoryColumnsInjectable from "./get-category-columns.injectable";
|
|||||||
import type { RegisteredCustomCategoryViewDecl } from "./custom-views.injectable";
|
import type { RegisteredCustomCategoryViewDecl } from "./custom-views.injectable";
|
||||||
import customCategoryViewsInjectable from "./custom-views.injectable";
|
import customCategoryViewsInjectable from "./custom-views.injectable";
|
||||||
import type { CustomCategoryViewComponents } from "./custom-views";
|
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<CatalogViewRouteParam> {}
|
export interface CatalogProps extends RouteComponentProps<CatalogViewRouteParam> {}
|
||||||
|
|
||||||
@ -44,6 +46,7 @@ interface Dependencies {
|
|||||||
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>>>;
|
||||||
|
emitEvent: (event: AppEvent) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -104,6 +107,11 @@ class NonInjectedCatalog extends React.Component<CatalogProps & Dependencies> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
this.props.emitEvent({
|
||||||
|
name: "catalog",
|
||||||
|
action: "open",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addToHotbar(entity: CatalogEntity): void {
|
addToHotbar(entity: CatalogEntity): void {
|
||||||
@ -146,6 +154,14 @@ class NonInjectedCatalog extends React.Component<CatalogProps & Dependencies> {
|
|||||||
onTabChange = action((tabId: string | null) => {
|
onTabChange = action((tabId: string | null) => {
|
||||||
const activeCategory = this.categories.find(category => category.getId() === tabId);
|
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) {
|
if (activeCategory) {
|
||||||
navigate(catalogURL({ params: { group: activeCategory.spec.group, kind: activeCategory.spec.names.kind }}));
|
navigate(catalogURL({ params: { group: activeCategory.spec.group, kind: activeCategory.spec.names.kind }}));
|
||||||
} else {
|
} else {
|
||||||
@ -311,6 +327,7 @@ export const Catalog = withInjectables<Dependencies, CatalogProps>( NonInjectedC
|
|||||||
catalogPreviousActiveTabStorage: di.inject(catalogPreviousActiveTabStorageInjectable),
|
catalogPreviousActiveTabStorage: di.inject(catalogPreviousActiveTabStorageInjectable),
|
||||||
getCategoryColumns: di.inject(getCategoryColumnsInjectable),
|
getCategoryColumns: di.inject(getCategoryColumnsInjectable),
|
||||||
customCategoryViews: di.inject(customCategoryViewsInjectable),
|
customCategoryViews: di.inject(customCategoryViewsInjectable),
|
||||||
|
emitEvent: di.inject(appEventBusInjectable).emit,
|
||||||
...props,
|
...props,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user