Skip to content

Commit

Permalink
Merge pull request #459 from CBIIT/CRDCDH-1443
Browse files Browse the repository at this point in the history
  • Loading branch information
amattu2 authored Oct 1, 2024
2 parents 9b3e6ff + 193ad2c commit 3a3e79b
Show file tree
Hide file tree
Showing 8 changed files with 619 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export type { Input as UpdateMyUserInput, Response as UpdateMyUserResp } from ".
export { query as LIST_INSTITUTIONS } from "./listInstitutions";
export type { Response as ListInstitutionsResp } from "./listInstitutions";

export { query as RETRIEVE_CDEs } from "./retrieveCDEs";
export type { Response as RetrieveCDEsResp, Input as RetrieveCDEsInput } from "./retrieveCDEs";

// Data Submissions
export { mutation as CREATE_SUBMISSION } from "./createSubmission";
export type {
Expand Down
31 changes: 31 additions & 0 deletions src/graphql/retrieveCDEs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import gql from "graphql-tag";

export const query = gql`
query retrieveCDEs($cdeInfo: [CDEInput!]!) {
retrieveCDEs(CDEInfo: $cdeInfo) {
_id
CDEFullName
CDECode
CDEVersion
PermissibleValues
createdAt
updatedAt
}
}
`;

export type Input = {
cdeInfo: CDEInfo[];
};

export type Response = {
retrieveCDEs: {
_id: string;
CDEFullName: string;
CDECode: string;
CDEVersion: string;
PermissibleValues: string[];
createdAt: string;
updatedAt: string;
}[];
};
42 changes: 40 additions & 2 deletions src/hooks/useBuildReduxStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import {
} from "data-model-navigator";
import ReduxThunk from "redux-thunk";
import { createLogger } from "redux-logger";
import { useLazyQuery } from "@apollo/client";
import { defaultTo } from "lodash";
import { baseConfiguration, defaultReadMeTitle, graphViewConfig } from "../config/ModelNavigator";
import {
buildAssetUrls,
buildBaseFilterContainers,
buildFilterOptionsList,
updateEnums,
Logger,
} from "../utils";
import { RETRIEVE_CDEs, RetrieveCDEsInput, RetrieveCDEsResp } from "../graphql";

export type Status = "waiting" | "loading" | "error" | "success";

Expand Down Expand Up @@ -49,6 +53,14 @@ const useBuildReduxStore = (): [
const [status, setStatus] = useState<Status>("waiting");
const [store, setStore] = useState<Store>(makeStore());

const [retrieveCDEs, { error: retrieveCDEsError }] = useLazyQuery<
RetrieveCDEsResp,
RetrieveCDEsInput
>(RETRIEVE_CDEs, {
context: { clientName: "backend" },
fetchPolicy: "cache-and-network",
});

/**
* Rebuilds the store from scratch
*
Expand Down Expand Up @@ -78,6 +90,7 @@ const useBuildReduxStore = (): [
setStatus("loading");

const assets = buildAssetUrls(datacommon);

const response = await getModelExploreData(assets.model, assets.props)?.catch((e) => {
Logger.error(e);
return null;
Expand All @@ -87,19 +100,44 @@ const useBuildReduxStore = (): [
return;
}

let dictionary;
const { cdeMap, data: dataList } = response;

if (cdeMap) {
const cdeInfo: CDEInfo[] = Array.from(response.cdeMap.values());
try {
const CDEs = await retrieveCDEs({
variables: {
cdeInfo,
},
});

if (retrieveCDEsError) {
dictionary = updateEnums(cdeMap, dataList, [], true);
} else {
const retrievedCDEs = defaultTo(CDEs.data.retrieveCDEs, []);
dictionary = updateEnums(cdeMap, dataList, retrievedCDEs);
}
} catch (error) {
dictionary = updateEnums(cdeMap, dataList, [], true);
}
} else {
dictionary = dataList;
}

store.dispatch({ type: "RECEIVE_VERSION_INFO", data: response.version });

store.dispatch({
type: "REACT_FLOW_GRAPH_DICTIONARY",
dictionary: response.data,
dictionary,
pdfDownloadConfig: datacommon.configuration.pdfConfig,
graphViewConfig,
});

store.dispatch({
type: "RECEIVE_DICTIONARY",
payload: {
data: response.data,
data: dictionary,
facetfilterConfig: {
...baseConfiguration,
facetSearchData: datacommon.configuration.facetFilterSearchData,
Expand Down
4 changes: 4 additions & 0 deletions src/types/CDEs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type CDEInfo = {
CDECode: string;
CDEVersion: string;
};
Loading

0 comments on commit 3a3e79b

Please sign in to comment.