Skip to content
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

Merged
merged 1 commit into from
Jun 4, 2024

Conversation

jelly
Copy link
Member

@jelly jelly commented May 29, 2024

image

  • Make selectable visually work .selected-class-thing + td { background: var(--pf-v5--theBackGroundColor); }
  • Stop using a Card in the first column, <Icon isInline><p>File or dir</p> instead
  • Make the contextmenu and selecting event handlers work
  • Make everything sortable
  • Stretch goal, combine both views into one as per https://garrett.github.io/cockpit-mockweb/navigator/grid#

Re-useable table approach issues

  • Refactor / clean up render function
  • Size header is not allowed with content
    image
  • Directory is empty twice
    image
  • Too much spacing when there three items
    image
  • wrong icon for folders
  • Icon view not really centered
    image
  • Icon not centered / wrongly aligned
    image
  • General text/font

Follow up

  • More useful dates? "Yesterday at 12:00" instead?
  • Update & Merge the PF update PR as we no longer use a which blocked us from updating
  • Scrollbar position wrong
    image
  • Table should take the full height when available.
    image
    .pf-v5-c-sidebar__main, .pf-v5-c-sidebar__content, .pf-v5-c-card { height: 100%; }

@jelly jelly added the no-test label May 29, 2024
@jelly
Copy link
Member Author

jelly commented May 30, 2024

Dropping the Card and just using a label gives us a smaller row size.

image

@jelly
Copy link
Member Author

jelly commented May 30, 2024

@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:

<tbody>
<tr>
</tr>
</tbody>
<tbody>
...

This is likely due to the ListingTable also supporting expendable content.

Adjusted our CSS, but layout is still a small problem

image

This means we have two options:

  • Adjust our CSS and make it work
  • Use the normal PF table elements instead of a ListingTable, this mean that we lack some ct-table stuff.

Copy link
Member

@allisonkarlitskaya allisonkarlitskaya left a 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:

@@ -73,6 +74,14 @@ const compare = (sortBy) => {
? -1
: 1)
: compareFileType(a, b);
case "largest_size":
return (a, b) => (a.size > b.size
? -1
Copy link
Member

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.

Copy link
Member

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...

Copy link
Member Author

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 )

Copy link
Member Author

@jelly jelly Jun 4, 2024

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.

Copy link
Member Author

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 :)

@jelly jelly removed the no-test label Jun 4, 2024
@jelly jelly force-pushed the real-table-view branch from cf98789 to 0bad527 Compare June 4, 2024 13:50
@jelly jelly marked this pull request as ready for review June 4, 2024 14:30
Copy link
Member

@allisonkarlitskaya allisonkarlitskaya left a 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 }) {
Copy link
Member

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...

Copy link
Member Author

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.

Copy link
Member Author

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

Copy link
Member Author

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 :)

display: none;
}

.item-size,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!!!

}

.item-size,
.item-date {
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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]>
@jelly jelly force-pushed the real-table-view branch from 9967c03 to 4d6df99 Compare June 4, 2024 15:07
@jelly jelly requested a review from allisonkarlitskaya June 4, 2024 15:07
Comment on lines +359 to +360
onSort: (_event, index, direction) => {
setSortBy(filterColumns[index][direction].itemId);
Copy link
Contributor

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.

Copy link
Member

@allisonkarlitskaya allisonkarlitskaya left a 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...

@allisonkarlitskaya allisonkarlitskaya merged commit 15ee985 into cockpit-project:main Jun 4, 2024
8 of 12 checks passed
@allisonkarlitskaya
Copy link
Member

yolo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants