Skip to content

Conversation

@matejkubinec
Copy link
Contributor

@matejkubinec matejkubinec commented Dec 18, 2025

PMM-14651

Link to the Feature Build: SUBMODULES-4165

@matejkubinec matejkubinec requested a review from a team as a code owner December 18, 2025 12:19
@matejkubinec matejkubinec requested review from YashSartanpara1, dmitri-saricev-3pillargloball and fabio-silva and removed request for a team December 18, 2025 12:19

return dashboardUid;
};

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;

};

Copy link
Contributor Author

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];

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants