fix(explore): Enable saving metric after changing title (#23020)

This commit is contained in:
Kamil Gabryjelski 2023-02-07 23:23:52 +01:00 committed by GitHub
parent 493181c977
commit 98bf878d6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 0 deletions

View File

@ -162,6 +162,16 @@ test('Clicking on "Save" should call onChange and onClose for new metric', () =>
expect(props.onClose).toBeCalledTimes(1);
});
test('Clicking on "Save" should call onChange and onClose for new title', () => {
const props = createProps();
render(<AdhocMetricEditPopover {...props} isLabelModified />);
expect(props.onChange).toBeCalledTimes(0);
expect(props.onClose).toBeCalledTimes(0);
userEvent.click(screen.getByRole('button', { name: 'Save' }));
expect(props.onChange).toBeCalledTimes(1);
expect(props.onClose).toBeCalledTimes(1);
});
test('Should switch to tab:Simple', () => {
const props = createProps();
props.getCurrentTab.mockImplementation(tab => {

View File

@ -62,6 +62,7 @@ const propTypes = {
savedMetric: savedMetricType,
datasource: PropTypes.object,
isNewMetric: PropTypes.bool,
isLabelModified: PropTypes.bool,
};
const defaultProps = {
@ -299,6 +300,7 @@ export default class AdhocMetricEditPopover extends React.PureComponent {
onResize,
datasource,
isNewMetric,
isLabelModified,
...popoverProps
} = this.props;
const { adhocMetric, savedMetric } = this.state;
@ -345,6 +347,7 @@ export default class AdhocMetricEditPopover extends React.PureComponent {
const stateIsValid = adhocMetric.isValid() || savedMetric?.metric_name;
const hasUnsavedChanges =
isLabelModified ||
isNewMetric ||
!adhocMetric.equals(propsAdhocMetric) ||
(!(

View File

@ -225,6 +225,10 @@ class AdhocMetricPopoverTrigger extends React.PureComponent<
getCurrentTab={this.getCurrentTab}
getCurrentLabel={this.getCurrentLabel}
isNewMetric={this.props.isNew}
isLabelModified={
this.state.labelModified &&
adhocMetricLabel !== this.state.title.label
}
/>
</ExplorePopoverContent>
);