Skip to content

Commit

Permalink
Merge branch 'main' into feat/migrate-echarts-for-visual-editor
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhail-vl committed Feb 9, 2024
2 parents 5bfc681 + 4700f7d commit 17d99e7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Change Log

## 5.2.0 (2024-02-07)
## 5.2.0 (2024-02-08)

### Features / Enhancements

Expand All @@ -10,6 +10,7 @@
- Update dependencies and Actions (#238)
- Add context parameter to non-visual mode (#245)
- Add refresh function using Application Event Bus (#247)
- Update to disallow to choose already selected fields (#251)

## 5.1.0 (2023-08-11)

Expand Down
3 changes: 2 additions & 1 deletion src/__mocks__/@grafana/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const Select = jest.fn(({ options, onChange, value, isMulti, isClearable, ...res
if (isMulti) {
onChange(options.filter((option: any) => event.target.values.includes(option.value)));
} else {
onChange(options.find((option: any) => option.value === event.target.value));
const option = options.find((option: any) => option.value === event.target.value);
option && onChange(option);
}
}
}}
Expand Down
20 changes: 20 additions & 0 deletions src/components/DatasetEditor/DatasetEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@ describe('Dataset Editor', () => {
expect(selectors.item(true, 'A:Value')).not.toBeInTheDocument();
});

it('Should not allow selecting already selected fields', () => {
const { value, onChange } = createOnChangeHandler([{ name: 'Time', source: 'A' }]);

/**
* Render
*/
render(
getComponent({
value,
onChange,
})
);

/**
* Simulate select option doesn't exist
*/
fireEvent.change(selectors.newItemName(), { target: { value: 'A:Time' } });
expect(selectors.buttonAddNew()).toBeDisabled();
});

/**
* Items order
*/
Expand Down
26 changes: 15 additions & 11 deletions src/components/DatasetEditor/DatasetEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,21 @@ export const DatasetEditor: React.FC<Props> = ({ value, onChange, data }) => {
* Available Field Options
*/
const availableFieldOptions = useMemo(() => {
return data.reduce((acc: SelectableValue[], dataFrame) => {
return acc.concat(
dataFrame.fields.map((field) => ({
value: `${dataFrame.refId}:${field.name}`,
fieldName: field.name,
label: `${dataFrame.refId ? `${dataFrame.refId}:` : ''}${field.name}`,
source: dataFrame.refId,
}))
);
}, []);
}, [data]);
return data
.reduce((acc: SelectableValue[], dataFrame) => {
return acc.concat(
dataFrame.fields.map((field) => ({
value: `${dataFrame.refId}:${field.name}`,
fieldName: field.name,
label: `${dataFrame.refId ? `${dataFrame.refId}:` : ''}${field.name}`,
source: dataFrame.refId,
}))
);
}, [])
.filter((field) => {
return !items.some((item) => item.name === field.fieldName && item.source === field.source);
});
}, [items, data]);

/**
* Add New Item
Expand Down

0 comments on commit 17d99e7

Please sign in to comment.