change(ui): paginate the data in table of cards show more modal

This commit is contained in:
Shekar Siri 2024-10-08 17:19:01 +02:00
parent 18bb6e0263
commit 4cfc5d2517
3 changed files with 105 additions and 54 deletions

View file

@ -1,60 +1,106 @@
import React from 'react'; import React, { useEffect } from 'react';
import { Avatar, List, Progress, Typography } from 'antd'; import { Avatar, List, Progress, Typography, Pagination } from 'antd';
import cn from 'classnames'; import cn from 'classnames';
import { useStore } from '@/mstore';
import { WEB_VITALS } from '@/constants/card';
import { observer } from 'mobx-react-lite';
interface Props { interface Props {
list: any; list: any;
selected?: any; selected?: any;
onClickHandler?: (event: any, data: any) => void; onClickHandler?: (event: any, data: any) => void;
metric?: any;
total?: number;
paginated?: boolean;
} }
function CardSessionsByList({ list, selected, onClickHandler = () => null }: Props) { function CardSessionsByList({ list, selected, paginated, onClickHandler = () => null, metric, total }: Props) {
return ( const { dashboardStore, metricStore, sessionStore } = useStore();
<List const drillDownPeriod = dashboardStore.drillDownPeriod;
dataSource={list} const isOverviewWidget = metric?.metricType === WEB_VITALS;
split={false} const params = { density: isOverviewWidget ? 7 : 70 };
renderItem={(row: any, index: number) => ( const metricParams = { ...params };
<List.Item const [data, setData] = React.useState<any>(list);
key={row.name} const [loading, setLoading] = React.useState(false);
onClick={(e) => onClickHandler(e, row)} const page = dashboardStore.metricsPage;
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' : '')}
>
<List.Item.Meta
className="m-0"
avatar={<Avatar src={row.icon} />}
title={(
<div className="m-0">
<div className="flex justify-between m-0 p-0">
<Typography.Text ellipsis={true}>{row.displayName}</Typography.Text>
<Typography.Text type="secondary"> {row.sessionCount}</Typography.Text>
</div>
<Progress useEffect(() => {
percent={row.progress} if (!metric) return;
showInfo={false} const timestamps = drillDownPeriod.toTimestamps();
strokeColor={{ const payload = { ...metricParams, ...timestamps, ...metric?.toJson() };
'0%': '#394EFF', setLoading(true);
'100%': '#394EFF' dashboardStore.fetchMetricChartData({ ...metric, page }, payload, true, drillDownPeriod).then((res: any) => {
}} setData(res);
size={['small', 2]} }).finally(() => {
style={{ setLoading(false);
padding: '0 0px', });
margin: '0 0px', }, [metric, page]);
height: 4
}} return (
/> <div className="flex flex-col h-full">
</div> <div className="flex-1 overflow-y-auto">
)} <List
dataSource={data}
split={false}
loading={loading}
renderItem={(row: any, index: number) => (
<List.Item
key={row.name}
onClick={(e) => 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' : '')}
>
<List.Item.Meta
className="m-0"
avatar={<Avatar src={row.icon} />}
title={(
<div className="m-0">
<div className="flex justify-between m-0 p-0">
<Typography.Text ellipsis={true}>{row.displayName}</Typography.Text>
<Typography.Text type="secondary"> {row.sessionCount}</Typography.Text>
</div>
<Progress
percent={row.progress}
showInfo={false}
strokeColor={{
'0%': '#394EFF',
'100%': '#394EFF'
}}
size={['small', 2]}
style={{
padding: '0 0px',
margin: '0 0px',
height: 4
}}
/>
</div>
)}
/>
</List.Item>
)}
/>
</div>
{paginated && total && total > 20 && (
<div className="sticky bottom-0 bg-white py-2">
<Pagination
// showTotal={(total, range) => `${range[0]}-${range[1]} of ${total} items`}
defaultCurrent={page}
total={total}
showQuickJumper
pageSize={20}
showSizeChanger={false}
onChange={(page) => dashboardStore.updateKey('metricsPage', page)}
/> />
</List.Item> </div>
)} )}
/>
</div>
); );
} }
export default CardSessionsByList; export default observer(CardSessionsByList);

View file

@ -1,9 +1,8 @@
import React from 'react'; import React from 'react';
import { Button, Space } from 'antd'; import { Button, Space } from 'antd';
import { filtersMap } from 'Types/filter/newFilter'; import { filtersMap } from 'Types/filter/newFilter';
// import { Icon } from 'UI';
import { Empty } from 'antd'; import { Empty } from 'antd';
import { Info } from 'lucide-react' import { Info } from 'lucide-react';
import { ArrowRight } from 'lucide-react'; import { ArrowRight } from 'lucide-react';
import CardSessionsByList from 'Components/Dashboard/Widgets/CardSessionsByList'; import CardSessionsByList from 'Components/Dashboard/Widgets/CardSessionsByList';
import { useModal } from 'Components/ModalContext'; import { useModal } from 'Components/ModalContext';
@ -18,7 +17,7 @@ interface Props {
function SessionsBy(props: Props) { function SessionsBy(props: Props) {
const { metric = {}, data = { values: [] }, onClick = () => null, isTemplate } = props; const { metric = {}, data = { values: [] }, onClick = () => null, isTemplate } = props;
const [selected, setSelected] = React.useState<any>(null); const [selected, setSelected] = React.useState<any>(null);
const total = data.values.length; const total = data.count;
const { openModal, closeModal } = useModal(); const { openModal, closeModal } = useModal();
const onClickHandler = (event: any, data: any) => { const onClickHandler = (event: any, data: any) => {
@ -42,10 +41,15 @@ function SessionsBy(props: Props) {
const showMore = (e: any) => { const showMore = (e: any) => {
e.stopPropagation(); e.stopPropagation();
openModal( openModal(
<CardSessionsByList list={data.values} onClickHandler={(e, item) => { <CardSessionsByList
closeModal(); paginated={true}
onClickHandler(null, item); metric={metric}
}} selected={selected} />, { total={total}
list={data.values}
onClickHandler={(e, item) => {
closeModal();
onClickHandler(null, item);
}} selected={selected} />, {
title: metric.name, title: metric.name,
width: 600 width: 600
}); });
@ -58,7 +62,7 @@ function SessionsBy(props: Props) {
image={null} image={null}
style={{ minHeight: 220 }} style={{ minHeight: 220 }}
className="flex flex-col items-center justify-center" className="flex flex-col items-center justify-center"
imageStyle={{ height: 0}} imageStyle={{ height: 0 }}
description={ description={
<div className="flex items-center gap-2 justify-center text-black"> <div className="flex items-center gap-2 justify-center text-black">
<Info size={14} /> <Info size={14} />

View file

@ -68,6 +68,7 @@ export default class DashboardStore {
const timeStamps = this.drillDownPeriod.toTimestamps(); const timeStamps = this.drillDownPeriod.toTimestamps();
this.drillDownFilter.updateKey('startTimestamp', timeStamps.startTimestamp); this.drillDownFilter.updateKey('startTimestamp', timeStamps.startTimestamp);
this.drillDownFilter.updateKey('endTimestamp', timeStamps.endTimestamp); this.drillDownFilter.updateKey('endTimestamp', timeStamps.endTimestamp);
this.updateKey('metricsPage', 1)
} }
get filteredList() { get filteredList() {