ReturnToPrevious: Check the state of the RTP feature toggle in the hook (#83087)

This commit is contained in:
Laura Fernández 2024-02-20 15:05:12 +01:00 committed by GitHub
parent 5431c51490
commit c237a39020
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 25 deletions

View File

@ -90,6 +90,10 @@ export class AppChromeService {
}
public setReturnToPrevious = (returnToPrevious: ReturnToPreviousProps) => {
const isReturnToPreviousEnabled = config.featureToggles.returnToPrevious;
if (!isReturnToPreviousEnabled) {
return;
}
const previousPage = this.state.getValue().returnToPrevious;
reportInteraction('grafana_return_to_previous_button_created', {
page: returnToPrevious.href,
@ -101,6 +105,10 @@ export class AppChromeService {
};
public clearReturnToPrevious = (interactionAction: 'clicked' | 'dismissed' | 'auto_dismissed') => {
const isReturnToPreviousEnabled = config.featureToggles.returnToPrevious;
if (!isReturnToPreviousEnabled) {
return;
}
const existingRtp = this.state.getValue().returnToPrevious;
if (existingRtp) {
reportInteraction('grafana_return_to_previous_button_dismissed', {

View File

@ -135,33 +135,22 @@ export const RuleDetailsActionButtons = ({ rule, rulesSource, isViewMode }: Prop
}
if (rule.annotations[Annotation.dashboardUID]) {
const dashboardUID = rule.annotations[Annotation.dashboardUID];
const isReturnToPreviousEnabled = config.featureToggles.returnToPrevious;
if (dashboardUID) {
buttons.push(
config.featureToggles.returnToPrevious ? (
<LinkButton
size="sm"
key="dashboard"
variant="primary"
icon="apps"
href={`d/${encodeURIComponent(dashboardUID)}`}
onClick={() => {
setReturnToPrevious(rule.name);
}}
>
Go to dashboard
</LinkButton>
) : (
<LinkButton
size="sm"
key="dashboard"
variant="primary"
icon="apps"
target="_blank"
href={`d/${encodeURIComponent(dashboardUID)}`}
>
Go to dashboard
</LinkButton>
)
<LinkButton
size="sm"
key="dashboard"
variant="primary"
icon="apps"
target={isReturnToPreviousEnabled ? undefined : '_blank'}
href={`d/${encodeURIComponent(dashboardUID)}`}
onClick={() => {
setReturnToPrevious(rule.name);
}}
>
Go to dashboard
</LinkButton>
);
const panelId = rule.annotations[Annotation.panelID];
if (panelId) {