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

Feature/pdct 1754 render af metadata in family form #128

Merged
merged 90 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
b1af0a0
Add dynamic metadata field rendering
katybaulch Dec 3, 2024
bd7a91d
Move dynamic metadata field rendering to new file
katybaulch Dec 3, 2024
0b717b9
Rename from familySchema
katybaulch Dec 3, 2024
911450b
Fix style
katybaulch Dec 3, 2024
27156fb
FIx formatting
katybaulch Dec 3, 2024
987debe
Split schema generation to new file
katybaulch Dec 3, 2024
98088ca
Optimise image
katybaulch Dec 3, 2024
bbf7d10
Auto fix
katybaulch Dec 3, 2024
f59001c
Add AF schema
katybaulch Dec 3, 2024
b5ea116
Use taxonomy to determine required and free text fields
katybaulch Dec 4, 2024
92e9e0a
Fix formatting
katybaulch Dec 4, 2024
5822436
Fix eslint errors
katybaulch Dec 4, 2024
a78df90
Dynamically initialise AF metadata
katybaulch Dec 4, 2024
9a49b57
Show text/num field values
katybaulch Dec 4, 2024
4ac876f
Fix document and event forms
katybaulch Dec 5, 2024
7c1024b
Remove console logs
katybaulch Dec 5, 2024
d859074
Delete file
katybaulch Dec 5, 2024
deec3fd
Remove Organisation type
katybaulch Dec 5, 2024
f351454
Rename types
katybaulch Dec 5, 2024
a8d7fab
Fix schema
katybaulch Dec 5, 2024
493af4c
Refactor
katybaulch Dec 5, 2024
7d44bbe
Refactor & lint
katybaulch Dec 5, 2024
7d521de
Fix imports & make summary required field
katybaulch Dec 5, 2024
397500b
Fix required metadata fields
katybaulch Dec 5, 2024
95f41de
Fix tests for event section
katybaulch Dec 5, 2024
9a46095
Fix tests
katybaulch Dec 5, 2024
bfbb6f2
With all the type errors
katybaulch Dec 5, 2024
2bbe5f6
Rename metadata.ts to Metadata.ts
katybaulch Dec 5, 2024
5974ba7
Rename metadata.ts to Metadata.ts
katybaulch Dec 5, 2024
0410e0c
Fix some eslint erros
katybaulch Dec 5, 2024
3fd1f01
Allow conditional render of metadata
katybaulch Dec 9, 2024
b03ec0a
Remove unused imports
katybaulch Dec 9, 2024
117fc44
Type errors
katybaulch Dec 9, 2024
f0a4fb1
Type errors
katybaulch Dec 9, 2024
b224cd0
Make family form more type safe
katybaulch Dec 9, 2024
9859425
Make family form more type safe
katybaulch Dec 9, 2024
fd23a70
Refactor
katybaulch Dec 9, 2024
5518306
Refactor
katybaulch Dec 9, 2024
a97c7fd
Fix definition
katybaulch Dec 9, 2024
2d06017
Type errors
katybaulch Dec 9, 2024
e6815c7
Type errors
katybaulch Dec 9, 2024
57527cb
Type errors
katybaulch Dec 9, 2024
e0e55f5
Update types
katybaulch Dec 9, 2024
5d189a6
Update declaration
katybaulch Dec 9, 2024
3d09a22
Type errors
katybaulch Dec 9, 2024
eab9553
Unused imports
katybaulch Dec 9, 2024
5c3c0cd
Type errors
katybaulch Dec 9, 2024
64975e0
Type errors
katybaulch Dec 9, 2024
4811e79
Fix tests
katybaulch Dec 9, 2024
71b07bd
Tsc errors
katybaulch Dec 9, 2024
203b10b
Tsc errors
katybaulch Dec 9, 2024
bf6b1a0
Tsc errors
katybaulch Dec 9, 2024
08ecfdf
Fix metadata form
katybaulch Dec 9, 2024
7718a5e
Tsc errors
katybaulch Dec 10, 2024
d5a1735
Type errors
katybaulch Dec 10, 2024
b8e9ee8
Type errors
katybaulch Dec 10, 2024
ff468fb
Type errors
katybaulch Dec 10, 2024
effd2ac
Type errors
katybaulch Dec 10, 2024
48b43d9
Type errors
katybaulch Dec 10, 2024
9ec1cf0
Type errors
katybaulch Dec 10, 2024
9a544ed
Remove unused code
katybaulch Dec 10, 2024
6774abf
Tsc errors
katybaulch Dec 10, 2024
21355b5
Refactor document selects
katybaulch Dec 10, 2024
d48e8d2
Remove unused code
katybaulch Dec 10, 2024
17774ca
Tsc errors
katybaulch Dec 10, 2024
a2d3b9e
Fixed props errors
katybaulch Dec 10, 2024
f6c78c0
Resolve tsc error
katybaulch Dec 10, 2024
a7e0181
Resolve tsc error
katybaulch Dec 10, 2024
860e8ae
Adding new type for nested _document model
PatFawbertMills Dec 10, 2024
89ff4e5
Resolve tsc error
katybaulch Dec 10, 2024
31a47d8
Merge branch 'main' into feature/pdct-1754-render-af-metadata-in-fami…
katybaulch Dec 16, 2024
bf13094
Update mocks.tsx
katybaulch Dec 16, 2024
5f8ee4a
Fix tsc error
katybaulch Dec 16, 2024
bf7d16c
Fix ESLint error
katybaulch Dec 16, 2024
40b1066
Rename variable
katybaulch Dec 16, 2024
26bdb75
Fix loading of existing metadata
katybaulch Dec 17, 2024
d4f04af
Move to utils
katybaulch Dec 17, 2024
64785e4
Strip html from family summary
katybaulch Dec 17, 2024
8987daf
Fix document sub taxonomy for MCF
katybaulch Dec 17, 2024
40d4886
Fix family tests
katybaulch Dec 17, 2024
9e7f00e
Test WIP
katybaulch Dec 17, 2024
035d0b0
Fix tests
katybaulch Dec 17, 2024
e48c6e3
Remove debug
katybaulch Dec 17, 2024
1ed74c4
Fix tsc errors
katybaulch Dec 17, 2024
28a7ad0
Reorder interfaces
katybaulch Dec 17, 2024
a62ccd0
Merge branch 'main' into feature/pdct-1754-render-af-metadata-in-fami…
katybaulch Dec 17, 2024
e2789c1
Add AF family metadata
katybaulch Dec 17, 2024
7fd9ca4
Fix typing
katybaulch Dec 17, 2024
4f1ab76
Update familyForm.ts
katybaulch Dec 17, 2024
34c9658
Fix collection ID to name mapping
katybaulch Dec 18, 2024
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
57 changes: 31 additions & 26 deletions src/components/forms/FamilyForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ import { ApiError } from '../feedback/ApiError'
import { IDocument } from '@/interfaces/Document'
import { IEvent } from '@/interfaces/Event'
import { IError } from '@/interfaces/Auth'
import { IChakraSelect, IConfigCorpora, TTaxonomy } from '@/interfaces'
import {
IChakraSelect,
ICollection,
IConfigCorpora,
TTaxonomy,
} from '@/interfaces'
import {
getMetadataHandler,
IFamilyFormIntlAgreements,
IFamilyFormLawsAndPolicies,
TFamilyFormSubmit,
} from './metadata-handlers/familyForm'

