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

[shared-ux] Migrate toolbar button component #124372

Closed
wants to merge 25 commits into from

Conversation

rshen91
Copy link
Contributor

@rshen91 rshen91 commented Feb 2, 2022

Summary

This PR migrates the toolbar button component from the kibana-react folder to the shared-ux directory

Where toolbars similarly are used in the codebase:

  • Lens has a ToolbarPopover component that seems similar x-pack/plugins/lens/public/shared_components/toolbar_popover.tsx

    • used as LegendSettingsPopover in lens/public/shared_components/legend_settings_popover.tsx
    • Lens has ToolbarPopover used in datatable_visualization in x-pack/plugins/lens/public/datatable_visualization/components/toolbar.tsx
    • used in HeatmapToolbar in heatmap_visualization/toolbar_component.tsx
    • used in PieToolbar in pie_visualization/toolbar.tsx
    • used in GaugeToolbar in visualizations/gauge/toolbar_component/index.tsx
    • AxisSettingsPopover in xy_visualization/xy_config_panel/axis_settings_popover.tsx
    • VisualOptionsPopover in xy_visualization/xy_config_panel/visual_options_popover/index.tsx
  • SolutionToolbarPopover PresentationToolbar in src/plugins/presentation_util/public/components/solution_toolbar/solution_toolbar.tsx

    • this might just need to be migrated over too e9a025b
    • EditorMenu in dashboard has SolutionToolbarPopover in src/plugins/dashboard/public/application/top_nav/editor_menu.tsx

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@rshen91 rshen91 added loe:medium Medium Level of Effort backport:skip This commit does not require backporting Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) labels Feb 2, 2022
@rshen91
Copy link
Contributor Author

rshen91 commented Feb 3, 2022

@elasticmachine merge upstream

@rshen91
Copy link
Contributor Author

rshen91 commented Feb 7, 2022

@elasticmachine merge upstream

@rshen91 rshen91 changed the title [shared-ux]migrate toolbar button component [shared-ux] Migrate toolbar button component Feb 7, 2022
@rshen91
Copy link
Contributor Author

rshen91 commented Feb 8, 2022

@elasticmachine merge upstream

<SolutionToolbarButton
{...rest}
iconType="folderOpen"
onClick={onClick}
Copy link
Contributor

@majagrubic majagrubic Feb 11, 2022

Choose a reason for hiding this comment

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

Why is onClick destructured explicitly and not with the rest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think what's happening is that the solution toolbar allows consumers to pass their own onClick handler. I'm looking at button.tsx with the props extending EUIButtonPropsForButton and seeing the following:

export interface Props
  extends Pick<EuiButtonPropsForButton, 'onClick' | 'iconType' | 'iconSide' | 'className'> 

Copy link
Contributor

Choose a reason for hiding this comment

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

@majagrubic has a point: there's no need to destructure props on line 17 to extract onClick, because we're not doing anything with it. You could actually do:

<SolutionToolbarButton iconType="folderOpen" {...props} />

