Skip to content

Commit

Permalink
Apply PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stratoula committed Aug 17, 2021
1 parent 91edaff commit bb8e561
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export interface HeatmapLegendConfig {
*/
maxLines?: number;
/**
* Defines the number of lines per legend item
* Defines if the legend items should be truncated
*/
truncate?: boolean;
shouldTruncate?: boolean;
}

export type HeatmapLegendConfigResult = HeatmapLegendConfig & {
Expand Down Expand Up @@ -68,10 +68,10 @@ export const heatmapLegendConfig: ExpressionFunctionDefinition<
defaultMessage: 'Specifies the number of lines per legend item.',
}),
},
truncate: {
shouldTruncate: {
types: ['boolean'],
default: true,
help: i18n.translate('xpack.lens.heatmapChart.legend.truncate.help', {
help: i18n.translate('xpack.lens.heatmapChart.legend.shouldTruncate.help', {
defaultMessage: 'Specifies whether or not the legend items should be truncated.',
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export interface LegendConfig {
*/
maxLines?: number;
/**
* Flag whether the legend is inside the chart
* Flag whether the legend items are truncated or not
*/
truncate?: boolean;
shouldTruncate?: boolean;
}

export type LegendConfigResult = LegendConfig & { type: 'lens_xy_legendConfig' };
Expand Down Expand Up @@ -114,10 +114,10 @@ export const legendConfig: ExpressionFunctionDefinition<
defaultMessage: 'Specifies the number of lines per legend item.',
}),
},
truncate: {
shouldTruncate: {
types: ['boolean'],
default: true,
help: i18n.translate('xpack.lens.xyChart.truncate.help', {
help: i18n.translate('xpack.lens.xyChart.shouldTruncate.help', {
defaultMessage: 'Specifies whether the legend items will be truncated or not',
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export const HeatmapComponent: FC<HeatmapRenderProps> = ({
theme={{
...chartTheme,
legend: {
labelOptions: { maxLines: args.legend.truncate ? args.legend?.maxLines ?? 1 : 0 },
labelOptions: { maxLines: args.legend.shouldTruncate ? args.legend?.maxLines ?? 1 : 0 },
},
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ export const HeatmapToolbar = memo(
legend: { ...state.legend, maxLines: val },
});
}}
truncate={state?.legend.truncate ?? true}
shouldTruncate={state?.legend.shouldTruncate ?? true}
onTruncateLegendChange={() => {
const current = state.legend.truncate ?? true;
const current = state.legend.shouldTruncate ?? true;
setState({
...state,
legend: { ...state.legend, truncate: !current },
legend: { ...state.legend, shouldTruncate: !current },
});
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function exampleState(): HeatmapVisualizationState {
position: Position.Right,
type: LEGEND_FUNCTION,
maxLines: 1,
truncate: true,
shouldTruncate: true,
},
gridConfig: {
type: HEATMAP_GRID_FUNCTION,
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('heatmap', () => {
position: Position.Right,
type: LEGEND_FUNCTION,
maxLines: 1,
truncate: true,
shouldTruncate: true,
},
gridConfig: {
type: HEATMAP_GRID_FUNCTION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function getInitialState(): Omit<HeatmapVisualizationState, 'layerId' | 'layerTy
isVisible: true,
position: Position.Right,
maxLines: 1,
truncate: true,
shouldTruncate: true,
type: LEGEND_FUNCTION,
},
gridConfig: {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/pie_visualization/toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export function PieToolbar(props: VisualizationToolbarProps<PieVisualizationStat
layers: [{ ...layer, nestedLegend: !layer.nestedLegend }],
});
}}
truncate={layer.truncateLegend ?? true}
shouldTruncate={layer.truncateLegend ?? true}
onTruncateLegendChange={() => {
const current = layer.truncateLegend ?? true;
setState({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ describe('Legend Settings', () => {
});

it('should set the truncate switch state when truncate prop value is false', () => {
const component = shallow(<LegendSettingsPopover {...props} truncate={false} />);
const component = shallow(<LegendSettingsPopover {...props} shouldTruncate={false} />);
expect(
component.find('[data-test-subj="lens-legend-truncate-switch"]').prop('checked')
).toEqual(false);
});

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

it('should have called the onTruncateLegendChange function on truncate switch change', () => {
const nestedProps = {
...props,
truncate: true,
shouldTruncate: true,
onTruncateLegendChange: jest.fn(),
};
const component = shallow(<LegendSettingsPopover {...nestedProps} />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export interface LegendSettingsPopoverProps {
/**
* Defines if the legend items will be truncated or not
*/
truncate?: boolean;
shouldTruncate?: boolean;
/**
* Callback on nested switch status change
*/
Expand Down Expand Up @@ -146,13 +146,7 @@ export const MaxLinesInput = ({
const val = Number(e.target.value);
// we want to automatically change the values to the limits
// if the user enters a value that is outside the limits
if (val > MAX_TRUNCATE_LINES) {
handleInputChange(MAX_TRUNCATE_LINES);
} else if (val < MIN_TRUNCATE_LINES) {
handleInputChange(MIN_TRUNCATE_LINES);
} else {
handleInputChange(val);
}
handleInputChange(Math.min(MAX_TRUNCATE_LINES, Math.max(val, MIN_TRUNCATE_LINES)));
}}
/>
);
Expand Down Expand Up @@ -180,7 +174,7 @@ export const LegendSettingsPopover: React.FunctionComponent<LegendSettingsPopove
groupPosition = 'right',
maxLines,
onMaxLinesChange = () => {},
truncate,
shouldTruncate,
onTruncateLegendChange = () => {},
}) => {
return (
Expand Down Expand Up @@ -246,7 +240,7 @@ export const LegendSettingsPopover: React.FunctionComponent<LegendSettingsPopove
data-test-subj="lens-legend-truncate-switch"
showLabel={false}
disabled={mode === 'hide'}
checked={truncate ?? true}
checked={shouldTruncate ?? true}
onChange={onTruncateLegendChange}
/>
</TooltipWrapper>
Expand All @@ -265,18 +259,18 @@ export const LegendSettingsPopover: React.FunctionComponent<LegendSettingsPopove
defaultMessage: 'Requires legend to be shown',
})
: i18n.translate('xpack.lens.shared.legendIsTruncated', {
defaultMessage: 'Requires legend to be truncated',
defaultMessage: 'Requires text to be truncated',
})
}
condition={mode === 'hide' || !truncate}
condition={mode === 'hide' || !shouldTruncate}
position="top"
delay="regular"
display="block"
>
<MaxLinesInput
value={maxLines ?? DEFAULT_TRUNCATE_LINES}
setValue={onMaxLinesChange}
isDisabled={mode === 'hide' || !truncate}
isDisabled={mode === 'hide' || !shouldTruncate}
/>
</TooltipWrapper>
</EuiFormRow>
Expand Down

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

2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/xy_visualization/expression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ export function XYChart({
color: undefined, // removes background for embeddables
},
legend: {
labelOptions: { maxLines: legend.truncate ? legend?.maxLines ?? 1 : 0 },
labelOptions: { maxLines: legend.shouldTruncate ? legend?.maxLines ?? 1 : 0 },
},
}}
baseTheme={chartBaseTheme}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const buildExpression = (
? [Math.min(5, state.legend.floatingColumns)]
: [],
maxLines: state.legend.maxLines ? [state.legend.maxLines] : [],
truncate: [state.legend.truncate ?? true],
shouldTruncate: [state.legend.shouldTruncate ?? true],
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,12 @@ export const XyToolbar = memo(function XyToolbar(props: VisualizationToolbarProp
legend: { ...state.legend, maxLines: val },
});
}}
truncate={state?.legend.truncate ?? true}
shouldTruncate={state?.legend.shouldTruncate ?? true}
onTruncateLegendChange={() => {
const current = state?.legend.truncate ?? true;
const current = state?.legend.shouldTruncate ?? true;
setState({
...state,
legend: { ...state.legend, truncate: !current },
legend: { ...state.legend, shouldTruncate: !current },
});
}}
onPositionChange={(id) => {
Expand Down

0 comments on commit bb8e561

Please sign in to comment.