-
Notifications
You must be signed in to change notification settings - Fork 186
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
base: v3
Are you sure you want to change the base?
Conversation
|
|
||
| return dashboardUid; | ||
| }; | ||
|
|
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];
// Return undefined if we couldn't extract a valid DB type
if (!dashboardUid || dashboardUid === '') {
return undefined;
}
return dashboardUid.includes('-') ? dashboardUid.split('-')[0] : dashboardUid;
};
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.
| .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.
.split('/')[0]; - Could potentially fail if split returns empty array
Not likely in practice since you're working with paths, but it might be worth adding a safety check or a comment explaining why it's safe.
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.
PMM-14651
Link to the Feature Build: SUBMODULES-4165