-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace legend width setting input with select, make it disabled for …
…horizontal legends and move number of columns setting outside of legend location settings component to place legend width setting above
- Loading branch information
1 parent
3db0748
commit 91840fd
Showing
6 changed files
with
193 additions
and
208 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
x-pack/plugins/lens/public/shared_components/columns_number_setting.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { mountWithIntl as mount } from '@kbn/test-jest-helpers'; | ||
import { ColumnsNumberSetting } from './columns_number_setting'; | ||
|
||
describe('Columns Number Setting', () => { | ||
it('should have default the columns input to 1 when no value is given', () => { | ||
const component = mount(<ColumnsNumberSetting isDisabled={false} isLegendOutside={false} />); | ||
expect( | ||
component.find('[data-test-subj="lens-legend-location-columns-input"]').at(0).prop('value') | ||
).toEqual(1); | ||
}); | ||
}); |
84 changes: 84 additions & 0 deletions
84
x-pack/plugins/lens/public/shared_components/columns_number_setting.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiFieldNumber, EuiFormRow } from '@elastic/eui'; | ||
import { useDebouncedValue } from './debounced_value'; | ||
import { TooltipWrapper } from './tooltip_wrapper'; | ||
|
||
export const DEFAULT_FLOATING_COLUMNS = 1; | ||
|
||
interface ColumnsNumberSettingProps { | ||
/** | ||
* Sets the number of columns for legend inside chart | ||
*/ | ||
floatingColumns?: number; | ||
/** | ||
* Callback on horizontal alignment option change | ||
*/ | ||
onFloatingColumnsChange?: (value: number) => void; | ||
/** | ||
* Flag to disable the location settings | ||
*/ | ||
isDisabled: boolean; | ||
/** | ||
* Indicates if legend is located outside | ||
*/ | ||
isLegendOutside: boolean; | ||
} | ||
|
||
export const ColumnsNumberSetting = ({ | ||
floatingColumns, | ||
onFloatingColumnsChange = () => {}, | ||
isDisabled, | ||
isLegendOutside, | ||
}: ColumnsNumberSettingProps) => { | ||
const { inputValue, handleInputChange } = useDebouncedValue({ | ||
value: floatingColumns ?? DEFAULT_FLOATING_COLUMNS, | ||
onChange: onFloatingColumnsChange, | ||
}); | ||
|
||
return ( | ||
<EuiFormRow | ||
label={i18n.translate('xpack.lens.shared.legendInsideColumnsLabel', { | ||
defaultMessage: 'Number of columns', | ||
})} | ||
fullWidth | ||
display="columnCompressed" | ||
> | ||
<TooltipWrapper | ||
tooltipContent={ | ||
isDisabled | ||
? i18n.translate('xpack.lens.shared.legendVisibleTooltip', { | ||
defaultMessage: 'Requires legend to be shown', | ||
}) | ||
: i18n.translate('xpack.lens.shared.legendInsideTooltip', { | ||
defaultMessage: 'Requires legend to be located inside visualization', | ||
}) | ||
} | ||
condition={isDisabled || isLegendOutside} | ||
position="top" | ||
delay="regular" | ||
display="block" | ||
> | ||
<EuiFieldNumber | ||
data-test-subj="lens-legend-location-columns-input" | ||
value={inputValue} | ||
min={1} | ||
max={5} | ||
compressed | ||
disabled={isDisabled || isLegendOutside} | ||
onChange={(e) => { | ||
handleInputChange(Number(e.target.value)); | ||
}} | ||
step={1} | ||
/> | ||
</TooltipWrapper> | ||
</EuiFormRow> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.