Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix: removed cleanup variable url function to avoid url reseting (#9449)

SagarRajput-7c9e0f2b9ca53
diff --git a/frontend/src/container/NewDashboard/DashboardDescription/__tests__/DashboardDescription.test.tsx b/frontend/src/container/NewDashboard/DashboardDescription/__tests__/DashboardDescription.test.tsx
index eac398d42d..4b15fff5f8 100644
--- a/frontend/src/container/NewDashboard/DashboardDescription/__tests__/DashboardDescription.test.tsx
+++ b/frontend/src/container/NewDashboard/DashboardDescription/__tests__/DashboardDescription.test.tsx
@@ -1,3 +1,4 @@
+/* eslint-disable sonarjs/no-identical-functions */
import { getNonIntegrationDashboardById } from 'mocks-server/__mockdata__/dashboards';
import { server } from 'mocks-server/server';
import { rest } from 'msw';
@@ -7,6 +8,16 @@ import { fireEvent, render, screen, waitFor } from 'tests/test-utils';
import DashboardDescription from '..';
+interface MockSafeNavigateReturn {
+ safeNavigate: jest.MockedFunction<(url: string) => void>;
+}
+
+const DASHBOARD_TEST_ID = 'dashboard-title';
+const DASHBOARD_TITLE_TEXT = 'thor';
+const DASHBOARD_PATH = '/dashboard/4';
+
+const mockSafeNavigate = jest.fn();
+
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useLocation: jest.fn(),
@@ -26,20 +37,24 @@ jest.mock(
);
jest.mock('hooks/useSafeNavigate', () => ({
- useSafeNavigate: (): any => ({
- safeNavigate: jest.fn(),
+ useSafeNavigate: (): MockSafeNavigateReturn => ({
+ safeNavigate: mockSafeNavigate,
}),
}));
describe('Dashboard landing page actions header tests', () => {
+ beforeEach(() => {
+ mockSafeNavigate.mockClear();
+ });
+
it('unlock dashboard should be disabled for integrations created dashboards', async () => {
const mockLocation = {
- pathname: `${process.env.FRONTEND_API_ENDPOINT}/dashboard/4`,
+ pathname: `${process.env.FRONTEND_API_ENDPOINT}${DASHBOARD_PATH}`,
search: '',
};
(useLocation as jest.Mock).mockReturnValue(mockLocation);
const { getByTestId } = render(
- <MemoryRouter initialEntries={['/dashboard/4']}>
+ <MemoryRouter initialEntries={[DASHBOARD_PATH]}>
<DashboardProvider>
<DashboardDescription
handle={{
@@ -54,7 +69,9 @@ describe('Dashboard landing page actions header tests', () => {
);
await waitFor(() =>
- expect(getByTestId('dashboard-title')).toHaveTextContent('thor'),
+ expect(getByTestId(DASHBOARD_TEST_ID)).toHaveTextContent(
+ DASHBOARD_TITLE_TEXT,
+ ),
);
const dashboardSettingsTrigger = getByTestId('options');
@@ -65,9 +82,10 @@ describe('Dashboard landing page actions header tests', () => {
await waitFor(() => expect(lockUnlockButton).toBeDisabled());
});
+
it('unlock dashboard should not be disabled for non integration created dashboards', async () => {
const mockLocation = {
- pathname: `${process.env.FRONTEND_API_ENDPOINT}/dashboard/4`,
+ pathname: `${process.env.FRONTEND_API_ENDPOINT}${DASHBOARD_PATH}`,
search: '',
};
(useLocation as jest.Mock).mockReturnValue(mockLocation);
@@ -77,7 +95,7 @@ describe('Dashboard landing page actions header tests', () => {
),
);
const { getByTestId } = render(
- <MemoryRouter initialEntries={['/dashboard/4']}>
+ <MemoryRouter initialEntries={[DASHBOARD_PATH]}>
<DashboardProvider>
<DashboardDescription
handle={{
@@ -92,7 +110,9 @@ describe('Dashboard landing page actions header tests', () => {
);
await waitFor(() =>
- expect(getByTestId('dashboard-title')).toHaveTextContent('thor'),
+ expect(getByTestId(DASHBOARD_TEST_ID)).toHaveTextContent(
+ DASHBOARD_TITLE_TEXT,
+ ),
);
const dashboardSettingsTrigger = getByTestId('options');
@@ -103,4 +123,58 @@ describe('Dashboard landing page actions header tests', () => {
await waitFor(() => expect(lockUnlockButton).not.toBeDisabled());
});
+
+ it('should navigate to dashboard list with correct params and exclude variables', async () => {
+ const dashboardUrlWithVariables = `${DASHBOARD_PATH}?variables=%7B%22var1%22%3A%22value1%22%7D&otherParam=test`;
+ const mockLocation = {
+ pathname: DASHBOARD_PATH,
+ search: '?variables=%7B%22var1%22%3A%22value1%22%7D&otherParam=test',
+ };
+
+ (useLocation as jest.Mock).mockReturnValue(mockLocation);
+
+ const { getByText } = render(
+ <MemoryRouter initialEntries={[dashboardUrlWithVariables]}>
+ <DashboardProvider>
+ <DashboardDescription
+ handle={{
+ active: false,
+ enter: (): Promise<void> => Promise.resolve(),
+ exit: (): Promise<void> => Promise.resolve(),
+ node: { current: null },
+ }}
+ />
+ </DashboardProvider>
+ </MemoryRouter>,
+ );
+
+ await waitFor(() =>
+ expect(screen.getByTestId(DASHBOARD_TEST_ID)).toHaveTextContent(
+ DASHBOARD_TITLE_TEXT,
+ ),
+ );
+
+ // Click the dashboard breadcrumb to navigate back to list
+ const dashboardButton = getByText('Dashboard /');
+ fireEvent.click(dashboardButton);
+
+ // Verify navigation was called with correct URL
+ expect(mockSafeNavigate).toHaveBeenCalledWith(
+ '/dashboard?columnKey=updatedAt&order=descend&page=1&search=',
+ );
+
+ // Ensure the URL contains only essential dashboard list params
+ const calledUrl = mockSafeNavigate.mock.calls[0][0] as string;
+ const urlParams = new URLSearchParams(calledUrl.split('?')[1]);
+
+ // Should have essential dashboard list params
+ expect(urlParams.get('columnKey')).toBe('updatedAt');
+ expect(urlParams.get('order')).toBe('descend');
+ expect(urlParams.get('page')).toBe('1');
+ expect(urlParams.get('search')).toBe('');
+
+ // Should NOT have variables or other dashboard-specific params
+ expect(urlParams.has('variables')).toBeFalsy();
+ expect(urlParams.has('relativeTime')).toBeFalsy();
+ });
});
diff --git a/frontend/src/container/NewDashboard/DashboardDescription/index.tsx b/frontend/src/container/NewDashboard/DashboardDescription/index.tsx
index 154c636749..e620b9f337 100644
--- a/frontend/src/container/NewDashboard/DashboardDescription/index.tsx
+++ b/frontend/src/container/NewDashboard/DashboardDescription/index.tsx
@@ -13,7 +13,6 @@ import {
} from 'antd';
import logEvent from 'api/common/logEvent';
import HeaderRightSection from 'components/HeaderRightSection/HeaderRightSection';
-import { QueryParams } from 'constants/query';
import { PANEL_GROUP_TYPES, PANEL_TYPES } from 'constants/queryBuilder';
import ROUTES from 'constants/routes';
import { DeleteButton } from 'container/ListOfDashboard/TableComponents/DeleteButton';
@@ -22,7 +21,6 @@ import { useUpdateDashboard } from 'hooks/dashboard/useUpdateDashboard';
import useComponentPermission from 'hooks/useComponentPermission';
import { useNotifications } from 'hooks/useNotifications';
import { useSafeNavigate } from 'hooks/useSafeNavigate';
-import useUrlQuery from 'hooks/useUrlQuery';
import { isEmpty } from 'lodash-es';
import {
Check,
@@ -116,8 +114,6 @@ function DashboardDescription(props: DashboardDescriptionProps): JSX.Element {
const updateDashboardMutation = useUpdateDashboard();
- const urlQuery = useUrlQuery();
-
const { user } = useAppContext();
const [editDashboard] = useComponentPermission(['edit_dashboard'], user.role);
const [isDashboardSettingsOpen, setIsDashbordSettingsOpen] = useState<boolean>(
@@ -291,13 +287,13 @@ function DashboardDescription(props: DashboardDescriptionProps): JSX.Element {
}
function goToListPage(): void {
- urlQuery.set('columnKey', listSortOrder.columnKey as string);
- urlQuery.set('order', listSortOrder.order as string);
- urlQuery.set('page', listSortOrder.pagination as string);
- urlQuery.set('search', listSortOrder.search as string);
- urlQuery.delete(QueryParams.relativeTime);
+ const urlParams = new URLSearchParams();
+ urlParams.set('columnKey', listSortOrder.columnKey as string);
+ urlParams.set('order', listSortOrder.order as string);
+ urlParams.set('page', listSortOrder.pagination as string);
+ urlParams.set('search', listSortOrder.search as string);
- const generatedUrl = `${ROUTES.ALL_DASHBOARD}?${urlQuery.toString()}`;
+ const generatedUrl = `${ROUTES.ALL_DASHBOARD}?${urlParams.toString()}`;
safeNavigate(generatedUrl);
}
diff --git a/frontend/src/hooks/dashboard/useVariablesFromUrl.tsx b/frontend/src/hooks/dashboard/useVariablesFromUrl.tsx
index bf19f518ec..7e845ae691 100644
--- a/frontend/src/hooks/dashboard/useVariablesFromUrl.tsx
+++ b/frontend/src/hooks/dashboard/useVariablesFromUrl.tsx
@@ -18,7 +18,6 @@ interface UseVariablesFromUrlReturn {
name: string,
selectedValue: IDashboardVariable['selectedValue'],
) => void;
- clearUrlVariables: () => void;
}
const useVariablesFromUrl = (): UseVariablesFromUrlReturn => {
@@ -68,15 +67,6 @@ const useVariablesFromUrl = (): UseVariablesFromUrlReturn => {
[history, urlQuery],
);
- const clearUrlVariables = useCallback((): void => {
- const params = new URLSearchParams(urlQuery.toString());
- params.delete(QueryParams.variables);
-
- history.replace({
- search: params.toString(),
- });
- }, [history, urlQuery]);
-
const updateUrlVariable = useCallback(
(name: string, selectedValue: IDashboardVariable['selectedValue']): void => {
const currentVariables = getUrlVariables();
@@ -95,7 +85,6 @@ const useVariablesFromUrl = (): UseVariablesFromUrlReturn => {
getUrlVariables,
setUrlVariables,
updateUrlVariable,
- clearUrlVariables,
};
};
diff --git a/frontend/src/providers/Dashboard/Dashboard.tsx b/frontend/src/providers/Dashboard/Dashboard.tsx
index 7c2db3944e..ad10d3605f 100644
--- a/frontend/src/providers/Dashboard/Dashboard.tsx
+++ b/frontend/src/providers/Dashboard/Dashboard.tsx
@@ -202,11 +202,7 @@ export function DashboardProvider({
updateLocalStorageDashboardVariables,
} = useDashboardVariablesFromLocalStorage(dashboardId);
- const {
- getUrlVariables,
- updateUrlVariable,
- clearUrlVariables,
- } = useVariablesFromUrl();
+ const { getUrlVariables, updateUrlVariable } = useVariablesFromUrl();
const updatedTimeRef = useRef<Dayjs | null>(null); // Using ref to store the updated time
const modalRef = useRef<any>(null);
@@ -218,14 +214,6 @@ export function DashboardProvider({
const [isDashboardFetching, setIsDashboardFetching] = useState<boolean>(false);
- // Clear variable configs when not on dashboard pages
- useEffect(() => {
- const isOnDashboardPage = !!isDashboardPage || !!isDashboardWidgetPage;
- if (!isOnDashboardPage) {
- clearUrlVariables();
- }
- }, [isDashboardPage, isDashboardWidgetPage, clearUrlVariables]);
-
const mergeDBWithLocalStorage = (
data: Dashboard,
localStorageVariables: any,
diff --git a/frontend/src/providers/Dashboard/__tests__/Dashboard.test.tsx b/frontend/src/providers/Dashboard/__tests__/Dashboard.test.tsx
index ec3983804b..12e4bfcdcc 100644
--- a/frontend/src/providers/Dashboard/__tests__/Dashboard.test.tsx
+++ b/frontend/src/providers/Dashboard/__tests__/Dashboard.test.tsx
@@ -121,7 +121,6 @@ function renderWithDashboardProvider(
// Mock URL variables hook
const mockGetUrlVariables = jest.fn();
const mockUpdateUrlVariable = jest.fn();
-const mockClearUrlVariables = jest.fn();
const mockSetUrlVariables = jest.fn();
jest.mock('hooks/dashboard/useVariablesFromUrl', () => ({
@@ -129,7 +128,6 @@ jest.mock('hooks/dashboard/useVariablesFromUrl', () => ({
default: jest.fn(() => ({
getUrlVariables: mockGetUrlVariables,
updateUrlVariable: mockUpdateUrlVariable,
- clearUrlVariables: mockClearUrlVariables,
setUrlVariables: mockSetUrlVariables,
})),
}));
@@ -524,16 +522,6 @@ describe('Dashboard Provider - URL Variables Integration', () => {
expect(parsedVariables.environment.allSelected).toBe(false);
});
});
-
- it('should clear URL variables when not on dashboard page', async () => {
- mockUseRouteMatch.mockReturnValue(null); // Not on dashboard page
-
- renderWithDashboardProvider('/other-page', null);
-
- await waitFor(() => {
- expect(mockClearUrlVariables).toHaveBeenCalled();
- });
- });
});
describe('Variable Value Normalization', () => {