Fix new metric popover showing previous popover's title (#12385)

This commit is contained in:
Kamil Gabryjelski 2021-01-09 15:05:25 +01:00 committed by GitHub
parent 64b49778c5
commit 14ccbe43b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -26,7 +26,6 @@ const propTypes = {
label: PropTypes.string,
hasCustomLabel: PropTypes.bool,
}),
defaultLabel: PropTypes.string,
onChange: PropTypes.func.isRequired,
};

View File

@ -37,6 +37,7 @@ export type AdhocMetricPopoverTriggerProps = {
export type AdhocMetricPopoverTriggerState = {
popoverVisible: boolean;
title: { label: string; hasCustomLabel: boolean };
labelModified: boolean;
};
class AdhocMetricPopoverTrigger extends React.PureComponent<
@ -55,6 +56,7 @@ class AdhocMetricPopoverTrigger extends React.PureComponent<
label: props.adhocMetric.label,
hasCustomLabel: props.adhocMetric.hasCustomLabel,
},
labelModified: false,
};
}
@ -65,6 +67,7 @@ class AdhocMetricPopoverTrigger extends React.PureComponent<
label: label || this.props.adhocMetric.label,
hasCustomLabel: !!label,
},
labelModified: true,
});
}
@ -74,6 +77,9 @@ class AdhocMetricPopoverTrigger extends React.PureComponent<
closePopover() {
this.togglePopover(false);
this.setState({
labelModified: false,
});
}
togglePopover(visible: boolean) {
@ -84,11 +90,15 @@ class AdhocMetricPopoverTrigger extends React.PureComponent<
render() {
const { adhocMetric } = this.props;
const { label, hasCustomLabel } = adhocMetric;
const title = this.state.labelModified
? this.state.title
: { label, hasCustomLabel };
const overlayContent = (
<AdhocMetricEditPopover
adhocMetric={adhocMetric}
title={this.state.title}
title={title}
columns={this.props.columns}
savedMetrics={this.props.savedMetrics}
savedMetric={this.props.savedMetric}
@ -101,8 +111,7 @@ class AdhocMetricPopoverTrigger extends React.PureComponent<
const popoverTitle = (
<AdhocMetricEditPopoverTitle
title={this.state.title}
defaultLabel={adhocMetric.label}
title={title}
onChange={this.onLabelChange}
/>
);