-
Notifications
You must be signed in to change notification settings - Fork 188
PMM-14651 Improve & fix dashboard menu variables sharing #4857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
matejkubinec
merged 8 commits into
v3
from
PMM-14651-menu-variables-sharing-improvement
Jan 12, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2341a91
PMM-14651 Improve & fix dashboard menu variables sharing
matejkubinec c4b6632
Merge branch 'v3' into PMM-14651-menu-variables-sharing-improvement
matejkubinec e37ddf8
PMM-14651 Add unit tests
matejkubinec 8d3939f
Merge branch 'v3' into PMM-14651-menu-variables-sharing-improvement
matejkubinec b292c55
Merge branch 'v3' of github.com:percona/pmm into PMM-14651-menu-varia…
matejkubinec 632979b
PMM-14651 Improve db type parsing
matejkubinec 4a97eeb
Merge branch 'v3' into PMM-14651-menu-variables-sharing-improvement
matejkubinec b4cd180
Merge branch 'v3' of github.com:percona/pmm into PMM-14651-menu-varia…
matejkubinec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { describe, it, expect, beforeEach, jest } from '@jest/globals'; | ||
| import { getLinkWithVariables, shouldIncludeVars } from './variables'; | ||
|
|
||
| const prefixes = { | ||
| grafana: '/graph', | ||
| pmm: '/pmm-ui/next', | ||
| }; | ||
|
|
||
| const dashboards = { | ||
| pg: '/d/postgresql-instance-overview/postgresql-instances-overview', | ||
| pgSummary: '/d/postgresql-instance-summary/postgresql-instance-summary', | ||
| mysql: '/d/mysql-instance-summary/mysql-instance-summary', | ||
| node: '/d/node-overview/node-overview', | ||
| }; | ||
|
|
||
| const mockLocation = (pathname: string) => { | ||
| Object.defineProperty(window, 'location', { | ||
| value: { | ||
| pathname, | ||
| origin: 'https://percona.com', | ||
| }, | ||
| writable: true, | ||
| }); | ||
| }; | ||
|
|
||
| describe('getLinkWithVariables', () => { | ||
| beforeEach(() => { | ||
| mockLocation('/percona.com'); | ||
| }); | ||
|
|
||
| it('should return the same url if it is not a dashboard url', () => { | ||
| const url = 'https://percona.com'; | ||
| const result = getLinkWithVariables(url); | ||
| expect(result).toBe(url); | ||
| }); | ||
| }); | ||
|
|
||
| describe('shouldIncludeVars', () => { | ||
| it('should handle different prefixes', () => { | ||
| const urls = [ | ||
| dashboards.pg, | ||
| `${prefixes.grafana}${dashboards.pg}`, | ||
| `${prefixes.pmm}${prefixes.grafana}${dashboards.pg}`, | ||
| ]; | ||
|
|
||
| urls.forEach((url) => { | ||
| mockLocation(dashboards.pg); | ||
| const result = shouldIncludeVars(url); | ||
| expect(result).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| it('should return true if the db type matches the current one', () => { | ||
| mockLocation(dashboards.pg); | ||
| const result = shouldIncludeVars(dashboards.pgSummary); | ||
| expect(result).toBe(true); | ||
| }); | ||
|
|
||
| it('should return true if the target db type is node', () => { | ||
| mockLocation(dashboards.pg); | ||
| const result = shouldIncludeVars(dashboards.node); | ||
| expect(result).toBe(true); | ||
| }); | ||
|
|
||
| it('should return false if the target db type is not the same as the current one', () => { | ||
| mockLocation(dashboards.pg); | ||
| const result = shouldIncludeVars(dashboards.mysql); | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it('should return false if current db type is node and target db type is not node', () => { | ||
| mockLocation(dashboards.node); | ||
| const result = shouldIncludeVars(dashboards.pg); | ||
| expect(result).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Line 7-11
export const shouldIncludeVars = (url: string): boolean => {
const currentDB = getDbType(window.location.pathname);
const targetDB = getDbType(url);
return (currentDB !== undefined && currentDB === targetDB) || targetDB === 'node';
// ^^^^^^^^^^^^^^^^^^^^^^^^ This check doesn't work as intended
};
// Line 13-23
const getDbType = (url: string): string => {
// ^^^^^^ Always returns string, never undefined
// ...
return dashboardUid.includes('-') ? dashboardUid.split('-')[0] : dashboardUid;
};
The thing is: getDbType() always returns a string (never undefined), but on line 10 shouldIncludeVars() checks currentDB !== undefined. This check will always be true, so it doesn't really do anything.
Maybe what you meant was:
// Line 13
const getDbType = (url: string): string | undefined => {
const pathname = new URL(url, window.location.origin).pathname;
const dashboardUid = pathname
.replace('/pmm-ui', '')
.replace('/next', '')
.replace('/graph', '')
.replace('/d/', '')
.split('/')[0];
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.