forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Control round and decimal places in Gauge Visualization when using ag…
…gregate functions like average (elastic#91293) (elastic#93014) * Add field for providing format in percentage mode * Fix CI * Add tests * Fix ci * Fix some remarks * Fix ci * Fix some remarks * Fix ci * Fix width * Fix some remarks * Fix text * Fix i18n * Remove unneeded import * Remove unneeded code Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
9a97394
commit 0772e20
Showing
27 changed files
with
280 additions
and
52 deletions.
There are no files selected for viewing
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
48 changes: 48 additions & 0 deletions
48
src/plugins/vis_default_editor/public/components/options/percentage_mode.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,48 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { mountWithIntl } from '@kbn/test/jest'; | ||
import { PercentageModeOption, PercentageModeOptionProps } from './percentage_mode'; | ||
import { EuiFieldText } from '@elastic/eui'; | ||
|
||
describe('PercentageModeOption', () => { | ||
let props: PercentageModeOptionProps; | ||
let component; | ||
beforeAll(() => { | ||
props = { | ||
percentageMode: true, | ||
setValue: jest.fn(), | ||
}; | ||
}); | ||
|
||
it('renders the EuiFieldText', () => { | ||
component = mountWithIntl(<PercentageModeOption {...props} />); | ||
expect(component.find(EuiFieldText).length).toBe(1); | ||
}); | ||
|
||
it('should call setValue when value was putted in fieldText', () => { | ||
component = mountWithIntl(<PercentageModeOption {...props} />); | ||
const fieldText = component.find(EuiFieldText); | ||
fieldText.props().onChange!({ | ||
target: { | ||
value: '0.0%', | ||
}, | ||
} as React.ChangeEvent<HTMLInputElement>); | ||
|
||
expect(props.setValue).toHaveBeenCalledWith('percentageFormatPattern', '0.0%'); | ||
}); | ||
|
||
it('fieldText should be disabled when percentageMode is false', () => { | ||
props.percentageMode = false; | ||
component = mountWithIntl(<PercentageModeOption {...props} />); | ||
const fieldText = component.find(EuiFieldText); | ||
|
||
expect(fieldText.props().disabled).toBeTruthy(); | ||
}); | ||
}); |
80 changes: 80 additions & 0 deletions
80
src/plugins/vis_default_editor/public/components/options/percentage_mode.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,80 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { EuiFieldText, EuiFormRow, EuiLink } from '@elastic/eui'; | ||
import { SwitchOption } from './switch'; | ||
import { useKibana } from '../../../../kibana_react/public'; | ||
import { UI_SETTINGS } from '../../../../data/public'; | ||
|
||
export interface PercentageModeOptionProps { | ||
setValue: ( | ||
paramName: 'percentageMode' | 'percentageFormatPattern', | ||
value: boolean | string | undefined | ||
) => void; | ||
percentageMode: boolean; | ||
formatPattern?: string; | ||
'data-test-subj'?: string; | ||
} | ||
|
||
function PercentageModeOption({ | ||
'data-test-subj': dataTestSubj, | ||
setValue, | ||
percentageMode, | ||
formatPattern, | ||
}: PercentageModeOptionProps) { | ||
const { services } = useKibana(); | ||
const defaultPattern = services.uiSettings?.get(UI_SETTINGS.FORMAT_PERCENT_DEFAULT_PATTERN); | ||
|
||
return ( | ||
<> | ||
<SwitchOption | ||
data-test-subj={dataTestSubj} | ||
label={i18n.translate('visDefaultEditor.options.percentageMode.percentageModeLabel', { | ||
defaultMessage: 'Percentage mode', | ||
})} | ||
paramName="percentageMode" | ||
value={percentageMode} | ||
setValue={setValue} | ||
/> | ||
<EuiFormRow | ||
fullWidth | ||
label={ | ||
<FormattedMessage | ||
id="visDefaultEditor.options.percentageMode.numeralLabel" | ||
defaultMessage="Format pattern" | ||
/> | ||
} | ||
helpText={ | ||
<EuiLink target="_blank" href="https://adamwdraper.github.io/Numeral-js/"> | ||
<FormattedMessage | ||
id="visDefaultEditor.options.percentageMode.documentationLabel" | ||
defaultMessage="Numeral.js documentation" | ||
/> | ||
</EuiLink> | ||
} | ||
> | ||
<EuiFieldText | ||
fullWidth | ||
compressed | ||
data-test-subj={`${dataTestSubj}FormatPattern`} | ||
value={formatPattern || ''} | ||
placeholder={defaultPattern} | ||
onChange={(e) => { | ||
setValue('percentageFormatPattern', e.target.value ? e.target.value : undefined); | ||
}} | ||
disabled={!percentageMode} | ||
/> | ||
</EuiFormRow> | ||
</> | ||
); | ||
} | ||
|
||
export { PercentageModeOption }; |
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
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
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
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.