-
Notifications
You must be signed in to change notification settings - Fork 37
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
Useful listing table #481
Useful listing table #481
Conversation
@garrett I have come quite far porting your CSS to the file viewer one big interesting detail is that our tables are a bit weird:
This is likely due to the ListingTable also supporting expendable content. Adjusted our CSS, but layout is still a small problem This means we have two options:
|
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.
Some assorted drive-bys:
src/files-card-body.jsx
Outdated
@@ -73,6 +74,14 @@ const compare = (sortBy) => { | |||
? -1 | |||
: 1) | |||
: compareFileType(a, b); | |||
case "largest_size": | |||
return (a, b) => (a.size > b.size | |||
? -1 |
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 just want (a, b) => b.size - a.size
for this. The sort function here doesn't properly handle the "two items equal" case, and it's more complicated than it needs to be, anyway.
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.
Also: this appears not to respect "directories" first...
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 does not, and in my opinion why would directories need to be first if I am sorting on size. We have no file count information or directory size information so I don't see how sorting on file size is useful in that regard by listing directories first. (@garrett )
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.
Not going to block on this but it doesn't feel like it makes sense to me.
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 you mean it doesn't handle two items equal and then sort them alphabetically? Then yes that is true :)
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 looks great!
Some minor comments below, but feel free to handle them as follow-ups...
}; | ||
|
||
// Memoize the Item component as rendering thousands of them on each render of parent component is costly. | ||
const Row = React.memo(function Item({ file, isSelected }) { |
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.
For the record, I don't think the memoize currently protects us from changes to unrelated files since we re-create the list on every single fsinfo event, but I'm happy to see what we are theoretically memoized, because it means that we can fix that bug and benefit from 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.
It does, I tested this on /bin, the event listener took ~ 200-300ms and with memozing its a lot faster.
React can be a bit confusing :)
So re-render => props/state changes and the render function is called again forcing all children to "re-render". By memozing React does not re-run the render
function as the props did not change.
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.
Soooo you are right if fsinfo updates and generates a new Object
because like setstate react compares objects on identity. So we could fix this by passing:
- name
- mtime
- size
- type
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.
Another issue might be that we memoize the sort order of the array. But then again changing our state to an Object might help with that :)
src/files-card-body.scss
Outdated
display: none; | ||
} | ||
|
||
.item-size, |
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.
Cool!!!
src/files-card-body.scss
Outdated
} | ||
|
||
.item-size, | ||
.item-date { |
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 the inclusion of .item-date
here is probably accidental since you display: none
it, just below?
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.
Howso, we want the font-size and color to be the same?
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.
But we don't show the date...
Our card listingtable could not easily support showing columns for size, modified and name. But instead we can use a Table with CSS to accommodate both views. The added benefits of dropping the card, showing the icons via CSS outweigh using a Card or a per view specific component. The ListingTable is not used as it has a <tbody> for every row which is simply unneeded and we already require our own CSS customization for styling the Table to support both views. Co-Authored-By: Garrett LeSage <[email protected]>
onSort: (_event, index, direction) => { | ||
setSortBy(filterColumns[index][direction].itemId); |
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 2 added lines are not executed by any test.
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.
As a wise man once said...
15ee985
into
cockpit-project:main
yolo. |
.selected-class-thing + td { background: var(--pf-v5--theBackGroundColor); }
<Icon isInline><p>File or dir</p>
insteadRe-useable table approach issues
Follow up
.pf-v5-c-sidebar__main, .pf-v5-c-sidebar__content, .pf-v5-c-card { height: 100%; }