Fix Activity Index not showing up on Players Tables

This commit is contained in:
Aurora Lahtela 2023-10-10 09:05:28 +03:00
parent 549a26bcc8
commit a74fb36b10
4 changed files with 17 additions and 4 deletions

View File

@ -137,6 +137,7 @@ public class PlayersTableJSONCreator {
.map(player -> TablePlayerDto.builder()
.withUuid(player.getPlayerUUID())
.withName(player.getName().orElseGet(() -> player.getPlayerUUID().toString()))
.withActivityIndex(player.getCurrentActivityIndex().map(ActivityIndex::getValue).orElse(0.0))
.withSessionCount((long) player.getSessionCount().orElse(0))
.withPlaytimeActive(player.getActivePlaytime().orElse(null))
.withLastSeen(player.getLastSeen().orElse(null))

View File

@ -11,6 +11,8 @@ import FormattedDate from "../../text/FormattedDate";
import FormattedTime from "../../text/FormattedTime";
import ExtensionIcon from "../../extensions/ExtensionIcon";
import {ExtensionValueTableCell} from "../../extensions/ExtensionCard";
import {usePreferences} from "../../../hooks/preferencesHook";
import {formatDecimals} from "../../../util/formatters";
const getActivityGroup = value => {
const VERY_ACTIVE = 3.75;
@ -32,6 +34,8 @@ const getActivityGroup = value => {
const PlayerListCard = ({data, title, justList, orderBy}) => {
const {t} = useTranslation();
const {preferencesLoaded, decimalFormat} = usePreferences();
const [options, setOptions] = useState(undefined);
useEffect(() => {
@ -73,7 +77,7 @@ const PlayerListCard = ({data, title, justList, orderBy}) => {
uuid: player.playerUUID,
link: <Link to={"/player/" + player.playerUUID}>{player.playerName}</Link>,
activityIndex: player.activityIndex,
activityIndexAndGroup: player.activityIndex + " (" + t(getActivityGroup(player.activityIndex)) + ")",
activityIndexAndGroup: formatDecimals(player.activityIndex, decimalFormat) + " (" + t(getActivityGroup(player.activityIndex)) + ")",
activePlaytime: player.playtimeActive,
activePlaytimeFormatted: <FormattedTime timeMs={player.playtimeActive}/>,
sessions: player.sessionCount,
@ -97,13 +101,14 @@ const PlayerListCard = ({data, title, justList, orderBy}) => {
data: rows,
order: [[orderBy !== undefined ? orderBy : 5, "desc"]]
});
}, [data, orderBy, t]);
}, [data, orderBy, t, formatDecimals, decimalFormat]);
const rowKeyFunction = useCallback((row, column) => {
return row.uuid + "-" + (column ? JSON.stringify(column.data) : '');
}, []);
if (!options) return <CardLoader/>
if (!preferencesLoaded) return <></>;
if (!options) return <CardLoader/>;
if (justList) {
return (

View File

@ -122,7 +122,7 @@ const DataTablesTable = ({id, rowKeyFunction, options}) => {
if (valA === undefined && valB === undefined) return 0;
if (valA === undefined) return sortReversed ? 1 : -1;
if (valB === undefined) return sortReversed ? 1 : -1;
if (Number.isSafeInteger(valA) && Number.isSafeInteger(valB)) {
if (typeof valA === 'number' && typeof valB === 'number') {
return sortReversed ? valA - valB : valB - valA;
}
return sortReversed ? valB.localeCompare(valA) : valA.localeCompare(valB);

View File

@ -22,4 +22,11 @@ export const formatTimeAmount = (ms) => {
out += seconds.toString() + "s ";
return out;
}
export const formatDecimals = (value, formatPattern) => {
if (!formatPattern) return value;
const split = formatPattern.split('.');
if (split.length <= 1) return value.toFixed(0);
return value.toFixed(split[1].length);
}