mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-15 21:15:56 +08:00
fix: dashboard listing default sorting by updatedAt (#5200)
* fix: dashboard listing default sorting by createdAt * fix: respect pagination options * fix: make it backwards compatible * fix: sort by default by updated at * fix: sort by default by updated at
This commit is contained in:
parent
191a2a319d
commit
f391ca8bb1
@ -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, isNull, isUndefined } from 'lodash-es';
|
import { get, isEmpty } from 'lodash-es';
|
||||||
import {
|
import {
|
||||||
ArrowDownWideNarrow,
|
ArrowDownWideNarrow,
|
||||||
ArrowUpRight,
|
ArrowUpRight,
|
||||||
@ -195,7 +195,6 @@ function DashboardsList(): JSX.Element {
|
|||||||
}, [sortOrder]);
|
}, [sortOrder]);
|
||||||
|
|
||||||
const sortHandle = (key: string): void => {
|
const sortHandle = (key: string): void => {
|
||||||
console.log(dashboards);
|
|
||||||
if (!dashboards) return;
|
if (!dashboards) return;
|
||||||
if (key === 'createdAt') {
|
if (key === 'createdAt') {
|
||||||
sortDashboardsByCreatedAt(dashboards);
|
sortDashboardsByCreatedAt(dashboards);
|
||||||
@ -214,13 +213,6 @@ 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,
|
||||||
@ -233,8 +225,25 @@ function DashboardsList(): JSX.Element {
|
|||||||
searchString,
|
searchString,
|
||||||
dashboardListResponse,
|
dashboardListResponse,
|
||||||
);
|
);
|
||||||
setDashboards(filteredDashboards || []);
|
if (sortOrder.columnKey === 'updatedAt') {
|
||||||
}, [dashboardListResponse, searchString]);
|
sortDashboardsByUpdatedAt(filteredDashboards || []);
|
||||||
|
} else if (sortOrder.columnKey === 'createdAt') {
|
||||||
|
sortDashboardsByCreatedAt(filteredDashboards || []);
|
||||||
|
} else if (sortOrder.columnKey === 'null') {
|
||||||
|
setSortOrder({
|
||||||
|
columnKey: 'updatedAt',
|
||||||
|
order: 'descend',
|
||||||
|
pagination: sortOrder.pagination || '1',
|
||||||
|
});
|
||||||
|
sortDashboardsByUpdatedAt(filteredDashboards || []);
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
dashboardListResponse,
|
||||||
|
searchString,
|
||||||
|
setSortOrder,
|
||||||
|
sortOrder.columnKey,
|
||||||
|
sortOrder.pagination,
|
||||||
|
]);
|
||||||
|
|
||||||
const [newDashboardState, setNewDashboardState] = useState({
|
const [newDashboardState, setNewDashboardState] = useState({
|
||||||
loading: false,
|
loading: false,
|
||||||
@ -810,6 +819,7 @@ function DashboardsList(): JSX.Element {
|
|||||||
showTotal: showPaginationItem,
|
showTotal: showPaginationItem,
|
||||||
showSizeChanger: false,
|
showSizeChanger: false,
|
||||||
onChange: (page): void => handlePageSizeUpdate(page),
|
onChange: (page): void => handlePageSizeUpdate(page),
|
||||||
|
current: Number(sortOrder.pagination),
|
||||||
defaultCurrent: Number(sortOrder.pagination) || 1,
|
defaultCurrent: Number(sortOrder.pagination) || 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import { Button, Card, Input, Modal, Popover, Tag, Typography } from 'antd';
|
|||||||
import FacingIssueBtn from 'components/facingIssueBtn/FacingIssueBtn';
|
import FacingIssueBtn from 'components/facingIssueBtn/FacingIssueBtn';
|
||||||
import { dashboardHelpMessage } from 'components/facingIssueBtn/util';
|
import { dashboardHelpMessage } from 'components/facingIssueBtn/util';
|
||||||
import { SOMETHING_WENT_WRONG } from 'constants/api';
|
import { SOMETHING_WENT_WRONG } from 'constants/api';
|
||||||
|
import { QueryParams } from 'constants/query';
|
||||||
import { PANEL_GROUP_TYPES, PANEL_TYPES } from 'constants/queryBuilder';
|
import { PANEL_GROUP_TYPES, PANEL_TYPES } from 'constants/queryBuilder';
|
||||||
import ROUTES from 'constants/routes';
|
import ROUTES from 'constants/routes';
|
||||||
import { DeleteButton } from 'container/ListOfDashboard/TableComponents/DeleteButton';
|
import { DeleteButton } from 'container/ListOfDashboard/TableComponents/DeleteButton';
|
||||||
@ -258,6 +259,7 @@ function DashboardDescription(props: DashboardDescriptionProps): JSX.Element {
|
|||||||
urlQuery.set('columnKey', listSortOrder.columnKey as string);
|
urlQuery.set('columnKey', listSortOrder.columnKey as string);
|
||||||
urlQuery.set('order', listSortOrder.order as string);
|
urlQuery.set('order', listSortOrder.order as string);
|
||||||
urlQuery.set('page', listSortOrder.pagination as string);
|
urlQuery.set('page', listSortOrder.pagination as string);
|
||||||
|
urlQuery.delete(QueryParams.relativeTime);
|
||||||
|
|
||||||
const generatedUrl = `${ROUTES.ALL_DASHBOARD}?${urlQuery.toString()}`;
|
const generatedUrl = `${ROUTES.ALL_DASHBOARD}?${urlQuery.toString()}`;
|
||||||
history.replace(generatedUrl);
|
history.replace(generatedUrl);
|
||||||
|
@ -68,7 +68,7 @@ function getStackedSeries(apiResponse: QueryData[]): QueryData[] {
|
|||||||
const { values } = series[i];
|
const { values } = series[i];
|
||||||
for (let j = 0; j < values.length; j++) {
|
for (let j = 0; j < values.length; j++) {
|
||||||
values[j][1] = String(
|
values[j][1] = String(
|
||||||
parseFloat(values[j][1]) + parseFloat(series[i + 1].values[j][1]),
|
parseFloat(values[j]?.[1]) + parseFloat(series[i + 1].values[j]?.[1]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ const DashboardContext = createContext<IDashboardContext>({
|
|||||||
layouts: [],
|
layouts: [],
|
||||||
panelMap: {},
|
panelMap: {},
|
||||||
setPanelMap: () => {},
|
setPanelMap: () => {},
|
||||||
listSortOrder: { columnKey: null, order: null, pagination: '1' },
|
listSortOrder: { columnKey: 'createdAt', order: 'descend', pagination: '1' },
|
||||||
setListSortOrder: () => {},
|
setListSortOrder: () => {},
|
||||||
setLayouts: () => {},
|
setLayouts: () => {},
|
||||||
setSelectedDashboard: () => {},
|
setSelectedDashboard: () => {},
|
||||||
@ -88,9 +88,9 @@ export function DashboardProvider({
|
|||||||
const paginationParam = params.get('page');
|
const paginationParam = params.get('page');
|
||||||
|
|
||||||
const [listSortOrder, setListSortOrder] = useState({
|
const [listSortOrder, setListSortOrder] = useState({
|
||||||
columnKey: orderColumnParam,
|
columnKey: orderColumnParam || 'updatedAt',
|
||||||
order: orderQueryParam,
|
order: orderQueryParam || 'descend',
|
||||||
pagination: paginationParam,
|
pagination: paginationParam || '1',
|
||||||
});
|
});
|
||||||
|
|
||||||
const dispatch = useDispatch<Dispatch<AppActions>>();
|
const dispatch = useDispatch<Dispatch<AppActions>>();
|
||||||
|
@ -16,15 +16,15 @@ export interface IDashboardContext {
|
|||||||
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: {
|
listSortOrder: {
|
||||||
columnKey: string | null;
|
columnKey: string;
|
||||||
order: string | null;
|
order: string;
|
||||||
pagination: string | null;
|
pagination: string;
|
||||||
};
|
};
|
||||||
setListSortOrder: Dispatch<
|
setListSortOrder: Dispatch<
|
||||||
SetStateAction<{
|
SetStateAction<{
|
||||||
columnKey: string | null;
|
columnKey: string;
|
||||||
order: string | null;
|
order: string;
|
||||||
pagination: string | null;
|
pagination: string;
|
||||||
}>
|
}>
|
||||||
>;
|
>;
|
||||||
setLayouts: React.Dispatch<React.SetStateAction<Layout[]>>;
|
setLayouts: React.Dispatch<React.SetStateAction<Layout[]>>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user