-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Before hook for onRun of Catalog entities #3911
Conversation
onClickDetailIcon(context: CatalogEntityActionContext) { | ||
catalogCategoryRegistry | ||
.getCategoryForEntity<WebLinkCategory>(this) | ||
?.emit("onClickDetailIcon", this, context); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From talking to @msa0311 I was under the impression that we were wanting to block the "onRun" if any of these pre-hooks calls the equivalent of preventDefault
which this form cannot support because the handlers are run concurrently.
I don't understand the need for this but instead of adding |
That would also be a possible solution. However, according to @msa0311 this is desirable to happen on attempts for |
bcf0480
to
d6f5517
Compare
Because we need to add the hooks to onRun via extension, from extension there is no way of changing |
9d37487
to
600ee9d
Compare
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
/** | ||
* Returns one catalog entity onRun hook by catalog entity uid | ||
*/ | ||
getOnRunHook(catalogEntityUid: CatalogEntity["metadata"]["uid"]): CatelogEntityOnRunHook | undefined { | ||
return registry.getOnRunHook(catalogEntityUid); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should support several onRunHooks. You sort of do already but not very well since you only ever return the first hook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be another PR,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No because this will have to be supported until the next major
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least in current timeframe I don't think I can do this before 5.3. @Nokel81 would you like to to take over on the multiple hooks part?
protected entityOnRunHooks = observable.set<{ | ||
catalogEntityUid: CatalogEntityUid; | ||
onRunHook: CatelogEntityOnRunHook | ||
}>([], { | ||
deep: false, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very strange type, why is it not observable.map<string, CatalogEnitytOnRunHook[]>([], { deep: false });
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need catalogEntityUid
because there are getOnRunHook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The top level map's key would be CatalogEntityUid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string
is not as obvious as catalogEntityUid
, but again, just my opinion, maybe you know more about the convention in Lens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really have a convention... (namely we use both styles). What I meant was I should have suggested the type observable.map<CatalogEntityUid, IObservableSet<CatelogEntityOnRunHook>>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks for clarify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed c863134
onClick={() => item.onRun(catalogEntityRunContext)} | ||
size={128} /> | ||
onClick={() => { | ||
this.props.onClickDetailPanelIcon(item); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should pass this in as props, we should have an unexported function that takes an CatalogEntity
and does the work once (DRY as it were).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the refactoring be another PR?
if (!onRunHook) { | ||
this.entity.onRun(ctx); | ||
|
||
return; | ||
} | ||
|
||
if (typeof onRunHook === "function") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two checks can be combined:
if (typeof onRunHook !== "function") {
...
return;
}
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, but with less readability IMHO.
* @param onRunHook The function that should return a boolean if the onRun of catalog entity should be triggered. | ||
* @returns A function to remove that hook | ||
*/ | ||
addOnRunHook(catalogEntityUid: CatalogEntity["metadata"]["uid"], onRunHook: CatelogEntityOnRunHook) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be instead called onBeforeRun
so as to be more descriptive of when it will be run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to support multiple hooks in the future, onBeforeRun
is less descriptive IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is it less descriptive? It better shows when we plan on running them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's just my opinion, if you think "onBeforeRun" is better, I would just change it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant the argument would be onBeforeRun
and this method would be addOnBeforeRun
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, addOnBeforeRun
makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edited 74eb89c
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
@@ -114,14 +114,14 @@ export class Icon extends React.PureComponent<IconProps> { | |||
}; | |||
|
|||
// render as inline svg-icon | |||
if (svg) { | |||
if (typeof svg === "string") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is here just for easier mocking in tests (less crashes in components)
@@ -77,7 +77,7 @@ export class LensRendererExtension extends LensExtension { | |||
} | |||
|
|||
/** | |||
* Add a filtering function for the catalog catogries. This will be removed if the extension is disabled. | |||
* Add a filtering function for the catalog categories. This will be removed if the extension is disabled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was a typo.
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
Signed-off-by: Sebastian Malton <[email protected]>
Signed-off-by: Sebastian Malton <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: Sebastian Malton <[email protected]>
Signed-off-by: Sebastian Malton <[email protected]>
Signed-off-by: Sebastian Malton <[email protected]>
Renderer.Catalog.catalogEntities.addOnRunHook
Can be used like
prettier
to be able to use.toMatchInlineSnapshot()