Skip to content

Commit

Permalink
Fixed up a bunch of issues around possible optional detail
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Jan 2, 2024
1 parent aeaf016 commit ed8ff15
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 50 deletions.
6 changes: 3 additions & 3 deletions frontend/src/lib/components/ActivityLog/humanizeActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export type ActivityLogItem = {
created_at: string
scope: ActivityScope
item_id?: string
detail: ActivityLogDetail
detail?: ActivityLogDetail
unread?: boolean // when used as a notification
is_system?: boolean // when auto-created e.g. an exported image when sharing an insight
}
Expand Down Expand Up @@ -140,7 +140,7 @@ export function defaultDescriber(
asNotification = false,
resource?: string | JSX.Element
): HumanizedChange {
resource = resource || logItem.detail.name || `a ${humanizeScope(logItem.scope, true)}`
resource = resource || logItem.detail?.name || `a ${humanizeScope(logItem.scope, true)}`

if (logItem.activity == 'deleted') {
return {
Expand Down Expand Up @@ -169,7 +169,7 @@ export function defaultDescriber(
</>
)
}
const commentContent = logItem.detail.changes?.[0].after as string | undefined
const commentContent = logItem.detail?.changes?.[0].after as string | undefined

return {
description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ const dataManagementActionsMapping: Record<

function nameAndLink(logItem?: ActivityLogItem): JSX.Element {
return logItem?.item_id ? (
<Link to={urls.eventDefinition(logItem.item_id)}>{logItem?.detail.name || 'unknown'}</Link>
) : logItem?.detail.name ? (
<Link to={urls.eventDefinition(logItem.item_id)}>{logItem?.detail?.name || 'unknown'}</Link>
) : logItem?.detail?.name ? (
<>{logItem?.detail.name}</>
) : (
<>unknown</>
Expand Down Expand Up @@ -106,7 +106,7 @@ export function dataManagementActivityDescriber(logItem: ActivityLogItem, asNoti
</>
)

for (const change of logItem.detail.changes || []) {
for (const change of logItem.detail?.changes || []) {
if (!change?.field || !dataManagementActionsMapping[change.field]) {
continue // updates have to have a "field" to be described
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/scenes/feature-flags/activityDescriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ export function flagActivityDescriber(logItem: ActivityLogItem, asNotification?:
let changeSuffix: Description = (
<>
on {asNotification && ' the flag '}
{nameOrLinkToFlag(logItem?.item_id, logItem?.detail.name)}
{nameOrLinkToFlag(logItem?.item_id, logItem.detail?.name)}
</>
)

for (const change of logItem.detail.changes || []) {
for (const change of logItem.detail?.changes || []) {
if (!change?.field) {
continue // feature flag updates have to have a "field" to be described
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/scenes/notebooks/Notebook/NotebookHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ActivityScope } from '~/types'
import { notebookLogic } from './notebookLogic'

const getFieldChange = (logItem: ActivityLogItem, field: string): any => {
return logItem.detail.changes?.find((x) => x.field === field)?.after
return logItem.detail?.changes?.find((x) => x.field === field)?.after
}

function NotebookHistoryList({ onItemClick }: { onItemClick: (logItem: ActivityLogItem) => void }): JSX.Element {
Expand Down Expand Up @@ -101,7 +101,7 @@ export function NotebookHistory(): JSX.Element {
const { setShowHistory, setPreviewContent } = useActions(notebookLogic)

const onRevert = (logItem: ActivityLogItem): void => {
const content = logItem.detail.changes?.find((x) => x.field === 'content')?.after
const content = logItem.detail?.changes?.find((x) => x.field === 'content')?.after

if (!content) {
lemonToast.error('Could not revert to this version')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const notebookActionsMapping: Record<

function nameAndLink(logItem?: ActivityLogItem): JSX.Element {
return logItem?.detail?.short_id ? (
<Link to={urls.notebook(logItem.detail.short_id)}>{logItem?.detail.name || 'unknown'}</Link>
) : logItem?.detail.name ? (
<>{logItem?.detail.name}</>
<Link to={urls.notebook(logItem.detail.short_id)}>{logItem.detail.name || 'unknown'}</Link>
) : logItem?.detail?.name ? (
<>{logItem.detail.name}</>
) : (
<i>Untitled</i>
)
Expand All @@ -45,7 +45,7 @@ export function notebookActivityDescriber(logItem: ActivityLogItem, asNotificati
let changes: Description[] = []
let changeSuffix: Description = <>on {nameAndLink(logItem)}</>

for (const change of logItem.detail.changes || []) {
for (const change of logItem.detail?.changes || []) {
if (!change?.field || !notebookActionsMapping[change.field]) {
continue // not all notebook fields are describable
}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/scenes/persons/activityDescriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function personActivityDescriber(logItem: ActivityLogItem, asNotification
return {
description: (
<>
<strong>{userNameForLogItem(logItem)}</strong> deleted the person: {logItem.detail.name}
<strong>{userNameForLogItem(logItem)}</strong> deleted the person: {logItem.detail?.name}
</>
),
}
Expand All @@ -39,7 +39,7 @@ export function personActivityDescriber(logItem: ActivityLogItem, asNotification
}
}
if (logItem.activity === 'people_merged_into') {
if (logItem.detail.merge?.source) {
if (logItem.detail?.merge?.source) {
return {
description: (
<SentenceList
Expand All @@ -48,7 +48,7 @@ export function personActivityDescriber(logItem: ActivityLogItem, asNotification
<strong>{userNameForLogItem(logItem)}</strong> merged
</>
}
listParts={logItem.detail.merge.source.flatMap((di) => (
listParts={logItem.detail?.merge.source.flatMap((di) => (
<span className={'highlighted-activity'}>
<PersonDisplay person={di} />
</span>
Expand All @@ -61,7 +61,7 @@ export function personActivityDescriber(logItem: ActivityLogItem, asNotification
}

if (logItem.activity === 'split_person') {
const distinctIds: string[] | undefined = logItem.detail.changes?.[0].after?.['distinct_ids']
const distinctIds: string[] | undefined = logItem.detail?.changes?.[0].after?.['distinct_ids']
if (distinctIds) {
return {
description: (
Expand Down
32 changes: 16 additions & 16 deletions frontend/src/scenes/plugins/pluginActivityDescriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function pluginActivityDescriber(logItem: ActivityLogItem, asNotification
return {
description: (
<>
<strong>{userNameForLogItem(logItem)}</strong> installed the app: <b>{logItem.detail.name}</b>
<strong>{userNameForLogItem(logItem)}</strong> installed the app: <b>{logItem.detail?.name}</b>
</>
),
}
Expand All @@ -31,15 +31,15 @@ export function pluginActivityDescriber(logItem: ActivityLogItem, asNotification
return {
description: (
<>
<strong>{userNameForLogItem(logItem)}</strong> uninstalled the app: <b>{logItem.detail.name}</b>
<strong>{userNameForLogItem(logItem)}</strong> uninstalled the app: <b>{logItem.detail?.name}</b>
</>
),
}
}

if (logItem.activity == 'enabled') {
const changes: (string | JSX.Element)[] = []
for (const change of logItem.detail.changes || []) {
for (const change of logItem.detail?.changes || []) {
const newValue = change.after === SECRET_FIELD_VALUE ? '<secret_value>' : change.after
changes.push(
<>
Expand All @@ -53,8 +53,8 @@ export function pluginActivityDescriber(logItem: ActivityLogItem, asNotification
listParts={changes}
prefix={
<>
<strong>{userNameForLogItem(logItem)}</strong> enabled the app: <b>{logItem.detail.name}</b>{' '}
with config ID {logItem.item_id}
<strong>{userNameForLogItem(logItem)}</strong> enabled the app:{' '}
<b>{logItem.detail?.name}</b> with config ID {logItem.item_id}
{changes.length > 0 ? ', with' : '.'}
</>
}
Expand All @@ -67,14 +67,14 @@ export function pluginActivityDescriber(logItem: ActivityLogItem, asNotification
return {
description: (
<>
<strong>{userNameForLogItem(logItem)}</strong> disabled the app: <b>{logItem.detail.name}</b> with
<strong>{userNameForLogItem(logItem)}</strong> disabled the app: <b>{logItem.detail?.name}</b> with
config ID {logItem.item_id}.
</>
),
}
}

if (logItem.activity == 'job_triggered' && logItem.detail.trigger?.job_type == 'Export historical events V2') {
if (logItem.activity == 'job_triggered' && logItem.detail?.trigger?.job_type == 'Export historical events V2') {
const [startDate, endDate] = logItem.detail.trigger.payload.dateRange
return {
description: (
Expand All @@ -86,23 +86,23 @@ export function pluginActivityDescriber(logItem: ActivityLogItem, asNotification
}
}

if (logItem.activity == 'job_triggered' && logItem.detail.trigger) {
if (logItem.activity == 'job_triggered' && logItem.detail?.trigger) {
return {
description: (
<>
<strong>{userNameForLogItem(logItem)}</strong> triggered job:{' '}
<code>{logItem.detail.trigger.job_type}</code> with config ID {logItem.item_id}.
<code>{logItem.detail?.trigger.job_type}</code> with config ID {logItem.item_id}.
</>
),
extendedDescription: (
<>
Payload: <code>{JSON.stringify(logItem.detail.trigger.payload, null, 2)}</code>
Payload: <code>{JSON.stringify(logItem.detail?.trigger.payload, null, 2)}</code>
</>
),
}
}

if (logItem.activity == 'export_success' && logItem.detail.trigger) {
if (logItem.activity == 'export_success' && logItem.detail?.trigger) {
const { dateFrom, dateTo } = logItem.detail.trigger.payload
const startDate = dayjs(dateFrom).format('YYYY-MM-DD')
// :TRICKY: Internally export date range is non-inclusive so transform it to be inclusive
Expand All @@ -117,7 +117,7 @@ export function pluginActivityDescriber(logItem: ActivityLogItem, asNotification
}
}

if (logItem.activity == 'export_fail' && logItem.detail.trigger) {
if (logItem.activity == 'export_fail' && logItem.detail?.trigger) {
const { dateFrom, dateTo } = logItem.detail.trigger.payload
const startDate = dayjs(dateFrom).format('YYYY-MM-DD')
// :TRICKY: Internally export date range is non-inclusive so transform it to be inclusive
Expand All @@ -135,7 +135,7 @@ export function pluginActivityDescriber(logItem: ActivityLogItem, asNotification

if (logItem.activity == 'config_updated') {
const changes: (string | JSX.Element)[] = []
for (const change of logItem.detail.changes || []) {
for (const change of logItem.detail?.changes || []) {
let changeWording: string | JSX.Element = ''
const changeBefore = change.before === SECRET_FIELD_VALUE ? '<secret_value>' : change.before
const changeAfter = change.after === SECRET_FIELD_VALUE ? '<secret_value>' : change.after
Expand Down Expand Up @@ -168,7 +168,7 @@ export function pluginActivityDescriber(logItem: ActivityLogItem, asNotification
listParts={changes}
suffix={
<>
on app <b>{logItem.detail.name}</b> with config ID {logItem.item_id}.
on app <b>{logItem.detail?.name}</b> with config ID {logItem.item_id}.
</>
}
/>
Expand All @@ -177,7 +177,7 @@ export function pluginActivityDescriber(logItem: ActivityLogItem, asNotification
}

if (logItem.activity.startsWith('attachment_')) {
for (const change of logItem.detail.changes || []) {
for (const change of logItem.detail?.changes || []) {
let changeWording: string | JSX.Element = ''

if (logItem.activity === 'attachment_created') {
Expand Down Expand Up @@ -213,7 +213,7 @@ export function pluginActivityDescriber(logItem: ActivityLogItem, asNotification
description: (
<>
<strong>{userNameForLogItem(logItem)}</strong> {changeWording} on app:{' '}
<b>{logItem.detail.name}</b> with config ID {logItem.item_id}
<b>{logItem.detail?.name}</b> with config ID {logItem.item_id}
</>
),
}
Expand Down
Loading

0 comments on commit ed8ff15

Please sign in to comment.