mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Samne to <HotBarMenu />
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
This commit is contained in:
parent
24f5f9950a
commit
807aefdd26
@ -119,14 +119,14 @@ export class CatalogEntityItem<T extends CatalogEntity> implements ItemObject {
|
||||
try {
|
||||
shouldRun = onRunHook(toJS(this.entity));
|
||||
} catch (error) {
|
||||
if (process?.env?.NODE_ENV !== "test") console.warn(`[CATALOG-ENTITY-ITEM] onRunHook of entity.metadata.uid ${this.entity.metadata.uid} throw an exception, stop before onRun`, error);
|
||||
if (process?.env?.NODE_ENV !== "test") console.warn(`[CATALOG-ENTITY-ITEM] onRunHook of entity.metadata.uid ${this.entity?.metadata?.uid} throw an exception, stop before onRun`, error);
|
||||
}
|
||||
|
||||
if (isPromise(shouldRun)) {
|
||||
Promise.resolve(shouldRun).then((shouldRun) => {
|
||||
if (shouldRun) this.entity.onRun(ctx);
|
||||
}).catch((error) => {
|
||||
if (process?.env?.NODE_ENV !== "test") console.warn(`[CATALOG-ENTITY-ITEM] onRunHook of entity.metadata.uid ${this.entity.metadata.uid} rejects, stop before onRun`, error);
|
||||
if (process?.env?.NODE_ENV !== "test") console.warn(`[CATALOG-ENTITY-ITEM] onRunHook of entity.metadata.uid ${this.entity?.metadata?.uid} rejects, stop before onRun`, error);
|
||||
});
|
||||
} else if (shouldRun) {
|
||||
this.entity.onRun(ctx);
|
||||
|
||||
@ -40,6 +40,8 @@ interface Props {
|
||||
className?: IClassName;
|
||||
}
|
||||
|
||||
const isPromise = (obj: any): obj is Promise<any> => (obj?.then && typeof obj?.then === "function") ? true: false;
|
||||
|
||||
@observer
|
||||
export class HotbarMenu extends React.Component<Props> {
|
||||
get hotbar() {
|
||||
@ -140,11 +142,23 @@ export class HotbarMenu extends React.Component<Props> {
|
||||
}
|
||||
|
||||
if (typeof onRunHook === "function") {
|
||||
// if onRunHook() returns a Promise, we wait for it to resolve
|
||||
// if not, just take whatever it returns
|
||||
Promise.resolve(onRunHook(toJS(entity))).then((shouldRun) => {
|
||||
if (shouldRun) entity.onRun(catalogEntityRunContext);
|
||||
});
|
||||
let shouldRun;
|
||||
|
||||
try {
|
||||
shouldRun = onRunHook(toJS(entity));
|
||||
} catch (error) {
|
||||
if (process?.env?.NODE_ENV !== "test") console.warn(`[HOT-BAR] onRunHook of entity.metadata.uid ${entity?.metadata?.uid} throw an exception, stop before onRun`, error);
|
||||
}
|
||||
|
||||
if (isPromise(shouldRun)) {
|
||||
Promise.resolve(shouldRun).then((shouldRun) => {
|
||||
if (shouldRun) entity.onRun(catalogEntityRunContext);
|
||||
}).catch((error) => {
|
||||
if (process?.env?.NODE_ENV !== "test") console.warn(`[HOT-BAR] onRunHook of entity.metadata.uid ${entity?.metadata?.uid} rejects, stop before onRun`, error);
|
||||
});
|
||||
} else if (shouldRun) {
|
||||
entity.onRun(catalogEntityRunContext);
|
||||
}
|
||||
}
|
||||
}}
|
||||
className={cssNames({ isDragging: snapshot.isDragging })}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user