From b10fdfc9c99bc97c3fc29be8df5e92bdf5f64be8 Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Tue, 8 Oct 2024 18:23:51 +0200 Subject: [PATCH] change(ui): paginate the data in table of cards show more modal --- .../Dashboard/Widgets/CardSessionsByList.tsx | 25 ++++++++++--------- .../CustomMetricsWidgets/SessionsBy.tsx | 11 ++++---- frontend/app/mstore/types/widget.ts | 4 +++ 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/frontend/app/components/Dashboard/Widgets/CardSessionsByList.tsx b/frontend/app/components/Dashboard/Widgets/CardSessionsByList.tsx index 283c2f74b..9032dc917 100644 --- a/frontend/app/components/Dashboard/Widgets/CardSessionsByList.tsx +++ b/frontend/app/components/Dashboard/Widgets/CardSessionsByList.tsx @@ -4,6 +4,7 @@ import cn from 'classnames'; import { useStore } from '@/mstore'; import { WEB_VITALS } from '@/constants/card'; import { observer } from 'mobx-react-lite'; +import { metricService } from '@/services'; interface Props { list: any; @@ -20,21 +21,18 @@ function CardSessionsByList({ list, selected, paginated, onClickHandler = () => const isOverviewWidget = metric?.metricType === WEB_VITALS; const params = { density: isOverviewWidget ? 7 : 70 }; const metricParams = { ...params }; - const [data, setData] = React.useState(list); const [loading, setLoading] = React.useState(false); - const page = dashboardStore.metricsPage; + const data = paginated ? metric?.data[0]?.values : list; - useEffect(() => { - if (!metric) return; + const loadData = async (page: number) => { const timestamps = drillDownPeriod.toTimestamps(); const payload = { ...metricParams, ...timestamps, ...metric?.toJson() }; + const params = { ...drillDownPeriod, ...payload, key: metric.predefinedKey }; setLoading(true); - dashboardStore.fetchMetricChartData({ ...metric, page }, payload, true, drillDownPeriod).then((res: any) => { - setData(res); - }).finally(() => { - setLoading(false); - }); - }, [metric, page]); + const data = await metricService.getMetricChartData(metric, { ...params, page, limit: 20 }, false); + metric.setData(data, drillDownPeriod); + setLoading(false); + }; return (
@@ -89,12 +87,15 @@ function CardSessionsByList({ list, selected, paginated, onClickHandler = () =>
`${range[0]}-${range[1]} of ${total} items`} - defaultCurrent={page} + defaultCurrent={metric.page} total={total} showQuickJumper pageSize={20} showSizeChanger={false} - onChange={(page) => dashboardStore.updateKey('metricsPage', page)} + onChange={(page) => { + metric.setPage(page); + void loadData(page); + }} />
)} diff --git a/frontend/app/components/Dashboard/Widgets/CustomMetricsWidgets/SessionsBy.tsx b/frontend/app/components/Dashboard/Widgets/CustomMetricsWidgets/SessionsBy.tsx index 1e6a63535..702b67520 100644 --- a/frontend/app/components/Dashboard/Widgets/CustomMetricsWidgets/SessionsBy.tsx +++ b/frontend/app/components/Dashboard/Widgets/CustomMetricsWidgets/SessionsBy.tsx @@ -6,6 +6,7 @@ import { Info } from 'lucide-react'; import { ArrowRight } from 'lucide-react'; import CardSessionsByList from 'Components/Dashboard/Widgets/CardSessionsByList'; import { useModal } from 'Components/ModalContext'; +import Widget from '@/mstore/types/widget'; interface Props { metric?: any; @@ -19,6 +20,7 @@ function SessionsBy(props: Props) { const [selected, setSelected] = React.useState(null); const total = data.count; const { openModal, closeModal } = useModal(); + const modalMetric = React.useMemo(() => Object.assign(new Widget(), metric), [metric]); const onClickHandler = (event: any, data: any) => { const filters = Array(); @@ -43,7 +45,7 @@ function SessionsBy(props: Props) { openModal( { @@ -72,10 +74,9 @@ function SessionsBy(props: Props) { /> ) : (
- {/* TODO - remove slice once the api pagination is fixed */} - + {metric && } {total > 3 && (