export interface IFamilyFormBase {
Expand All @@ -56,16 +60,16 @@ export interface IFamilyFormBase {
collections?: IChakraSelect[]
}

export type TFamilyFormSubmit =
| IFamilyFormLawsAndPolicies
| IFamilyFormIntlAgreements

type TChildEntity = 'event' | 'document'

type TProps = {
family?: TFamily
}

const getCollection = (collectionId: string, collections: ICollection[]) => {
return collections.find((collection) => collection.import_id === collectionId)
}

export const FamilyForm = ({ family: loadedFamily }: TProps) => {
const [isLeavingModalOpen, setIsLeavingModalOpen] = useState(false)
const [isFormSubmitting, setIsFormSubmitting] = useState(false)
Expand Down Expand Up @@ -234,22 +238,15 @@ export const FamilyForm = ({ family: loadedFamily }: TProps) => {
await handleFormSubmission(data)
} catch (error) {
console.log('onSubmitErrorHandler', error)
setFormError(error as IError)
toast({
title: 'Form submission error',
description: (error as IError).message,
status: 'error',
})
}
}

// object type is workaround for SubmitErrorHandler<FieldErrors> throwing a tsc error.
const onSubmitErrorHandler = (error: object) => {
console.log('onSubmitErrorHandler', error)

// Handle any submission errors
setFormError(error as IError)
toast({
title: 'Form submission error',
description: (error as IError).message,
status: 'error',
})
}

useEffect(() => {
if (loadedFamily) {
setFamilyDocuments(loadedFamily.documents || [])
Expand All @@ -273,13 +270,21 @@ export const FamilyForm = ({ family: loadedFamily }: TProps) => {
}
: undefined,
category: isMCFCorpus ? 'MCF' : loadedFamily.category,
collections: loadedFamily.collections?.map((collection) => ({
value: collection,
label: collection,
})),
collections: loadedFamily.collections
?.map((collectionId) => {
const collection = getCollection(collectionId, collections)
if (!collection) return null
return {
value: collection.import_id,
label: collection.title,
}
})
.filter(
(collection): collection is IChakraSelect => collection !== null,
),
})
}
}, [config, loadedFamily, reset, isMCFCorpus])
}, [config, loadedFamily, reset, isMCFCorpus, collections])

