diff --git a/frontend/src/container/ErrorDetails/index.tsx b/frontend/src/container/ErrorDetails/index.tsx index 561114a289..e5fd91b1cb 100644 --- a/frontend/src/container/ErrorDetails/index.tsx +++ b/frontend/src/container/ErrorDetails/index.tsx @@ -5,6 +5,7 @@ import { ResizeTable } from 'components/ResizeTable'; import { getNanoSeconds } from 'container/AllError/utils'; import dayjs from 'dayjs'; import { useNotifications } from 'hooks/useNotifications'; +import createQueryParams from 'lib/createQueryParams'; import history from 'lib/history'; import { urlKey } from 'pages/ErrorDetails/utils'; import { useMemo, useState } from 'react'; @@ -95,10 +96,14 @@ function ErrorDetails(props: ErrorDetailsProps): JSX.Element { return; } + const queryParams = { + groupId: idPayload.groupID, + timestamp: getNanoSeconds(timestamp), + errorId: id, + }; + history.replace( - `${history.location.pathname}?&groupId=${ - idPayload.groupID - }×tamp=${getNanoSeconds(timestamp)}&errorId=${id}`, + `${history.location.pathname}?${createQueryParams(queryParams)}`, ); } catch (error) { notifications.error({ diff --git a/frontend/src/container/GridGraphLayout/Graph/WidgetGraphComponent.tsx b/frontend/src/container/GridGraphLayout/Graph/WidgetGraphComponent.tsx index 4d3d6867ca..d0931fdac6 100644 --- a/frontend/src/container/GridGraphLayout/Graph/WidgetGraphComponent.tsx +++ b/frontend/src/container/GridGraphLayout/Graph/WidgetGraphComponent.tsx @@ -4,6 +4,7 @@ import { Events } from 'constants/events'; import GridPanelSwitch from 'container/GridPanelSwitch'; import { useChartMutable } from 'hooks/useChartMutable'; import { useNotifications } from 'hooks/useNotifications'; +import createQueryParams from 'lib/createQueryParams'; import history from 'lib/history'; import { isEmpty, isEqual } from 'lodash-es'; import { @@ -190,9 +191,13 @@ function WidgetGraphComponent({ message: 'Panel cloned successfully, redirecting to new copy.', }); + const queryParams = { + graphType: widget?.panelTypes, + widgetId: uuid, + }; setTimeout(() => { history.push( - `${history.location.pathname}/new?graphType=${widget?.panelTypes}&widgetId=${uuid}`, + `${history.location.pathname}/new?${createQueryParams(queryParams)}`, ); }, 1500); }); diff --git a/frontend/src/container/NewDashboard/ComponentsSlider/index.tsx b/frontend/src/container/NewDashboard/ComponentsSlider/index.tsx index a5c48ed307..11de0e071e 100644 --- a/frontend/src/container/NewDashboard/ComponentsSlider/index.tsx +++ b/frontend/src/container/NewDashboard/ComponentsSlider/index.tsx @@ -2,6 +2,7 @@ import { initialQueriesMap, PANEL_TYPES } from 'constants/queryBuilder'; import { queryParamNamesMap } from 'constants/queryBuilderQueryNames'; import { useIsDarkMode } from 'hooks/useDarkMode'; import { useNotifications } from 'hooks/useNotifications'; +import createQueryParams from 'lib/createQueryParams'; import history from 'lib/history'; import { CSSProperties, useCallback } from 'react'; import { connect, useSelector } from 'react-redux'; @@ -42,12 +43,16 @@ function DashboardGraphSlider({ toggleAddWidget }: Props): JSX.Element { toggleAddWidget(false); + const queryParams = { + graphType: name, + widgetId: emptyLayout.i, + [queryParamNamesMap.compositeQuery]: JSON.stringify( + initialQueriesMap.metrics, + ), + }; + history.push( - `${history.location.pathname}/new?graphType=${name}&widgetId=${ - emptyLayout.i - }&${queryParamNamesMap.compositeQuery}=${encodeURIComponent( - JSON.stringify(initialQueriesMap.metrics), - )}`, + `${history.location.pathname}/new?${createQueryParams(queryParams)}`, ); } catch (error) { notifications.error({ diff --git a/frontend/src/lib/createQueryParams.ts b/frontend/src/lib/createQueryParams.ts index 5630098cb2..7ab387934d 100644 --- a/frontend/src/lib/createQueryParams.ts +++ b/frontend/src/lib/createQueryParams.ts @@ -1,6 +1,8 @@ const createQueryParams = (params: { [x: string]: string | number }): string => Object.keys(params) - .map((k) => `${k}=${encodeURI(String(params[k]))}`) + .map( + (k) => `${encodeURIComponent(k)}=${encodeURIComponent(String(params[k]))}`, + ) .join('&'); export default createQueryParams; diff --git a/frontend/src/store/actions/trace/util.ts b/frontend/src/store/actions/trace/util.ts index 20e677ad97..fab19acac3 100644 --- a/frontend/src/store/actions/trace/util.ts +++ b/frontend/src/store/actions/trace/util.ts @@ -1,4 +1,5 @@ import { AllTraceFilterEnum } from 'container/Trace/Filters'; +import createQueryParams from 'lib/createQueryParams'; import history from 'lib/history'; import { PayloadProps as GetFilterPayload } from 'types/api/trace/getFilters'; import { TraceFilterEnum, TraceReducer } from 'types/reducer/trace'; @@ -51,20 +52,25 @@ export const updateURL = ( } }); + const preResultParams = preResult.reduce((acc, item) => { + acc[item.key] = item.value; + return acc; + }, {} as Record); + + const queryParams = { + selected: JSON.stringify(Object.fromEntries(selectedFilter)), + filterToFetchData: JSON.stringify(filterToFetchData), + spanAggregateCurrentPage, + spanAggregateOrder, + spanAggregateCurrentPageSize, + spanAggregateOrderParam, + selectedTags: JSON.stringify(selectedTags), + ...preResultParams, + isFilterExclude: JSON.stringify(Object.fromEntries(isFilterExclude)), + userSelectedFilter: JSON.stringify(Object.fromEntries(userSelectedFilter)), + }; history.replace( - `${history.location.pathname}?selected=${JSON.stringify( - Object.fromEntries(selectedFilter), - )}&filterToFetchData=${JSON.stringify( - filterToFetchData, - )}&spanAggregateCurrentPage=${spanAggregateCurrentPage}&selectedTags=${JSON.stringify( - selectedTags, - )}&${preResult - .map((e) => `${e.key}=${e.value}`) - .join('&')}&isFilterExclude=${JSON.stringify( - Object.fromEntries(isFilterExclude), - )}&userSelectedFilter=${JSON.stringify( - Object.fromEntries(userSelectedFilter), - )}&spanAggregateCurrentPage=${spanAggregateCurrentPage}&spanAggregateOrder=${spanAggregateOrder}&spanAggregateCurrentPageSize=${spanAggregateCurrentPageSize}&spanAggregateOrderParam=${spanAggregateOrderParam}`, + `${history.location.pathname}?${createQueryParams(queryParams)}`, ); };