From 303589f300b6d027835a4ca77ae8b60fdea631af Mon Sep 17 00:00:00 2001 From: Gary Zhao Date: Tue, 12 Mar 2024 14:19:34 -0400 Subject: [PATCH 1/7] removed old GetIsCollaborator and its types --- .../Collaborators/GetIsCollaborator.ts | 10 --------- .../Collaborators/types/GetIsCollaborator.ts | 22 ------------------- 2 files changed, 32 deletions(-) delete mode 100644 src/queries/Collaborators/GetIsCollaborator.ts delete mode 100644 src/queries/Collaborators/types/GetIsCollaborator.ts diff --git a/src/queries/Collaborators/GetIsCollaborator.ts b/src/queries/Collaborators/GetIsCollaborator.ts deleted file mode 100644 index 9e5ea72829..0000000000 --- a/src/queries/Collaborators/GetIsCollaborator.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { gql } from '@apollo/client'; - -export default gql` - query GetIsCollaborator($id: UUID!) { - modelPlan(id: $id) { - id - isCollaborator - } - } -`; diff --git a/src/queries/Collaborators/types/GetIsCollaborator.ts b/src/queries/Collaborators/types/GetIsCollaborator.ts deleted file mode 100644 index d6c5563d69..0000000000 --- a/src/queries/Collaborators/types/GetIsCollaborator.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -// @generated -// This file was automatically generated and should not be edited. - -// ==================================================== -// GraphQL query operation: GetIsCollaborator -// ==================================================== - -export interface GetIsCollaborator_modelPlan { - __typename: "ModelPlan"; - id: UUID; - isCollaborator: boolean; -} - -export interface GetIsCollaborator { - modelPlan: GetIsCollaborator_modelPlan; -} - -export interface GetIsCollaboratorVariables { - id: UUID; -} From 463dad712786afed700e83a1efcc412323eb9451 Mon Sep 17 00:00:00 2001 From: Gary Zhao Date: Tue, 12 Mar 2024 14:20:25 -0400 Subject: [PATCH 2/7] add new GetIsCollaborator and updated modelaccesswrapper --- .../Collaborator/GetIsCollaborator.ts | 10 ++++ src/gql/gen/graphql.ts | 48 +++++++++++++++++++ src/gql/gen/types/GetIsCollaborator.ts | 22 +++++++++ src/views/ModelAccessWrapper/index.tsx | 12 +---- 4 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 src/gql/apolloGQL/Collaborator/GetIsCollaborator.ts create mode 100644 src/gql/gen/types/GetIsCollaborator.ts diff --git a/src/gql/apolloGQL/Collaborator/GetIsCollaborator.ts b/src/gql/apolloGQL/Collaborator/GetIsCollaborator.ts new file mode 100644 index 0000000000..e81b1f9013 --- /dev/null +++ b/src/gql/apolloGQL/Collaborator/GetIsCollaborator.ts @@ -0,0 +1,10 @@ +import { gql } from '@apollo/client'; + +export default gql(/* GraphQL */ ` + query GetIsCollaborator($id: UUID!) { + modelPlan(id: $id) { + id + isCollaborator + } + } +`); diff --git a/src/gql/gen/graphql.ts b/src/gql/gen/graphql.ts index 7192e85bcb..80ad8dfc45 100644 --- a/src/gql/gen/graphql.ts +++ b/src/gql/gen/graphql.ts @@ -2990,6 +2990,13 @@ export type UpdateTdlMutationVariables = Exact<{ export type UpdateTdlMutation = { __typename: 'Mutation', updatePlanTDL: { __typename: 'PlanTDL', id: UUID, modelPlanID: UUID, idNumber: string, dateInitiated: Time, title: string, note?: string | null } }; +export type GetIsCollaboratorQueryVariables = Exact<{ + id: Scalars['UUID']['input']; +}>; + + +export type GetIsCollaboratorQuery = { __typename: 'Query', modelPlan: { __typename: 'ModelPlan', id: UUID, isCollaborator: boolean } }; + export type CreateModelPlanDiscussionMutationVariables = Exact<{ input: PlanDiscussionCreateInput; }>; @@ -4322,6 +4329,47 @@ export function useUpdateTdlMutation(baseOptions?: Apollo.MutationHookOptions; export type UpdateTdlMutationResult = Apollo.MutationResult; export type UpdateTdlMutationOptions = Apollo.BaseMutationOptions; +export const GetIsCollaboratorDocument = gql` + query GetIsCollaborator($id: UUID!) { + modelPlan(id: $id) { + id + isCollaborator + } +} + `; + +/** + * __useGetIsCollaboratorQuery__ + * + * To run a query within a React component, call `useGetIsCollaboratorQuery` and pass it any options that fit your needs. + * When your component renders, `useGetIsCollaboratorQuery` returns an object from Apollo Client that contains loading, error, and data properties + * you can use to render your UI. + * + * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; + * + * @example + * const { data, loading, error } = useGetIsCollaboratorQuery({ + * variables: { + * id: // value for 'id' + * }, + * }); + */ +export function useGetIsCollaboratorQuery(baseOptions: Apollo.QueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useQuery(GetIsCollaboratorDocument, options); + } +export function useGetIsCollaboratorLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useLazyQuery(GetIsCollaboratorDocument, options); + } +export function useGetIsCollaboratorSuspenseQuery(baseOptions?: Apollo.SuspenseQueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useSuspenseQuery(GetIsCollaboratorDocument, options); + } +export type GetIsCollaboratorQueryHookResult = ReturnType; +export type GetIsCollaboratorLazyQueryHookResult = ReturnType; +export type GetIsCollaboratorSuspenseQueryHookResult = ReturnType; +export type GetIsCollaboratorQueryResult = Apollo.QueryResult; export const CreateModelPlanDiscussionDocument = gql` mutation CreateModelPlanDiscussion($input: PlanDiscussionCreateInput!) { createPlanDiscussion(input: $input) { diff --git a/src/gql/gen/types/GetIsCollaborator.ts b/src/gql/gen/types/GetIsCollaborator.ts new file mode 100644 index 0000000000..d6c5563d69 --- /dev/null +++ b/src/gql/gen/types/GetIsCollaborator.ts @@ -0,0 +1,22 @@ +/* tslint:disable */ +/* eslint-disable */ +// @generated +// This file was automatically generated and should not be edited. + +// ==================================================== +// GraphQL query operation: GetIsCollaborator +// ==================================================== + +export interface GetIsCollaborator_modelPlan { + __typename: "ModelPlan"; + id: UUID; + isCollaborator: boolean; +} + +export interface GetIsCollaborator { + modelPlan: GetIsCollaborator_modelPlan; +} + +export interface GetIsCollaboratorVariables { + id: UUID; +} diff --git a/src/views/ModelAccessWrapper/index.tsx b/src/views/ModelAccessWrapper/index.tsx index 8bf97bb53c..10dae13d17 100644 --- a/src/views/ModelAccessWrapper/index.tsx +++ b/src/views/ModelAccessWrapper/index.tsx @@ -8,14 +8,9 @@ import React, { useEffect } from 'react'; import { RootStateOrAny, useSelector } from 'react-redux'; import { useHistory, useLocation } from 'react-router-dom'; -import { useQuery } from '@apollo/client'; +import { useGetIsCollaboratorQuery } from 'gql/gen/graphql'; import { useFlags } from 'launchdarkly-react-client-sdk'; -import GetIsCollaborator from 'queries/Collaborators/GetIsCollaborator'; -import { - GetIsCollaborator as GetIsCollaboratorType, - GetIsCollaboratorVariables -} from 'queries/Collaborators/types/GetIsCollaborator'; import { isUUID } from 'utils/modelPlan'; import { isAssessment, isMAC } from 'utils/user'; @@ -44,10 +39,7 @@ const ModelAccessWrapper = ({ children }: ModelAccessWrapperProps) => { const helpArticle: boolean = pathname.split('/')[1] === 'help-and-knowledge'; - const { data, loading } = useQuery< - GetIsCollaboratorType, - GetIsCollaboratorVariables - >(GetIsCollaborator, { + const { data, loading } = useGetIsCollaboratorQuery({ variables: { id: modelID }, From 8ae246a8618aad86cb84b285b747b5a53089e452 Mon Sep 17 00:00:00 2001 From: Gary Zhao Date: Tue, 12 Mar 2024 14:52:05 -0400 Subject: [PATCH 3/7] Convert GetModelCollaborators --- src/data/mock/readonly.ts | 6 +- .../Collaborator}/GetModelCollaborators.ts | 4 +- src/gql/gen/graphql.ts | 61 +++++++++++++++++++ .../gen}/types/GetModelCollaborators.ts | 0 src/utils/modelPlan.test.tsx | 9 ++- src/utils/modelPlan.ts | 2 +- .../Collaborators/AddCollaborator/index.tsx | 12 ++-- .../ModelPlan/Collaborators/index.test.tsx | 8 +-- src/views/ModelPlan/Collaborators/index.tsx | 21 +++---- src/views/ModelPlan/Collaborators/table.tsx | 2 +- src/views/ModelPlan/ReadOnly/Team/index.tsx | 19 ++---- .../_components/ContactInfo/index.tsx | 10 +-- .../_components/TaskListSideNav/index.tsx | 2 +- 13 files changed, 97 insertions(+), 59 deletions(-) rename src/{queries/Collaborators => gql/apolloGQL/Collaborator}/GetModelCollaborators.ts (90%) rename src/{queries/Collaborators => gql/gen}/types/GetModelCollaborators.ts (100%) diff --git a/src/data/mock/readonly.ts b/src/data/mock/readonly.ts index aa0f3892ca..e22a8c1ac9 100644 --- a/src/data/mock/readonly.ts +++ b/src/data/mock/readonly.ts @@ -35,6 +35,7 @@ import { GetAllParticipantsAndProvidersQuery, GetAllPaymentsDocument, GetAllPaymentsQuery, + GetModelCollaboratorsDocument, KeyCharacteristic, ModelCategory, ModelLearningSystemType, @@ -66,9 +67,8 @@ import { YesNoOtherType, YesNoType } from 'gql/gen/graphql'; +import { GetModelCollaborators_modelPlan_collaborators as GetModelCollaboratorsType } from 'gql/gen/types/GetModelCollaborators'; -import GetModelPlanCollaborators from 'queries/Collaborators/GetModelCollaborators'; -import { GetModelCollaborators_modelPlan_collaborators as GetModelCollaboratorsType } from 'queries/Collaborators/types/GetModelCollaborators'; import GetOperationalNeeds from 'queries/ITSolutions/GetOperationalNeeds'; import { GetOperationalNeeds as GetOperationalNeedsType } from 'queries/ITSolutions/types/GetOperationalNeeds'; import GetModelSummary from 'queries/ReadOnly/GetModelSummary'; @@ -753,7 +753,7 @@ const collaboratorsData: GetModelCollaboratorsType[] = [ export const collaboratorsMocks = [ { request: { - query: GetModelPlanCollaborators, + query: GetModelCollaboratorsDocument, variables: { id: modelID } }, result: { diff --git a/src/queries/Collaborators/GetModelCollaborators.ts b/src/gql/apolloGQL/Collaborator/GetModelCollaborators.ts similarity index 90% rename from src/queries/Collaborators/GetModelCollaborators.ts rename to src/gql/apolloGQL/Collaborator/GetModelCollaborators.ts index 2e4ab3f166..c116237775 100644 --- a/src/queries/Collaborators/GetModelCollaborators.ts +++ b/src/gql/apolloGQL/Collaborator/GetModelCollaborators.ts @@ -1,6 +1,6 @@ import { gql } from '@apollo/client'; -export default gql` +export default gql(/* GraphQL */ ` query GetModelCollaborators($id: UUID!) { modelPlan(id: $id) { id @@ -20,4 +20,4 @@ export default gql` } } } -`; +`); diff --git a/src/gql/gen/graphql.ts b/src/gql/gen/graphql.ts index 80ad8dfc45..c798955aee 100644 --- a/src/gql/gen/graphql.ts +++ b/src/gql/gen/graphql.ts @@ -2997,6 +2997,13 @@ export type GetIsCollaboratorQueryVariables = Exact<{ export type GetIsCollaboratorQuery = { __typename: 'Query', modelPlan: { __typename: 'ModelPlan', id: UUID, isCollaborator: boolean } }; +export type GetModelCollaboratorsQueryVariables = Exact<{ + id: Scalars['UUID']['input']; +}>; + + +export type GetModelCollaboratorsQuery = { __typename: 'Query', modelPlan: { __typename: 'ModelPlan', id: UUID, modelName: string, collaborators: Array<{ __typename: 'PlanCollaborator', id: UUID, userID: UUID, teamRoles: Array, modelPlanID: UUID, createdDts: Time, userAccount: { __typename: 'UserAccount', id: UUID, commonName: string, email: string, username: string } }> } }; + export type CreateModelPlanDiscussionMutationVariables = Exact<{ input: PlanDiscussionCreateInput; }>; @@ -4370,6 +4377,60 @@ export type GetIsCollaboratorQueryHookResult = ReturnType; export type GetIsCollaboratorSuspenseQueryHookResult = ReturnType; export type GetIsCollaboratorQueryResult = Apollo.QueryResult; +export const GetModelCollaboratorsDocument = gql` + query GetModelCollaborators($id: UUID!) { + modelPlan(id: $id) { + id + modelName + collaborators { + id + userAccount { + id + commonName + email + username + } + userID + teamRoles + modelPlanID + createdDts + } + } +} + `; + +/** + * __useGetModelCollaboratorsQuery__ + * + * To run a query within a React component, call `useGetModelCollaboratorsQuery` and pass it any options that fit your needs. + * When your component renders, `useGetModelCollaboratorsQuery` returns an object from Apollo Client that contains loading, error, and data properties + * you can use to render your UI. + * + * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; + * + * @example + * const { data, loading, error } = useGetModelCollaboratorsQuery({ + * variables: { + * id: // value for 'id' + * }, + * }); + */ +export function useGetModelCollaboratorsQuery(baseOptions: Apollo.QueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useQuery(GetModelCollaboratorsDocument, options); + } +export function useGetModelCollaboratorsLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useLazyQuery(GetModelCollaboratorsDocument, options); + } +export function useGetModelCollaboratorsSuspenseQuery(baseOptions?: Apollo.SuspenseQueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useSuspenseQuery(GetModelCollaboratorsDocument, options); + } +export type GetModelCollaboratorsQueryHookResult = ReturnType; +export type GetModelCollaboratorsLazyQueryHookResult = ReturnType; +export type GetModelCollaboratorsSuspenseQueryHookResult = ReturnType; +export type GetModelCollaboratorsQueryResult = Apollo.QueryResult; export const CreateModelPlanDiscussionDocument = gql` mutation CreateModelPlanDiscussion($input: PlanDiscussionCreateInput!) { createPlanDiscussion(input: $input) { diff --git a/src/queries/Collaborators/types/GetModelCollaborators.ts b/src/gql/gen/types/GetModelCollaborators.ts similarity index 100% rename from src/queries/Collaborators/types/GetModelCollaborators.ts rename to src/gql/gen/types/GetModelCollaborators.ts diff --git a/src/utils/modelPlan.test.tsx b/src/utils/modelPlan.test.tsx index c320dae173..cfdd8d3303 100644 --- a/src/utils/modelPlan.test.tsx +++ b/src/utils/modelPlan.test.tsx @@ -1,6 +1,5 @@ import { TeamRole } from 'gql/gen/graphql'; - -import { GetModelCollaborators_modelPlan_collaborators as CollaboratorType } from 'queries/Collaborators/types/GetModelCollaborators'; +import { GetModelCollaborators_modelPlan_collaborators as GetCollaboratorsType } from 'gql/gen/types/GetModelCollaborators'; import { collaboratorsOrderedByModelLeads, @@ -23,7 +22,7 @@ describe('model plan util', () => { }); it('returns array ordered by last name', () => { - const normalPerson: CollaboratorType = { + const normalPerson: GetCollaboratorsType = { __typename: 'PlanCollaborator', id: '123', userID: '123', @@ -38,7 +37,7 @@ describe('model plan util', () => { }, teamRoles: [TeamRole.IT_LEAD] }; - const steveRogers: CollaboratorType = { + const steveRogers: GetCollaboratorsType = { __typename: 'PlanCollaborator', id: '123', userID: '123', @@ -53,7 +52,7 @@ describe('model plan util', () => { }, teamRoles: [TeamRole.MODEL_LEAD] }; - const peterParker: CollaboratorType = { + const peterParker: GetCollaboratorsType = { __typename: 'PlanCollaborator', id: '123', userID: '123', diff --git a/src/utils/modelPlan.ts b/src/utils/modelPlan.ts index d7bc8fb1d8..9a80b88b98 100644 --- a/src/utils/modelPlan.ts +++ b/src/utils/modelPlan.ts @@ -1,8 +1,8 @@ import { TeamRole } from 'gql/gen/graphql'; +import { GetModelCollaborators_modelPlan_collaborators as GetCollaboratorsType } from 'gql/gen/types/GetModelCollaborators'; import i18next from 'i18next'; import { orderBy } from 'lodash'; -import { GetModelCollaborators_modelPlan_collaborators as GetCollaboratorsType } from 'queries/Collaborators/types/GetModelCollaborators'; import { GetModelPlan_modelPlan_discussions as DiscussionType } from 'queries/types/GetModelPlan'; import { DocumentType, diff --git a/src/views/ModelPlan/Collaborators/AddCollaborator/index.tsx b/src/views/ModelPlan/Collaborators/AddCollaborator/index.tsx index ae66127f48..81749f3c85 100644 --- a/src/views/ModelPlan/Collaborators/AddCollaborator/index.tsx +++ b/src/views/ModelPlan/Collaborators/AddCollaborator/index.tsx @@ -1,10 +1,11 @@ import React, { useRef } from 'react'; import { useTranslation } from 'react-i18next'; import { useHistory, useLocation, useParams } from 'react-router-dom'; -import { useMutation, useQuery } from '@apollo/client'; +import { useMutation } from '@apollo/client'; import { Button, Fieldset, Label, TextInput } from '@trussworks/react-uswds'; import { Field, Form, Formik, FormikProps } from 'formik'; -import { TeamRole } from 'gql/gen/graphql'; +import { TeamRole, useGetModelCollaboratorsQuery } from 'gql/gen/graphql'; +import { GetModelCollaborators_modelPlan_collaborators as GetCollaboratorsType } from 'gql/gen/types/GetModelCollaborators'; import UswdsReactLink from 'components/LinkWrapper'; import MainContent from 'components/MainContent'; @@ -19,16 +20,11 @@ import Spinner from 'components/Spinner'; import useMessage from 'hooks/useMessage'; import usePlanTranslation from 'hooks/usePlanTranslation'; import CreateModelPlanCollaborator from 'queries/Collaborators/CreateModelPlanCollaborator'; -import GetModelPlanCollaborators from 'queries/Collaborators/GetModelCollaborators'; import { CreateModelPlanCollaborator as CreateCollaboratorsType, CreateModelPlanCollaboratorVariables } from 'queries/Collaborators/types/CreateModelPlanCollaborator'; import { GetModelCollaborator_planCollaboratorByID as CollaboratorFormType } from 'queries/Collaborators/types/GetModelCollaborator'; -import { - GetModelCollaborators, - GetModelCollaborators_modelPlan_collaborators as GetCollaboratorsType -} from 'queries/Collaborators/types/GetModelCollaborators'; import { UpdateModelPlanCollaborator as UpdateModelPlanCollaboratorType, UpdateModelPlanCollaboratorVariables @@ -77,7 +73,7 @@ const Collaborators = () => { const { data: allCollaboratorsData, loading: queryLoading - } = useQuery(GetModelPlanCollaborators, { + } = useGetModelCollaboratorsQuery({ variables: { id: modelID } diff --git a/src/views/ModelPlan/Collaborators/index.test.tsx b/src/views/ModelPlan/Collaborators/index.test.tsx index 6881b17b12..89dc010716 100644 --- a/src/views/ModelPlan/Collaborators/index.test.tsx +++ b/src/views/ModelPlan/Collaborators/index.test.tsx @@ -8,12 +8,12 @@ import { waitFor, waitForElementToBeRemoved } from '@testing-library/react'; +import { GetModelCollaboratorsDocument } from 'gql/gen/graphql'; +import { GetModelCollaborators_modelPlan as GetModelPlanType } from 'gql/gen/types/GetModelCollaborators'; import configureMockStore from 'redux-mock-store'; import { ASSESSMENT } from 'constants/jobCodes'; import { MessageProvider } from 'hooks/useMessage'; -import GetModelPlanCollaborators from 'queries/Collaborators/GetModelCollaborators'; -import { GetModelCollaborators_modelPlan as GetModelPlanCollaboratorsType } from 'queries/Collaborators/types/GetModelCollaborators'; import { TeamRole } from 'types/graphql-global-types'; import { CollaboratorsContent } from './index'; @@ -27,7 +27,7 @@ const mockAuthReducer = { const mockStore = configureMockStore(); const store = mockStore({ auth: mockAuthReducer }); -const mockCollaborator: GetModelPlanCollaboratorsType = { +const mockCollaborator: GetModelPlanType = { __typename: 'ModelPlan', id: '123', modelName: 'My Model', @@ -53,7 +53,7 @@ const mockCollaborator: GetModelPlanCollaboratorsType = { const mocks = [ { request: { - query: GetModelPlanCollaborators, + query: GetModelCollaboratorsDocument, variables: { id: 'f11eb129-2c80-4080-9440-439cbe1a286f' } }, result: { diff --git a/src/views/ModelPlan/Collaborators/index.tsx b/src/views/ModelPlan/Collaborators/index.tsx index 3c09c84ea7..72efe31be5 100644 --- a/src/views/ModelPlan/Collaborators/index.tsx +++ b/src/views/ModelPlan/Collaborators/index.tsx @@ -8,9 +8,10 @@ import { useLocation, useParams } from 'react-router-dom'; -import { useMutation, useQuery } from '@apollo/client'; +import { useMutation } from '@apollo/client'; import { Button, Grid, GridContainer } from '@trussworks/react-uswds'; -import { TeamRole } from 'gql/gen/graphql'; +import { TeamRole, useGetModelCollaboratorsQuery } from 'gql/gen/graphql'; +import { GetModelCollaborators_modelPlan_collaborators as GetCollaboratorsType } from 'gql/gen/types/GetModelCollaborators'; import Breadcrumbs from 'components/Breadcrumbs'; import UswdsReactLink from 'components/LinkWrapper'; @@ -22,15 +23,10 @@ import Alert from 'components/shared/Alert'; import Expire from 'components/shared/Expire'; import useMessage from 'hooks/useMessage'; import DeleteModelPlanCollaborator from 'queries/Collaborators/DeleteModelPlanCollaborator'; -import GetModelPlanCollaborators from 'queries/Collaborators/GetModelCollaborators'; import { DeleteModelPlanCollaborator as DeleteModelPlanCollaboratorType, DeleteModelPlanCollaborator_deletePlanCollaborator as ModelPlanCollaboratorType } from 'queries/Collaborators/types/DeleteModelPlanCollaborator'; -import { - GetModelCollaborators, - GetModelCollaborators_modelPlan_collaborators as GetCollaboratorsType -} from 'queries/Collaborators/types/GetModelCollaborators'; import { collaboratorsOrderedByModelLeads } from 'utils/modelPlan'; import { ModelInfoContext } from 'views/ModelInfoWrapper'; import NotFound from 'views/NotFound'; @@ -99,14 +95,11 @@ export const CollaboratorsContent = () => { DeleteModelPlanCollaborator ); - const { error, data, refetch, loading } = useQuery( - GetModelPlanCollaborators, - { - variables: { - id: modelID - } + const { error, data, refetch, loading } = useGetModelCollaboratorsQuery({ + variables: { + id: modelID } - ); + }); const collaborators = useMemo(() => { return (data?.modelPlan?.collaborators ?? []) as GetCollaboratorsType[]; diff --git a/src/views/ModelPlan/Collaborators/table.tsx b/src/views/ModelPlan/Collaborators/table.tsx index 0250b531d7..78adde221f 100644 --- a/src/views/ModelPlan/Collaborators/table.tsx +++ b/src/views/ModelPlan/Collaborators/table.tsx @@ -4,10 +4,10 @@ import { useLocation, useParams } from 'react-router-dom'; import { useSortBy, useTable } from 'react-table'; import { Table as UswdsTable } from '@trussworks/react-uswds'; import { TeamRole } from 'gql/gen/graphql'; +import { GetModelCollaborators_modelPlan_collaborators as CollaboratorType } from 'gql/gen/types/GetModelCollaborators'; import UswdsReactLink from 'components/LinkWrapper'; import IconInitial from 'components/shared/IconInitial'; -import { GetModelCollaborators_modelPlan_collaborators as CollaboratorType } from 'queries/Collaborators/types/GetModelCollaborators'; import { formatDateLocal } from 'utils/date'; import { currentTableSortDescription, diff --git a/src/views/ModelPlan/ReadOnly/Team/index.tsx b/src/views/ModelPlan/ReadOnly/Team/index.tsx index 1f55ece868..d4fe5b6a1b 100644 --- a/src/views/ModelPlan/ReadOnly/Team/index.tsx +++ b/src/views/ModelPlan/ReadOnly/Team/index.tsx @@ -1,13 +1,9 @@ import React from 'react'; import { Trans, useTranslation } from 'react-i18next'; -import { useQuery } from '@apollo/client'; import { Card, CardHeader, Grid, Icon, Link } from '@trussworks/react-uswds'; +import { useGetModelCollaboratorsQuery } from 'gql/gen/graphql'; +import { GetModelCollaborators_modelPlan_collaborators as CollaboratorsType } from 'gql/gen/types/GetModelCollaborators'; -import GetModelPlanCollaborators from 'queries/Collaborators/GetModelCollaborators'; -import { - GetModelCollaborators, - GetModelCollaborators_modelPlan_collaborators as CollaboratorsType -} from 'queries/Collaborators/types/GetModelCollaborators'; import { TeamRole } from 'types/graphql-global-types'; import { collaboratorsOrderedByModelLeads } from 'utils/modelPlan'; import { NotFoundPartial } from 'views/NotFound'; @@ -106,14 +102,11 @@ const ReadOnlyTeamInfo = ({ filteredView?: string; }) => { const { t } = useTranslation('generalReadOnly'); - const { data, loading, error } = useQuery( - GetModelPlanCollaborators, - { - variables: { - id: modelID - } + const { data, loading, error } = useGetModelCollaboratorsQuery({ + variables: { + id: modelID } - ); + }); if ((!loading && error) || (!loading && !data?.modelPlan)) { return ; diff --git a/src/views/ModelPlan/ReadOnly/_components/ContactInfo/index.tsx b/src/views/ModelPlan/ReadOnly/_components/ContactInfo/index.tsx index 2980e5b95d..20be956524 100644 --- a/src/views/ModelPlan/ReadOnly/_components/ContactInfo/index.tsx +++ b/src/views/ModelPlan/ReadOnly/_components/ContactInfo/index.tsx @@ -1,14 +1,10 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; -import { useQuery } from '@apollo/client'; import { Icon, Link } from '@trussworks/react-uswds'; +import { useGetModelCollaboratorsQuery } from 'gql/gen/graphql'; +import { GetModelCollaborators_modelPlan_collaborators as GetCollaboratorsType } from 'gql/gen/types/GetModelCollaborators'; import UswdsReactLink from 'components/LinkWrapper'; -import GetModelPlanCollaborators from 'queries/Collaborators/GetModelCollaborators'; -import { - GetModelCollaborators, - GetModelCollaborators_modelPlan_collaborators as GetCollaboratorsType -} from 'queries/Collaborators/types/GetModelCollaborators'; import { TeamRole } from 'types/graphql-global-types'; const ContactInfo = ({ @@ -20,7 +16,7 @@ const ContactInfo = ({ }) => { const { t: h } = useTranslation('generalReadOnly'); - const { data } = useQuery(GetModelPlanCollaborators, { + const { data } = useGetModelCollaboratorsQuery({ variables: { id: modelID } diff --git a/src/views/ModelPlan/TaskList/_components/TaskListSideNav/index.tsx b/src/views/ModelPlan/TaskList/_components/TaskListSideNav/index.tsx index b4d5a135c4..d0c6e64e44 100644 --- a/src/views/ModelPlan/TaskList/_components/TaskListSideNav/index.tsx +++ b/src/views/ModelPlan/TaskList/_components/TaskListSideNav/index.tsx @@ -3,6 +3,7 @@ import { Trans, useTranslation } from 'react-i18next'; import { useHistory } from 'react-router-dom'; import { useMutation } from '@apollo/client'; import { Button } from '@trussworks/react-uswds'; +import { GetModelCollaborators_modelPlan_collaborators as GetCollaboratorsType } from 'gql/gen/types/GetModelCollaborators'; import UswdsReactLink from 'components/LinkWrapper'; import Modal from 'components/Modal'; @@ -12,7 +13,6 @@ import IconInitial from 'components/shared/IconInitial'; import ShareExportModal from 'components/ShareExport'; import useMessage from 'hooks/useMessage'; import ArchiveModelPlan from 'queries/ArchiveModelPlan'; -import { GetModelCollaborators_modelPlan_collaborators as GetCollaboratorsType } from 'queries/Collaborators/types/GetModelCollaborators'; import { ArchiveModelPlanVariables } from 'queries/types/ArchiveModelPlan'; import { GetModelPlan_modelPlan as GetModelPlanType } from 'queries/types/GetModelPlan'; import { collaboratorsOrderedByModelLeads } from 'utils/modelPlan'; From 97ddac75f0d5930df9e3c414a03b251fcd7083f3 Mon Sep 17 00:00:00 2001 From: Gary Zhao Date: Tue, 12 Mar 2024 14:59:07 -0400 Subject: [PATCH 4/7] convert GetModelPlanCollaborator --- .../GetIndividualModelPlanCollaborator.ts} | 6 +- src/gql/gen/graphql.ts | 55 +++++++++++++++++++ .../GetIndividualModelPlanCollaborator.ts} | 14 ++--- .../Collaborators/AddCollaborator/index.tsx | 2 +- 4 files changed, 66 insertions(+), 11 deletions(-) rename src/{queries/Collaborators/GetModelPlanCollaborator.ts => gql/apolloGQL/Collaborator/GetIndividualModelPlanCollaborator.ts} (68%) rename src/{queries/Collaborators/types/GetModelCollaborator.ts => gql/gen/types/GetIndividualModelPlanCollaborator.ts} (50%) diff --git a/src/queries/Collaborators/GetModelPlanCollaborator.ts b/src/gql/apolloGQL/Collaborator/GetIndividualModelPlanCollaborator.ts similarity index 68% rename from src/queries/Collaborators/GetModelPlanCollaborator.ts rename to src/gql/apolloGQL/Collaborator/GetIndividualModelPlanCollaborator.ts index fc1d3f836b..c721ee436f 100644 --- a/src/queries/Collaborators/GetModelPlanCollaborator.ts +++ b/src/gql/apolloGQL/Collaborator/GetIndividualModelPlanCollaborator.ts @@ -1,7 +1,7 @@ import { gql } from '@apollo/client'; -export default gql` - query GetModelCollaborator($id: UUID!) { +export default gql(/* GraphQL */ ` + query GetIndividualModelPlanCollaborator($id: UUID!) { planCollaboratorByID(id: $id) { id userAccount { @@ -14,4 +14,4 @@ export default gql` teamRoles } } -`; +`); diff --git a/src/gql/gen/graphql.ts b/src/gql/gen/graphql.ts index c798955aee..99224d62a5 100644 --- a/src/gql/gen/graphql.ts +++ b/src/gql/gen/graphql.ts @@ -2990,6 +2990,13 @@ export type UpdateTdlMutationVariables = Exact<{ export type UpdateTdlMutation = { __typename: 'Mutation', updatePlanTDL: { __typename: 'PlanTDL', id: UUID, modelPlanID: UUID, idNumber: string, dateInitiated: Time, title: string, note?: string | null } }; +export type GetIndividualModelPlanCollaboratorQueryVariables = Exact<{ + id: Scalars['UUID']['input']; +}>; + + +export type GetIndividualModelPlanCollaboratorQuery = { __typename: 'Query', planCollaboratorByID: { __typename: 'PlanCollaborator', id: UUID, userID: UUID, teamRoles: Array, userAccount: { __typename: 'UserAccount', id: UUID, commonName: string, email: string, username: string } } }; + export type GetIsCollaboratorQueryVariables = Exact<{ id: Scalars['UUID']['input']; }>; @@ -4336,6 +4343,54 @@ export function useUpdateTdlMutation(baseOptions?: Apollo.MutationHookOptions; export type UpdateTdlMutationResult = Apollo.MutationResult; export type UpdateTdlMutationOptions = Apollo.BaseMutationOptions; +export const GetIndividualModelPlanCollaboratorDocument = gql` + query GetIndividualModelPlanCollaborator($id: UUID!) { + planCollaboratorByID(id: $id) { + id + userAccount { + id + commonName + email + username + } + userID + teamRoles + } +} + `; + +/** + * __useGetIndividualModelPlanCollaboratorQuery__ + * + * To run a query within a React component, call `useGetIndividualModelPlanCollaboratorQuery` and pass it any options that fit your needs. + * When your component renders, `useGetIndividualModelPlanCollaboratorQuery` returns an object from Apollo Client that contains loading, error, and data properties + * you can use to render your UI. + * + * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; + * + * @example + * const { data, loading, error } = useGetIndividualModelPlanCollaboratorQuery({ + * variables: { + * id: // value for 'id' + * }, + * }); + */ +export function useGetIndividualModelPlanCollaboratorQuery(baseOptions: Apollo.QueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useQuery(GetIndividualModelPlanCollaboratorDocument, options); + } +export function useGetIndividualModelPlanCollaboratorLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useLazyQuery(GetIndividualModelPlanCollaboratorDocument, options); + } +export function useGetIndividualModelPlanCollaboratorSuspenseQuery(baseOptions?: Apollo.SuspenseQueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useSuspenseQuery(GetIndividualModelPlanCollaboratorDocument, options); + } +export type GetIndividualModelPlanCollaboratorQueryHookResult = ReturnType; +export type GetIndividualModelPlanCollaboratorLazyQueryHookResult = ReturnType; +export type GetIndividualModelPlanCollaboratorSuspenseQueryHookResult = ReturnType; +export type GetIndividualModelPlanCollaboratorQueryResult = Apollo.QueryResult; export const GetIsCollaboratorDocument = gql` query GetIsCollaborator($id: UUID!) { modelPlan(id: $id) { diff --git a/src/queries/Collaborators/types/GetModelCollaborator.ts b/src/gql/gen/types/GetIndividualModelPlanCollaborator.ts similarity index 50% rename from src/queries/Collaborators/types/GetModelCollaborator.ts rename to src/gql/gen/types/GetIndividualModelPlanCollaborator.ts index fb17be1186..cd4f8dae0b 100644 --- a/src/queries/Collaborators/types/GetModelCollaborator.ts +++ b/src/gql/gen/types/GetIndividualModelPlanCollaborator.ts @@ -6,10 +6,10 @@ import { TeamRole } from "./../../../types/graphql-global-types"; // ==================================================== -// GraphQL query operation: GetModelCollaborator +// GraphQL query operation: GetIndividualModelPlanCollaborator // ==================================================== -export interface GetModelCollaborator_planCollaboratorByID_userAccount { +export interface GetIndividualModelPlanCollaborator_planCollaboratorByID_userAccount { __typename: "UserAccount"; id: UUID; commonName: string; @@ -17,18 +17,18 @@ export interface GetModelCollaborator_planCollaboratorByID_userAccount { username: string; } -export interface GetModelCollaborator_planCollaboratorByID { +export interface GetIndividualModelPlanCollaborator_planCollaboratorByID { __typename: "PlanCollaborator"; id: UUID; - userAccount: GetModelCollaborator_planCollaboratorByID_userAccount; + userAccount: GetIndividualModelPlanCollaborator_planCollaboratorByID_userAccount; userID: UUID; teamRoles: TeamRole[]; } -export interface GetModelCollaborator { - planCollaboratorByID: GetModelCollaborator_planCollaboratorByID; +export interface GetIndividualModelPlanCollaborator { + planCollaboratorByID: GetIndividualModelPlanCollaborator_planCollaboratorByID; } -export interface GetModelCollaboratorVariables { +export interface GetIndividualModelPlanCollaboratorVariables { id: UUID; } diff --git a/src/views/ModelPlan/Collaborators/AddCollaborator/index.tsx b/src/views/ModelPlan/Collaborators/AddCollaborator/index.tsx index 81749f3c85..67bfb4917b 100644 --- a/src/views/ModelPlan/Collaborators/AddCollaborator/index.tsx +++ b/src/views/ModelPlan/Collaborators/AddCollaborator/index.tsx @@ -5,6 +5,7 @@ import { useMutation } from '@apollo/client'; import { Button, Fieldset, Label, TextInput } from '@trussworks/react-uswds'; import { Field, Form, Formik, FormikProps } from 'formik'; import { TeamRole, useGetModelCollaboratorsQuery } from 'gql/gen/graphql'; +import { GetIndividualModelPlanCollaborator_planCollaboratorByID as CollaboratorFormType } from 'gql/gen/types/GetIndividualModelPlanCollaborator'; import { GetModelCollaborators_modelPlan_collaborators as GetCollaboratorsType } from 'gql/gen/types/GetModelCollaborators'; import UswdsReactLink from 'components/LinkWrapper'; @@ -24,7 +25,6 @@ import { CreateModelPlanCollaborator as CreateCollaboratorsType, CreateModelPlanCollaboratorVariables } from 'queries/Collaborators/types/CreateModelPlanCollaborator'; -import { GetModelCollaborator_planCollaboratorByID as CollaboratorFormType } from 'queries/Collaborators/types/GetModelCollaborator'; import { UpdateModelPlanCollaborator as UpdateModelPlanCollaboratorType, UpdateModelPlanCollaboratorVariables From f126e192c7fc6f3413cbfc5a1d9ba4d5aaccda80 Mon Sep 17 00:00:00 2001 From: Gary Zhao Date: Tue, 12 Mar 2024 15:05:48 -0400 Subject: [PATCH 5/7] Convert CreateModelPlanCollaborator --- .../CreateModelPlanCollaborator.ts | 4 +- src/gql/gen/graphql.ts | 47 +++++++++++++++++++ .../gen}/types/CreateModelPlanCollaborator.ts | 0 .../Collaborators/AddCollaborator/index.tsx | 16 +++---- 4 files changed, 55 insertions(+), 12 deletions(-) rename src/{queries/Collaborators => gql/apolloGQL/Collaborator}/CreateModelPlanCollaborator.ts (88%) rename src/{queries/Collaborators => gql/gen}/types/CreateModelPlanCollaborator.ts (100%) diff --git a/src/queries/Collaborators/CreateModelPlanCollaborator.ts b/src/gql/apolloGQL/Collaborator/CreateModelPlanCollaborator.ts similarity index 88% rename from src/queries/Collaborators/CreateModelPlanCollaborator.ts rename to src/gql/apolloGQL/Collaborator/CreateModelPlanCollaborator.ts index ca03013976..2bfc39420c 100644 --- a/src/queries/Collaborators/CreateModelPlanCollaborator.ts +++ b/src/gql/apolloGQL/Collaborator/CreateModelPlanCollaborator.ts @@ -1,6 +1,6 @@ import { gql } from '@apollo/client'; -export default gql` +export default gql(/* GraphQL */ ` mutation CreateModelPlanCollaborator($input: PlanCollaboratorCreateInput!) { createPlanCollaborator(input: $input) { teamRoles @@ -13,4 +13,4 @@ export default gql` modelPlanID } } -`; +`); diff --git a/src/gql/gen/graphql.ts b/src/gql/gen/graphql.ts index 99224d62a5..a833571e1d 100644 --- a/src/gql/gen/graphql.ts +++ b/src/gql/gen/graphql.ts @@ -2990,6 +2990,13 @@ export type UpdateTdlMutationVariables = Exact<{ export type UpdateTdlMutation = { __typename: 'Mutation', updatePlanTDL: { __typename: 'PlanTDL', id: UUID, modelPlanID: UUID, idNumber: string, dateInitiated: Time, title: string, note?: string | null } }; +export type CreateModelPlanCollaboratorMutationVariables = Exact<{ + input: PlanCollaboratorCreateInput; +}>; + + +export type CreateModelPlanCollaboratorMutation = { __typename: 'Mutation', createPlanCollaborator: { __typename: 'PlanCollaborator', teamRoles: Array, userID: UUID, modelPlanID: UUID, userAccount: { __typename: 'UserAccount', id: UUID, commonName: string, email: string } } }; + export type GetIndividualModelPlanCollaboratorQueryVariables = Exact<{ id: Scalars['UUID']['input']; }>; @@ -4343,6 +4350,46 @@ export function useUpdateTdlMutation(baseOptions?: Apollo.MutationHookOptions; export type UpdateTdlMutationResult = Apollo.MutationResult; export type UpdateTdlMutationOptions = Apollo.BaseMutationOptions; +export const CreateModelPlanCollaboratorDocument = gql` + mutation CreateModelPlanCollaborator($input: PlanCollaboratorCreateInput!) { + createPlanCollaborator(input: $input) { + teamRoles + userAccount { + id + commonName + email + } + userID + modelPlanID + } +} + `; +export type CreateModelPlanCollaboratorMutationFn = Apollo.MutationFunction; + +/** + * __useCreateModelPlanCollaboratorMutation__ + * + * To run a mutation, you first call `useCreateModelPlanCollaboratorMutation` within a React component and pass it any options that fit your needs. + * When your component renders, `useCreateModelPlanCollaboratorMutation` returns a tuple that includes: + * - A mutate function that you can call at any time to execute the mutation + * - An object with fields that represent the current status of the mutation's execution + * + * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; + * + * @example + * const [createModelPlanCollaboratorMutation, { data, loading, error }] = useCreateModelPlanCollaboratorMutation({ + * variables: { + * input: // value for 'input' + * }, + * }); + */ +export function useCreateModelPlanCollaboratorMutation(baseOptions?: Apollo.MutationHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useMutation(CreateModelPlanCollaboratorDocument, options); + } +export type CreateModelPlanCollaboratorMutationHookResult = ReturnType; +export type CreateModelPlanCollaboratorMutationResult = Apollo.MutationResult; +export type CreateModelPlanCollaboratorMutationOptions = Apollo.BaseMutationOptions; export const GetIndividualModelPlanCollaboratorDocument = gql` query GetIndividualModelPlanCollaborator($id: UUID!) { planCollaboratorByID(id: $id) { diff --git a/src/queries/Collaborators/types/CreateModelPlanCollaborator.ts b/src/gql/gen/types/CreateModelPlanCollaborator.ts similarity index 100% rename from src/queries/Collaborators/types/CreateModelPlanCollaborator.ts rename to src/gql/gen/types/CreateModelPlanCollaborator.ts diff --git a/src/views/ModelPlan/Collaborators/AddCollaborator/index.tsx b/src/views/ModelPlan/Collaborators/AddCollaborator/index.tsx index 67bfb4917b..9971b5d430 100644 --- a/src/views/ModelPlan/Collaborators/AddCollaborator/index.tsx +++ b/src/views/ModelPlan/Collaborators/AddCollaborator/index.tsx @@ -4,7 +4,11 @@ import { useHistory, useLocation, useParams } from 'react-router-dom'; import { useMutation } from '@apollo/client'; import { Button, Fieldset, Label, TextInput } from '@trussworks/react-uswds'; import { Field, Form, Formik, FormikProps } from 'formik'; -import { TeamRole, useGetModelCollaboratorsQuery } from 'gql/gen/graphql'; +import { + TeamRole, + useCreateModelPlanCollaboratorMutation, + useGetModelCollaboratorsQuery +} from 'gql/gen/graphql'; import { GetIndividualModelPlanCollaborator_planCollaboratorByID as CollaboratorFormType } from 'gql/gen/types/GetIndividualModelPlanCollaborator'; import { GetModelCollaborators_modelPlan_collaborators as GetCollaboratorsType } from 'gql/gen/types/GetModelCollaborators'; @@ -20,11 +24,6 @@ import MultiSelect from 'components/shared/MultiSelect'; import Spinner from 'components/Spinner'; import useMessage from 'hooks/useMessage'; import usePlanTranslation from 'hooks/usePlanTranslation'; -import CreateModelPlanCollaborator from 'queries/Collaborators/CreateModelPlanCollaborator'; -import { - CreateModelPlanCollaborator as CreateCollaboratorsType, - CreateModelPlanCollaboratorVariables -} from 'queries/Collaborators/types/CreateModelPlanCollaborator'; import { UpdateModelPlanCollaborator as UpdateModelPlanCollaboratorType, UpdateModelPlanCollaboratorVariables @@ -60,10 +59,7 @@ const Collaborators = () => { const formikRef = useRef>(null); - const [create, { loading }] = useMutation< - CreateCollaboratorsType, - CreateModelPlanCollaboratorVariables - >(CreateModelPlanCollaborator); + const [create, { loading }] = useCreateModelPlanCollaboratorMutation(); const [update, { loading: updateLoading }] = useMutation< UpdateModelPlanCollaboratorType, From 1f9a72873cd8854b2758cd5f09add2bfef48b4cf Mon Sep 17 00:00:00 2001 From: Gary Zhao Date: Tue, 12 Mar 2024 15:12:32 -0400 Subject: [PATCH 6/7] Convert CreateModelPlanCollaborator and DeleteModelPlanCollaborator --- .../CreateModelPlanCollaborator.ts | 0 .../DeleteModelPlanCollaborator.ts | 4 +- .../GetIndividualModelPlanCollaborator.ts | 0 .../GetIsCollaborator.ts | 0 .../GetModelCollaborators.ts | 0 .../UpdateModelPlanCollaborator.ts | 4 +- src/gql/gen/graphql.ts | 98 +++++++++++++++++++ .../gen}/types/DeleteModelPlanCollaborator.ts | 0 .../gen}/types/UpdateModelPlanCollaborator.ts | 0 .../Collaborators/AddCollaborator/index.tsx | 17 ++-- src/views/ModelPlan/Collaborators/index.tsx | 17 ++-- 11 files changed, 115 insertions(+), 25 deletions(-) rename src/gql/apolloGQL/{Collaborator => Collaborators}/CreateModelPlanCollaborator.ts (100%) rename src/{queries => gql/apolloGQL}/Collaborators/DeleteModelPlanCollaborator.ts (87%) rename src/gql/apolloGQL/{Collaborator => Collaborators}/GetIndividualModelPlanCollaborator.ts (100%) rename src/gql/apolloGQL/{Collaborator => Collaborators}/GetIsCollaborator.ts (100%) rename src/gql/apolloGQL/{Collaborator => Collaborators}/GetModelCollaborators.ts (100%) rename src/{queries => gql/apolloGQL}/Collaborators/UpdateModelPlanCollaborator.ts (88%) rename src/{queries/Collaborators => gql/gen}/types/DeleteModelPlanCollaborator.ts (100%) rename src/{queries/Collaborators => gql/gen}/types/UpdateModelPlanCollaborator.ts (100%) diff --git a/src/gql/apolloGQL/Collaborator/CreateModelPlanCollaborator.ts b/src/gql/apolloGQL/Collaborators/CreateModelPlanCollaborator.ts similarity index 100% rename from src/gql/apolloGQL/Collaborator/CreateModelPlanCollaborator.ts rename to src/gql/apolloGQL/Collaborators/CreateModelPlanCollaborator.ts diff --git a/src/queries/Collaborators/DeleteModelPlanCollaborator.ts b/src/gql/apolloGQL/Collaborators/DeleteModelPlanCollaborator.ts similarity index 87% rename from src/queries/Collaborators/DeleteModelPlanCollaborator.ts rename to src/gql/apolloGQL/Collaborators/DeleteModelPlanCollaborator.ts index 43e3dcfabc..4d6ead1333 100644 --- a/src/queries/Collaborators/DeleteModelPlanCollaborator.ts +++ b/src/gql/apolloGQL/Collaborators/DeleteModelPlanCollaborator.ts @@ -1,6 +1,6 @@ import { gql } from '@apollo/client'; -export default gql` +export default gql(/* GraphQL */ ` mutation DeleteModelPlanCollaborator($id: UUID!) { deletePlanCollaborator(id: $id) { id @@ -15,4 +15,4 @@ export default gql` modelPlanID } } -`; +`); diff --git a/src/gql/apolloGQL/Collaborator/GetIndividualModelPlanCollaborator.ts b/src/gql/apolloGQL/Collaborators/GetIndividualModelPlanCollaborator.ts similarity index 100% rename from src/gql/apolloGQL/Collaborator/GetIndividualModelPlanCollaborator.ts rename to src/gql/apolloGQL/Collaborators/GetIndividualModelPlanCollaborator.ts diff --git a/src/gql/apolloGQL/Collaborator/GetIsCollaborator.ts b/src/gql/apolloGQL/Collaborators/GetIsCollaborator.ts similarity index 100% rename from src/gql/apolloGQL/Collaborator/GetIsCollaborator.ts rename to src/gql/apolloGQL/Collaborators/GetIsCollaborator.ts diff --git a/src/gql/apolloGQL/Collaborator/GetModelCollaborators.ts b/src/gql/apolloGQL/Collaborators/GetModelCollaborators.ts similarity index 100% rename from src/gql/apolloGQL/Collaborator/GetModelCollaborators.ts rename to src/gql/apolloGQL/Collaborators/GetModelCollaborators.ts diff --git a/src/queries/Collaborators/UpdateModelPlanCollaborator.ts b/src/gql/apolloGQL/Collaborators/UpdateModelPlanCollaborator.ts similarity index 88% rename from src/queries/Collaborators/UpdateModelPlanCollaborator.ts rename to src/gql/apolloGQL/Collaborators/UpdateModelPlanCollaborator.ts index cc1f47ee9b..3f53be3ba0 100644 --- a/src/queries/Collaborators/UpdateModelPlanCollaborator.ts +++ b/src/gql/apolloGQL/Collaborators/UpdateModelPlanCollaborator.ts @@ -1,6 +1,6 @@ import { gql } from '@apollo/client'; -export default gql` +export default gql(/* GraphQL */ ` mutation UpdateModelPlanCollaborator($id: UUID!, $newRole: [TeamRole!]!) { updatePlanCollaborator(id: $id, newRoles: $newRole) { teamRoles @@ -13,4 +13,4 @@ export default gql` modelPlanID } } -`; +`); diff --git a/src/gql/gen/graphql.ts b/src/gql/gen/graphql.ts index a833571e1d..05b9284749 100644 --- a/src/gql/gen/graphql.ts +++ b/src/gql/gen/graphql.ts @@ -2997,6 +2997,13 @@ export type CreateModelPlanCollaboratorMutationVariables = Exact<{ export type CreateModelPlanCollaboratorMutation = { __typename: 'Mutation', createPlanCollaborator: { __typename: 'PlanCollaborator', teamRoles: Array, userID: UUID, modelPlanID: UUID, userAccount: { __typename: 'UserAccount', id: UUID, commonName: string, email: string } } }; +export type DeleteModelPlanCollaboratorMutationVariables = Exact<{ + id: Scalars['UUID']['input']; +}>; + + +export type DeleteModelPlanCollaboratorMutation = { __typename: 'Mutation', deletePlanCollaborator: { __typename: 'PlanCollaborator', id: UUID, teamRoles: Array, userID: UUID, modelPlanID: UUID, userAccount: { __typename: 'UserAccount', id: UUID, commonName: string, email: string, username: string } } }; + export type GetIndividualModelPlanCollaboratorQueryVariables = Exact<{ id: Scalars['UUID']['input']; }>; @@ -3018,6 +3025,14 @@ export type GetModelCollaboratorsQueryVariables = Exact<{ export type GetModelCollaboratorsQuery = { __typename: 'Query', modelPlan: { __typename: 'ModelPlan', id: UUID, modelName: string, collaborators: Array<{ __typename: 'PlanCollaborator', id: UUID, userID: UUID, teamRoles: Array, modelPlanID: UUID, createdDts: Time, userAccount: { __typename: 'UserAccount', id: UUID, commonName: string, email: string, username: string } }> } }; +export type UpdateModelPlanCollaboratorMutationVariables = Exact<{ + id: Scalars['UUID']['input']; + newRole: Array | TeamRole; +}>; + + +export type UpdateModelPlanCollaboratorMutation = { __typename: 'Mutation', updatePlanCollaborator: { __typename: 'PlanCollaborator', teamRoles: Array, userID: UUID, modelPlanID: UUID, userAccount: { __typename: 'UserAccount', commonName: string, email: string, username: string } } }; + export type CreateModelPlanDiscussionMutationVariables = Exact<{ input: PlanDiscussionCreateInput; }>; @@ -4390,6 +4405,48 @@ export function useCreateModelPlanCollaboratorMutation(baseOptions?: Apollo.Muta export type CreateModelPlanCollaboratorMutationHookResult = ReturnType; export type CreateModelPlanCollaboratorMutationResult = Apollo.MutationResult; export type CreateModelPlanCollaboratorMutationOptions = Apollo.BaseMutationOptions; +export const DeleteModelPlanCollaboratorDocument = gql` + mutation DeleteModelPlanCollaborator($id: UUID!) { + deletePlanCollaborator(id: $id) { + id + teamRoles + userAccount { + id + commonName + email + username + } + userID + modelPlanID + } +} + `; +export type DeleteModelPlanCollaboratorMutationFn = Apollo.MutationFunction; + +/** + * __useDeleteModelPlanCollaboratorMutation__ + * + * To run a mutation, you first call `useDeleteModelPlanCollaboratorMutation` within a React component and pass it any options that fit your needs. + * When your component renders, `useDeleteModelPlanCollaboratorMutation` returns a tuple that includes: + * - A mutate function that you can call at any time to execute the mutation + * - An object with fields that represent the current status of the mutation's execution + * + * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; + * + * @example + * const [deleteModelPlanCollaboratorMutation, { data, loading, error }] = useDeleteModelPlanCollaboratorMutation({ + * variables: { + * id: // value for 'id' + * }, + * }); + */ +export function useDeleteModelPlanCollaboratorMutation(baseOptions?: Apollo.MutationHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useMutation(DeleteModelPlanCollaboratorDocument, options); + } +export type DeleteModelPlanCollaboratorMutationHookResult = ReturnType; +export type DeleteModelPlanCollaboratorMutationResult = Apollo.MutationResult; +export type DeleteModelPlanCollaboratorMutationOptions = Apollo.BaseMutationOptions; export const GetIndividualModelPlanCollaboratorDocument = gql` query GetIndividualModelPlanCollaborator($id: UUID!) { planCollaboratorByID(id: $id) { @@ -4533,6 +4590,47 @@ export type GetModelCollaboratorsQueryHookResult = ReturnType; export type GetModelCollaboratorsSuspenseQueryHookResult = ReturnType; export type GetModelCollaboratorsQueryResult = Apollo.QueryResult; +export const UpdateModelPlanCollaboratorDocument = gql` + mutation UpdateModelPlanCollaborator($id: UUID!, $newRole: [TeamRole!]!) { + updatePlanCollaborator(id: $id, newRoles: $newRole) { + teamRoles + userAccount { + commonName + email + username + } + userID + modelPlanID + } +} + `; +export type UpdateModelPlanCollaboratorMutationFn = Apollo.MutationFunction; + +/** + * __useUpdateModelPlanCollaboratorMutation__ + * + * To run a mutation, you first call `useUpdateModelPlanCollaboratorMutation` within a React component and pass it any options that fit your needs. + * When your component renders, `useUpdateModelPlanCollaboratorMutation` returns a tuple that includes: + * - A mutate function that you can call at any time to execute the mutation + * - An object with fields that represent the current status of the mutation's execution + * + * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; + * + * @example + * const [updateModelPlanCollaboratorMutation, { data, loading, error }] = useUpdateModelPlanCollaboratorMutation({ + * variables: { + * id: // value for 'id' + * newRole: // value for 'newRole' + * }, + * }); + */ +export function useUpdateModelPlanCollaboratorMutation(baseOptions?: Apollo.MutationHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useMutation(UpdateModelPlanCollaboratorDocument, options); + } +export type UpdateModelPlanCollaboratorMutationHookResult = ReturnType; +export type UpdateModelPlanCollaboratorMutationResult = Apollo.MutationResult; +export type UpdateModelPlanCollaboratorMutationOptions = Apollo.BaseMutationOptions; export const CreateModelPlanDiscussionDocument = gql` mutation CreateModelPlanDiscussion($input: PlanDiscussionCreateInput!) { createPlanDiscussion(input: $input) { diff --git a/src/queries/Collaborators/types/DeleteModelPlanCollaborator.ts b/src/gql/gen/types/DeleteModelPlanCollaborator.ts similarity index 100% rename from src/queries/Collaborators/types/DeleteModelPlanCollaborator.ts rename to src/gql/gen/types/DeleteModelPlanCollaborator.ts diff --git a/src/queries/Collaborators/types/UpdateModelPlanCollaborator.ts b/src/gql/gen/types/UpdateModelPlanCollaborator.ts similarity index 100% rename from src/queries/Collaborators/types/UpdateModelPlanCollaborator.ts rename to src/gql/gen/types/UpdateModelPlanCollaborator.ts diff --git a/src/views/ModelPlan/Collaborators/AddCollaborator/index.tsx b/src/views/ModelPlan/Collaborators/AddCollaborator/index.tsx index 9971b5d430..6652eabb20 100644 --- a/src/views/ModelPlan/Collaborators/AddCollaborator/index.tsx +++ b/src/views/ModelPlan/Collaborators/AddCollaborator/index.tsx @@ -1,13 +1,13 @@ import React, { useRef } from 'react'; import { useTranslation } from 'react-i18next'; import { useHistory, useLocation, useParams } from 'react-router-dom'; -import { useMutation } from '@apollo/client'; import { Button, Fieldset, Label, TextInput } from '@trussworks/react-uswds'; import { Field, Form, Formik, FormikProps } from 'formik'; import { TeamRole, useCreateModelPlanCollaboratorMutation, - useGetModelCollaboratorsQuery + useGetModelCollaboratorsQuery, + useUpdateModelPlanCollaboratorMutation } from 'gql/gen/graphql'; import { GetIndividualModelPlanCollaborator_planCollaboratorByID as CollaboratorFormType } from 'gql/gen/types/GetIndividualModelPlanCollaborator'; import { GetModelCollaborators_modelPlan_collaborators as GetCollaboratorsType } from 'gql/gen/types/GetModelCollaborators'; @@ -24,11 +24,6 @@ import MultiSelect from 'components/shared/MultiSelect'; import Spinner from 'components/Spinner'; import useMessage from 'hooks/useMessage'; import usePlanTranslation from 'hooks/usePlanTranslation'; -import { - UpdateModelPlanCollaborator as UpdateModelPlanCollaboratorType, - UpdateModelPlanCollaboratorVariables -} from 'queries/Collaborators/types/UpdateModelPlanCollaborator'; -import UpdateModelPlanCollaborator from 'queries/Collaborators/UpdateModelPlanCollaborator'; import { getKeys } from 'types/translation'; import flattenErrors from 'utils/flattenErrors'; import { composeMultiSelectOptions } from 'utils/modelPlan'; @@ -61,10 +56,10 @@ const Collaborators = () => { const [create, { loading }] = useCreateModelPlanCollaboratorMutation(); - const [update, { loading: updateLoading }] = useMutation< - UpdateModelPlanCollaboratorType, - UpdateModelPlanCollaboratorVariables - >(UpdateModelPlanCollaborator); + const [ + update, + { loading: updateLoading } + ] = useUpdateModelPlanCollaboratorMutation(); const { data: allCollaboratorsData, diff --git a/src/views/ModelPlan/Collaborators/index.tsx b/src/views/ModelPlan/Collaborators/index.tsx index 72efe31be5..824b6e4236 100644 --- a/src/views/ModelPlan/Collaborators/index.tsx +++ b/src/views/ModelPlan/Collaborators/index.tsx @@ -8,9 +8,13 @@ import { useLocation, useParams } from 'react-router-dom'; -import { useMutation } from '@apollo/client'; import { Button, Grid, GridContainer } from '@trussworks/react-uswds'; -import { TeamRole, useGetModelCollaboratorsQuery } from 'gql/gen/graphql'; +import { + TeamRole, + useDeleteModelPlanCollaboratorMutation, + useGetModelCollaboratorsQuery +} from 'gql/gen/graphql'; +import { DeleteModelPlanCollaborator_deletePlanCollaborator as ModelPlanCollaboratorType } from 'gql/gen/types/DeleteModelPlanCollaborator'; import { GetModelCollaborators_modelPlan_collaborators as GetCollaboratorsType } from 'gql/gen/types/GetModelCollaborators'; import Breadcrumbs from 'components/Breadcrumbs'; @@ -22,11 +26,6 @@ import PageLoading from 'components/PageLoading'; import Alert from 'components/shared/Alert'; import Expire from 'components/shared/Expire'; import useMessage from 'hooks/useMessage'; -import DeleteModelPlanCollaborator from 'queries/Collaborators/DeleteModelPlanCollaborator'; -import { - DeleteModelPlanCollaborator as DeleteModelPlanCollaboratorType, - DeleteModelPlanCollaborator_deletePlanCollaborator as ModelPlanCollaboratorType -} from 'queries/Collaborators/types/DeleteModelPlanCollaborator'; import { collaboratorsOrderedByModelLeads } from 'utils/modelPlan'; import { ModelInfoContext } from 'views/ModelInfoWrapper'; import NotFound from 'views/NotFound'; @@ -91,9 +90,7 @@ export const CollaboratorsContent = () => { // Current user's EUA id - to warn about removing yourself from model plan const { euaId } = useSelector((state: RootStateOrAny) => state.auth); - const [mutate] = useMutation( - DeleteModelPlanCollaborator - ); + const [mutate] = useDeleteModelPlanCollaboratorMutation(); const { error, data, refetch, loading } = useGetModelCollaboratorsQuery({ variables: { From 686e3bddb98678770b4566a8a5b49356bf28ae62 Mon Sep 17 00:00:00 2001 From: Gary Zhao Date: Tue, 12 Mar 2024 15:15:29 -0400 Subject: [PATCH 7/7] Convert UpdateNDA --- .../apolloGQL}/NDA/UpdateNDA.ts | 4 +- src/gql/gen/graphql.ts | 38 +++++++++++++++++++ .../NDA => gql/gen}/types/UpdateNDA.ts | 0 src/views/NDA/index.tsx | 5 +-- 4 files changed, 42 insertions(+), 5 deletions(-) rename src/{queries => gql/apolloGQL}/NDA/UpdateNDA.ts (77%) rename src/{queries/NDA => gql/gen}/types/UpdateNDA.ts (100%) diff --git a/src/queries/NDA/UpdateNDA.ts b/src/gql/apolloGQL/NDA/UpdateNDA.ts similarity index 77% rename from src/queries/NDA/UpdateNDA.ts rename to src/gql/apolloGQL/NDA/UpdateNDA.ts index 2a22c9bd58..a9b9c635e4 100644 --- a/src/queries/NDA/UpdateNDA.ts +++ b/src/gql/apolloGQL/NDA/UpdateNDA.ts @@ -1,10 +1,10 @@ import { gql } from '@apollo/client'; -export default gql` +export default gql(/* GraphQL */ ` mutation UpdateNDA { agreeToNDA(agree: true) { agreed agreedDts } } -`; +`); diff --git a/src/gql/gen/graphql.ts b/src/gql/gen/graphql.ts index 05b9284749..440a8ddbd6 100644 --- a/src/gql/gen/graphql.ts +++ b/src/gql/gen/graphql.ts @@ -3152,6 +3152,11 @@ export type GetNdaQueryVariables = Exact<{ [key: string]: never; }>; export type GetNdaQuery = { __typename: 'Query', ndaInfo: { __typename: 'NDAInfo', agreed: boolean, agreedDts?: Time | null } }; +export type UpdateNdaMutationVariables = Exact<{ [key: string]: never; }>; + + +export type UpdateNdaMutation = { __typename: 'Mutation', agreeToNDA: { __typename: 'NDAInfo', agreed: boolean, agreedDts?: Time | null } }; + export type GetNotificationSettingsQueryVariables = Exact<{ [key: string]: never; }>; @@ -5512,6 +5517,39 @@ export type GetNdaQueryHookResult = ReturnType; export type GetNdaLazyQueryHookResult = ReturnType; export type GetNdaSuspenseQueryHookResult = ReturnType; export type GetNdaQueryResult = Apollo.QueryResult; +export const UpdateNdaDocument = gql` + mutation UpdateNDA { + agreeToNDA(agree: true) { + agreed + agreedDts + } +} + `; +export type UpdateNdaMutationFn = Apollo.MutationFunction; + +/** + * __useUpdateNdaMutation__ + * + * To run a mutation, you first call `useUpdateNdaMutation` within a React component and pass it any options that fit your needs. + * When your component renders, `useUpdateNdaMutation` returns a tuple that includes: + * - A mutate function that you can call at any time to execute the mutation + * - An object with fields that represent the current status of the mutation's execution + * + * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; + * + * @example + * const [updateNdaMutation, { data, loading, error }] = useUpdateNdaMutation({ + * variables: { + * }, + * }); + */ +export function useUpdateNdaMutation(baseOptions?: Apollo.MutationHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useMutation(UpdateNdaDocument, options); + } +export type UpdateNdaMutationHookResult = ReturnType; +export type UpdateNdaMutationResult = Apollo.MutationResult; +export type UpdateNdaMutationOptions = Apollo.BaseMutationOptions; export const GetNotificationSettingsDocument = gql` query GetNotificationSettings { currentUser { diff --git a/src/queries/NDA/types/UpdateNDA.ts b/src/gql/gen/types/UpdateNDA.ts similarity index 100% rename from src/queries/NDA/types/UpdateNDA.ts rename to src/gql/gen/types/UpdateNDA.ts diff --git a/src/views/NDA/index.tsx b/src/views/NDA/index.tsx index b0a26c00f8..dd6dd0eb5c 100644 --- a/src/views/NDA/index.tsx +++ b/src/views/NDA/index.tsx @@ -2,14 +2,13 @@ import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { RootStateOrAny, useDispatch, useSelector } from 'react-redux'; import { useHistory, useLocation } from 'react-router-dom'; -import { useMutation } from '@apollo/client'; import { Button, Checkbox, Grid, GridContainer } from '@trussworks/react-uswds'; import { Field, Form, Formik, FormikProps } from 'formik'; +import { useUpdateNdaMutation } from 'gql/gen/graphql'; import UswdsReactLink from 'components/LinkWrapper'; import MainContent from 'components/MainContent'; import Alert from 'components/shared/Alert'; -import UpdateNDA from 'queries/NDA/UpdateNDA'; import { setUser } from 'reducers/authReducer'; import { formatDateLocal } from 'utils/date'; @@ -31,7 +30,7 @@ const NDA = () => { (state: RootStateOrAny) => state.auth ); - const [signNDA] = useMutation(UpdateNDA); + const [signNDA] = useUpdateNdaMutation(); useEffect(() => { if (locationState?.nextState) setOriginalRoute(locationState?.nextState);