Skip to content

Commit

Permalink
fix(explore): Enable saving metric after changing title (#23020)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje committed Feb 7, 2023
1 parent 493181c commit 98bf878
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const propTypes = {
savedMetric: savedMetricType,
datasource: PropTypes.object,
isNewMetric: PropTypes.bool,
isLabelModified: PropTypes.bool,
};

const defaultProps = {
Expand Down Expand Up @@ -299,6 +300,7 @@ export default class AdhocMetricEditPopover extends React.PureComponent {
onResize,
datasource,
isNewMetric,
isLabelModified,
...popoverProps
} = this.props;
const { adhocMetric, savedMetric } = this.state;
Expand Down Expand Up @@ -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) ||
(!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
);
Expand Down

0 comments on commit 98bf878

Please sign in to comment.