Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Pre-Selection for multi selection elements #474

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features / Enhancements

- Added Expandable Editors (#472)
- Updated Pre-Selection for multi selection elements (#474)

## 4.3.1 (2024-08-16)

Expand Down
77 changes: 77 additions & 0 deletions src/components/FormPanel/FormPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,83 @@ describe('Panel', () => {
);
});

it('Should update elements with query result for multiselect elements', async () => {
/**
* Render
*/
await act(async () => {
render(
getComponent({
options: {
initial: {
method: RequestMethod.QUERY,
},
elements: [
{
...FORM_ELEMENT_DEFAULT,
type: FormElementType.CHECKBOX_LIST,
id: 'mapped',
queryField: {
refId: 'A',
value: 'metric',
},
},
{
...FORM_ELEMENT_DEFAULT,
id: 'unmapped',
queryField: undefined,
},
],
},
props: {
data: {
state: LoadingState.Done,
series: [
toDataFrame({
fields: [
{
name: 'metric',
values: ['metricA1', 'metricA2'],
},
],
refId: 'A',
}),
toDataFrame({
fields: [
{
name: 'metric',
values: ['metricB1', 'metricB2'],
},
],
refId: 'B',
}),
],
},
},
})
);

await waitFor(() => expect(selectors.loadingBar(true)).not.toBeInTheDocument());
});

expect(FormElements).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
elements: expect.arrayContaining([
expect.objectContaining({
id: 'mapped',
value: ['metricA1', 'metricA2'],
}),
expect.objectContaining({
id: 'unmapped',
value: '',
}),
]),
}),
expect.anything()
);
});

it('Should not update elements if no query result', async () => {
/**
* Render
Expand Down
7 changes: 7 additions & 0 deletions src/components/FormPanel/FormPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ export const FormPanel: React.FC<Props> = ({
*/
const values = getFieldValues(field);

/**
* Supports multi values
*/
if (element.type === FormElementType.CHECKBOX_LIST || element.type === FormElementType.MULTISELECT) {
return convertToElementValue(element, values);
}

return convertToElementValue(element, values[values.length - 1]);
}

Expand Down
Loading