mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 05:55:59 +08:00
fix: respect the sorting params present in the URL for dashboards list page (#5183)
* fix: respect the sorting params present in the URL for dashboards list page * fix: move the list order params to context
This commit is contained in:
parent
a3e36cbac9
commit
699f79d6ba
@ -34,7 +34,7 @@ import { useGetAllDashboard } from 'hooks/dashboard/useGetAllDashboard';
|
|||||||
import useComponentPermission from 'hooks/useComponentPermission';
|
import useComponentPermission from 'hooks/useComponentPermission';
|
||||||
import { useNotifications } from 'hooks/useNotifications';
|
import { useNotifications } from 'hooks/useNotifications';
|
||||||
import history from 'lib/history';
|
import history from 'lib/history';
|
||||||
import { get, isEmpty } from 'lodash-es';
|
import { get, isEmpty, isNull, isUndefined } from 'lodash-es';
|
||||||
import {
|
import {
|
||||||
ArrowDownWideNarrow,
|
ArrowDownWideNarrow,
|
||||||
ArrowUpRight,
|
ArrowUpRight,
|
||||||
@ -53,6 +53,7 @@ import {
|
|||||||
Search,
|
Search,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { handleContactSupport } from 'pages/Integrations/utils';
|
import { handleContactSupport } from 'pages/Integrations/utils';
|
||||||
|
import { useDashboard } from 'providers/Dashboard/Dashboard';
|
||||||
import {
|
import {
|
||||||
ChangeEvent,
|
ChangeEvent,
|
||||||
Key,
|
Key,
|
||||||
@ -91,6 +92,11 @@ function DashboardsList(): JSX.Element {
|
|||||||
|
|
||||||
const { role } = useSelector<AppState, AppReducer>((state) => state.app);
|
const { role } = useSelector<AppState, AppReducer>((state) => state.app);
|
||||||
|
|
||||||
|
const {
|
||||||
|
listSortOrder: sortOrder,
|
||||||
|
setListSortOrder: setSortOrder,
|
||||||
|
} = useDashboard();
|
||||||
|
|
||||||
const [action, createNewDashboard] = useComponentPermission(
|
const [action, createNewDashboard] = useComponentPermission(
|
||||||
['action', 'create_new_dashboards'],
|
['action', 'create_new_dashboards'],
|
||||||
role,
|
role,
|
||||||
@ -116,18 +122,9 @@ function DashboardsList(): JSX.Element {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const params = useUrlQuery();
|
const params = useUrlQuery();
|
||||||
const orderColumnParam = params.get('columnKey');
|
|
||||||
const orderQueryParam = params.get('order');
|
|
||||||
const paginationParam = params.get('page');
|
|
||||||
const searchParams = params.get('search');
|
const searchParams = params.get('search');
|
||||||
const [searchString, setSearchString] = useState<string>(searchParams || '');
|
const [searchString, setSearchString] = useState<string>(searchParams || '');
|
||||||
|
|
||||||
const [sortOrder, setSortOrder] = useState({
|
|
||||||
columnKey: orderColumnParam,
|
|
||||||
order: orderQueryParam,
|
|
||||||
pagination: paginationParam,
|
|
||||||
});
|
|
||||||
|
|
||||||
const getLocalStorageDynamicColumns = (): DashboardDynamicColumns => {
|
const getLocalStorageDynamicColumns = (): DashboardDynamicColumns => {
|
||||||
const dashboardDynamicColumnsString = localStorage.getItem('dashboard');
|
const dashboardDynamicColumnsString = localStorage.getItem('dashboard');
|
||||||
let dashboardDynamicColumns: DashboardDynamicColumns = {
|
let dashboardDynamicColumns: DashboardDynamicColumns = {
|
||||||
@ -217,6 +214,13 @@ function DashboardsList(): JSX.Element {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isUndefined(sortOrder.columnKey) && !isNull(sortOrder.columnKey)) {
|
||||||
|
sortHandle(sortOrder.columnKey);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [dashboards]);
|
||||||
|
|
||||||
function handlePageSizeUpdate(page: number): void {
|
function handlePageSizeUpdate(page: number): void {
|
||||||
setSortOrder((order) => ({
|
setSortOrder((order) => ({
|
||||||
...order,
|
...order,
|
||||||
@ -225,7 +229,6 @@ function DashboardsList(): JSX.Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
sortDashboardsByCreatedAt(dashboardListResponse);
|
|
||||||
const filteredDashboards = filterDashboard(
|
const filteredDashboards = filterDashboard(
|
||||||
searchString,
|
searchString,
|
||||||
dashboardListResponse,
|
dashboardListResponse,
|
||||||
|
@ -12,6 +12,7 @@ import DateTimeSelectionV2 from 'container/TopNav/DateTimeSelectionV2';
|
|||||||
import { useUpdateDashboard } from 'hooks/dashboard/useUpdateDashboard';
|
import { useUpdateDashboard } from 'hooks/dashboard/useUpdateDashboard';
|
||||||
import useComponentPermission from 'hooks/useComponentPermission';
|
import useComponentPermission from 'hooks/useComponentPermission';
|
||||||
import { useNotifications } from 'hooks/useNotifications';
|
import { useNotifications } from 'hooks/useNotifications';
|
||||||
|
import useUrlQuery from 'hooks/useUrlQuery';
|
||||||
import history from 'lib/history';
|
import history from 'lib/history';
|
||||||
import { isEmpty } from 'lodash-es';
|
import { isEmpty } from 'lodash-es';
|
||||||
import {
|
import {
|
||||||
@ -61,6 +62,7 @@ function DashboardDescription(props: DashboardDescriptionProps): JSX.Element {
|
|||||||
layouts,
|
layouts,
|
||||||
setLayouts,
|
setLayouts,
|
||||||
isDashboardLocked,
|
isDashboardLocked,
|
||||||
|
listSortOrder,
|
||||||
setSelectedDashboard,
|
setSelectedDashboard,
|
||||||
handleToggleDashboardSlider,
|
handleToggleDashboardSlider,
|
||||||
handleDashboardLockToggle,
|
handleDashboardLockToggle,
|
||||||
@ -82,6 +84,8 @@ function DashboardDescription(props: DashboardDescriptionProps): JSX.Element {
|
|||||||
|
|
||||||
const updateDashboardMutation = useUpdateDashboard();
|
const updateDashboardMutation = useUpdateDashboard();
|
||||||
|
|
||||||
|
const urlQuery = useUrlQuery();
|
||||||
|
|
||||||
const { featureResponse, user, role } = useSelector<AppState, AppReducer>(
|
const { featureResponse, user, role } = useSelector<AppState, AppReducer>(
|
||||||
(state) => state.app,
|
(state) => state.app,
|
||||||
);
|
);
|
||||||
@ -250,6 +254,15 @@ 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);
|
||||||
|
|
||||||
|
const generatedUrl = `${ROUTES.ALL_DASHBOARD}?${urlQuery.toString()}`;
|
||||||
|
history.replace(generatedUrl);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="dashboard-description-container">
|
<Card className="dashboard-description-container">
|
||||||
<div className="dashboard-header">
|
<div className="dashboard-header">
|
||||||
@ -258,7 +271,7 @@ function DashboardDescription(props: DashboardDescriptionProps): JSX.Element {
|
|||||||
type="text"
|
type="text"
|
||||||
icon={<LayoutGrid size={14} />}
|
icon={<LayoutGrid size={14} />}
|
||||||
className="dashboard-btn"
|
className="dashboard-btn"
|
||||||
onClick={(): void => history.push(ROUTES.ALL_DASHBOARD)}
|
onClick={(): void => goToListPage()}
|
||||||
>
|
>
|
||||||
Dashboard /
|
Dashboard /
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -9,6 +9,7 @@ import dayjs, { Dayjs } from 'dayjs';
|
|||||||
import { useDashboardVariablesFromLocalStorage } from 'hooks/dashboard/useDashboardFromLocalStorage';
|
import { useDashboardVariablesFromLocalStorage } from 'hooks/dashboard/useDashboardFromLocalStorage';
|
||||||
import useAxiosError from 'hooks/useAxiosError';
|
import useAxiosError from 'hooks/useAxiosError';
|
||||||
import useTabVisibility from 'hooks/useTabFocus';
|
import useTabVisibility from 'hooks/useTabFocus';
|
||||||
|
import useUrlQuery from 'hooks/useUrlQuery';
|
||||||
import { getUpdatedLayout } from 'lib/dashboard/getUpdatedLayout';
|
import { getUpdatedLayout } from 'lib/dashboard/getUpdatedLayout';
|
||||||
import { defaultTo } from 'lodash-es';
|
import { defaultTo } from 'lodash-es';
|
||||||
import isEqual from 'lodash-es/isEqual';
|
import isEqual from 'lodash-es/isEqual';
|
||||||
@ -51,6 +52,8 @@ const DashboardContext = createContext<IDashboardContext>({
|
|||||||
layouts: [],
|
layouts: [],
|
||||||
panelMap: {},
|
panelMap: {},
|
||||||
setPanelMap: () => {},
|
setPanelMap: () => {},
|
||||||
|
listSortOrder: { columnKey: null, order: null, pagination: '1' },
|
||||||
|
setListSortOrder: () => {},
|
||||||
setLayouts: () => {},
|
setLayouts: () => {},
|
||||||
setSelectedDashboard: () => {},
|
setSelectedDashboard: () => {},
|
||||||
updatedTimeRef: {} as React.MutableRefObject<Dayjs | null>,
|
updatedTimeRef: {} as React.MutableRefObject<Dayjs | null>,
|
||||||
@ -79,6 +82,17 @@ export function DashboardProvider({
|
|||||||
exact: true,
|
exact: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const params = useUrlQuery();
|
||||||
|
const orderColumnParam = params.get('columnKey');
|
||||||
|
const orderQueryParam = params.get('order');
|
||||||
|
const paginationParam = params.get('page');
|
||||||
|
|
||||||
|
const [listSortOrder, setListSortOrder] = useState({
|
||||||
|
columnKey: orderColumnParam,
|
||||||
|
order: orderQueryParam,
|
||||||
|
pagination: paginationParam,
|
||||||
|
});
|
||||||
|
|
||||||
const dispatch = useDispatch<Dispatch<AppActions>>();
|
const dispatch = useDispatch<Dispatch<AppActions>>();
|
||||||
|
|
||||||
const globalTime = useSelector<AppState, GlobalReducer>(
|
const globalTime = useSelector<AppState, GlobalReducer>(
|
||||||
@ -341,6 +355,8 @@ export function DashboardProvider({
|
|||||||
selectedDashboard,
|
selectedDashboard,
|
||||||
dashboardId,
|
dashboardId,
|
||||||
layouts,
|
layouts,
|
||||||
|
listSortOrder,
|
||||||
|
setListSortOrder,
|
||||||
panelMap,
|
panelMap,
|
||||||
setLayouts,
|
setLayouts,
|
||||||
setPanelMap,
|
setPanelMap,
|
||||||
@ -359,6 +375,8 @@ export function DashboardProvider({
|
|||||||
selectedDashboard,
|
selectedDashboard,
|
||||||
dashboardId,
|
dashboardId,
|
||||||
layouts,
|
layouts,
|
||||||
|
listSortOrder,
|
||||||
|
setListSortOrder,
|
||||||
panelMap,
|
panelMap,
|
||||||
toScrollWidgetId,
|
toScrollWidgetId,
|
||||||
updateLocalStorageDashboardVariables,
|
updateLocalStorageDashboardVariables,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
import { Dispatch, SetStateAction } from 'react';
|
||||||
import { Layout } from 'react-grid-layout';
|
import { Layout } from 'react-grid-layout';
|
||||||
import { UseQueryResult } from 'react-query';
|
import { UseQueryResult } from 'react-query';
|
||||||
import { Dashboard } from 'types/api/dashboard/getAll';
|
import { Dashboard } from 'types/api/dashboard/getAll';
|
||||||
@ -14,6 +15,18 @@ export interface IDashboardContext {
|
|||||||
layouts: Layout[];
|
layouts: Layout[];
|
||||||
panelMap: Record<string, { widgets: Layout[]; collapsed: boolean }>;
|
panelMap: Record<string, { widgets: Layout[]; collapsed: boolean }>;
|
||||||
setPanelMap: React.Dispatch<React.SetStateAction<Record<string, any>>>;
|
setPanelMap: React.Dispatch<React.SetStateAction<Record<string, any>>>;
|
||||||
|
listSortOrder: {
|
||||||
|
columnKey: string | null;
|
||||||
|
order: string | null;
|
||||||
|
pagination: string | null;
|
||||||
|
};
|
||||||
|
setListSortOrder: Dispatch<
|
||||||
|
SetStateAction<{
|
||||||
|
columnKey: string | null;
|
||||||
|
order: string | null;
|
||||||
|
pagination: string | null;
|
||||||
|
}>
|
||||||
|
>;
|
||||||
setLayouts: React.Dispatch<React.SetStateAction<Layout[]>>;
|
setLayouts: React.Dispatch<React.SetStateAction<Layout[]>>;
|
||||||
setSelectedDashboard: React.Dispatch<
|
setSelectedDashboard: React.Dispatch<
|
||||||
React.SetStateAction<Dashboard | undefined>
|
React.SetStateAction<Dashboard | undefined>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user