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

ag-grid PoC #574

Closed
wants to merge 7 commits into from
Closed

ag-grid PoC #574

wants to merge 7 commits into from

Conversation

DTCurrie
Copy link
Member

@DTCurrie DTCurrie commented Sep 5, 2024

This is a PoC to show a relatively quick-and-dirty implementation of ag-grid in Svelte. This gives us column sorting and drag-and-drop right out of the box, and one of the existing themes is already pretty close to what we probably want. I tried to make this a pretty straightforward passthrough of the ag-grid API, but the current props are large, deeply nesting objects, so there may be some performance concerns.

The following steps will be to add styles to overwrite the theme and match ours.

The large diff is due to updates in the pnpm lockfile.

Note to reviewers: I added you because the topic of using an ag-grid for tables has been raised a few times now, and I wanted to start the conversation about what it would look like. Feel free to remove yourself from the PR if this isn't relevant to you.

Screenshot 2024-09-10 at 3 48 58 PM

@tahiyasalam
Copy link
Member

Super cool! This would be a great improvement.

@ehhong
Copy link
Member

ehhong commented Sep 9, 2024

can we add the deploy tag to play with this grid? also, are we worried about increase in bundle size from adding this dependency?

@DTCurrie
Copy link
Member Author

DTCurrie commented Sep 9, 2024

can we add the deploy tag to play with this grid? also, are we worried about increase in bundle size from adding this dependency?

Do we have a deploy tag in this repo? I didn't see a label for it.

@ehhong
Copy link
Member

ehhong commented Sep 9, 2024

Do we have a deploy tag in this repo? I didn't see a label for it.

oh my bad, didn't realize this was in prime 🤦

@DTCurrie
Copy link
Member Author

I updated the PoC to tweak some styles and show how to sort and filter. I also broke out the columns and rows into their props so they could be changed without forcing an entire re-render. You can test it out with the "Remove row" button.

CC: @micheal-parks

@DTCurrie
Copy link
Member Author

also, are we worried about increase in bundle size from adding this dependency?

I don't think so, but I will do a build to compare. I updated the PoC to use modules provided by ag-grid which should reduce the bundle size.

@DTCurrie
Copy link
Member Author

Added row variants. Only outstanding feature is the TableVariant which switches between table-auto and table-fixed classes, but I think we will want to ignore those anyway and instead rely on ag-grid rendering.

@DTCurrie
Copy link
Member Author

Updated styles to match more recent table designs.

@DTCurrie
Copy link
Member Author

Please let me know if there is a use case you would like to see me include in the example.

data?.variant === 'error',
'!border-green-100 !bg-green-50 !text-green-700': ({ data }) =>
data?.variant === 'success',
'!bg-gray-50 !text-gray-500': ({ data }) => data?.variant === 'disabled',
Copy link
Member

Choose a reason for hiding this comment

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

[minor] can we update these to our theme colors?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think so, these were taken straight from the table component but we are tweaking the designs anyway so we should just keep to the theme.

flex: 1,
},
}}
/>
Copy link
Member

Choose a reason for hiding this comment

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

is there a way to add table data with custom elements? ie. in the fleet dashboard project, some of the values should be in pills

Copy link
Member Author

Choose a reason for hiding this comment

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

There is, but we will have to figure out how to make that work with svelte. I can make that the next thing to try in the example.

Copy link
Member

@mcous mcous left a comment

Choose a reason for hiding this comment

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

Very cool PoC! Left some initial thoughts that are primarily concerns about productionization and integrating this into the existing app architecture. So far, I still need convincing that ag-grid is a good choice for our app - I'm a little worried that, for our needs, it makes the wrong tradeoffs. That being said, my current focus is on the needs of the fleet dashboard specifically, and there my be other functionality needs elsewhere in the app that I'm not familiar with

Copy link
Member

@mcous mcous Sep 11, 2024

Choose a reason for hiding this comment

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

I think this lockfile change contains unnecessary changes, it can be regenerated from main to remove unrelated bumps

git checkout main -- pnpm-lock.yaml
pnpm install
pnpm dedupe
git add pnpm-lock.yaml

I'm showing a much smaller diff after this:

❯ git diff --stat main -- pnpm-lock.yaml
 pnpm-lock.yaml | 925 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------
 1 file changed, 579 insertions(+), 346 deletions(-)

Comment on lines +461 to +467
{
id: 1,
first_name: 'Bobette',
last_name: 'Dankov',
email: '[email protected]',
ip_address: '212.10.172.113',
},
Copy link
Member

Choose a reason for hiding this comment

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

I'm struggling to see how this proposed API of the component would be used by the machines dashboard table, where cells are are frequently made up of interactable elements and/or other Prime components.

I can see that ag-grid has an API for defining cell components, which we could use to live-render Svelte components, but managing that sort of compatibility layer makes me uneasy.

I think doing this work in the prime repository might be too much of a bottom-up approach for this kind of UI component. Would it be possible to take this work and drop it into app instead, so we can iterate on a PoC with the actual use case of the all machines table? This decision happened while my review was in progress

Copy link
Member Author

Choose a reason for hiding this comment

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

That is the row data API, I think we should look at defining custom components to be used in the columnDefs. The components would need to accept the expected data object and understand how to render (like the status badge) based on that.

There is a few different ways they manage creating cell renderers. I think the only layer we would need is something to make that accept Svelte components, which I saw a svelte 3 example of here. I think a similar wrapper that allows us to pass svelte components as a part of the object should work, that is next on my plan to experiment with.

Comment on lines +69 to +76
onMount(() => {
grid = createGrid(
eGui,
{ ...options, columnDefs, rowData, rowClassRules },
params
);
return () => grid.destroy();
});
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit concerned about taking a table approach that is entirely client-side rendered. We have "tables" that are currently capable of being rendered at build time, but switching to this would lock us out of that possibility - e.g. /registry

I have no experience with the library, but I wonder if a headless solution like tanstack table (20.3 kB (gzip)), where we define our own markup directly, would have an acceptable feature set / performance for our needs

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't dig too deep, but server-side rendering for rows is an enterprise feature.

Copy link
Member

Choose a reason for hiding this comment

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

All for considering tanstack table if it's a better solution since we haven't started investing in ag-grid yet

Comment on lines +49 to +51
"@ag-grid-community/client-side-row-model": "^32.1.0",
"@ag-grid-community/core": "^32.1.0",
"@ag-grid-community/styles": "^32.1.0",
Copy link
Member

Choose a reason for hiding this comment

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

Did a quick check on bundle.js, and it looks like these packages will add 221 kB (gzip) to our page bundles where they're used. If we go this route, I think we'll need try to make it easy to code split

@DTCurrie
Copy link
Member Author

Closing this, @mcous is opening another PR on the app side so we can start using and iterating on this. Keep an eye out for that PR, and thanks for the input!

@DTCurrie DTCurrie closed this Sep 11, 2024
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.

5 participants