Skip to content

Commit

Permalink
Add package name to contractResolver to stop having to pass state pro…
Browse files Browse the repository at this point in the history
…grams everywhere
  • Loading branch information
haworku committed Mar 6, 2024
1 parent 96ec567 commit c917349
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
18 changes: 17 additions & 1 deletion services/app-api/src/resolvers/contract/contractResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { logError } from '../../logger'
import type { Store } from '../../postgres'
import { GraphQLError } from 'graphql'
import { setErrorAttributesOnActiveSpan } from '../attributeHelper'
import { packageName } from '../../../../app-web/src/common-code/healthPlanFormDataType'

export function contractResolver(store: Store): Resolvers['Contract'] {
return {
Expand Down Expand Up @@ -32,7 +33,22 @@ export function contractResolver(store: Store): Resolvers['Contract'] {
},

draftRevision(parent) {
return parent.draftRevision || {}
const programsForContractState = statePrograms.states
.find((state) => state.code === parent.stateCode)
?.programs.filter((program) => program !== undefined)
const contractName = packageName(
parent.stateCode,
parent.stateNumber,
parent.draftRevision?.formData.programIDs ?? [],
programsForContractState ?? []
)

return (
{
...parent.draftRevision,
contractName,
} || {}
)
},
draftRates: async (parent, _args, context) => {
const { span } = context
Expand Down
1 change: 1 addition & 0 deletions services/app-graphql/src/queries/fetchContract.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ fragment contractRevisionFragment on ContractRevision {
id
createdAt
updatedAt
contractName

submitInfo {
updatedAt
Expand Down
5 changes: 5 additions & 0 deletions services/app-graphql/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,11 @@ type ContractRevision {

"formData is all the contract specific info part of this submission"
formData: ContractFormData!
"""
Represents the name of the contract pacakge.
This value is auto generated based on contract state number, contract type, dates, and state program details"\
"""
contractName: String!
}

"SubmittableRevision is what can appear in a submission"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useEffect } from 'react'
import { Button, Fieldset, Form as UswdsForm } from '@trussworks/react-uswds'
import { FieldArray, FieldArrayRenderProps, Formik, FormikErrors } from 'formik'
import { useNavigate } from 'react-router-dom'
Expand Down Expand Up @@ -50,6 +50,7 @@ import {
} from '../../ErrorOrLoadingPage'
import { featureFlags } from '../../../../common-code/featureFlags'
import { useLDClient } from 'launchdarkly-react-client-sdk'
import { usePage } from '../../../../contexts/PageContext'

export type RateDetailFormValues = {
id?: string // no id if its a new rate
Expand Down Expand Up @@ -141,6 +142,8 @@ const RateDetailsV2 = ({
const displayAsStandaloneRate = type === 'SINGLE'
const { loggedInUser } = useAuth()
const ldClient = useLDClient()
const { updateHeading } = usePage()

const useLinkedRates = ldClient?.variation(
featureFlags.LINK_RATES.flag,
featureFlags.LINK_RATES.defaultValue
Expand Down Expand Up @@ -196,8 +199,17 @@ const RateDetailsV2 = ({
const initialRequestLoading = fetchContractLoading || fetchRateLoading
const initialRequestError = fetchContractError || fetchRateError
const previousDocuments: string[] = []
const submissionIDForHeading =
fetchContractData?.fetchContract.contract?.draftRevision
?.contractName ||
fetchRateData?.fetchRate.rate?.draftRevision?.formData
.rateCertificationName

useEffect(() => {
updateHeading({ customHeading: submissionIDForHeading ?? undefined })
}, [submissionIDForHeading, updateHeading])

React.useEffect(() => {
useEffect(() => {
if (focusNewRate) {
newRateNameRef?.current?.focus()
setFocusNewRate(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function mockContractPackage(partial?: Partial<Contract>): Contract {
id: '123',
createdAt: new Date(),
updatedAt: new Date(),
contractName: 'MCR-0005-alvhalfhdsalf',
formData: {
programIDs: ['pmap'],
populationCovered: 'MEDICAID',
Expand Down

0 comments on commit c917349

Please sign in to comment.