Skip to content

Commit

Permalink
[JN-1536] more typescript fixes (#1363)
Browse files Browse the repository at this point in the history
  • Loading branch information
devonbush authored Jan 6, 2025
1 parent 1a5e7e9 commit 0191e3f
Show file tree
Hide file tree
Showing 38 changed files with 111 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"answerPopDtos": [
{"questionStableId": "hd_hd_basic_firstName", "stringValue": "Child 2"},
{"questionStableId": "hd_hd_basic_lastName", "stringValue": "Family 2"},
{"questionStableId": "hd_hd_basic_dateOfBirth", "stringValue": "08/24/2019"},
{"questionStableId": "hd_hd_basic_streetAddress", "stringValue": "105 Broadway"},
{"questionStableId": "hd_hd_basic_mghPatient", "stringValue": "yes"}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"answerPopDtos": [
{"questionStableId": "hd_hd_basic_firstName", "stringValue": "Invited"},
{"questionStableId": "hd_hd_basic_lastName", "stringValue": "PriorUser"},
{"questionStableId": "hd_hd_basic_dateOfBirth", "stringValue": "05/04/1990"},
{"questionStableId": "hd_hd_basic_streetAddress", "stringValue": "465 Spruce Street"},
{"questionStableId": "hd_hd_basic_mghPatient", "stringValue": "yes"},
{"questionStableId": "hd_hd_basic_sexualOrientation", "stringValue": "preferNoAnswer"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"answerPopDtos": [
{"questionStableId": "hd_hd_basic_firstName", "stringValue": "Jonas", "viewedLanguage": "en"},
{"questionStableId": "hd_hd_basic_lastName", "stringValue": "Salk", "viewedLanguage": "en"},
{"questionStableId": "hd_hd_basic_dateOfBirth", "stringValue": "11/13/1983", "viewedLanguage": "en"},
{"questionStableId": "hd_hd_basic_streetAddress", "stringValue": "1223 Walnut Street", "viewedLanguage": "es"},
{"questionStableId": "hd_hd_basic_mghPatient", "stringValue": "yes", "viewedLanguage": "es"},
{"questionStableId": "hd_hd_basic_languages", "objectValue": "[{\"language\": \"English\", \"proficiency\": \"native\", \"workUse\": [\"yes\"]}, {\"language\": \"Dutch\", \"proficiency\": \"fluent\", \"workUse\": []}]", "viewedLanguage": "es"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"answerPopDtos": [
{"questionStableId": "hd_hd_basic_firstName", "stringValue": "Lost"},
{"questionStableId": "hd_hd_basic_lastName", "stringValue": "Interest"},
{"questionStableId": "hd_hd_basic_dateOfBirth", "stringValue": "02/24/2000"},
{"questionStableId": "hd_hd_basic_streetAddress", "stringValue": "857 Spruce Street"},
{"questionStableId": "hd_hd_basic_mghPatient", "stringValue": "yes"}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"answerPopDtos": [
{"questionStableId": "hd_hd_basic_firstName", "stringValue": "Recurrence"},
{"questionStableId": "hd_hd_basic_lastName", "stringValue": "Due"},
{"questionStableId": "hd_hd_basic_dateOfBirth", "stringValue": "05/07/1983"},
{"questionStableId": "hd_hd_basic_streetAddress", "stringValue": "99 Spruce Street"},
{"questionStableId": "hd_hd_basic_mghPatient", "stringValue": "yes"}
],
Expand Down
3 changes: 2 additions & 1 deletion ui-admin/src/forms/FormContentEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ describe('FormContentEditor', () => {
initialAnswerMappings={[]}
currentLanguage={{ languageCode: 'en', languageName: 'English', id: '' }}
supportedLanguages={[]}
initialContent={formContent} visibleVersionPreviews={[]} readOnly={false}
initialContent={formContent}
readOnly={false}
onFormContentChange={jest.fn()}
onAnswerMappingChange={jest.fn()}
/>)
Expand Down
6 changes: 3 additions & 3 deletions ui-admin/src/forms/FormPreviewOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type FormPreviewOptions = {
ignoreValidation: boolean
showInvisibleElements: boolean
locale: string
profile?: Profile
profile: Profile
proxyProfile?: Profile
isGovernedUser: boolean
}
Expand Down Expand Up @@ -117,7 +117,7 @@ export const FormPreviewOptions = (props: FormPreviewOptionsProps) => {
<TextInput onChange={text => onChange({
...value,
proxyProfile: {
...value.proxyProfile,
...value.proxyProfile!,
givenName: text
}
})}
Expand All @@ -128,7 +128,7 @@ export const FormPreviewOptions = (props: FormPreviewOptionsProps) => {
<TextInput onChange={text => onChange({
...value,
proxyProfile: {
...value.proxyProfile,
...value.proxyProfile!,
familyName: text
}
})}
Expand Down
31 changes: 19 additions & 12 deletions ui-admin/src/forms/designer/split/QuestionDesigner.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React, { useState } from 'react'

import { HtmlQuestion, PortalEnvironmentLanguage, Question, QuestionType } from '@juniper/ui-core'
import {
HtmlQuestion,
PortalEnvironmentLanguage,
Question,
SimpleQuestion,
SimpleQuestionType
} from '@juniper/ui-core'

import { Textarea } from 'components/forms/Textarea'
import { i18nSurveyText, updateI18nSurveyText } from 'util/juniperSurveyUtils'
Expand Down Expand Up @@ -59,14 +65,15 @@ export const QuestionDesigner = (props: QuestionDesignerProps) => {
</div>
{ (!isTemplated && question.type !== 'html') &&
<IconButton
className={classNames('mb-2', 'ms-1', 'border', question.isRequired ? 'text-danger' : 'text-muted')}
className={classNames('mb-2', 'ms-1', 'border',
(question as SimpleQuestion).isRequired ? 'text-danger' : 'text-muted')}
icon={faAsterisk}
aria-label={'Toggle required'}
onClick={() => {
onChange({
onChange(({
...question,
isRequired: !question.isRequired
})
isRequired: !(question as SimpleQuestion).isRequired
}) as SimpleQuestion)
}}
/> }
</div>
Expand All @@ -75,7 +82,7 @@ export const QuestionDesigner = (props: QuestionDesignerProps) => {
questionType={question.type}
onChange={newType => {
onChange({
...baseQuestions[newType as QuestionType],
...baseQuestions[newType as SimpleQuestionType],
...question,
// @ts-ignore
type: newType
Expand All @@ -99,7 +106,7 @@ export const QuestionDesigner = (props: QuestionDesignerProps) => {
disabled={readOnly}
currentLanguage={currentLanguage}
supportedLanguages={supportedLanguages}
question={question}
question={question as SimpleQuestion}
onChange={onChange}
/>

Expand Down Expand Up @@ -143,7 +150,7 @@ export const QuestionDesigner = (props: QuestionDesignerProps) => {
>
<VisibilityFields
disabled={readOnly}
question={question}
question={question as SimpleQuestion}
onChange={onChange}
/>
</Tab>
Expand Down Expand Up @@ -184,17 +191,17 @@ export const QuestionDesigner = (props: QuestionDesignerProps) => {
label="Description"
labelClassname={'mb-0'}
rows={2}
value={i18nSurveyText(question.description, currentLanguage.languageCode)}
value={i18nSurveyText((question as SimpleQuestion).description, currentLanguage.languageCode)}
onChange={value => {
onChange({
onChange(({
...question,
description: updateI18nSurveyText({
valueText: value,
oldValue: question.description,
oldValue: (question as SimpleQuestion).description,
languageCode: currentLanguage.languageCode,
supportedLanguages
})
})
}) as SimpleQuestion)
}}
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions ui-admin/src/navbar/StudySidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ test('renders the study selector and sub menus', async () => {
const { study } = mockStudyEnvContext()
const portal = mockPortal()
portal.portalStudies.push({
createdAt: 0,
study
})
const { RoutedComponent } = setupRouterTest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const StudyTrendsWidget = ({ portal, study }: { portal: Portal, study: St
const lastWeek = new Date()
lastWeek.setDate(lastWeek.getDate() - 7)
return new Date((datum.time || 0) * 1000) > lastWeek
}))
}), 'live')
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test('renders a list of changes', async () => {
}])
const portal = mockPortal()
renderInPortalRouter(portal, <PortalChangeHistoryView portal={portal}/>, {
user: mockAdminUser(true),
adminUsers: [{
...mockAdminUser(false), id: 'admin1', username: 'staffPerson'
}]
Expand Down
8 changes: 4 additions & 4 deletions ui-admin/src/search/SearchQueryBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,17 +372,17 @@ const CustomValueEditor = (props: ValueEditorProps) => {
}

const OperatorSelector = (props: OperatorSelectorProps) => {
const options = props.options as { name: string, label: string }[]
const options = (props.options as { name: string, label: string }[])
.map(option => ({ ...option, value: option.name }))

const selectedOptions = options.find(o => o.name === props.value)

return <div className="w-50">
<Select
options={options}
value={selectedOptions ? { value: selectedOptions.name, label: selectedOptions.label } : undefined}
onChange={newVal => {
if (newVal?.name != props.value) {
props.handleOnChange(newVal?.name || '')
if (newVal?.value != props.value) {
props.handleOnChange(newVal?.value || '')
}
}}
/>
Expand Down
2 changes: 1 addition & 1 deletion ui-admin/src/study/CreateNewCohortModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function CreateNewCohortModal({ onDismiss }: {onDismiss: () => vo
const response = await Api.exportEnrollees(
selectedPortal.shortcode,
selectedStudy.study.shortcode,
'live', { fileFormat: 'JSON', rowLimit: 0 })
'live', { fileFormat: 'JSON', rowLimit: 0, includeFields: [] })
const result = await response.json()
setParticipantFields(result)
}, [selectedStudy], 'Failed to load cohort criteria options')
Expand Down
2 changes: 1 addition & 1 deletion ui-admin/src/study/StudyEnvironmentRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export const studyEnvMailingListPath = (studyEnvParams: OptionalStudyEnvParams)
if (!studyEnvParams.studyShortcode || !studyEnvParams.envName) {
return `/${mailingListPath(studyEnvParams.portalShortcode, 'live')}`
}
return `${baseStudyEnvPath(studyEnvParams)}/mailingList`
return `${baseStudyEnvPath(studyEnvParams as StudyEnvParams)}/mailingList`
}

export const studyEnvSiteContentPath = (studyEnvParams: StudyEnvParams) => {
Expand Down
4 changes: 2 additions & 2 deletions ui-admin/src/study/families/FamilyRelations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const FamilyRelations = ({
}

const enrollee = row.original.enrollee || family.members?.find(m => m.id === row.original.targetEnrolleeId)
return <EnrolleeLink studyEnvContext={studyEnvContext} enrollee={enrollee}/>
return <EnrolleeLink studyEnvContext={studyEnvContext} enrollee={enrollee!}/>
}
}, {
header: 'Relation',
Expand Down Expand Up @@ -169,7 +169,7 @@ export const FamilyRelations = ({
}

const enrollee = row.original.targetEnrollee || family.members?.find(m => m.id === row.original.targetEnrolleeId)
return <EnrolleeLink studyEnvContext={studyEnvContext} enrollee={enrollee}/>
return <EnrolleeLink studyEnvContext={studyEnvContext} enrollee={enrollee!}/>
}
},
{
Expand Down
14 changes: 7 additions & 7 deletions ui-admin/src/study/families/FamilyStructureTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import LoadingSpinner from 'util/LoadingSpinner'
import { EnrolleeLink } from 'study/participants/enrolleeView/EnrolleeLink'

type FamilyMemberWithSubrows = {
member: Enrollee,
member?: Enrollee,
relationToParentRow?: EnrolleeRelation
subrows: FamilyMemberWithSubrows[]
}
Expand Down Expand Up @@ -74,15 +74,15 @@ export const FamilyStructureTable = (
id: 'enrollee',
header: 'Enrollee',
cell: ({ row }) => {
return <EnrolleeLink studyEnvContext={studyEnvContext} enrollee={row.original.member}/>
return <EnrolleeLink studyEnvContext={studyEnvContext} enrollee={row.original.member!}/>
}
},
{
id: 'proxyRelation',
header: 'Proxies',
cell: ({ row }) => {
return <ProxyList
member={row.original.member}
member={row.original.member!}
family={family}
studyEnvContext={studyEnvContext}/>
}
Expand All @@ -108,7 +108,7 @@ export const FamilyStructureTable = (
if (!isNil(parentRow)) {
const parent = parentRow.original
const relation = row.original.relationToParentRow?.familyRelationship
const subRowIdx = parent.subrows.findIndex(s => s.member.id === row.original.member.id)
const subRowIdx = parent.subrows.findIndex(s => s.member!.id === row.original.member!.id)
const showHeader = (
subRowIdx === 0 || parent.subrows[subRowIdx - 1].relationToParentRow?.familyRelationship != relation
)
Expand Down Expand Up @@ -148,7 +148,7 @@ const groupFamilyMembersWithSubrows = (family: Family): FamilyMemberWithSubrows[
// sort relations by number of parent relations
// to ensure that parents are created before children
const relations = (family.relations || []).sort(
(a, b) => getNumParentRelations(a, family) - getNumParentRelations(b, family)
(a, b) => getNumParentRelations(a.enrollee!, family) - getNumParentRelations(b.enrollee!, family)
).filter(r => {
return family.members?.find(m => m.id === r.enrolleeId) && family.members?.find(m => m.id === r.targetEnrolleeId)
})
Expand Down Expand Up @@ -195,7 +195,7 @@ const getNumParentRelations = (member: Enrollee, family: Family): number => {

const findRowOrSubrow = (data: FamilyMemberWithSubrows[], id: string): FamilyMemberWithSubrows | undefined => {
return data.find(d => {
if (d.member.id === id) {
if (d.member!.id === id) {
return d
}
return findRowOrSubrow(d.subrows, id)
Expand Down Expand Up @@ -226,7 +226,7 @@ const ProxyList = ({ member, family, studyEnvContext }: {
.filter(r => r.targetEnrolleeId === member.id && r.relationshipType === 'PROXY')
.map(async r => {
// see if the proxy is in the family, if so we already have it loaded
const familyProxy: Enrollee = family.members?.find(m => m.id === r.enrolleeId)
const familyProxy: Enrollee | undefined = family.members?.find(m => m.id === r.enrolleeId)
if (!isNil(familyProxy)) {
return Promise.resolve(familyProxy)
}
Expand Down
8 changes: 4 additions & 4 deletions ui-admin/src/study/families/ProbandEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const ProbandEditor = (
studyEnvContext: StudyEnvContextT,
reloadFamily: () => void
}) => {
const [proband, setProband] = React.useState<Enrollee>(family.proband)
const [proband, setProband] = React.useState<Enrollee>(family.proband!)
const [editMode, setEditMode] = React.useState<boolean>(false)
const [openSaveNewProbandModal, setOpenSaveNewProbandModal] = React.useState<boolean>(false)

Expand All @@ -56,7 +56,7 @@ export const ProbandEditor = (
disabled={!editMode}
selectedEnrollee={proband}
studyEnvContext={studyEnvContext}
onEnrolleeSelected={newProband => setProband(newProband || family.proband)}
onEnrolleeSelected={newProband => setProband(newProband || family.proband!)}
searchExpFilter={`{family.shortcode} = '${family.shortcode}'`}
/>
</div>
Expand All @@ -67,7 +67,7 @@ export const ProbandEditor = (
onClick={() => {
setEditMode(!editMode)
if (!editMode) {
setProband(family.proband)
setProband(family.proband!)
}
}}>
<FontAwesomeIcon icon={faPencil} />
Expand All @@ -83,7 +83,7 @@ export const ProbandEditor = (
<button
className="btn btn-secondary"
onClick={() => {
setProband(family.proband)
setProband(family.proband!)
setEditMode(false)
}}>
<FontAwesomeIcon icon={faX}/>
Expand Down
4 changes: 2 additions & 2 deletions ui-admin/src/study/kits/KitEnrolleeSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
VisibilityState
} from '@tanstack/react-table'

import Api from 'api/api'
import Api, { ParticipantTask } from 'api/api'
import { StudyEnvContextT } from 'study/StudyEnvironmentRouter'
import {
basicTableLayout,
Expand Down Expand Up @@ -60,7 +60,7 @@ export default function KitEnrolleeSelection({ studyEnvContext }: { studyEnvCont
const enrolleeRows = enrollees.map(enrollee => {
const taskCompletionStatus = _mapValues(
_keyBy(enrollee.participantTasks, task => task.targetStableId),
task => task.status === 'COMPLETE'
task => (task as ParticipantTask).status === 'COMPLETE'
)

return { ...enrollee, taskCompletionStatus }
Expand Down
10 changes: 5 additions & 5 deletions ui-admin/src/study/notifications/TriggerList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import {
} from 'test-utils/mocking-utils'
import TriggerList from './TriggerList'
import { userEvent } from '@testing-library/user-event'
import Api from 'api/api'
import Api, { Trigger } from 'api/api'
import { ReactNotifications } from 'react-notifications-component'
import { setupRouterTest } from '@juniper/ui-core'

test('renders routable trigger list', async () => {
const studyEnvContext = mockStudyEnvContext()
const enrollEmailConfig = {
const enrollEmailConfig: Trigger = {
...mockTrigger(),
id: 'event1',
triggerType: 'EVENT',
eventType: 'STUDY_ENROLLMENT'
}
const triggers = [
const triggers: Trigger[] = [
enrollEmailConfig,
{
...mockTrigger(),
Expand Down Expand Up @@ -61,13 +61,13 @@ test('renders routable trigger list', async () => {

test('allows deletion of notification config', async () => {
const studyEnvContext = mockStudyEnvContext()
const consentConfig = {
const consentConfig: Trigger = {
...mockTrigger(),
id: 'reminder1',
triggerType: 'TASK_REMINDER',
taskType: 'CONSENT'
}
const notificationConfigs = [
const notificationConfigs: Trigger[] = [
{
...mockTrigger(),
id: 'event1',
Expand Down
Loading

0 comments on commit 0191e3f

Please sign in to comment.