Skip to content

Commit 48af9bc

Browse files
committed
Fix activity log rendering; closes pterodactyl#4208
1 parent 0d0c595 commit 48af9bc

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

app/Transformers/Api/Client/ActivityLogTransformer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ protected function properties(ActivityLog $model): array
5555
}
5656

5757
if (!is_array($value)) {
58+
// Perform some directory normalization at this point.
59+
if ($key === 'directory') {
60+
$value = str_replace('//', '/', '/' . trim($value, '/') . '/');
61+
}
62+
5863
return [$key => $value];
5964
}
6065

resources/scripts/components/elements/activity/ActivityLogEntry.tsx

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,40 @@ import ActivityLogMetaButton from '@/components/elements/activity/ActivityLogMet
88
import { TerminalIcon } from '@heroicons/react/solid';
99
import classNames from 'classnames';
1010
import style from './style.module.css';
11-
import { isObject } from '@/lib/objects';
1211
import Avatar from '@/components/Avatar';
1312
import useLocationHash from '@/plugins/useLocationHash';
13+
import { getObjectKeys, isObject } from '@/lib/objects';
1414

1515
interface Props {
1616
activity: ActivityLog;
1717
children?: React.ReactNode;
1818
}
1919

20-
const formatProperties = (properties: Record<string, unknown>): Record<string, unknown> => {
21-
return Object.keys(properties).reduce((obj, key) => {
22-
const value = properties[key];
23-
// noinspection SuspiciousTypeOfGuard
24-
const isCount = key === 'count' || (typeof key === 'string' && key.endsWith('_count'));
20+
function wrapProperties(value: unknown): any {
21+
if (value === null || typeof value === 'string' || typeof value === 'number') {
22+
return `<strong>${String(value)}</strong>`;
23+
}
2524

26-
return {
27-
...obj,
28-
[key]:
29-
isCount || typeof value !== 'string'
30-
? isObject(value)
31-
? formatProperties(value)
32-
: value
33-
: `<strong>${value}</strong>`,
34-
};
35-
}, {});
36-
};
25+
if (isObject(value)) {
26+
return getObjectKeys(value).reduce((obj, key) => {
27+
if (key === 'count' || (typeof key === 'string' && key.endsWith('_count'))) {
28+
return { ...obj, [key]: value[key] };
29+
}
30+
return { ...obj, [key]: wrapProperties(value[key]) };
31+
}, {} as Record<string, unknown>);
32+
}
33+
34+
if (Array.isArray(value)) {
35+
return value.map(wrapProperties);
36+
}
37+
38+
return value;
39+
}
3740

3841
export default ({ activity, children }: Props) => {
3942
const { pathTo } = useLocationHash();
4043
const actor = activity.relationships.actor;
41-
const properties = formatProperties(activity.properties);
44+
const properties = wrapProperties(activity.properties);
4245

4346
return (
4447
<div className={'grid grid-cols-10 py-4 border-b-2 border-gray-800 last:rounded-b last:border-0 group'}>

0 commit comments

Comments
 (0)