Skip to content

Commit

Permalink
Remove legacy toolbar component (#170761)
Browse files Browse the repository at this point in the history
## Summary

This PR removes the duplicated ToolbarButton component that has been
marked for deprecation since
cf16057.

In this changeset; 
- The import declaration for `ToolbarButton` & `ToolbarButtonProps` from
`@kbn/kibana-react-plugin/public` is changed to
`@kbn/shared-ux-button-toolbar`.
- The visual expectation from the legacy `ToolbarButton` is preserved in
the new component
- A prop `as` is introduced to handle rendering toolbar buttons that are
simply just icons, a use case for this can be found when configuring
Legend settings for a visualisation. The `as` prop accepts values of
`standard` and `iconButton` and in either case the same styling is
preserved.
- When the standard version of the toolbar is being used, by default the
button will rendered with a down arrow positioned to the right, this
icon can be changed by specifying any eui compatible `IconType`.

### Checklist

<!--
Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
-->
- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [x] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
<!-- - [ ] If a plugin configuration key changed, check if it needs to
be allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces&mdash;unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes&mdash;Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
-->
  • Loading branch information
eokoneyo authored Nov 15, 2023
1 parent 4d61cd7 commit fc808a4
Show file tree
Hide file tree
Showing 24 changed files with 353 additions and 504 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { i18n } from '@kbn/i18n';
import React from 'react';
import { ToolbarButton, ToolbarButtonProps } from '../toolbar_button';

export type Props = Omit<ToolbarButtonProps, 'iconType' | 'label' | 'type'>;
export type Props = Omit<ToolbarButtonProps<'standard'>, 'iconType' | 'label' | 'type'>;

const label = {
getLibraryButtonLabel: () =>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export default {
};

const argTypes = {
buttonStyle: {
defaultValue: 'standard',
control: {
type: 'radio',
options: ['standard', 'iconButton'],
},
},
buttonType: {
defaultValue: 'empty',
control: {
Expand All @@ -39,9 +46,15 @@ const argTypes = {

type Params = Record<keyof typeof argTypes, any>;

export const ToolbarButton = ({ buttonType, iconSide }: Params) => {
export const ToolbarButton = ({ buttonStyle, buttonType, iconSide }: Params) => {
return (
<Component label="Toolbar button" iconType="lensApp" type={buttonType} iconSide={iconSide} />
<Component
as={buttonStyle}
label="Toolbar button"
iconType="lensApp"
type={buttonType}
iconSide={iconSide}
/>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,39 @@

import { UseEuiTheme } from '@elastic/eui';

export const fontWeightDefinitions = (euiTheme: UseEuiTheme['euiTheme']) => ({
bold: euiTheme.font.weight.bold,
normal: euiTheme.font.weight.regular,
});

export const ToolbarButtonStyles = ({ euiTheme }: UseEuiTheme) => {
return {
default: {
// style declaration carried over from https://github.com/elastic/kibana/blob/v8.10.4/src/plugins/kibana_react/public/toolbar_button/toolbar_button.scss
// informed by issue https://github.com/elastic/eui/issues/4730
borderStyle: 'solid',
border: euiTheme.border.thin,
borderColor: euiTheme.border.color,
},
emptyButton: {
backgroundColor: euiTheme.colors.emptyShade,
border: `${euiTheme.border.thin} !important`,
border: `${euiTheme.border.thin}`,
color: `${euiTheme.colors.text}`,
},
buttonPositions: {
left: {
borderTopRightRadius: 0,
borderBottomRightRadius: 0,
},
right: {
borderTopLeftRadius: 0,
borderBottomLeftRadius: 0,
borderLeft: 'none',
},
center: {
borderRadius: 0,
borderLeft: 'none',
},
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,47 @@ import { mountWithIntl } from '@kbn/test-jest-helpers';
import { ToolbarButton } from './toolbar_button';

describe('<ToolbarButton />', () => {
test('is rendered - default', () => {
const component = mountWithIntl(<ToolbarButton label="Create chart" onClick={() => 'click'} />);
expect(component.render()).toMatchSnapshot();
});
describe('standard', () => {
test('is rendered - default', () => {
const component = mountWithIntl(
<ToolbarButton label="Create chart" onClick={() => 'click'} />
);
expect(component.render()).toMatchSnapshot();
});

test('is rendered - primary', () => {
const component = mountWithIntl(
<ToolbarButton type="primary" label="Create chart" onClick={() => 'click'} />
);
expect(component.render()).toMatchSnapshot();
});

test('is rendered - text wth icon', () => {
const component = mountWithIntl(
<ToolbarButton
type="primary"
iconType="plusInCircle"
label="Create chart"
onClick={() => 'click'}
/>
);
expect(component.render()).toMatchSnapshot();
});

test('is rendered - primary', () => {
const component = mountWithIntl(
<ToolbarButton type="primary" label="Create chart" onClick={() => 'click'} />
);
expect(component.render()).toMatchSnapshot();
test('accepts an onClick handler', () => {
const mockHandler = jest.fn();
const component = mountWithIntl(<ToolbarButton label="Create chart" onClick={mockHandler} />);
component.find('button').simulate('click');
expect(mockHandler).toHaveBeenCalled();
});
});

test('accepts an onClick handler', () => {
const mockHandler = jest.fn();
const component = mountWithIntl(<ToolbarButton label="Create chart" onClick={mockHandler} />);
component.find('button').simulate('click');
expect(mockHandler).toHaveBeenCalled();
describe('iconButton', () => {
test('is rendered - default', () => {
const component = mountWithIntl(
<ToolbarButton as="iconButton" iconType="launch" onClick={jest.fn()} />
);
expect(component.render()).toMatchSnapshot();
});
});
});
Loading

0 comments on commit fc808a4

Please sign in to comment.