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

[Lens] Table column text alignment #89300

Merged
merged 73 commits into from
Feb 17, 2021
Merged

Conversation

flash1293
Copy link
Contributor

@flash1293 flash1293 commented Jan 26, 2021

Fixes #14524

Adds an option to set the text alignment of a column (left/right/center)

Screenshot 2021-01-26 at 15 33 10

Screenshot 2021-01-26 at 15 38 35

Behavior

  • Can be set for every column
  • As long as the user didn't specify an alignment, it is right aligned for numbers, left aligned for the rest
  • If the column data type changes, the alignment changes as well as long as the user didn't manually pick an alignment
  • Once the user picked an alignment once, it sticks, even if the column type changes later on
  • It's not possible to get back into the original "auto" mode without removing the dimension

Data grid has a bug with vertical scroll bars which becomes super obvious when implementing this feature. elastic/eui#4468 should take care of this, but this PR shouldn't be merged if it's not clear the EUI fix will be in the same version.

flash1293 and others added 30 commits January 4, 2021 15:29
@flash1293 flash1293 marked this pull request as ready for review February 5, 2021 08:14
@flash1293 flash1293 requested a review from a team February 5, 2021 08:14
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

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

All ok, but one tricky case with Unique count.

Tested in Firefox, Chrome and Safari. FF is all good, but the other two Webkit-based browsers show the scrollbar issue described above

Comment on lines +201 to +205
const isNumeric =
firstLocalTable.columns.find((dataColumn) => dataColumn.id === column.columnId)?.meta
.type === 'number';
alignmentMap[column.columnId] = isNumeric ? 'right' : 'left';
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic here seems to power the following behaviour:

As long as the user didn't specify an alignment, it is right aligned for numbers, left aligned for the rest

The only issue I found is that it tries to guess the type from the "field" rather than the operation. An example of the issue can be seen with Unique count as column of any field:

Screenshot 2021-02-05 at 14 34 29

Probably it's not a blocker as Unique count is the only operation affected (and of course any fullReference operation that uses Unique count as sub-operation).

@flash1293
Copy link
Contributor Author

Good catch! Previously I would look up the type in the datasource table spec, but that one is wrong in case of custom intervals (it thinks they are numbers). I will change it back.

@flash1293
Copy link
Contributor Author

@dej611 Looking further into it, I think it's just wrong the unique count metric is setting type to "string" in this case.
I will fix in a separate PR.

@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@mbondyra mbondyra left a comment

Choose a reason for hiding this comment

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

Tested in Safari, apart from the two issues mentioned in this PR, all works as expected. LGTM 🙆‍♀️

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

I reviewed and found that overall this is working well, but I did find 2 areas beyond what you've previously commented on that I think we should discuss before approving.

textAlign: currentAlignment,
},
});
}, [currentAlignment, setCellProps]);
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of useEffect here is causing visible flickering during scrolls. I know that the docs recommend setCellProps, but why aren't we using class names? I did a local test using classnames and found that the flickering goes away.

I recorded a video of the flickering effect, and here is a single frame from the video:

Screen Shot 2021-02-09 at 5 15 22 PM

As you can see in this frame, the text is not evenly aligned during the scroll.

Copy link
Contributor

Choose a reason for hiding this comment

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

@flash1293 It looks like you're now assigning the alignment twice: there's a className and a useEffect. Do we need both?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wylieconlon eh, I forgot to remove the setCellProps hook. I will fix it tomorrow morning.

frame.activeData[state.layerId].columns.find((col) => col.id === accessor)?.meta.type ===
'number'
? 'right'
: 'left');
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure that we should be applying right alignment to numbers without guaranteed decimal places? For example, when looking at Average of bytes I think the defaults got worse:

Screen Shot 2021-02-09 at 5 27 40 PM

Copy link
Contributor Author

@flash1293 flash1293 Feb 10, 2021

Choose a reason for hiding this comment

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

I don't think the default alignment should depend on whether or not decimal places are shown. I checked Google sheets and the Numbers app on Mac and both of them right align numbers without decimal places by default.

I think it's subjective whether the alignment looks better or worse - consistency is more important here IMHO. Once the bug with the horizontal scrollbar is gone it will be better as well I think.

@flash1293 flash1293 requested a review from a team as a code owner February 15, 2021 12:40
@flash1293
Copy link
Contributor Author

@wylieconlon I switched it to using a classname, let me know whether it looks better for you now.

Copy link
Contributor

@MichaelMarcialis MichaelMarcialis left a comment

Choose a reason for hiding this comment

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

LGTM!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
lens 899.6KB 903.8KB +4.2KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

Changes LGTM, tested yesterday without committing

@flash1293 flash1293 merged commit ce4c0cd into elastic:master Feb 17, 2021
flash1293 added a commit to flash1293/kibana that referenced this pull request Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.12.0 v8.0.0
Projects
None yet
8 participants