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

feat: enable setting custom column order by visibleColumns #1739

Merged
merged 10 commits into from Nov 21, 2023

Conversation

taefi
Copy link
Contributor

@taefi taefi commented Nov 15, 2023

Description

If the user define a custom column and gives it a unique key, the same key can be used in visibleColumns props to set its order of appearance among the columns:

<AutoGrid 
    service={...} 
    model={...} 
    visibleColumns={['fullName', 'gender', 'email', 'vip', 'birthDate', 'shiftStart']}
    customColumns={[
        <GridColumn key="fullName" autoWidth renderer={FullNameRenderer}></GridColumn>,
    ]}
/>,

In case the visibleColumns property is absent, the custom columns would be added at the end.

In the presence of visibleColumns, only those custom columns would appear in the grid that their key is listed in the visibleColumns.

Fixes #1448

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

Copy link

codecov bot commented Nov 15, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ac69280) 93.70% compared to head (c555e95) 93.72%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1739      +/-   ##
==========================================
+ Coverage   93.70%   93.72%   +0.01%     
==========================================
  Files          51       51              
  Lines        3259     3266       +7     
  Branches      448      450       +2     
==========================================
+ Hits         3054     3061       +7     
  Misses        172      172              
  Partials       33       33              
Flag Coverage Δ
unittests 93.72% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@cromoteca cromoteca left a comment

Choose a reason for hiding this comment

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

I like the idea. I'm not sure that custom columns without a key are retained. They should still find a place at the end of the list.

@taefi
Copy link
Contributor Author

taefi commented Nov 16, 2023

I like the idea. I'm not sure that custom columns without a key are retained. They should still find a place at the end of the list.

With 2.4.0.beta2, custom columns without a key are rendered at the end, however, react is complaining about the elements without a key. Unless, we come up with some automatic wrapping of each GridColumn (provided by the user) in an imaginary component such as AutoGridColumn that provides the key, the user needs to provide the key. This is one of the reasons I based my solution on the keys to minimize the effort for now.

We can change the implementation to make sure custom columns will end up at the end, in case the visibleColumns was absent. Supporting a mixture of naming some custom columns in visibleColumns to specify the order and rendering the unnamed ones in the end may both confusing for the users and unnecessarily more complex to maintain (Just my opinion).

Copy link

sonarcloud bot commented Nov 21, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@sissbruecker sissbruecker dismissed cromoteca’s stale review November 21, 2023 08:11

Concerns have been addressed

@sissbruecker sissbruecker enabled auto-merge (squash) November 21, 2023 08:11
@sissbruecker sissbruecker merged commit 54efacd into main Nov 21, 2023
15 checks passed
@sissbruecker sissbruecker deleted the taefi/set-custom-col-order-by-visiblecolumns branch November 21, 2023 09:20
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.

[autogrid] Make it possible to define where custom columns are added
3 participants