mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Allow CatalogEntityDetails to be opened anywhere (#6939)
* Extract CatalogEntityDetails to seperate root component Signed-off-by: Sebastian Malton <sebastian@malton.name> * Expose entity details to extension API Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add behavioural tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup catalog technical tests to use ApplicationBuilder Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshot Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update test and then fix it Signed-off-by: Sebastian Malton <sebastian@malton.name> --------- Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
f88555a1d7
commit
0084af56d6
20 files changed
+2680
-405
No files matched your search
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { CatalogEntity } from "../../catalog-entity";
|
||||
import catalogEntityRegistryInjectable from "./registry.injectable";
|
||||
|
||||
export type GetEntityById = (id: string) => CatalogEntity | undefined;
|
||||
|
||||
const getEntityByIdInjectable = getInjectable({
|
||||
id: "get-entity-by-id",
|
||||
instantiate: (di): GetEntityById => {
|
||||
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
|
||||
|
||||
return (id) => catalogEntityRegistry.getById(id);
|
||||
},
|
||||
});
|
||||
|
||||
export default getEntityByIdInjectable;
|
||||
@@ -23,7 +23,7 @@ export type CatalogEntityOnBeforeRun = (event: CatalogRunEvent) => void | Promis
|
||||
interface Dependencies {
|
||||
navigate: Navigate;
|
||||
readonly categoryRegistry: CatalogCategoryRegistry;
|
||||
logger: Logger;
|
||||
readonly logger: Logger;
|
||||
}
|
||||
|
||||
export class CatalogEntityRegistry {
|
||||
@@ -243,20 +243,24 @@ export class CatalogEntityRegistry {
|
||||
* Perform the onBeforeRun check and, if successful, then proceed to call `entity`'s onRun method
|
||||
* @param entity The instance to invoke the hooks and then execute the onRun
|
||||
*/
|
||||
onRun(entity: CatalogEntity): void {
|
||||
this.onBeforeRun(entity)
|
||||
.then(doOnRun => {
|
||||
if (doOnRun) {
|
||||
return entity.onRun?.({
|
||||
navigate: this.dependencies.navigate,
|
||||
setCommandPaletteContext: (entity) => {
|
||||
this.activeEntity = entity;
|
||||
},
|
||||
});
|
||||
} else {
|
||||
this.dependencies.logger.debug(`onBeforeRun for ${entity.getId()} returned false`);
|
||||
}
|
||||
})
|
||||
.catch(error => this.dependencies.logger.error(`[CATALOG-ENTITY-REGISTRY]: entity ${entity.getId()} onRun threw an error`, error));
|
||||
async onRun(entity: CatalogEntity) {
|
||||
try {
|
||||
const doOnRun = await this.onBeforeRun(entity);
|
||||
|
||||
if (!doOnRun) {
|
||||
this.dependencies.logger.debug(`onBeforeRun for ${entity.getId()} returned false`);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
await entity.onRun?.({
|
||||
navigate: this.dependencies.navigate,
|
||||
setCommandPaletteContext: (entity) => {
|
||||
this.activeEntity = entity;
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
this.dependencies.logger.error(`[CATALOG-ENTITY-REGISTRY]: entity ${entity.getId()} onRun threw an error`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user