RepeatRowSelect2: Use Combobox instead of deprecated Select component (#106170)
Actionlint / Lint GitHub Actions files (push) Waiting to run Details
Backend Code Checks / Validate Backend Configs (push) Waiting to run Details
Backend Unit Tests / Grafana (${{ matrix.shard }}) (1/8) (push) Waiting to run Details
Backend Unit Tests / Grafana (${{ matrix.shard }}) (2/8) (push) Waiting to run Details
Backend Unit Tests / Grafana (${{ matrix.shard }}) (3/8) (push) Waiting to run Details
Backend Unit Tests / Grafana (${{ matrix.shard }}) (4/8) (push) Waiting to run Details
Backend Unit Tests / Grafana (${{ matrix.shard }}) (5/8) (push) Waiting to run Details
Backend Unit Tests / Grafana (${{ matrix.shard }}) (6/8) (push) Waiting to run Details
Backend Unit Tests / Grafana (${{ matrix.shard }}) (7/8) (push) Waiting to run Details
Backend Unit Tests / Grafana (${{ matrix.shard }}) (8/8) (push) Waiting to run Details
Backend Unit Tests / Grafana Enterprise (${{ matrix.shard }}) (1/8) (push) Waiting to run Details
Backend Unit Tests / Grafana Enterprise (${{ matrix.shard }}) (2/8) (push) Waiting to run Details
Backend Unit Tests / Grafana Enterprise (${{ matrix.shard }}) (3/8) (push) Waiting to run Details
Backend Unit Tests / Grafana Enterprise (${{ matrix.shard }}) (4/8) (push) Waiting to run Details
Backend Unit Tests / Grafana Enterprise (${{ matrix.shard }}) (5/8) (push) Waiting to run Details
Backend Unit Tests / Grafana Enterprise (${{ matrix.shard }}) (6/8) (push) Waiting to run Details
Backend Unit Tests / Grafana Enterprise (${{ matrix.shard }}) (7/8) (push) Waiting to run Details
Backend Unit Tests / Grafana Enterprise (${{ matrix.shard }}) (8/8) (push) Waiting to run Details
CodeQL checks / Analyze (actions) (push) Waiting to run Details
CodeQL checks / Analyze (go) (push) Waiting to run Details
CodeQL checks / Analyze (javascript) (push) Waiting to run Details
Lint Frontend / Verify i18n (push) Waiting to run Details
Lint Frontend / Lint (push) Waiting to run Details
Lint Frontend / Typecheck (push) Waiting to run Details
Lint Frontend / Betterer (push) Waiting to run Details
golangci-lint / lint-go (push) Waiting to run Details
Crowdin Upload Action / upload-sources-to-crowdin (push) Waiting to run Details
Documentation / Build & Verify Docs (push) Waiting to run Details
End-to-end tests / Build & Package Grafana (push) Waiting to run Details
End-to-end tests / ${{ matrix.suite }} (dashboards-suite) (push) Blocked by required conditions Details
End-to-end tests / ${{ matrix.suite }} (panels-suite) (push) Blocked by required conditions Details
End-to-end tests / ${{ matrix.suite }} (smoke-tests-suite) (push) Blocked by required conditions Details
End-to-end tests / ${{ matrix.suite }} (various-suite) (push) Blocked by required conditions Details
End-to-end tests / ${{ matrix.suite }} (old arch) (old-arch/dashboards-suite) (push) Blocked by required conditions Details
End-to-end tests / ${{ matrix.suite }} (old arch) (old-arch/panels-suite) (push) Blocked by required conditions Details
End-to-end tests / ${{ matrix.suite }} (old arch) (old-arch/smoke-tests-suite) (push) Blocked by required conditions Details
End-to-end tests / ${{ matrix.suite }} (old arch) (old-arch/various-suite) (push) Blocked by required conditions Details
Frontend tests / Unit tests (${{ matrix.chunk }} / 8) (1) (push) Waiting to run Details
Frontend tests / Unit tests (${{ matrix.chunk }} / 8) (2) (push) Waiting to run Details
Frontend tests / Unit tests (${{ matrix.chunk }} / 8) (3) (push) Waiting to run Details
Frontend tests / Unit tests (${{ matrix.chunk }} / 8) (4) (push) Waiting to run Details
Frontend tests / Unit tests (${{ matrix.chunk }} / 8) (5) (push) Waiting to run Details
Frontend tests / Unit tests (${{ matrix.chunk }} / 8) (6) (push) Waiting to run Details
Frontend tests / Unit tests (${{ matrix.chunk }} / 8) (7) (push) Waiting to run Details
Frontend tests / Unit tests (${{ matrix.chunk }} / 8) (8) (push) Waiting to run Details
Integration Tests / Sqlite (${{ matrix.shard }}) (1/8) (push) Waiting to run Details
Integration Tests / Sqlite (${{ matrix.shard }}) (2/8) (push) Waiting to run Details
Integration Tests / Sqlite (${{ matrix.shard }}) (3/8) (push) Waiting to run Details
Integration Tests / Sqlite (${{ matrix.shard }}) (4/8) (push) Waiting to run Details
Integration Tests / Sqlite (${{ matrix.shard }}) (5/8) (push) Waiting to run Details
Integration Tests / Sqlite (${{ matrix.shard }}) (6/8) (push) Waiting to run Details
Integration Tests / Sqlite (${{ matrix.shard }}) (7/8) (push) Waiting to run Details
Integration Tests / Sqlite (${{ matrix.shard }}) (8/8) (push) Waiting to run Details
Integration Tests / MySQL (${{ matrix.shard }}) (1/8) (push) Waiting to run Details
Integration Tests / MySQL (${{ matrix.shard }}) (2/8) (push) Waiting to run Details
Integration Tests / MySQL (${{ matrix.shard }}) (3/8) (push) Waiting to run Details
Integration Tests / MySQL (${{ matrix.shard }}) (4/8) (push) Waiting to run Details
Integration Tests / MySQL (${{ matrix.shard }}) (5/8) (push) Waiting to run Details
Integration Tests / MySQL (${{ matrix.shard }}) (6/8) (push) Waiting to run Details
Integration Tests / MySQL (${{ matrix.shard }}) (7/8) (push) Waiting to run Details
Integration Tests / MySQL (${{ matrix.shard }}) (8/8) (push) Waiting to run Details
Integration Tests / Postgres (${{ matrix.shard }}) (1/8) (push) Waiting to run Details
Integration Tests / Postgres (${{ matrix.shard }}) (2/8) (push) Waiting to run Details
Integration Tests / Postgres (${{ matrix.shard }}) (3/8) (push) Waiting to run Details
Integration Tests / Postgres (${{ matrix.shard }}) (4/8) (push) Waiting to run Details
Integration Tests / Postgres (${{ matrix.shard }}) (5/8) (push) Waiting to run Details
Integration Tests / Postgres (${{ matrix.shard }}) (6/8) (push) Waiting to run Details
Integration Tests / Postgres (${{ matrix.shard }}) (7/8) (push) Waiting to run Details
Integration Tests / Postgres (${{ matrix.shard }}) (8/8) (push) Waiting to run Details
publish-technical-documentation-next / sync (push) Waiting to run Details
Reject GitHub secrets / reject-gh-secrets (push) Waiting to run Details
Run dashboard schema v2 e2e / dashboard-schema-v2-e2e (push) Waiting to run Details
Dispatch sync to mirror / dispatch-job (push) Waiting to run Details
Trivy Scan / trivy-scan (push) Waiting to run Details
publish-kinds-next / main (push) Has been cancelled Details
Verify Storybook / Verify Storybook (push) Has been cancelled Details
trigger-dashboard-search-e2e / trigger-search-e2e (push) Has been cancelled Details

* RepeatRowSelect: Use Combobox instead of deprecated Select component

* Add test (broken)

* Don't disable combobox if repeat is set

* Run i18n-extract

* add mockGetBoundingClientRect to combobox test

---------

Co-authored-by: Sergej-Vlasov <sergej.s.vlasov@gmail.com>
This commit is contained in:
kay delaney 2025-06-10 16:11:20 +01:00 committed by GitHub
parent 34ef571542
commit 1c6e08fa24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 108 additions and 15 deletions

View File

@ -0,0 +1,84 @@
import { render, screen } from '@testing-library/react';
import { useState } from 'react';
import { userEvent } from 'test/test-utils';
import { CustomVariable, SceneVariable, SceneVariableSet } from '@grafana/scenes';
import { DashboardScene } from 'app/features/dashboard-scene/scene/DashboardScene';
import { activateFullSceneTree } from 'app/features/dashboard-scene/utils/test-utils';
import { RepeatRowSelect2 } from './RepeatRowSelect';
async function buildTestScene(variables?: SceneVariable[]) {
const dashboard = new DashboardScene({
uid: 'A',
$variables: new SceneVariableSet({
variables: variables ?? [],
}),
});
activateFullSceneTree(dashboard);
await new Promise((r) => setTimeout(r, 1));
return dashboard;
}
const Wrapper = ({ scene }: { scene: DashboardScene }) => {
const [repeat, setRepeat] = useState<string | undefined>(undefined);
return <RepeatRowSelect2 sceneContext={scene} repeat={repeat} onChange={(newRepeat) => setRepeat(newRepeat)} />;
};
const setup = async (variables?: SceneVariable[]) => {
const scene = await buildTestScene(variables);
return render(<Wrapper scene={scene} />);
};
describe('RepeatRowSelect2', () => {
beforeAll(() => {
const mockGetBoundingClientRect = jest.fn(() => ({
width: 120,
height: 120,
top: 0,
left: 0,
bottom: 0,
right: 0,
}));
Object.defineProperty(Element.prototype, 'getBoundingClientRect', {
value: mockGetBoundingClientRect,
});
});
it('should render correct options', async () => {
const variableA = new CustomVariable({
name: 'testVar',
query: 'test, test2',
value: 'test',
text: 'testVar',
});
const variableB = new CustomVariable({
name: 'otherVar',
query: 'test, test2',
value: 'test',
text: 'otherVar',
});
await setup([variableA, variableB]);
const input = screen.getByRole('combobox');
expect(input).not.toBeDisabled();
expect(input).toHaveProperty('placeholder', 'Choose');
await userEvent.click(input);
expect(await screen.findByText(/Disable repeating/)).toBeInTheDocument();
expect(screen.getByText(/testVar/)).toBeInTheDocument();
expect(screen.getByText(/otherVar/)).toBeInTheDocument();
});
it('should be disabled when there are no template variables', async () => {
await setup();
expect(screen.getByRole('combobox')).toHaveProperty('placeholder', 'No template variables found');
expect(screen.getByRole('combobox')).toBeDisabled();
});
});

View File

@ -3,7 +3,7 @@ import { useCallback, useMemo } from 'react';
import { SelectableValue } from '@grafana/data';
import { useTranslate } from '@grafana/i18n';
import { SceneObject, sceneGraph } from '@grafana/scenes';
import { Select } from '@grafana/ui';
import { Combobox, ComboboxOption, Select } from '@grafana/ui';
import { useSelector } from 'app/types';
import { getLastKey, getVariablesByKey } from '../../../variables/state/selectors';
@ -61,30 +61,38 @@ export const RepeatRowSelect2 = ({ sceneContext, repeat, id, onChange }: Props2)
const variables = sceneVars.useState().variables;
const variableOptions = useMemo(() => {
const options: Array<SelectableValue<string | null>> = variables.map((item) => ({
const options: ComboboxOption[] = variables.map((item) => ({
label: item.state.name,
value: item.state.name,
}));
if (options.length === 0) {
options.unshift({
label: t(
'dashboard.repeat-row-select2.variable-options.label.no-template-variables-found',
'No template variables found'
),
value: null,
});
}
options.unshift({
label: t('dashboard.repeat-row-select2.variable-options.label.disable-repeating', 'Disable repeating'),
value: null,
value: '',
});
return options;
}, [variables, t]);
const onSelectChange = useCallback((option: SelectableValue<string | null>) => onChange(option.value!), [onChange]);
const onSelectChange = useCallback((value: ComboboxOption | null) => value && onChange(value.value), [onChange]);
return <Select inputId={id} value={repeat} onChange={onSelectChange} options={variableOptions} />;
const isDisabled = !repeat && variableOptions.length <= 1;
return (
<Combobox
id={id}
value={repeat}
onChange={onSelectChange}
options={variableOptions}
disabled={isDisabled}
placeholder={
isDisabled
? t(
'dashboard.repeat-row-select2.variable-options.label.no-template-variables-found',
'No template variables found'
)
: t('dashboard.repeat-row-select2.placeholder', 'Choose')
}
/>
);
};

View File

@ -4427,6 +4427,7 @@
}
},
"repeat-row-select2": {
"placeholder": "Choose",
"variable-options": {
"label": {
"disable-repeating": "Disable repeating",