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
Fixes #33078 - Add Traces bulk select & restart #9594
Fixes #33078 - Add Traces bulk select & restart #9594
Conversation
Issues: #33078 |
c20b07d
to
54a5aa4
Compare
const fetchItems = useCallback( | ||
params => | ||
(hostId ? getHostTraces(hostId, params) : null), | ||
[hostId], | ||
); | ||
const response = useSelector(state => selectAPIResponse(state, 'HOST_TRACES')); | ||
const { results, ...meta } = response; | ||
const onRestartApp = () => { | ||
dispatch(resolveHostTraces(hostId, { trace_ids: [...selectedTraces] }, dispatch)); |
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 spread syntax here in [...selectedTraces]
converts it back to an array :)
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 thought we were doing the onSuccess in the component? Not passing the dispatch up to the API.
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.
@Andrewgdewar thanks, updated! turns out this was left over anyway, and not even doing anything 😄
dispatch({ | ||
type: 'TOASTS_ADD', | ||
payload: { | ||
key: id, | ||
message: { | ||
type: 'success', | ||
message: `Restarting ${pluralize(traceCount, 'trace')}.`, | ||
link: { | ||
children: 'View task', | ||
href: `/foreman_tasks/tasks/${id}`, |
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 took me like 2 hours to figure out.. I didn't know about webpack/scenes/Tasks/helpers.js
😭 I will update this
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.
K, yeah I'd like to see the dispatch call made into it's own function, if only for clarity of purpose (can be local not exported).
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.
Turns out this same thing can also be accomplished in a single line
handleSuccess: response => renderTaskStartedToast(response.data),
(or close enough to the same thing, at least.) So I'm doing that instead.
To test:
100.times { |idx| Katello::HostTracer.create!(host_id: 12, application: "tracer_#{idx}", helper: "sudo systemctl restart blah", app_type: "daemon") } To test end-to-end:
|
This PR uses JavaScript Advantages:
const mySet = new Set([1,2,3])
mySet.add(3) // no change; 3 is already in the set
mySet.delete(2) // Set { 1, 3 }
mySet.size // 2
mySet.has(2) // false
mySet.has(1) // true
[...mySet] // [1, 3] - returns the Set as an array
mySet.clear() // Set { }
Disadvantages:
Mostly because of the above, I'm still ambivalent about whether this is a good approach. But I do really love being able to use the Set API for what it's meant for -- keeping track of a unique list of items and modifying that list easily. |
@jeremylenz
|
Thanks for looking at it @MariSvirik :)
The partially checked state being non-blue was just the way the Patternfly React component came. I didn't change anything, maybe it's being overridden with our CSS or something.. I'll look into it. Also, will update to address all your other comments. |
> | ||
<Thead> | ||
<Tr> | ||
<Th /> |
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.
Empy row, but why?
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.
It's the checkbox column header!
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 can't understand in the code how the select all is working..Would you need any updates to the rails traces controller or is it already supported?
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 updates to the backend were needed. We just keep track on the front end of which trace IDs are selected, and render accordingly.
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.
Backend updates will be needed to get 'Select all' functionality working, however. That is left for a future 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.
I can't understand in the code how the select all is working
To be clear, the 'Select all' checkbox is correctly rendering as checked, but the 'Select all' menu item doesn't work yet.
The checkbox rendering works just by comparing the number of selected items and the total from pagination metadata.
<DropdownItem key="select-all" component="button" isDisabled onClick={handleSelectAll}> | ||
{__('Select all')} | ||
</DropdownItem>, | ||
<DropdownItem key="select-page" component="button" isDisabled={areAllRowsOnPageSelected} onClick={handleSelectPage}> |
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.
There was talk of removing items instead of disabling them when not relevant, not sure if @MariaAga had weighed in on that for the dropdown items?
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 you're looking for @MariSvirik :)
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.
ahh... yes
56ae3a7
to
6b3ba0d
Compare
6b3ba0d
to
1fa481f
Compare
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.
Works great. Tested with dummy traces on the UI only cause I don't know enough about the entire flow..Code LGTM..Good to go from my perspective..🎉 🎉
I'll let @Andrewgdewar turn the button green..
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.
Code + functionality ACK!
Nice work @jeremylenz !
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.
Looks good!
<DropdownItem key="select-all" component="button" isDisabled onClick={handleSelectAll}> | ||
{__('Select all')} | ||
</DropdownItem>, | ||
<DropdownItem key="select-page" component="button" isDisabled={areAllRowsOnPageSelected} onClick={handleSelectPage}> |
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.
ahh... yes
const perPage = Number(metadata?.per_page ?? foremanPerPage); | ||
const page = Number(metadata?.page ?? 1); | ||
const total = Number(metadata?.subtotal ?? 0); | ||
const { pageRowCount } = getPageStats({ total, page, perPage }); |
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.
happy you pulled this out.
@MariSvirik I was finally able to spin up Firefox with this, and it confirmed something I suspected: The blue partially-selected checkbox comes from how the browser styles it. In Firefox it looks like the above. The non-blue one is just the way Chrome does it. |
This adds bulk table row selection to the Traces tab, and allows you to restart traces via remote execution.
Added a
<SelectAllCheckbox>
with the following features: