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 component from presentation to shared-ux #137224

Merged
merged 43 commits into from
Aug 29, 2022

Conversation

rshen91
Copy link
Contributor

@rshen91 rshen91 commented Jul 26, 2022

Summary

The Toolbar component was previously named SolutionToolbar component. It is currently only used in x-pack/plugins/canvas/public/components/workpad_header/workpad_header.component.tsx.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@rshen91 rshen91 self-assigned this Jul 27, 2022
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.

An awesome addition! Just a few changes and thoughts.

);

return (
<EuiFlexGroup id={`kbnPresentationToolbar__solutionToolbar`} gutterSize="s">
Copy link
Contributor

Choose a reason for hiding this comment

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

This ID is probably not necessary.

extraButtons?: Array<ReactElement<typeof PrimaryButton | typeof ToolbarPopover> | undefined>;
}

export interface Props {
Copy link
Contributor

Choose a reason for hiding this comment

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

needs docs

children: NamedSlots;
}

export const Toolbar = ({ children }: Props) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

needs docs

import { IconButtonGroup, PrimaryButton } from '../buttons';
import { ToolbarPopover } from '../popover';

interface NamedSlots {
Copy link
Contributor

Choose a reason for hiding this comment

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

This ends up getting exported as part of the Props interface, so it probably needs docs and inline docs per parameter:

  /** Some description **/
  primaryButton: ...

import { ToolbarPopover } from '../popover';

interface NamedSlots {
primaryButton: ReactElement<typeof PrimaryButton | typeof ToolbarPopover>;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we repeat typeof PrimaryButton | typeof ToolbarPopover in a number of places... let's introduce a type:

type Button = typeof PrimaryButton | typeof ToolbarPopover`

export const Toolbar = ({ children }: Props) => {
const { primaryButton, iconButtonGroup, extraButtons = [] } = children;

const extra = extraButtons.map((button, index) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we don't currently restrict this array to any particular length, but it stands to reason there's a maximum. We might want to consider logging a warning-- or throwing an error-- if the number of extra buttons exceeds a certain design limit. Thoughts @cchaos ?

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 added an error in fa629f2 for over 120 buttons. I'm open to lowering that number to...50? Would logging a warning be better? 😅

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 log a warning, yes... and I was thinking more like 5, maybe as many as 7. Maybe @ryankeairns can weigh in, but we don't need to block this PR from going in.

@rshen91 rshen91 requested a review from clintandrewhall August 2, 2022 21:32
@rshen91 rshen91 added v8.4.0 v8.5.0 release_note:skip Skip the PR/issue when compiling release notes labels Aug 16, 2022

export { Toolbar } from './toolbar';
export type { ToolbarProps } from './toolbar';
export type { Button } from './toolbar';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would better be called ToolbarButton or something.

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 can get behind that thanks! 3247796


describe('<Toolbar />', () => {
test('is rendered', () => {
const primaryButton = <PrimaryButton label="Create chart" onClick={() => 'click'} />;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: onClick be just empty function if we're not testing if it can be clicked. but can we add a test that click actually calls the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call - 379590c I got a little goofed up trying to get only the button clicked and I think this test nails it thanks!


if (extraButtons.length > 120) {
throw new Error(
'There are over 120 extra buttons. Please consider limiting the number of buttons.'
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the error be localized?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably, yes! Thank you! 3247796 I think I did it right? 🤞🏻

@rshen91 rshen91 requested a review from majagrubic August 25, 2022 19:31
@rshen91
Copy link
Contributor Author

rshen91 commented Aug 29, 2022

@elasticmachine merge upstream

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.

I don't have any additional comments, so on my end this is approved. Tested this by running storybook in Chrome on Mac OSX.

@rshen91 rshen91 enabled auto-merge (squash) August 29, 2022 19:18
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.

Great work!

export const Toolbar = ({ children }: Props) => {
const { primaryButton, iconButtonGroup, extraButtons = [] } = children;

const extra = extraButtons.map((button, index) =>
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 log a warning, yes... and I was thinking more like 5, maybe as many as 7. Maybe @ryankeairns can weigh in, but we don't need to block this PR from going in.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

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
@kbn/shared-ux-button-toolbar 6 8 +2
Unknown metric groups

API count

id before after diff
@kbn/shared-ux-button-toolbar 20 25 +5

History

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

cc @rshen91

@rshen91 rshen91 merged commit 1ebfd79 into elastic:main Aug 29, 2022
@rshen91 rshen91 deleted the toolbar-package branch August 29, 2022 20:25
@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.4 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 137224

Questions ?

Please refer to the Backport tool documentation

@rshen91 rshen91 added the backport:skip This commit does not require backporting label Aug 29, 2022
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 release_note:skip Skip the PR/issue when compiling release notes v8.4.0 v8.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants