@@ -8,37 +8,40 @@ import ActivityLogMetaButton from '@/components/elements/activity/ActivityLogMet
88import { TerminalIcon } from '@heroicons/react/solid' ;
99import classNames from 'classnames' ;
1010import style from './style.module.css' ;
11- import { isObject } from '@/lib/objects' ;
1211import Avatar from '@/components/Avatar' ;
1312import useLocationHash from '@/plugins/useLocationHash' ;
13+ import { getObjectKeys , isObject } from '@/lib/objects' ;
1414
1515interface 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
3841export 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