Skip to content

Commit

Permalink
Fix getChangeHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
zichongkao committed Apr 29, 2023
1 parent 51fd91b commit eda4526
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
35 changes: 28 additions & 7 deletions src/components/edit/RecentChangeHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Link from 'next/link'
import { PlusIcon, UserCircleIcon, MinusIcon, PencilIcon, PencilSquareIcon, MinusCircleIcon, PlusCircleIcon } from '@heroicons/react/24/outline'
import { formatDistanceToNow } from 'date-fns'

import { ChangesetType, ChangeType, AreaType, ClimbType } from '../../js/types'
import { ChangesetType, ChangeType, AreaType, ClimbType, OrganizationType, DocumentKind } from '../../js/types'

export interface RecentChangeHistoryProps {
history: ChangesetType[]
Expand Down Expand Up @@ -43,15 +43,16 @@ const ChangesetRow = ({ changeset }: ChangsetRowProps): JSX.Element => {
<React.Fragment key={change.changeId}>
<AreaChange {...change} />
<ClimbChange {...change} />
<OrganizationChange {...change} />
</React.Fragment>))}
</div>
</div>
</div>
)
}

const ClimbChange = ({ changeId, fullDocument, updateDescription, dbOp }: ChangeType): JSX.Element | null => {
if ((fullDocument as ClimbType)?.name == null) {
const ClimbChange = ({ changeId, fullDocument, updateDescription, dbOp, kind }: ChangeType): JSX.Element | null => {
if (kind !== DocumentKind.climbs) {
return null
}
const { name, id } = fullDocument as ClimbType
Expand All @@ -75,10 +76,8 @@ const ClimbChange = ({ changeId, fullDocument, updateDescription, dbOp }: Change
)
}

const AreaChange = ({ changeId, fullDocument, updateDescription, dbOp }: ChangeType): JSX.Element | null => {
// @ts-expect-error
// eslint-disable-next-line
if (fullDocument?.areaName == null) {
const AreaChange = ({ changeId, fullDocument, updateDescription, dbOp, kind }: ChangeType): JSX.Element | null => {
if (kind !== DocumentKind.areas) {
return null
}
const { areaName, uuid } = fullDocument as AreaType
Expand All @@ -103,6 +102,28 @@ const AreaChange = ({ changeId, fullDocument, updateDescription, dbOp }: ChangeT
)
}

const OrganizationChange = ({ changeId, fullDocument, updateDescription, dbOp, kind }: ChangeType): JSX.Element | null => {
if (kind !== DocumentKind.organizations) {
return null
}
const { displayName} = fullDocument as OrganizationType

return (
<div className='ml-2 flex gap-x-2'>
<div className='flex gap-2'>{dbOpIcon[dbOp]} <span className='badge badge-sm badge-warning'>Organization</span></div>

<div className=''>
<div className=''>
<span>{displayName}</span>
</div>
<div className='text-xs text-base-300'>
<UpdatedFields fields={updateDescription?.updatedFields} />
</div>
</div>
</div>
)
}

interface UpdatedFieldsProps {
fields: string[] | undefined
}
Expand Down
4 changes: 4 additions & 0 deletions src/js/graphql/gql/contribs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const FRAGMENT_CHANGE_HISTORY = gql`
updatedFields
}
fullDocument {
kind
... on Area {
areaName
uuid
Expand All @@ -112,6 +113,9 @@ export const FRAGMENT_CHANGE_HISTORY = gql`
name
uuid
}
... on Organization {
displayName
}
}
}
}`
Expand Down
29 changes: 28 additions & 1 deletion src/js/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export enum SafetyType {
X = 'X',
}

export enum OrgType {
LOCAL_CLIMBING_ORGANIZATION = 'LOCAL_CLIMBING_ORGANIZATION',
}

export interface ClimbMetadataType {
lat: number
lng: number
Expand Down Expand Up @@ -112,6 +116,22 @@ export interface EditMetadataType {
createdBy?: string
}

export type OrganizationType = EditMetadataType & {
orgId: string
orgType: OrgType
associatedAreaIds: string[]
excludedAreaIds: string[]
displayName: string
content: {
facebookLink: string
instagramLink: string
donationLink: string
description: string
website: string
email: string
}
}

export type AreaType = EditMetadataType & {
id: string
uuid: string
Expand Down Expand Up @@ -282,11 +302,18 @@ export interface UpdateDescriptionType {
truncatedArrays?: any[]
}

export enum DocumentKind {
areas = 'areas',
climbs = 'climbs',
organizations = 'organizations',
}

export interface ChangeType {
dbOp: string
changeId: string
fullDocument: AreaType | ClimbType
fullDocument: AreaType | ClimbType | OrganizationType
updateDescription: UpdateDescriptionType
kind: DocumentKind
}

export interface ChangesetType {
Expand Down

0 comments on commit eda4526

Please sign in to comment.