2023-08-04 22:10:03 +02:00
|
|
|
import { useContext } from 'react';
|
2023-08-07 23:01:53 +02:00
|
|
|
import { GridTable, GridColumn } from 'react-basics';
|
2023-08-04 22:10:03 +02:00
|
|
|
import { ReportContext } from '../Report';
|
2023-08-13 05:13:11 +02:00
|
|
|
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
|
|
|
|
import styles from './RetentionTable.module.css';
|
2023-08-04 22:10:03 +02:00
|
|
|
|
|
|
|
export function RetentionTable() {
|
|
|
|
const { report } = useContext(ReportContext);
|
2023-08-13 05:13:11 +02:00
|
|
|
const { data } = report || {};
|
2023-08-07 23:01:53 +02:00
|
|
|
|
2023-08-13 05:13:11 +02:00
|
|
|
if (!data) {
|
|
|
|
return <EmptyPlaceholder />;
|
|
|
|
}
|
|
|
|
|
|
|
|
const dates = data.reduce((arr, { date }) => {
|
|
|
|
if (!arr.includes(date)) {
|
|
|
|
return arr.concat(date);
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const days = Array(14).fill(null);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className={styles.table}>
|
|
|
|
<div className={styles.row}>
|
|
|
|
{days.map((n, i) => (
|
|
|
|
<div key={i} className={styles.header}>
|
|
|
|
Day {i}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
{dates.map((date, i) => {
|
|
|
|
return (
|
|
|
|
<div key={i} className={styles.row}>
|
|
|
|
{days.map((n, day) => {
|
|
|
|
return (
|
|
|
|
<div key={day} className={styles.cell}>
|
|
|
|
{data.find(row => row.date === date && row.day === day)?.percentage.toFixed(2)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
<DataTable data={data} />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function DataTable({ data }) {
|
2023-08-04 22:10:03 +02:00
|
|
|
return (
|
2023-08-13 05:13:11 +02:00
|
|
|
<GridTable data={data || []}>
|
2023-08-08 20:57:58 +02:00
|
|
|
<GridColumn name="date" label={'Date'}>
|
|
|
|
{row => row.date}
|
|
|
|
</GridColumn>
|
|
|
|
<GridColumn name="day" label={'Day'}>
|
|
|
|
{row => row.day}
|
|
|
|
</GridColumn>
|
2023-08-13 05:13:11 +02:00
|
|
|
<GridColumn name="visitors" label={'Visitors'}>
|
2023-08-08 20:57:58 +02:00
|
|
|
{row => row.visitors}
|
|
|
|
</GridColumn>
|
|
|
|
<GridColumn name="returnVisitors" label={'Return Visitors'}>
|
|
|
|
{row => row.returnVisitors}
|
|
|
|
</GridColumn>
|
|
|
|
<GridColumn name="percentage" label={'Percentage'}>
|
|
|
|
{row => row.percentage}
|
2023-08-07 23:01:53 +02:00
|
|
|
</GridColumn>
|
|
|
|
</GridTable>
|
2023-08-04 22:10:03 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default RetentionTable;
|