Skip to content

Commit

Permalink
Fix getChangeHistory (#805)
Browse files Browse the repository at this point in the history
  • Loading branch information
zichongkao authored and actuallyyun committed May 7, 2023
1 parent 3c6b786 commit d4645e6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
31 changes: 26 additions & 5 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, DocumentTypeName } from '../../js/types'

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

const ClimbChange = ({ changeId, fullDocument, updateDescription, dbOp }: ChangeType): JSX.Element | null => {
if ((fullDocument as ClimbType)?.name == null) {
if (fullDocument.__typeName !== DocumentTypeName.Climb) {
return null
}
const { name, id } = fullDocument as ClimbType
Expand All @@ -76,9 +77,7 @@ 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) {
if (fullDocument.__typeName !== DocumentTypeName.Area) {
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 }: ChangeType): JSX.Element | null => {
if (fullDocument.__typeName !== DocumentTypeName.Organization) {
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 {
__typename
... on Area {
areaName
uuid
Expand All @@ -112,6 +113,9 @@ export const FRAGMENT_CHANGE_HISTORY = gql`
name
uuid
}
... on Organization {
displayName
}
}
}
}`
Expand Down
32 changes: 31 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,10 +302,20 @@ export interface UpdateDescriptionType {
truncatedArrays?: any[]
}

export enum DocumentTypeName {
Area = 'Area',
Climb = 'Climb',
Organization = 'Organization',
}

export interface WithDocumentTypeName {
__typeName: DocumentTypeName
}

export interface ChangeType {
dbOp: string
changeId: string
fullDocument: AreaType | ClimbType
fullDocument: (AreaType | ClimbType | OrganizationType) & WithDocumentTypeName
updateDescription: UpdateDescriptionType
}

Expand Down

0 comments on commit d4645e6

Please sign in to comment.