mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Field color: Filter out editor options that have excludeFromPicker=true (#79907)
* filter color palette options to to remove excluded items * add test * make betterer happy * remove unused
This commit is contained in:
parent
120e9044c7
commit
63ac32a4ae
54
public/app/core/components/OptionsUI/fieldColor.test.tsx
Normal file
54
public/app/core/components/OptionsUI/fieldColor.test.tsx
Normal file
@ -0,0 +1,54 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import React from 'react';
|
||||
|
||||
import { FieldColorEditor } from './fieldColor';
|
||||
|
||||
const testRegistryItems = [
|
||||
{
|
||||
id: 'foo',
|
||||
name: 'Foo',
|
||||
description: 'This option will appear in the picker',
|
||||
getCalculator: () => 'red',
|
||||
},
|
||||
{
|
||||
id: 'bar',
|
||||
name: 'Bar',
|
||||
description: 'This option will also appear in the picker',
|
||||
getCalculator: () => 'green',
|
||||
},
|
||||
{
|
||||
id: 'baz',
|
||||
name: 'Baz',
|
||||
description: 'This option will not appear in the picker',
|
||||
getCalculator: () => 'blue',
|
||||
excludeFromPicker: true,
|
||||
},
|
||||
];
|
||||
|
||||
jest.mock('@grafana/data', () => {
|
||||
const actualData = jest.requireActual('@grafana/data');
|
||||
return {
|
||||
...actualData,
|
||||
fieldColorModeRegistry: new actualData.Registry(() => testRegistryItems),
|
||||
};
|
||||
});
|
||||
|
||||
describe('fieldColor', () => {
|
||||
it('filters out registry options with excludeFromPicker=true', async () => {
|
||||
render(
|
||||
<FieldColorEditor
|
||||
value={undefined}
|
||||
onChange={() => {}}
|
||||
id="test"
|
||||
data-testid="test"
|
||||
context={{ data: [] }}
|
||||
item={testRegistryItems[0]}
|
||||
/>
|
||||
);
|
||||
await userEvent.type(screen.getByRole('combobox'), '{arrowdown}');
|
||||
expect(screen.getByText(/^Foo/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/^Bar/i)).toBeInTheDocument();
|
||||
expect(screen.queryByText(/^Baz/i)).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
@ -28,20 +28,22 @@ export const FieldColorEditor = ({ value, onChange, item, id }: Props) => {
|
||||
? fieldColorModeRegistry.list()
|
||||
: fieldColorModeRegistry.list().filter((m) => !m.isByValue);
|
||||
|
||||
const options = availableOptions.map((mode) => {
|
||||
let suffix = mode.isByValue ? ' (by value)' : '';
|
||||
const options = availableOptions
|
||||
.filter((mode) => !mode.excludeFromPicker)
|
||||
.map((mode) => {
|
||||
let suffix = mode.isByValue ? ' (by value)' : '';
|
||||
|
||||
return {
|
||||
value: mode.id,
|
||||
label: `${mode.name}${suffix}`,
|
||||
description: mode.description,
|
||||
isContinuous: mode.isContinuous,
|
||||
isByValue: mode.isByValue,
|
||||
component() {
|
||||
return <FieldColorModeViz mode={mode} theme={theme} />;
|
||||
},
|
||||
};
|
||||
});
|
||||
return {
|
||||
value: mode.id,
|
||||
label: `${mode.name}${suffix}`,
|
||||
description: mode.description,
|
||||
isContinuous: mode.isContinuous,
|
||||
isByValue: mode.isByValue,
|
||||
component() {
|
||||
return <FieldColorModeViz mode={mode} theme={theme} />;
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const onModeChange = (newMode: SelectableValue<string>) => {
|
||||
onChange({
|
||||
|
Loading…
Reference in New Issue
Block a user