Skip to content

Commit

Permalink
Merge branch '3.1.0' into CRDCDH-1613
Browse files Browse the repository at this point in the history
  • Loading branch information
amattu2 authored Oct 1, 2024
2 parents f939221 + 6c61eba commit 5cffcf2
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 21 deletions.
29 changes: 18 additions & 11 deletions src/content/organizations/OrganizationView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
ListCuratorsResp,
EditOrgInput,
CreateOrgInput,
ListApprovedStudiesInput,
} from "../../graphql";
import ConfirmDialog from "../../components/Organizations/ConfirmDialog";
import usePageTitle from "../../hooks/usePageTitle";
Expand Down Expand Up @@ -209,13 +210,19 @@ const OrganizationView: FC<Props> = ({ _id }: Props) => {
fetchPolicy: "cache-and-network",
});

const { data: approvedStudies, refetch: refetchStudies } = useQuery<ListApprovedStudiesResp>(
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<GetOrgResp>(GET_ORG, {
context: { clientName: "backend" },
Expand Down Expand Up @@ -304,7 +311,7 @@ const OrganizationView: FC<Props> = ({ _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;
});

Expand Down Expand Up @@ -354,10 +361,10 @@ const OrganizationView: FC<Props> = ({ _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);
Expand Down Expand Up @@ -463,7 +470,7 @@ const OrganizationView: FC<Props> = ({ _id }: Props) => {
inputProps={{ "aria-labelledby": "studiesLabel" }}
multiple
>
{approvedStudies?.listApprovedStudies?.map(
{approvedStudies?.listApprovedStudies?.studies?.map(
({ _id, studyName, studyAbbreviation }) => (
<MenuItem key={_id} value={_id}>
{formatFullStudyName(studyName, studyAbbreviation)}
Expand Down
8 changes: 7 additions & 1 deletion src/content/users/ProfileView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ const ProfileView: FC<Props> = ({ _id, viewType }: Props) => {
});

const { data: approvedStudies } = useQuery<ListApprovedStudiesResp>(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",
Expand All @@ -208,7 +214,7 @@ const ProfileView: FC<Props> = ({ _id, viewType }: Props) => {
// TODO: This is temporary until the API supports sorting natively
const sortedStudies = useMemo<ApprovedStudy[]>(
() =>
cloneDeep(approvedStudies?.listApprovedStudies)?.sort((a, b) =>
cloneDeep(approvedStudies?.listApprovedStudies?.studies)?.sort((a, b) =>
a.studyName.localeCompare(b.studyName)
) || [],
[approvedStudies]
Expand Down
5 changes: 4 additions & 1 deletion src/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
52 changes: 45 additions & 7 deletions src/graphql/listApprovedStudies.ts
Original file line number Diff line number Diff line change
@@ -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[];
};
};
2 changes: 1 addition & 1 deletion src/graphql/listApprovedStudiesOfMyOrganization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export const query = gql`
`;

export type Response = {
listApprovedStudiesOfMyOrganization: ApprovedStudy[];
listApprovedStudiesOfMyOrganization: ApprovedStudyOfMyOrganization[];
};
24 changes: 24 additions & 0 deletions src/types/ApprovedStudies.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type ApprovedStudy = {
_id: string;
originalOrg: string;
/**
* Study name
*
Expand All @@ -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"
>;
2 changes: 2 additions & 0 deletions src/types/Submissions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,5 @@ type SubmitButtonResult = {
tooltip?: string;
_identifier?: string;
};

type AccessType = "All" | "Controlled" | "Open";
5 changes: 5 additions & 0 deletions src/utils/formUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit 5cffcf2

Please sign in to comment.