Skip to content
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

fix: disabled same url check for redirect in logs explorer #7187

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions frontend/src/hooks/useSafeNavigate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ interface SafeNavigateParams {
search?: string;
}

interface UseSafeNavigateProps {
enableSameURLCheck?: boolean;
}

const areUrlsEffectivelySame = (url1: URL, url2: URL): boolean => {
if (url1.pathname !== url2.pathname) return false;

Expand Down Expand Up @@ -78,7 +82,9 @@ const isDefaultNavigation = (currentUrl: URL, targetUrl: URL): boolean => {

return newKeys.length > 0;
};
export const useSafeNavigate = (): {
export const useSafeNavigate = (
{ enableSameURLCheck }: UseSafeNavigateProps = { enableSameURLCheck: true },
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we slightly change this to make it more readable?

e.g.

we can change this to

	{ preventSameUrlNavigation }: UseSafeNavigateProps = { preventSameUrlNavigation: true },

if we want to enable same url navigation in the consumers. we could say

	const { safeNavigate } = useSafeNavigate({
		preventSameUrlNavigation: false,
	});

): {
safeNavigate: (
to: string | SafeNavigateParams,
options?: NavigateOptions,
Expand Down Expand Up @@ -108,7 +114,7 @@ export const useSafeNavigate = (): {
const urlsAreSame = areUrlsEffectivelySame(currentUrl, targetUrl);
const isDefaultParamsNavigation = isDefaultNavigation(currentUrl, targetUrl);

if (urlsAreSame) {
if (enableSameURLCheck && urlsAreSame) {
return;
}

Expand All @@ -129,7 +135,7 @@ export const useSafeNavigate = (): {
);
}
},
[navigate, location.pathname, location.search],
[navigate, location.pathname, location.search, enableSameURLCheck],
);

return { safeNavigate };
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/providers/QueryBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,9 @@ export function QueryBuilderProvider({
[panelType, stagedQuery],
);

const { safeNavigate } = useSafeNavigate();
const { safeNavigate } = useSafeNavigate({
enableSameURLCheck: !(initialDataSource === DataSource.LOGS),
Copy link
Contributor

Choose a reason for hiding this comment

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

Have we checked the same on traces page? Why only logs here.

Copy link
Member Author

Choose a reason for hiding this comment

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

For now, just did for logs. After Shaheer shares his reasoning for the same change. Will either remove the whole check or add the flag from required sources.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@sawhil ,

in the areUrlsEffectivelySame function, we are checking if the urls are effectively the same i.e. if the composite query and other params are the same. if so, we prevent the navigation. (#6701)

I think we need to add the enableSameURLCheck flag for traces as well.

});

const redirectWithQueryBuilderData = useCallback(
(
Expand Down
Loading