const onAddNewEntityClick = (entityType: TChildEntity) => {
setEditingEntity(entityType)
Expand Down Expand Up @@ -413,7 +418,7 @@ export const FamilyForm = ({ family: loadedFamily }: TProps) => {
)}

{canLoadForm && (
<form onSubmit={handleSubmit(onSubmit, onSubmitErrorHandler)}>
<form onSubmit={handleSubmit(onSubmit)}>
<VStack gap='4' mb={12} mt={4} align={'stretch'}>
{formError && <ApiError error={formError} />}

Expand Down
48 changes: 44 additions & 4 deletions src/components/forms/metadata-handlers/familyForm.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { IFamilyFormBase } from '@/components/forms/FamilyForm'
import {
IFamilyFormBase,
TFamilyFormSubmit,
} from '@/components/forms/FamilyForm'
import {
IAFProjectsFamilyFormPost,
IAFProjectsMetadata,
IFamilyFormPostBase,
IInternationalAgreementsMetadata,
ILawsAndPoliciesMetadata,
Expand Down Expand Up @@ -39,6 +38,22 @@ export interface IFamilyFormLawsAndPolicies extends IFamilyFormBase {
framework?: IChakraSelect[]
instrument?: IChakraSelect[]
}
export interface IFamilyFormAFProjects extends IFamilyFormBase {
// AF Projects
region?: IChakraSelect[]
sector?: IChakraSelect[]
implementing_agency?: IChakraSelect[]
status?: IChakraSelect
project_id?: string
project_url?: string
project_value_co_financing?: string
project_value_fund_spend?: string
}

export type TFamilyFormSubmit =
| IFamilyFormLawsAndPolicies
| IFamilyFormIntlAgreements
| IFamilyFormAFProjects

// Mapping of corpus types to their specific metadata handlers
export const corpusMetadataHandlers: Record<
Expand Down Expand Up @@ -80,6 +95,31 @@ export const corpusMetadataHandlers: Record<
metadata,
}) as ILawsAndPoliciesFamilyFormPost,
},
AF: {
extractMetadata: (formData: TFamilyFormSubmit) => {
const afData = formData as IFamilyFormAFProjects
return {
region: afData.region?.map((region) => region.value) || [],
sector: afData.sector?.map((sector) => sector.value) || [],
implementing_agency:
afData.implementing_agency?.map((agency) => agency.value) || [],
status: afData.status ? [afData.status?.value] : [],
project_id: afData.project_id ? [afData.project_id] : [],
project_url: afData.project_url ? [afData.project_url] : [],
project_value_co_financing: afData.project_value_co_financing
? [afData.project_value_co_financing]
: [0],
project_value_fund_spend: afData.project_value_fund_spend
? [afData.project_value_fund_spend]
: [0],
} as IAFProjectsMetadata
},
createSubmissionData: (baseData, metadata) =>
({
...baseData,
metadata,
}) as IAFProjectsFamilyFormPost,
},
// Add other corpus types here with their specific metadata extraction logic
}

Expand Down
16 changes: 16 additions & 0 deletions src/interfaces/Family.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,21 @@ export interface ILawsAndPoliciesMetadata extends IMetadata {
instrument: string[]
}

export interface IAFProjectsMetadata extends IMetadata {
region: string[]
sector: string[]
implementing_agency: string[]
status: string[]
project_id: string[]
project_url: string[]
project_value_co_financing: string[]
project_value_fund_spend: string[]
}

export type TFamilyMetadata =
| IInternationalAgreementsMetadata
| ILawsAndPoliciesMetadata
| IAFProjectsMetadata

// Read DTOs.
interface IFamilyBase {
Expand Down Expand Up @@ -69,7 +81,11 @@ export interface IInternationalAgreementsFamilyFormPost
extends IFamilyFormPostBase {
metadata: IInternationalAgreementsMetadata
}
export interface IAFProjectsFamilyFormPost extends IFamilyFormPostBase {
metadata: IAFProjectsMetadata
}

export type TFamilyFormPost =
| ILawsAndPoliciesFamilyFormPost
| IInternationalAgreementsFamilyFormPost
| IAFProjectsFamilyFormPost
22 changes: 22 additions & 0 deletions src/interfaces/Metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ export const CORPUS_METADATA_CONFIG: CorpusMetadataConfig = {
'instrument',
],
},
AF: {
renderFields: {
region: { type: FieldType.MULTI_SELECT },
sector: { type: FieldType.MULTI_SELECT },
implementing_agency: { type: FieldType.MULTI_SELECT },
status: { type: FieldType.SINGLE_SELECT },
project_id: { type: FieldType.TEXT },
project_url: { type: FieldType.TEXT },
project_value_co_financing: { type: FieldType.NUMBER },
project_value_fund_spend: { type: FieldType.NUMBER },
},
validationFields: [
'project_id',
'project_url',
'region',
'sector',
'status',
'implementing_agency',
'project_value_co_financing',
'project_value_fund_spend',
],
},
default: {
renderFields: {},
validationFields: [],
Expand Down
Loading