Skip to content

Commit

Permalink
[Discover] field formatter truncated hex color pickers (#201676)
Browse files Browse the repository at this point in the history
## Summary

Updates data view color field formatter to allow
easier hex color entry (the UI is truncated today)
  • Loading branch information
ghudgins authored Nov 26, 2024
1 parent 9addb53 commit 398dcbf
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import React from 'react';
import { shallowWithI18nProvider } from '@kbn/test-jest-helpers';
import { shallowWithI18nProvider, mountWithI18nProvider } from '@kbn/test-jest-helpers';

import { ColorFormatEditor } from './color';
import { FieldFormat, DEFAULT_CONVERTER_COLOR } from '@kbn/field-formats-plugin/common';
Expand All @@ -28,6 +28,21 @@ describe('ColorFormatEditor', () => {
expect(ColorFormatEditor.formatId).toEqual('color');
});

it('renders the color swatch icon inside the button', () => {
const component = mountWithI18nProvider(
<ColorFormatEditor
fieldType={'color'}
format={format as unknown as FieldFormat}
formatParams={formatParams}
onChange={onChange}
onError={onError}
/>
);

const button = component.find('[data-test-subj="buttonColorSwatchIcon"]').at(0);
expect(button.exists()).toBe(true);
});

it('should render string type normally (regex field)', async () => {
const component = shallowWithI18nProvider(
<ColorFormatEditor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@

import React, { Fragment } from 'react';

import { EuiBasicTable, EuiButton, EuiColorPicker, EuiFieldText, EuiSpacer } from '@elastic/eui';
import {
EuiBasicTable,
EuiButton,
EuiColorPicker,
EuiIcon,
EuiFieldText,
EuiSpacer,
} from '@elastic/eui';

import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
Expand Down Expand Up @@ -156,6 +163,32 @@ export class ColorFormatEditor extends DefaultFormatEditor<ColorFormatEditorForm
item.index
);
}}
button={
<EuiButton
minWidth="false"
iconType="lettering"
color="text"
onClick={() => {}}
aria-label={i18n.translate(
'indexPatternFieldEditor.color.letteringButtonAriaLabel',
{
defaultMessage: 'Select a text color for item {index}',
values: {
index: item.index,
},
}
)}
>
<EuiIcon
aria-label={color}
color={color}
size="l"
type="stopFilled"
data-test-subj={'buttonColorSwatchIcon'}
/>
</EuiButton>
}
secondaryInputDisplay="bottom"
/>
);
},
Expand All @@ -181,6 +214,32 @@ export class ColorFormatEditor extends DefaultFormatEditor<ColorFormatEditorForm
item.index
);
}}
button={
<EuiButton
minWidth="false"
iconType="color"
color="text"
onClick={() => {}}
aria-label={i18n.translate(
'indexPatternFieldEditor.color.letteringButtonAriaLabel',
{
defaultMessage: 'Select a background color for item {index}',
values: {
index: item.index,
},
}
)}
>
<EuiIcon
aria-label={color}
color={color}
size="l"
type="stopFilled"
data-test-subj={'buttonColorSwatchIcon'}
/>
</EuiButton>
}
secondaryInputDisplay="bottom"
/>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
beforeSave: async () => {
await testSubjects.click('colorEditorAddColor');
await testSubjects.setValue('~colorEditorKeyPattern', 'red');
await testSubjects.setValue('~colorEditorColorPicker', '#ffffff');
await testSubjects.setValue('~colorEditorBackgroundPicker', '#ff0000');
await testSubjects.click('~colorEditorColorPicker');
await testSubjects.setValue('~euiColorPickerInput_bottom', '#ffffff');
await testSubjects.click('~colorEditorBackgroundPicker');
await testSubjects.setValue('~euiColorPickerInput_bottom', '#ff0000');
},
expect: async (renderedValueContainer) => {
const span = await renderedValueContainer.findByTagName('span');
Expand Down
6 changes: 4 additions & 2 deletions test/functional/services/field_editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ export class FieldEditorService extends FtrService {
public async setColorFormat(value: string, color: string, backgroundColor?: string) {
await this.testSubjects.click('colorEditorAddColor');
await this.testSubjects.setValue('~colorEditorKeyPattern', value);
await this.testSubjects.setValue('~colorEditorColorPicker', color);
await this.testSubjects.click('~colorEditorColorPicker');
await this.testSubjects.setValue('~euiColorPickerInput_bottom', color);
if (backgroundColor) {
await this.testSubjects.setValue('~colorEditorBackgroundPicker', backgroundColor);
await this.testSubjects.click('~colorEditorBackgroundPicker');
await this.testSubjects.setValue('~euiColorPickerInput_bottom', backgroundColor);
}
}

Expand Down

0 comments on commit 398dcbf

Please sign in to comment.