Skip to content

Commit

Permalink
Merge pull request #526 from IQSS/510/prefill-depositor-name-and-date
Browse files Browse the repository at this point in the history
Pre populate depositor name and date of deposit on dataset creation
  • Loading branch information
ofahimIQSS authored Oct 28, 2024
2 parents 02bc675 + 97ae0bd commit 82e4779
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import { MouseEvent, useEffect, useMemo, useRef } from 'react'
import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { FieldErrors, FormProvider, useForm } from 'react-hook-form'
import { useSession } from '../../../../session/SessionContext'
import { useSession } from '@/sections/session/SessionContext'
import { Accordion, Alert, Button } from '@iqss/dataverse-design-system'
import { type DatasetRepository } from '../../../../../dataset/domain/repositories/DatasetRepository'
import { type MetadataBlockInfo } from '../../../../../metadata-block-info/domain/models/MetadataBlockInfo'
import { type DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository'
import { type MetadataBlockInfo } from '@/metadata-block-info/domain/models/MetadataBlockInfo'
import { type DatasetMetadataFormValues } from '../MetadataFieldsHelper'
import { type DatasetMetadataFormMode } from '..'
import { SubmissionStatus, useSubmitDataset } from '../useSubmitDataset'
import { MetadataBlockFormFields } from './MetadataBlockFormFields'
import { RequiredFieldText } from '../../RequiredFieldText/RequiredFieldText'
import { SeparationLine } from '../../../layout/SeparationLine/SeparationLine'
import { SeparationLine } from '@/sections/shared/layout/SeparationLine/SeparationLine'
import { DateHelper } from '@/shared/helpers/DateHelper'
import styles from './index.module.scss'

interface FormProps {
Expand Down Expand Up @@ -64,6 +65,9 @@ export const MetadataForm = ({
setValue('citation.datasetContact.0.datasetContactEmail', user.email, {
shouldValidate: true
})
setValue('citation.depositor', displayName)
setValue('citation.dateOfDeposit', DateHelper.toISO8601Format(new Date()))

if (user.affiliation) {
setValue('citation.datasetContact.0.datasetContactAffiliation', user.affiliation)
setValue('citation.author.0.authorAffiliation', user.affiliation)
Expand Down
4 changes: 4 additions & 0 deletions src/shared/helpers/DateHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ export class DateHelper {
day: '2-digit'
})
}

static toISO8601Format(date: Date): string {
return date.toISOString().split('T')[0]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,37 @@ export class MetadataBlockInfoMother {
displayOrder: 34,
typeClass: 'primitive',
displayOnCreate: true
},
depositor: {
name: 'depositor',
displayName: 'Depositor',
displayOnCreate: true,
title: 'Depositor',
type: 'TEXT',
typeClass: 'primitive',
watermark: '1) FamilyName, GivenName or 2) Organization',
description:
'The entity, such as a person or organization, that deposited the Dataset in the repository',
multiple: false,
isControlledVocabulary: false,
displayFormat: '',
displayOrder: 58,
isRequired: false
},
dateOfDeposit: {
name: 'dateOfDeposit',
displayName: 'Deposit Date',
displayOnCreate: true,
title: 'Deposit Date',
type: 'DATE',
typeClass: 'primitive',
watermark: 'YYYY-MM-DD',
description: 'The date when the Dataset was deposited into the repository',
multiple: false,
isControlledVocabulary: false,
displayFormat: '',
displayOrder: 59,
isRequired: false
}
}
},
Expand Down
41 changes: 38 additions & 3 deletions tests/component/sections/collection/Collection.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import { Collection } from '../../../../src/sections/collection/Collection'
import { CollectionRepository } from '../../../../src/collection/domain/repositories/CollectionRepository'
import { CollectionMother } from '../../collection/domain/models/CollectionMother'
import { Collection } from '@/sections/collection/Collection'
import { CollectionRepository } from '@/collection/domain/repositories/CollectionRepository'
import { CollectionMother } from '@tests/component/collection/domain/models/CollectionMother'
import { CollectionItemsMother } from '@tests/component/collection/domain/models/CollectionItemsMother'
import { CollectionItemSubset } from '@/collection/domain/models/CollectionItemSubset'

const collectionRepository = {} as CollectionRepository
const collection = CollectionMother.create({ name: 'Collection Name' })
const userPermissionsMock = CollectionMother.createUserPermissions()

const items = CollectionItemsMother.createItems({
numberOfCollections: 4,
numberOfDatasets: 3,
numberOfFiles: 3
})

const itemsWithCount: CollectionItemSubset = { items, totalItemCount: 200 }

describe('Collection page', () => {
beforeEach(() => {
collectionRepository.getById = cy.stub().resolves(collection)
collectionRepository.getUserPermissions = cy.stub().resolves(userPermissionsMock)
collectionRepository.getItems = cy.stub().resolves(itemsWithCount)
})

it('renders skeleton while loading', () => {
Expand Down Expand Up @@ -161,4 +172,28 @@ describe('Collection page', () => {

cy.findByRole('button', { name: /Add Data/i }).should('not.exist')
})

it('opens and close the publish collection modal', () => {
cy.viewport(1200, 800)
const collection = CollectionMother.createUnpublished()

collectionRepository.getById = cy.stub().resolves(collection)

cy.mountAuthenticated(
<Collection
collectionRepository={collectionRepository}
collectionId="collection"
created={false}
published={false}
collectionQueryParams={{ pageQuery: 1 }}
/>
)
cy.findByRole('button', { name: /Publish/i }).should('exist')

cy.findByRole('button', { name: /Publish/i }).click()
cy.findByText('Publish Collection').should('exist')

cy.findByRole('button', { name: /Cancel/i }).click()
cy.findByText('Publish Collection').should('not.exist')
})
})
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { MetadataBlockName } from '../../../../../src/dataset/domain/models/Dataset'
import { DatasetRepository } from '../../../../../src/dataset/domain/repositories/DatasetRepository'
import { TypeMetadataFieldOptions } from '../../../../../src/metadata-block-info/domain/models/MetadataBlockInfo'
import { MetadataBlockInfoRepository } from '../../../../../src/metadata-block-info/domain/repositories/MetadataBlockInfoRepository'
import { DatasetMetadataForm } from '../../../../../src/sections/shared/form/DatasetMetadataForm'
import { UserRepository } from '../../../../../src/users/domain/repositories/UserRepository'
import { DateHelper } from '@/shared/helpers/DateHelper'
import { MetadataBlockName } from '@/dataset/domain/models/Dataset'
import { DatasetRepository } from '@/dataset/domain/repositories/DatasetRepository'
import { TypeMetadataFieldOptions } from '@/metadata-block-info/domain/models/MetadataBlockInfo'
import { MetadataBlockInfoRepository } from '@/metadata-block-info/domain/repositories/MetadataBlockInfoRepository'
import { DatasetMetadataForm } from '@/sections/shared/form/DatasetMetadataForm'
import { UserRepository } from '@/users/domain/repositories/UserRepository'
import { DatasetMother } from '../../../dataset/domain/models/DatasetMother'
import { MetadataBlockInfoMother } from '../../../metadata-block-info/domain/models/MetadataBlockInfoMother'
import { UserMother } from '../../../users/domain/models/UserMother'
Expand Down Expand Up @@ -1446,6 +1447,8 @@ describe('DatasetMetadataForm', () => {

it('pre-fills the form with user data', () => {
const displayName = `${testUser.lastName}, ${testUser.firstName}`
const expectedDepositDate = DateHelper.toISO8601Format(new Date())

cy.mountAuthenticated(
<DatasetMetadataForm
mode="create"
Expand Down Expand Up @@ -1475,6 +1478,8 @@ describe('DatasetMetadataForm', () => {
cy.findByLabelText(/^Affiliation/i).should('have.value', testUser.affiliation)
})
cy.findByLabelText(/^E-mail/i).should('have.value', testUser.email)
cy.findByLabelText(/^Depositor/i).should('have.value', displayName)
cy.findByLabelText(/^Deposit Date/i).should('have.value', expectedDepositDate)
})

it('shows the skeleton while loading', () => {
Expand Down

0 comments on commit 82e4779

Please sign in to comment.