extends Pick<EuiButtonPropsForButton, 'onClick' | 'iconType' | 'iconSide' | 'className'> {
label: string;
primary?: boolean;
isDarkModeEnabled?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this being used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some of it is being used in the solution_toolbar.tsx file in the props. In the solution toolbar implementation, the primary styling is used consistently in how the toolbar is set up.

I'm tempted to keep this as is since the items directory comes directly from the presentation team. I'm thinking as I migrate more components over, more and more references will occur with parts of the items folder.


return (
<EuiPopover
anchorPosition="downLeft"
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be customizable or are we ok with it always being down & left?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm open to making this customizable - thoughts @clintandrewhall?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would expose and default it.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's already exposed on line 18... just need to use it here. Pretty sure downLeft is the EUI default, as well.

className={`solutionToolbar ${
isDarkModeEnabled ? 'solutionToolbar--dark' : 'solutionToolbar--light'
}`}
id={`kbnPresentationToolbar__solutionToolbar`}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to be adding ids here? I would say it needs to be passed as a prop then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

17c81e7 for changes, let me know if I'm understanding correctly, thanks

Copy link
Contributor

@clintandrewhall clintandrewhall left a comment

Choose a reason for hiding this comment

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

This is a great start...! Keep up the good work. You might find that splitting this into smaller PRs allows you to focus on the individual components... but that's up to you.

*/

export { SolutionToolbar } from './solution_toolbar';
export * from './items';
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: best practice is to explicitly name the exports.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok! Fixed in e27b041 thank you!

<SolutionToolbarButton
{...rest}
iconType="folderOpen"
onClick={onClick}
Copy link
Contributor

Choose a reason for hiding this comment

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

@majagrubic has a point: there's no need to destructure props on line 17 to extract onClick, because we're not doing anything with it. You could actually do:

<SolutionToolbarButton iconType="folderOpen" {...props} />

@@ -0,0 +1,12 @@
.solutionToolbarButton {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not be introducing any SASS to SharedUX, and it we must, we must document it here: #122594

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed it in e27b041 thank you!


return (
<EuiPopover
anchorPosition="downLeft"
Copy link
Contributor

Choose a reason for hiding this comment

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

It's already exposed on line 18... just need to use it here. Pretty sure downLeft is the EUI default, as well.

primary={true}
className={`solutionToolbar__primaryButton ${
isDarkModeEnabled
? 'solutionToolbar__primaryButton--dark'
Copy link
Contributor

Choose a reason for hiding this comment

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

I really want to see all of this SASS gone. :-/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in 7fa17de - is this the right approach or should I document it in the #122594?


import { i18n } from '@kbn/i18n';

export const ComponentStrings = {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a deprecated approach from my time on Presentation Team. See: #103013

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if my changes in 7fa17de make sense thanks!

* Side Public License, v 1.
*/

export * from './labs';
Copy link
Contributor

Choose a reason for hiding this comment

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

copy-pasta error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in e27b041 thanks!

import { FormattedMessage } from '@kbn/i18n-react';
import { EuiCode } from '@elastic/eui';

export const LabsStrings = {
Copy link
Contributor

Choose a reason for hiding this comment

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

we shouldn't be bringing labs strings in...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in e27b041 thanks!

@rshen91
Copy link
Contributor Author

rshen91 commented Feb 15, 2022

@elasticmachine merge upstream

@rshen91 rshen91 marked this pull request as ready for review February 15, 2022 19:29
@rshen91 rshen91 added v8.2.0 release_note:skip Skip the PR/issue when compiling release notes labels Feb 15, 2022
Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Quick question: Why do the Toolbar Button storybook examples not have any text in the buttons?
Screen Shot 2022-02-15 at 14 34 38 PM

@rshen91
Copy link
Contributor Author

rshen91 commented Feb 15, 2022

Quick question: Why do the Toolbar Button storybook examples not have any text in the buttons? Screen Shot 2022-02-15 at 14 34 38 PM

Good call let me add some in the examples thanks!

Copy link
Contributor

@majagrubic majagrubic left a comment

Choose a reason for hiding this comment

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

Codewise looks good, waiting for the design to approve

@clintandrewhall
Copy link
Contributor

I'm working on an in-depth review. Please don't merge yet.

Copy link
Contributor

@clintandrewhall clintandrewhall left a comment

Choose a reason for hiding this comment

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

I have some comments in the works. Bear with me for a few minutes.

@rshen91 rshen91 requested a review from cchaos February 16, 2022 19:26
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
sharedUX 23 35 +12

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
sharedUX 0 4 +4

Async chunks

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

id before after diff
sharedUX 8.5KB 9.4KB +882.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
sharedUX 3.8KB 4.6KB +874.0B
Unknown metric groups

API count

id before after diff
sharedUX 10 16 +6

async chunk count

id before after diff
sharedUX 1 2 +1

ESLint disabled in files

id before after diff
sharedUX 2 3 +1

Total ESLint disabled count

id before after diff
sharedUX 3 4 +1

History

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

@rshen91
Copy link
Contributor Author

rshen91 commented Feb 17, 2022

Closing in favor of splitting this PR into smaller PRs that are more targeted in scope thanks!

@rshen91 rshen91 closed this Feb 17, 2022
@rshen91 rshen91 deleted the migrate-toolbar-button branch March 2, 2022 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting loe:medium Medium Level of Effort release_note:skip Skip the PR/issue when compiling release notes Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants