diff --git a/frontend/app/components/Dashboard/Widgets/CardSessionsByList.tsx b/frontend/app/components/Dashboard/Widgets/CardSessionsByList.tsx index 2037fed6e..283c2f74b 100644 --- a/frontend/app/components/Dashboard/Widgets/CardSessionsByList.tsx +++ b/frontend/app/components/Dashboard/Widgets/CardSessionsByList.tsx @@ -1,60 +1,106 @@ -import React from 'react'; -import { Avatar, List, Progress, Typography } from 'antd'; +import React, { useEffect } from 'react'; +import { Avatar, List, Progress, Typography, Pagination } from 'antd'; import cn from 'classnames'; +import { useStore } from '@/mstore'; +import { WEB_VITALS } from '@/constants/card'; +import { observer } from 'mobx-react-lite'; interface Props { list: any; selected?: any; onClickHandler?: (event: any, data: any) => void; + metric?: any; + total?: number; + paginated?: boolean; } -function CardSessionsByList({ list, selected, onClickHandler = () => null }: Props) { - return ( - ( - onClickHandler(e, row)} - style={{ - borderBottom: index === list.length - 1 ? 'none' : '1px dotted rgba(0, 0, 0, 0.05)', - padding: '4px 10px', - lineHeight: '1px' - }} - className={cn('rounded', selected === row.name ? 'bg-active-blue' : '')} - > - } - title={( -
-
- {row.displayName} - {row.sessionCount} -
+function CardSessionsByList({ list, selected, paginated, onClickHandler = () => null, metric, total }: Props) { + const { dashboardStore, metricStore, sessionStore } = useStore(); + const drillDownPeriod = dashboardStore.drillDownPeriod; + 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; - -
- )} + useEffect(() => { + if (!metric) return; + const timestamps = drillDownPeriod.toTimestamps(); + const payload = { ...metricParams, ...timestamps, ...metric?.toJson() }; + setLoading(true); + dashboardStore.fetchMetricChartData({ ...metric, page }, payload, true, drillDownPeriod).then((res: any) => { + setData(res); + }).finally(() => { + setLoading(false); + }); + }, [metric, page]); + + return ( +
+
+ ( + onClickHandler(e, row)} + style={{ + borderBottom: index === data.length - 1 ? 'none' : '1px dotted rgba(0, 0, 0, 0.05)', + padding: '4px 10px', + lineHeight: '1px' + }} + className={cn('rounded', selected === row.name ? 'bg-active-blue' : '')} + > + } + title={( +
+
+ {row.displayName} + {row.sessionCount} +
+ + +
+ )} + /> +
+ )} + /> +
+ {paginated && total && total > 20 && ( +
+ `${range[0]}-${range[1]} of ${total} items`} + defaultCurrent={page} + total={total} + showQuickJumper + pageSize={20} + showSizeChanger={false} + onChange={(page) => dashboardStore.updateKey('metricsPage', page)} /> - +
)} - /> + +
); } -export default CardSessionsByList; +export default observer(CardSessionsByList); diff --git a/frontend/app/components/Dashboard/Widgets/CustomMetricsWidgets/SessionsBy.tsx b/frontend/app/components/Dashboard/Widgets/CustomMetricsWidgets/SessionsBy.tsx index 66efee122..1e6a63535 100644 --- a/frontend/app/components/Dashboard/Widgets/CustomMetricsWidgets/SessionsBy.tsx +++ b/frontend/app/components/Dashboard/Widgets/CustomMetricsWidgets/SessionsBy.tsx @@ -1,9 +1,8 @@ import React from 'react'; import { Button, Space } from 'antd'; import { filtersMap } from 'Types/filter/newFilter'; -// import { Icon } from 'UI'; import { Empty } from 'antd'; -import { Info } from 'lucide-react' +import { Info } from 'lucide-react'; import { ArrowRight } from 'lucide-react'; import CardSessionsByList from 'Components/Dashboard/Widgets/CardSessionsByList'; import { useModal } from 'Components/ModalContext'; @@ -18,7 +17,7 @@ interface Props { function SessionsBy(props: Props) { const { metric = {}, data = { values: [] }, onClick = () => null, isTemplate } = props; const [selected, setSelected] = React.useState(null); - const total = data.values.length; + const total = data.count; const { openModal, closeModal } = useModal(); const onClickHandler = (event: any, data: any) => { @@ -42,10 +41,15 @@ function SessionsBy(props: Props) { const showMore = (e: any) => { e.stopPropagation(); openModal( - { - closeModal(); - onClickHandler(null, item); - }} selected={selected} />, { + { + closeModal(); + onClickHandler(null, item); + }} selected={selected} />, { title: metric.name, width: 600 }); @@ -58,7 +62,7 @@ function SessionsBy(props: Props) { image={null} style={{ minHeight: 220 }} className="flex flex-col items-center justify-center" - imageStyle={{ height: 0}} + imageStyle={{ height: 0 }} description={
diff --git a/frontend/app/mstore/dashboardStore.ts b/frontend/app/mstore/dashboardStore.ts index 5ef97697a..2df572264 100644 --- a/frontend/app/mstore/dashboardStore.ts +++ b/frontend/app/mstore/dashboardStore.ts @@ -68,6 +68,7 @@ export default class DashboardStore { const timeStamps = this.drillDownPeriod.toTimestamps(); this.drillDownFilter.updateKey('startTimestamp', timeStamps.startTimestamp); this.drillDownFilter.updateKey('endTimestamp', timeStamps.endTimestamp); + this.updateKey('metricsPage', 1) } get filteredList() {