Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ba 2298 web package placeholder #222

Merged
merged 5 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @baseapp-frontend/components

## 1.0.24

### Patch Changes

- Add user activities to the Activity Log
- updated dependencies
- @baseapp-frontend/components

## 1.0.23

### Patch Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ export const ActivityLogsFragmentQuery = graphql`
node {
id
createdAt
events {
edges {
node {
label
diff
}
}
}
verb
url
user {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FetchParameters } from '../common/types'
import { FetchParameters } from '../../../common/types'

export interface DateFilterChipProps {
fetchParameters: FetchParameters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DateTime } from 'luxon'

import { FetchParameters } from '../common/types'
import { FetchParameters } from '../../../common/types'

export interface DateFilterComponentProps {
createdFrom: DateTime | null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,30 @@ import { FC } from 'react'

import { Box, Typography, useTheme } from '@mui/material'

import { LogItemProps } from './types'
import { getUpdateMessage } from '../utils'
import { LogDiff, LogItemProps } from './types'

const verbMapping: { [key: string]: string } = {
'comments.add_comment': 'Created a comment',
'comments.change_comment': 'Edited a comment',
'comments.delete_comment': 'Deleted a comment',
'comments.reply_comment': 'Replied to a comment',
'comments.pin_comment': 'Pinned a comment',
'profiles.update_profile': 'Updated their profile',
'baseapp_reactions.add_reaction': 'Added a reaction',
}

const getDisplayText = (verb: string) => verbMapping[verb] ?? verb

const LogItem: FC<LogItemProps> = ({ log, sx }) => {
const theme = useTheme()
if (!log?.verb) {
return null
if (!log?.verb) return null

const getLogMessage = (verb: string, diff?: LogDiff) => {
if (diff) return getUpdateMessage(verb, diff)
return verbMapping[verb] ?? verb
}

const diff = log.events?.edges?.[0]?.node?.diff ?? null
const displayText = getLogMessage(log.verb, diff)

return (
<Box
sx={sx}
Expand All @@ -31,7 +35,7 @@ const LogItem: FC<LogItemProps> = ({ log, sx }) => {
marginLeft="20px"
>
<Typography ml="30px" lineHeight="22px" color={theme.palette.text.secondary} variant="body2">
{getDisplayText(log.verb)}
{displayText}
</Typography>
</Box>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { SxProps, Theme } from '@mui/system'

import { ActivityLogNode } from '../../../common'
import { ActivityLogsFragment$data } from '../../../../../__generated__/ActivityLogsFragment.graphql'

export type ActivityLogs = NonNullable<ActivityLogsFragment$data['activityLogs']>
export type ActivityLogEdges = ActivityLogs['edges']
export type ActivityLogNode = NonNullable<ActivityLogEdges[number]>['node']
export type LogEvent = NonNullable<ActivityLogNode>['events']

export type LogEventEdges = NonNullable<LogEvent>['edges']
export type LogEventEdgesNode = NonNullable<LogEventEdges[number]>['node']
export type LogDiff = NonNullable<LogEventEdgesNode>['diff']

export interface LogItemProps {
log: ActivityLogNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { Box, Typography } from '@mui/material'
import { useForm } from 'react-hook-form'

import { SearchNotFoundState } from '../../../__shared__/web'
import DateFilterChip from '../../DateFilterChip'
import { FetchParameters, useActivityLogs } from '../../common'
import DateFilterChip from './DateFilterChip'
import EventFilterChip from './EventFilterChip'
import DefaultLogGroups from './LogGroups'
import { ActivityLogComponentProps, EventFilterOption } from './types'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const getUpdateMessage = (verb: string, diff: Record<string, any>): string => {
const baseMessage = `Updated ${verb.split('.')[0]}`

if (!diff) {
return baseMessage
}

const updateMessages: string[] = Object.keys(diff).map((key) => {
switch (key) {
case 'image':
return 'Updated their profile picture'
case 'banner_image':
return 'Updated their profile banner'
case 'biography':
return 'Updated their bio'
default:
return `Updated ${key.replace('_', ' ')}`
}
})

return updateMessages.length > 0 ? updateMessages.join(', ') : baseMessage
}
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@baseapp-frontend/components",
"description": "BaseApp components modules such as comments, notifications, messages, and more.",
"version": "1.0.23",
"version": "1.0.24",
"sideEffects": false,
"scripts": {
"babel:transpile": "babel modules -d tmp-babel --extensions .ts,.tsx --ignore '**/__tests__/**','**/__storybook__/**'",
Expand Down
1 change: 1 addition & 0 deletions packages/components/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ActivityLog implements Node {
user: User
ipAddress: String
verb: String
diff: GenericScalar
visibility: VisibilityTypes
url: String
pk: Int!
Expand Down
Loading