change(ui): paginate the data in table of cards show more modal
This commit is contained in:
parent
18bb6e0263
commit
4cfc5d2517
3 changed files with 105 additions and 54 deletions
|
|
@ -1,24 +1,54 @@
|
||||||
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) {
|
||||||
|
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<any>(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 (
|
return (
|
||||||
|
<div className="flex flex-col h-full">
|
||||||
|
<div className="flex-1 overflow-y-auto">
|
||||||
<List
|
<List
|
||||||
dataSource={list}
|
dataSource={data}
|
||||||
split={false}
|
split={false}
|
||||||
|
loading={loading}
|
||||||
renderItem={(row: any, index: number) => (
|
renderItem={(row: any, index: number) => (
|
||||||
<List.Item
|
<List.Item
|
||||||
key={row.name}
|
key={row.name}
|
||||||
onClick={(e) => onClickHandler(e, row)}
|
onClick={(e) => onClickHandler(e, row)}
|
||||||
style={{
|
style={{
|
||||||
borderBottom: index === list.length - 1 ? 'none' : '1px dotted rgba(0, 0, 0, 0.05)',
|
borderBottom: index === data.length - 1 ? 'none' : '1px dotted rgba(0, 0, 0, 0.05)',
|
||||||
padding: '4px 10px',
|
padding: '4px 10px',
|
||||||
lineHeight: '1px'
|
lineHeight: '1px'
|
||||||
}}
|
}}
|
||||||
|
|
@ -54,7 +84,23 @@ function CardSessionsByList({ list, selected, onClickHandler = () => null }: Pro
|
||||||
</List.Item>
|
</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)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CardSessionsByList;
|
export default observer(CardSessionsByList);
|
||||||
|
|
|
||||||
|
|
@ -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,7 +41,12 @@ 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
|
||||||
|
paginated={true}
|
||||||
|
metric={metric}
|
||||||
|
total={total}
|
||||||
|
list={data.values}
|
||||||
|
onClickHandler={(e, item) => {
|
||||||
closeModal();
|
closeModal();
|
||||||
onClickHandler(null, item);
|
onClickHandler(null, item);
|
||||||
}} selected={selected} />, {
|
}} selected={selected} />, {
|
||||||
|
|
@ -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} />
|
||||||
|
|
|
||||||
|
|
@ -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() {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue