-
Notifications
You must be signed in to change notification settings - Fork 179
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
[dataquery] Add ability for other modules to add actions #9302
base: main
Are you sure you want to change the base?
Conversation
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 know anything about the dataquery module or its code logic, so here is my very surface-level review.
modules/dataquery/jsx/nextsteps.tsx
Outdated
steps.push(<ButtonElement | ||
label={fieldLabel} | ||
columnSize='col-sm-12' | ||
key='fields' | ||
onUserInput={() => props.changePage('DefineFields')} | ||
onUserInput={() => props.changePage(Tabs.Fields)} | ||
/>); |
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 button element seems to be repeated a lot, can it be factorized ?
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 didn't change the button, just the argument to the callback which had the wrong type
if (steps[Tabs.Info]) { | ||
steps[Tabs.Info].push({ | ||
label: widget.label, | ||
action: func, | ||
}); | ||
} | ||
break; |
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 pattern of this switch
should maybe be factorized ?
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.
What do you mean? The switch is delegating which bucket to put the item in. It's one if statement per case.
if (activeTab == Tabs.Fields | ||
|| activeTab == Tabs.Filters | ||
|| activeTab == Tabs.Data) { |
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.
Could you use strict equality here (and in a few other places) ?
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 guess? I'm not sure what it would change since the compiler should be enforcing the types, but sure.
function getCallback(name: string): (() => void) | null { | ||
const namepieces = name.split('.').reverse(); | ||
let level: any = window; | ||
for (let name = namepieces.pop(); name; name = namepieces.pop()) { |
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.
Could you use for of
here ?
/>); | ||
break; | ||
} | ||
|
||
for (const osteps of (props.extrasteps[props.page] || [])) { |
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'd personally put the for
inside a if
instead.
|
||
|
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.
Extra line breaks (we should probably add a lint for that).
This adds the ability for other modules to add custom actions to the "Next Steps" of the dataquery module. An example of an "Action" that might be added is a "Package Data Release" for the data_release module or a "Send to CBRAIN" for a theoretical CBRAIN module on the final view data page.
To add an action, the module's getWidgets must return an array of
\LORIS\dataquery\ActionWidget
s to be added when called with the type argument ofdataquery:action
. Each ActionWidget adds a button on a particular dataquery page which, when clicked, invokes a javascript callback that can be customized by the module.Plugin actions provided by a module are displayed in a second row underneath the "Next Steps" .