Skip to content

Commit

Permalink
PMM-13122 Include variables in main menus dashboard links (#752)
Browse files Browse the repository at this point in the history
* PMM-13122 Include variables in dashboard links in main menu

* PMM-13122 Pass variables only to same db type dashboards
  • Loading branch information
matejkubinec authored Jun 19, 2024
1 parent fe5d27d commit 5ea2ec4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from 'react';
import { GrafanaTheme2 } from '@grafana/data';
import { selectors } from '@grafana/e2e-selectors';
import { Icon, Link, useTheme2 } from '@grafana/ui';
import { useLinkWithVariables } from 'app/percona/shared/helpers/navigation';

export interface Props {
children: React.ReactNode;
Expand All @@ -17,6 +18,8 @@ export function MegaMenuItemText({ children, isActive, onClick, target, url }: P
const theme = useTheme2();
const styles = getStyles(theme, isActive);
const LinkComponent = !target && url.startsWith('/') ? Link : 'a';
// @PERCONA
const urlWithVariables = useLinkWithVariables(url);

const linkContent = (
<div className={styles.linkContent}>
Expand All @@ -35,7 +38,7 @@ export function MegaMenuItemText({ children, isActive, onClick, target, url }: P
className={cx(styles.container, {
[styles.containerActive]: isActive,
})}
href={url}
href={urlWithVariables}
target={target}
onClick={onClick}
>
Expand Down
21 changes: 21 additions & 0 deletions public/app/percona/shared/helpers/navigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getLinkSrv } from 'app/features/panel/panellinks/link_srv';

export const useLinkWithVariables = (url?: string) => {
if (url?.match('/d/')) {
return getLinkSrv().getLinkUrl({
url: url,
keepTime: true,
// Check if the DB type matches the current one used
includeVars: checkDbType(url),
});
} else {
return url ? url : '#';
}
};

const checkDbType = (url: string): boolean => {
const currentDB = window.location.pathname.split('/')[3].split('-')[0];
const urlDB = url.split('/')[3].split('-')[0];

return currentDB === urlDB;
};

0 comments on commit 5ea2ec4

Please sign in to comment.