Skip to content

Commit f8dbb31

Browse files
[Lens] Hide disabled toolbar entries (#129994)
* hide toolbar entries * remove unused stuff * remove unnecessary test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent 3877763 commit f8dbb31

File tree

13 files changed

+175
-347
lines changed

13 files changed

+175
-347
lines changed

x-pack/plugins/lens/public/pie_visualization/toolbar.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export function PieToolbar(props: VisualizationToolbarProps<PieVisualizationStat
183183
</EuiFormRow>
184184
) : null}
185185

186-
{numberOptions.length ? (
186+
{numberOptions.length && layer.categoryDisplay !== 'hide' ? (
187187
<EuiFormRow
188188
label={i18n.translate('xpack.lens.pieChart.numberLabels', {
189189
defaultMessage: 'Values',
@@ -193,8 +193,7 @@ export function PieToolbar(props: VisualizationToolbarProps<PieVisualizationStat
193193
>
194194
<EuiSuperSelect
195195
compressed
196-
disabled={layer.categoryDisplay === 'hide'}
197-
valueOfSelected={layer.categoryDisplay === 'hide' ? 'hidden' : layer.numberDisplay}
196+
valueOfSelected={layer.numberDisplay}
198197
options={numberOptions}
199198
onChange={onNumberDisplayChange}
200199
/>

x-pack/plugins/lens/public/shared_components/columns_number_setting.test.tsx

Lines changed: 0 additions & 19 deletions
This file was deleted.

x-pack/plugins/lens/public/shared_components/columns_number_setting.tsx

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import React from 'react';
99
import { i18n } from '@kbn/i18n';
1010
import { EuiFieldNumber, EuiFormRow } from '@elastic/eui';
1111
import { useDebouncedValue } from './debounced_value';
12-
import { TooltipWrapper } from './tooltip_wrapper';
1312

1413
export const DEFAULT_FLOATING_COLUMNS = 1;
1514

@@ -22,10 +21,6 @@ interface ColumnsNumberSettingProps {
2221
* Callback on horizontal alignment option change
2322
*/
2423
onFloatingColumnsChange?: (value: number) => void;
25-
/**
26-
* Flag to disable the location settings
27-
*/
28-
isDisabled: boolean;
2924
/**
3025
* Indicates if legend is located outside
3126
*/
@@ -35,14 +30,15 @@ interface ColumnsNumberSettingProps {
3530
export const ColumnsNumberSetting = ({
3631
floatingColumns,
3732
onFloatingColumnsChange = () => {},
38-
isDisabled,
3933
isLegendOutside,
4034
}: ColumnsNumberSettingProps) => {
4135
const { inputValue, handleInputChange } = useDebouncedValue({
4236
value: floatingColumns ?? DEFAULT_FLOATING_COLUMNS,
4337
onChange: onFloatingColumnsChange,
4438
});
4539

40+
if (isLegendOutside) return null;
41+
4642
return (
4743
<EuiFormRow
4844
label={i18n.translate('xpack.lens.shared.legendInsideColumnsLabel', {
@@ -51,34 +47,17 @@ export const ColumnsNumberSetting = ({
5147
fullWidth
5248
display="columnCompressed"
5349
>
54-
<TooltipWrapper
55-
tooltipContent={
56-
isDisabled
57-
? i18n.translate('xpack.lens.shared.legendVisibleTooltip', {
58-
defaultMessage: 'Requires legend to be shown',
59-
})
60-
: i18n.translate('xpack.lens.shared.legendInsideTooltip', {
61-
defaultMessage: 'Requires legend to be located inside visualization',
62-
})
63-
}
64-
condition={isDisabled || isLegendOutside}
65-
position="top"
66-
delay="regular"
67-
display="block"
68-
>
69-
<EuiFieldNumber
70-
data-test-subj="lens-legend-location-columns-input"
71-
value={inputValue}
72-
min={1}
73-
max={5}
74-
compressed
75-
disabled={isDisabled || isLegendOutside}
76-
onChange={(e) => {
77-
handleInputChange(Number(e.target.value));
78-
}}
79-
step={1}
80-
/>
81-
</TooltipWrapper>
50+
<EuiFieldNumber
51+
data-test-subj="lens-legend-location-columns-input"
52+
value={inputValue}
53+
min={1}
54+
max={5}
55+
compressed
56+
onChange={(e) => {
57+
handleInputChange(Number(e.target.value));
58+
}}
59+
step={1}
60+
/>
8261
</EuiFormRow>
8362
);
8463
};

x-pack/plugins/lens/public/shared_components/legend_location_settings.test.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ describe('Legend Location Settings', () => {
3232
expect(props.onPositionChange).toHaveBeenCalled();
3333
});
3434

35-
it('should disable the position group if isDisabled prop is true', () => {
35+
it('should hide the position group if isDisabled prop is true', () => {
3636
const component = shallow(<LegendLocationSettings {...props} isDisabled />);
37-
expect(
38-
component.find('[data-test-subj="lens-legend-position-btn"]').prop('isDisabled')
39-
).toEqual(true);
37+
expect(component.exists('[data-test-subj="lens-legend-position-btn"]')).toEqual(false);
4038
});
4139

4240
it('should hide the position button group if location inside is given', () => {
@@ -104,18 +102,14 @@ describe('Legend Location Settings', () => {
104102
expect(newProps.onAlignmentChange).toHaveBeenCalled();
105103
});
106104

107-
it('should disable the components when is Disabled is true', () => {
105+
it('should hide the components when is Disabled is true', () => {
108106
const newProps = {
109107
...props,
110108
location: 'inside',
111109
isDisabled: true,
112110
} as LegendLocationSettingsProps;
113111
const component = shallow(<LegendLocationSettings {...newProps} />);
114-
expect(
115-
component.find('[data-test-subj="lens-legend-location-btn"]').prop('isDisabled')
116-
).toEqual(true);
117-
expect(
118-
component.find('[data-test-subj="lens-legend-inside-alignment-btn"]').prop('isDisabled')
119-
).toEqual(true);
112+
expect(component.exists('[data-test-subj="lens-legend-location-btn"]')).toEqual(false);
113+
expect(component.exists('[data-test-subj="lens-legend-inside-alignment-btn"]')).toEqual(false);
120114
});
121115
});

x-pack/plugins/lens/public/shared_components/legend_location_settings.tsx

Lines changed: 48 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import React from 'react';
99
import { i18n } from '@kbn/i18n';
1010
import { EuiFormRow, EuiButtonGroup } from '@elastic/eui';
1111
import { VerticalAlignment, HorizontalAlignment, Position } from '@elastic/charts';
12-
import { TooltipWrapper } from './tooltip_wrapper';
1312

1413
export interface LegendLocationSettingsProps {
1514
/**
@@ -151,6 +150,7 @@ export const LegendLocationSettings: React.FunctionComponent<LegendLocationSetti
151150
const alignment = `${verticalAlignment || VerticalAlignment.Top}_${
152151
horizontalAlignment || HorizontalAlignment.Right
153152
}`;
153+
if (isDisabled) return null;
154154
return (
155155
<>
156156
{location && (
@@ -160,32 +160,22 @@ export const LegendLocationSettings: React.FunctionComponent<LegendLocationSetti
160160
defaultMessage: 'Location',
161161
})}
162162
>
163-
<TooltipWrapper
164-
tooltipContent={i18n.translate('xpack.lens.shared.legendVisibleTooltip', {
165-
defaultMessage: 'Requires legend to be shown',
163+
<EuiButtonGroup
164+
isFullWidth
165+
legend={i18n.translate('xpack.lens.shared.legendLocationLabel', {
166+
defaultMessage: 'Location',
166167
})}
167-
condition={isDisabled}
168-
position="top"
169-
delay="regular"
170-
display="block"
171-
>
172-
<EuiButtonGroup
173-
isFullWidth
174-
legend={i18n.translate('xpack.lens.shared.legendLocationLabel', {
175-
defaultMessage: 'Location',
176-
})}
177-
data-test-subj="lens-legend-location-btn"
178-
name="legendLocation"
179-
buttonSize="compressed"
180-
options={locationOptions}
181-
isDisabled={isDisabled}
182-
idSelected={locationOptions.find(({ value }) => value === location)!.id}
183-
onChange={(optionId) => {
184-
const newLocation = locationOptions.find(({ id }) => id === optionId)!.value;
185-
onLocationChange(newLocation);
186-
}}
187-
/>
188-
</TooltipWrapper>
168+
data-test-subj="lens-legend-location-btn"
169+
name="legendLocation"
170+
buttonSize="compressed"
171+
options={locationOptions}
172+
isDisabled={isDisabled}
173+
idSelected={locationOptions.find(({ value }) => value === location)!.id}
174+
onChange={(optionId) => {
175+
const newLocation = locationOptions.find(({ id }) => id === optionId)!.value;
176+
onLocationChange(newLocation);
177+
}}
178+
/>
189179
</EuiFormRow>
190180
)}
191181
<EuiFormRow
@@ -196,62 +186,42 @@ export const LegendLocationSettings: React.FunctionComponent<LegendLocationSetti
196186
>
197187
<>
198188
{(!location || location === 'outside') && (
199-
<TooltipWrapper
200-
tooltipContent={i18n.translate('xpack.lens.shared.legendVisibleTooltip', {
201-
defaultMessage: 'Requires legend to be shown',
189+
<EuiButtonGroup
190+
legend={i18n.translate('xpack.lens.shared.legendAlignmentLabel', {
191+
defaultMessage: 'Alignment',
202192
})}
203-
condition={isDisabled}
204-
position="top"
205-
delay="regular"
206-
display="block"
207-
>
208-
<EuiButtonGroup
209-
legend={i18n.translate('xpack.lens.shared.legendAlignmentLabel', {
210-
defaultMessage: 'Alignment',
211-
})}
212-
isDisabled={isDisabled}
213-
data-test-subj="lens-legend-position-btn"
214-
name="legendPosition"
215-
buttonSize="compressed"
216-
options={toggleButtonsIcons}
217-
idSelected={position || Position.Right}
218-
onChange={onPositionChange}
219-
isIconOnly
220-
/>
221-
</TooltipWrapper>
193+
isDisabled={isDisabled}
194+
data-test-subj="lens-legend-position-btn"
195+
name="legendPosition"
196+
buttonSize="compressed"
197+
options={toggleButtonsIcons}
198+
idSelected={position || Position.Right}
199+
onChange={onPositionChange}
200+
isIconOnly
201+
/>
222202
)}
223203
{location === 'inside' && (
224-
<TooltipWrapper
225-
tooltipContent={i18n.translate('xpack.lens.shared.legendVisibleTooltip', {
226-
defaultMessage: 'Requires legend to be shown',
204+
<EuiButtonGroup
205+
legend={i18n.translate('xpack.lens.shared.legendInsideLocationAlignmentLabel', {
206+
defaultMessage: 'Alignment',
227207
})}
228-
condition={isDisabled}
229-
position="top"
230-
delay="regular"
231-
display="block"
232-
>
233-
<EuiButtonGroup
234-
legend={i18n.translate('xpack.lens.shared.legendInsideLocationAlignmentLabel', {
235-
defaultMessage: 'Alignment',
236-
})}
237-
type="single"
238-
data-test-subj="lens-legend-inside-alignment-btn"
239-
name="legendInsideAlignment"
240-
buttonSize="compressed"
241-
isDisabled={isDisabled}
242-
options={locationAlignmentButtonsIcons}
243-
idSelected={
244-
locationAlignmentButtonsIcons.find(({ value }) => value === alignment)!.id
245-
}
246-
onChange={(optionId) => {
247-
const newAlignment = locationAlignmentButtonsIcons.find(
248-
({ id }) => id === optionId
249-
)!.value;
250-
onAlignmentChange(newAlignment);
251-
}}
252-
isIconOnly
253-
/>
254-
</TooltipWrapper>
208+
type="single"
209+
data-test-subj="lens-legend-inside-alignment-btn"
210+
name="legendInsideAlignment"
211+
buttonSize="compressed"
212+
isDisabled={isDisabled}
213+
options={locationAlignmentButtonsIcons}
214+
idSelected={
215+
locationAlignmentButtonsIcons.find(({ value }) => value === alignment)!.id
216+
}
217+
onChange={(optionId) => {
218+
const newAlignment = locationAlignmentButtonsIcons.find(
219+
({ id }) => id === optionId
220+
)!.value;
221+
onAlignmentChange(newAlignment);
222+
}}
223+
isIconOnly
224+
/>
255225
)}
256226
</>
257227
</EuiFormRow>

x-pack/plugins/lens/public/shared_components/legend_settings_popover.test.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('Legend Settings', () => {
5656
});
5757

5858
it('should have default the max lines input to 1 when no value is given', () => {
59-
const component = shallow(<LegendSettingsPopover {...props} />);
59+
const component = shallow(<LegendSettingsPopover {...props} shouldTruncate />);
6060
expect(component.find(MaxLinesInput).prop('value')).toEqual(1);
6161
});
6262

@@ -74,9 +74,9 @@ describe('Legend Settings', () => {
7474
).toEqual(false);
7575
});
7676

77-
it('should have disabled the max lines input when truncate is set to false', () => {
77+
it('should hide the max lines input when truncate is set to false', () => {
7878
const component = shallow(<LegendSettingsPopover {...props} shouldTruncate={false} />);
79-
expect(component.find(MaxLinesInput).prop('isDisabled')).toEqual(true);
79+
expect(component.exists(MaxLinesInput)).toEqual(false);
8080
});
8181

8282
it('should have called the onTruncateLegendChange function on truncate switch change', () => {
@@ -115,12 +115,10 @@ describe('Legend Settings', () => {
115115
expect(nestedProps.onNestedLegendChange).toHaveBeenCalled();
116116
});
117117

118-
it('should disable switch group on hide mode', () => {
118+
it('should hide switch group on hide mode', () => {
119119
const component = shallow(
120120
<LegendSettingsPopover {...props} mode="hide" renderNestedLegendSwitch />
121121
);
122-
expect(component.find('[data-test-subj="lens-legend-nested-switch"]').prop('disabled')).toEqual(
123-
true
124-
);
122+
expect(component.exists('[data-test-subj="lens-legend-nested-switch"]')).toEqual(false);
125123
});
126124
});

0 commit comments

Comments
 (0)