DataTable.js
5 years ago
DatePicker.js
5 years ago
OverviewPanel.js
5 years ago
TopUsers.js
3 years ago
TopVideos.js
3 years ago
TotalVideoViewsByUser.js
4 years ago
TotalViewsGraph.js
4 years ago
TotalWatchGraph.js
4 years ago
VideoAverageWatchTime.js
4 years ago
VideoAverageWatchTimeByUser.js
4 years ago
VideoTimeline.js
4 years ago
VideoTotalWatchTimeByUser.js
4 years ago
VideoViews.js
5 years ago
TopUsers.js
86 lines
| 1 | const { __ } = wp.i18n; |
| 2 | const { useEffect } = wp.element; |
| 3 | const { compose } = wp.compose; |
| 4 | |
| 5 | import { history } from "@/router/context"; |
| 6 | import withDataList from "../hocs/withDataList"; |
| 7 | import { convertDateTimeToAbsoluteDate } from "../util"; |
| 8 | import DataTable from "./DataTable"; |
| 9 | |
| 10 | export default compose([withDataList()])( |
| 11 | ({ |
| 12 | loading, |
| 13 | page, |
| 14 | setPage, |
| 15 | total, |
| 16 | totalPages, |
| 17 | data, |
| 18 | error, |
| 19 | fetchData, |
| 20 | startDate, |
| 21 | endDate, |
| 22 | }) => { |
| 23 | // 10 per page |
| 24 | const per_page = 5; |
| 25 | |
| 26 | // fetch data when page changes |
| 27 | useEffect(() => { |
| 28 | fetchData({ |
| 29 | endpoint: "/presto-player/v1/analytics/top-users", |
| 30 | params: { |
| 31 | per_page, |
| 32 | ...(startDate |
| 33 | ? { start: convertDateTimeToAbsoluteDate(startDate) } |
| 34 | : {}), |
| 35 | ...(endDate ? { end: convertDateTimeToAbsoluteDate(endDate) } : {}), |
| 36 | }, |
| 37 | }); |
| 38 | }, [page, startDate, endDate]); |
| 39 | |
| 40 | // navigate to user screen here |
| 41 | const navigate = (id) => { |
| 42 | const { search } = history.location; |
| 43 | history.push(`${search}#/user/${id}`); |
| 44 | }; |
| 45 | |
| 46 | const columns = [ |
| 47 | { |
| 48 | key: "name", |
| 49 | label: __("Name", "presto-player"), |
| 50 | value: (row) => row?.user?.name, |
| 51 | }, |
| 52 | { |
| 53 | key: "total_view", |
| 54 | label: __("Total View", "presto-player"), |
| 55 | value: (row) => row?.stats?.[0]?.data, |
| 56 | }, |
| 57 | { |
| 58 | key: "avg_view_time", |
| 59 | label: __("Avg View Time", "presto-player"), |
| 60 | render: (row) => ( |
| 61 | <div className="presto-badge">{row?.stats?.[1]?.data}</div> |
| 62 | ), |
| 63 | }, |
| 64 | ]; |
| 65 | |
| 66 | if (error) { |
| 67 | return { error }; |
| 68 | } |
| 69 | |
| 70 | return ( |
| 71 | <DataTable |
| 72 | title={__("Top Users", "presto-player")} |
| 73 | page={page} |
| 74 | perPage={per_page} |
| 75 | setPage={setPage} |
| 76 | loading={loading} |
| 77 | total={total} |
| 78 | totalPages={totalPages} |
| 79 | columns={columns} |
| 80 | data={data} |
| 81 | onSelect={(row) => navigate(row?.user?.id)} |
| 82 | /> |
| 83 | ); |
| 84 | } |
| 85 | ); |
| 86 |