From 5f9df84a744511559ac090a02e1ed31a5951b07c Mon Sep 17 00:00:00 2001 From: Alejandro-Vega Date: Fri, 27 Sep 2024 11:04:09 -0400 Subject: [PATCH 1/3] Update study queries and types --- src/graphql/index.ts | 5 +- src/graphql/listApprovedStudies.ts | 52 ++++++++++++++++--- .../listApprovedStudiesOfMyOrganization.ts | 2 +- src/types/ApprovedStudies.d.ts | 24 +++++++++ src/types/Submissions.d.ts | 2 + 5 files changed, 76 insertions(+), 9 deletions(-) diff --git a/src/graphql/index.ts b/src/graphql/index.ts index 6eb9bd55..59ef864f 100644 --- a/src/graphql/index.ts +++ b/src/graphql/index.ts @@ -145,7 +145,10 @@ export { query as LIST_CURATORS } from "./listActiveCurators"; export type { Response as ListCuratorsResp } from "./listActiveCurators"; export { query as LIST_APPROVED_STUDIES } from "./listApprovedStudies"; -export type { Response as ListApprovedStudiesResp } from "./listApprovedStudies"; +export type { + Input as ListApprovedStudiesInput, + Response as ListApprovedStudiesResp, +} from "./listApprovedStudies"; export { mutation as CREATE_ORG } from "./createOrganization"; export type { Input as CreateOrgInput, Response as CreateOrgResp } from "./createOrganization"; diff --git a/src/graphql/listApprovedStudies.ts b/src/graphql/listApprovedStudies.ts index 5160a60e..04d4ecf2 100644 --- a/src/graphql/listApprovedStudies.ts +++ b/src/graphql/listApprovedStudies.ts @@ -1,16 +1,54 @@ import gql from "graphql-tag"; export const query = gql` - query listApprovedStudies { - listApprovedStudies { - _id - studyName - studyAbbreviation - dbGaPID + query listApprovedStudies( + $first: Int + $offset: Int + $orderBy: String + $sortDirection: String + $dbGaPID: String + $controlledAccess: String + $study: String + ) { + listApprovedStudies( + first: $first + offset: $offset + orderBy: $orderBy + sortDirection: $sortDirection + dbGaPID: $dbGaPID + controlledAccess: $controlledAccess + study: $study + ) { + total + studies { + _id + studyName + studyAbbreviation + dbGaPID + controlledAccess + openAccess + PI + ORCID + createdAt + } } } `; +export type Input = { + first?: number; + offset?: number; + orderBy?: string; + sortDirection?: Order; + dbGaPID?: string; + controlledAccess?: AccessType; + openAccess?: boolean; + study?: string; +}; + export type Response = { - listApprovedStudies: ApprovedStudy[]; + listApprovedStudies: { + total: number; + studies: ApprovedStudy[]; + }; }; diff --git a/src/graphql/listApprovedStudiesOfMyOrganization.ts b/src/graphql/listApprovedStudiesOfMyOrganization.ts index 3311921a..2e616b4f 100644 --- a/src/graphql/listApprovedStudiesOfMyOrganization.ts +++ b/src/graphql/listApprovedStudiesOfMyOrganization.ts @@ -13,5 +13,5 @@ export const query = gql` `; export type Response = { - listApprovedStudiesOfMyOrganization: ApprovedStudy[]; + listApprovedStudiesOfMyOrganization: ApprovedStudyOfMyOrganization[]; }; diff --git a/src/types/ApprovedStudies.d.ts b/src/types/ApprovedStudies.d.ts index b8364e56..e0ad11d9 100644 --- a/src/types/ApprovedStudies.d.ts +++ b/src/types/ApprovedStudies.d.ts @@ -1,5 +1,6 @@ type ApprovedStudy = { _id: string; + originalOrg: string; /** * Study name * @@ -20,4 +21,27 @@ type ApprovedStudy = { * Boolean flag dictating whether the study has controlled access data */ controlledAccess: boolean; + /** + * Boolean flag dictating whether the study has open access data + */ + openAccess: boolean; + /** + * Principal Investigator's name + */ + PI: string; + /** + * Open Researcher and Contributor ID. + * + * @example 0000-0001-2345-6789 + */ + ORCID: string; + /** + * Submission Request approval date or manual record creation date + */ + createdAt: string; }; + +type ApprovedStudyOfMyOrganization = Pick< + ApprovedStudy, + "_id" | "studyName" | "studyAbbreviation" | "dbGaPID" | "controlledAccess" +>; diff --git a/src/types/Submissions.d.ts b/src/types/Submissions.d.ts index 4c4af1cc..21d8bd72 100644 --- a/src/types/Submissions.d.ts +++ b/src/types/Submissions.d.ts @@ -381,3 +381,5 @@ type SubmitButtonResult = { tooltip?: string; _identifier?: string; }; + +type AccessType = "All" | "Controlled" | "Open"; From fbdb9d3a09c4d9ef25314c49b2d954c0c6233680 Mon Sep 17 00:00:00 2001 From: Alejandro-Vega Date: Fri, 27 Sep 2024 11:05:12 -0400 Subject: [PATCH 2/3] Update listApprovedStudies query usage to return all results --- .../organizations/OrganizationView.tsx | 29 ++++++++++++------- src/content/users/ProfileView.tsx | 8 ++++- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/content/organizations/OrganizationView.tsx b/src/content/organizations/OrganizationView.tsx index 643b723d..304a2fd3 100644 --- a/src/content/organizations/OrganizationView.tsx +++ b/src/content/organizations/OrganizationView.tsx @@ -32,6 +32,7 @@ import { ListCuratorsResp, EditOrgInput, CreateOrgInput, + ListApprovedStudiesInput, } from "../../graphql"; import ConfirmDialog from "../../components/Organizations/ConfirmDialog"; import usePageTitle from "../../hooks/usePageTitle"; @@ -209,13 +210,19 @@ const OrganizationView: FC = ({ _id }: Props) => { fetchPolicy: "cache-and-network", }); - const { data: approvedStudies, refetch: refetchStudies } = useQuery( - LIST_APPROVED_STUDIES, - { - context: { clientName: "backend" }, - fetchPolicy: "cache-and-network", - } - ); + const { data: approvedStudies, refetch: refetchStudies } = useQuery< + ListApprovedStudiesResp, + ListApprovedStudiesInput + >(LIST_APPROVED_STUDIES, { + variables: { + // show all access types + controlledAccess: "All", + first: -1, + offset: 0, + }, + context: { clientName: "backend" }, + fetchPolicy: "cache-and-network", + }); const [getOrganization] = useLazyQuery(GET_ORG, { context: { clientName: "backend" }, @@ -304,7 +311,7 @@ const OrganizationView: FC = ({ _id }: Props) => { const handlePreSubmit = (data: FormInput) => { if (_id !== "new") { const studyMap: { [_id: string]: ApprovedStudy["studyAbbreviation"] } = {}; - approvedStudies?.listApprovedStudies?.forEach(({ _id, studyAbbreviation }) => { + approvedStudies?.listApprovedStudies?.studies?.forEach(({ _id, studyAbbreviation }) => { studyMap[_id] = studyAbbreviation; }); @@ -354,10 +361,10 @@ const OrganizationView: FC = ({ _id }: Props) => { } // No studies or original request did not complete. Refetch - let studyList: ApprovedStudy[] = approvedStudies?.listApprovedStudies; + let studyList: ApprovedStudy[] = approvedStudies?.listApprovedStudies?.studies; if (!studyList?.length) { const { data } = await refetchStudies(); - studyList = data?.listApprovedStudies; + studyList = data?.listApprovedStudies?.studies; } setOrganization(data?.getOrganization); @@ -463,7 +470,7 @@ const OrganizationView: FC = ({ _id }: Props) => { inputProps={{ "aria-labelledby": "studiesLabel" }} multiple > - {approvedStudies?.listApprovedStudies?.map( + {approvedStudies?.listApprovedStudies?.studies?.map( ({ _id, studyName, studyAbbreviation }) => ( {formatFullStudyName(studyName, studyAbbreviation)} diff --git a/src/content/users/ProfileView.tsx b/src/content/users/ProfileView.tsx index 9955adb7..eb3bedcb 100644 --- a/src/content/users/ProfileView.tsx +++ b/src/content/users/ProfileView.tsx @@ -200,6 +200,12 @@ const ProfileView: FC = ({ _id, viewType }: Props) => { }); const { data: approvedStudies } = useQuery(LIST_APPROVED_STUDIES, { + variables: { + // show all access types + controlledAccess: "All", + first: -1, + offset: 0, + }, context: { clientName: "backend" }, fetchPolicy: "cache-and-network", skip: fieldset.studies !== "UNLOCKED", @@ -208,7 +214,7 @@ const ProfileView: FC = ({ _id, viewType }: Props) => { // TODO: This is temporary until the API supports sorting natively const sortedStudies = useMemo( () => - cloneDeep(approvedStudies?.listApprovedStudies)?.sort((a, b) => + cloneDeep(approvedStudies?.listApprovedStudies?.studies)?.sort((a, b) => a.studyName.localeCompare(b.studyName) ) || [], [approvedStudies] From 5ce8d526d544e1eab0c8e5eb0bf2acbfb5b13a3e Mon Sep 17 00:00:00 2001 From: Alejandro-Vega Date: Fri, 27 Sep 2024 11:05:46 -0400 Subject: [PATCH 3/3] Fix test base study --- src/utils/formUtils.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utils/formUtils.test.ts b/src/utils/formUtils.test.ts index 465c285e..0e7459b4 100644 --- a/src/utils/formUtils.test.ts +++ b/src/utils/formUtils.test.ts @@ -447,6 +447,11 @@ describe("renderStudySelectionValue cases", () => { studyAbbreviation: "", dbGaPID: "", controlledAccess: false, + originalOrg: "", + openAccess: false, + PI: "", + ORCID: "", + createdAt: "", }; it("should return the fallback value if studyIds is not an array", () => {