|
1 | 1 | import {useTranslation} from "react-i18next"; |
2 | 2 | import {faUser, faUserCircle, faUserPlus, faUsers} from "@fortawesome/free-solid-svg-icons"; |
3 | 3 | import React, {useCallback} from "react"; |
4 | | -import {TableRow} from "./TableRow"; |
5 | | -import ComparisonTable from "./ComparisonTable"; |
6 | | -import SmallTrend from "../trend/SmallTrend"; |
7 | 4 | import {FontAwesomeIcon as Fa} from "@fortawesome/react-fontawesome"; |
8 | | -import {faCalendarCheck, faClock, faEye, faQuestionCircle} from "@fortawesome/free-regular-svg-icons"; |
9 | | -import {CardLoader} from "../navigation/Loader.tsx"; |
| 5 | +import {faCalendarCheck, faClock, faQuestionCircle} from "@fortawesome/free-regular-svg-icons"; |
10 | 6 | import {useNavigation} from "../../hooks/navigationHook.tsx"; |
11 | | -import FormattedTime from "../text/FormattedTime.jsx"; |
12 | | -import {useTimeAmountFormatter} from "../../util/format/useTimeAmountFormatter.js"; |
| 7 | +import {MS_24H, MS_MONTH, MS_WEEK} from "../../util/format/useDateFormatter.js"; |
| 8 | +import {DatapointType} from "../../dataHooks/model/datapoint/Datapoint.ts"; |
| 9 | +import {QueryDatapointTable} from "./QueryDatapointTable.tsx"; |
| 10 | +import {useParams} from "react-router"; |
13 | 11 |
|
14 | | -const OnlineActivityAsNumbersTable = ({data}) => { |
| 12 | +const OnlineActivityAsNumbersTable = () => { |
15 | 13 | const {t} = useTranslation(); |
16 | 14 | const {setHelpModalTopic} = useNavigation(); |
17 | | - const {formatTime} = useTimeAmountFormatter(); |
| 15 | + const {identifier} = useParams(); |
18 | 16 | const openHelp = useCallback(() => setHelpModalTopic('new-player-retention'), [setHelpModalTopic]); |
19 | | - if (!data) return <CardLoader/>; |
20 | 17 |
|
21 | 18 | return ( |
22 | | - <ComparisonTable |
23 | | - headers={[t('html.label.last30days'), t('html.label.last7days'), t('html.label.last24hours')]} |
24 | | - comparisonHeader={t('html.text.comparing15days')} |
25 | | - > |
26 | | - <TableRow icon={faUsers} color="players-unique" text={t('html.label.uniquePlayers')} |
27 | | - values={[ |
28 | | - <>{data.unique_players_30d}{' '}<SmallTrend trend={data.unique_players_30d_trend}/></>, |
29 | | - data.unique_players_7d, |
30 | | - data.unique_players_24h |
31 | | - ]}/> |
32 | | - <TableRow icon={faUser} color="players-unique" |
33 | | - text={t('html.label.uniquePlayers') + ' ' + t('html.label.perDay')} |
34 | | - values={[ |
35 | | - <>{data.unique_players_30d_avg}{' '}<SmallTrend |
36 | | - trend={data.unique_players_30d_avg_trend}/></>, |
37 | | - data.unique_players_7d_avg, |
38 | | - data.unique_players_24h_avg |
39 | | - ]}/> |
40 | | - <TableRow icon={faUsers} color="players-new" text={t('html.label.newPlayers')} |
41 | | - values={[ |
42 | | - <>{data.new_players_30d}{' '}<SmallTrend trend={data.new_players_30d_trend}/></>, |
43 | | - data.new_players_7d, |
44 | | - data.new_players_24h |
45 | | - ]}/> |
46 | | - <TableRow icon={faUserPlus} color="players-new" |
47 | | - text={t('html.label.newPlayers') + ' ' + t('html.label.perDay')} |
48 | | - values={[ |
49 | | - <>{data.new_players_30d_avg}{' '}<SmallTrend trend={data.new_players_30d_avg_trend}/></>, |
50 | | - data.new_players_7d_avg, |
51 | | - data.new_players_24h_avg |
52 | | - ]}/> |
53 | | - <TableRow icon={faUserCircle} color="retention-new-players" |
54 | | - text={<>{t('html.label.newPlayerRetention')} <span> |
| 19 | + <QueryDatapointTable |
| 20 | + filter={{server: identifier}} |
| 21 | + columns={[{ |
| 22 | + key: '30d', |
| 23 | + filter: {afterMillisAgo: MS_MONTH} |
| 24 | + }, { |
| 25 | + key: '7d', |
| 26 | + filter: {afterMillisAgo: MS_WEEK} |
| 27 | + }, { |
| 28 | + key: '1d', |
| 29 | + filter: {afterMillisAgo: MS_24H} |
| 30 | + }]} |
| 31 | + rows={[{ |
| 32 | + dataType: DatapointType.UNIQUE_PLAYERS_COUNT, |
| 33 | + color: "players-unique", |
| 34 | + icon: faUsers, |
| 35 | + text: t('html.label.uniquePlayers') |
| 36 | + }, { |
| 37 | + dataType: DatapointType.UNIQUE_PLAYERS_AVERAGE, |
| 38 | + color: "players-unique", |
| 39 | + icon: faUser, |
| 40 | + text: t('html.label.uniquePlayers') + ' ' + t('html.label.perDay') |
| 41 | + }, { |
| 42 | + dataType: DatapointType.NEW_PLAYERS, |
| 43 | + color: "players-new", |
| 44 | + icon: faUsers, |
| 45 | + text: t('html.label.newPlayers') |
| 46 | + }, { |
| 47 | + dataType: DatapointType.NEW_PLAYERS_AVERAGE, |
| 48 | + color: "players-new", |
| 49 | + icon: faUserPlus, |
| 50 | + text: t('html.label.newPlayers') + ' ' + t('html.label.perDay') |
| 51 | + }, { |
| 52 | + dataType: DatapointType.NEW_PLAYER_RETENTION, |
| 53 | + color: "players-new", |
| 54 | + icon: faUserCircle, |
| 55 | + text: <>{t('html.label.newPlayerRetention')} <span> |
55 | 56 | <button onClick={openHelp}><Fa className={"col-text"} |
56 | 57 | icon={faQuestionCircle}/> |
57 | | - </button></span></>} |
58 | | - values={[ |
59 | | - `(${data.new_players_retention_30d}/${data.new_players_30d}) ${data.new_players_retention_30d_perc}`, |
60 | | - `(${data.new_players_retention_7d}/${data.new_players_7d}) ${data.new_players_retention_7d_perc}`, |
61 | | - <>{`(${data.new_players_retention_24h}/${data.new_players_24h}) ${data.new_players_retention_24h_perc}`} |
62 | | - {' '}<span title={t('html.description.newPlayerRetention')}><Fa icon={faEye}/></span></> |
63 | | - ]}/> |
64 | | - <TableRow icon={faClock} color="playtime" |
65 | | - text={t('html.label.playtime')} |
66 | | - values={[ |
67 | | - <>{<FormattedTime timeMs={data.playtime_30d}/>}{' '}<SmallTrend |
68 | | - trend={data.playtime_30d_trend} format={formatTime}/></>, |
69 | | - <FormattedTime timeMs={data.playtime_7d}/>, |
70 | | - <FormattedTime timeMs={data.playtime_24h}/> |
71 | | - ]}/> |
72 | | - <TableRow icon={faClock} color="playtime" |
73 | | - text={t('html.label.averagePlaytime') + ' ' + t('html.label.perDay')} |
74 | | - values={[ |
75 | | - <>{<FormattedTime timeMs={data.playtime_30d_avg}/>}{' '}<SmallTrend |
76 | | - trend={data.playtime_30d_avg_trend} format={formatTime}/></>, |
77 | | - <FormattedTime timeMs={data.playtime_7d_avg}/>, |
78 | | - <FormattedTime timeMs={data.playtime_24h_avg}/> |
79 | | - ]}/> |
80 | | - <TableRow icon={faClock} color="sessions" |
81 | | - text={t('html.label.averageSessionLength')} |
82 | | - values={[ |
83 | | - <>{<FormattedTime timeMs={data.session_length_30d_avg}/>}{' '}<SmallTrend |
84 | | - trend={data.session_length_30d_trend} format={formatTime}/></>, |
85 | | - <FormattedTime timeMs={data.session_length_7d_avg}/>, |
86 | | - <FormattedTime timeMs={data.session_length_24h_avg}/> |
87 | | - ]}/> |
88 | | - <TableRow icon={faCalendarCheck} color="sessions" |
89 | | - text={t('html.label.sessions')} |
90 | | - values={[ |
91 | | - <>{data.sessions_30d}{' '}<SmallTrend trend={data.sessions_30d_trend}/></>, |
92 | | - data.sessions_7d, |
93 | | - data.sessions_24h |
94 | | - ]}/> |
95 | | - </ComparisonTable> |
| 58 | + </button></span></> |
| 59 | + }, { |
| 60 | + dataType: DatapointType.PLAYTIME, |
| 61 | + color: "playtime", |
| 62 | + icon: faClock, |
| 63 | + text: t('html.label.playtime') |
| 64 | + }, { |
| 65 | + dataType: DatapointType.PLAYTIME_PER_DAY_AVERAGE, |
| 66 | + color: "playtime", |
| 67 | + icon: faClock, |
| 68 | + text: t('html.label.averagePlaytime') + ' ' + t('html.label.perDay') |
| 69 | + }, { |
| 70 | + dataType: DatapointType.SESSION_LENGTH_AVERAGE, |
| 71 | + color: "sessions", |
| 72 | + icon: faClock, |
| 73 | + text: t('html.label.averageSessionLength') |
| 74 | + }, { |
| 75 | + dataType: DatapointType.SESSION_COUNT, |
| 76 | + color: "sessions", |
| 77 | + icon: faCalendarCheck, |
| 78 | + text: t('html.label.sessions') |
| 79 | + }]}/> |
96 | 80 | ) |
97 | 81 | } |
98 | 82 |
|
|
0 commit comments