Skip to content

Commit 3a3e79b

Browse files
authored
Merge pull request #459 from CBIIT/CRDCDH-1443
CRDCDH-1443
2 parents 9b3e6ff + 193ad2c commit 3a3e79b

File tree

8 files changed

+619
-3
lines changed

8 files changed

+619
-3
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/graphql/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export type { Input as UpdateMyUserInput, Response as UpdateMyUserResp } from ".
3232
export { query as LIST_INSTITUTIONS } from "./listInstitutions";
3333
export type { Response as ListInstitutionsResp } from "./listInstitutions";
3434

35+
export { query as RETRIEVE_CDEs } from "./retrieveCDEs";
36+
export type { Response as RetrieveCDEsResp, Input as RetrieveCDEsInput } from "./retrieveCDEs";
37+
3538
// Data Submissions
3639
export { mutation as CREATE_SUBMISSION } from "./createSubmission";
3740
export type {

src/graphql/retrieveCDEs.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import gql from "graphql-tag";
2+
3+
export const query = gql`
4+
query retrieveCDEs($cdeInfo: [CDEInput!]!) {
5+
retrieveCDEs(CDEInfo: $cdeInfo) {
6+
_id
7+
CDEFullName
8+
CDECode
9+
CDEVersion
10+
PermissibleValues
11+
createdAt
12+
updatedAt
13+
}
14+
}
15+
`;
16+
17+
export type Input = {
18+
cdeInfo: CDEInfo[];
19+
};
20+
21+
export type Response = {
22+
retrieveCDEs: {
23+
_id: string;
24+
CDEFullName: string;
25+
CDECode: string;
26+
CDEVersion: string;
27+
PermissibleValues: string[];
28+
createdAt: string;
29+
updatedAt: string;
30+
}[];
31+
};

src/hooks/useBuildReduxStore.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ import {
88
} from "data-model-navigator";
99
import ReduxThunk from "redux-thunk";
1010
import { createLogger } from "redux-logger";
11+
import { useLazyQuery } from "@apollo/client";
12+
import { defaultTo } from "lodash";
1113
import { baseConfiguration, defaultReadMeTitle, graphViewConfig } from "../config/ModelNavigator";
1214
import {
1315
buildAssetUrls,
1416
buildBaseFilterContainers,
1517
buildFilterOptionsList,
18+
updateEnums,
1619
Logger,
1720
} from "../utils";
21+
import { RETRIEVE_CDEs, RetrieveCDEsInput, RetrieveCDEsResp } from "../graphql";
1822

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

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

56+
const [retrieveCDEs, { error: retrieveCDEsError }] = useLazyQuery<
57+
RetrieveCDEsResp,
58+
RetrieveCDEsInput
59+
>(RETRIEVE_CDEs, {
60+
context: { clientName: "backend" },
61+
fetchPolicy: "cache-and-network",
62+
});
63+
5264
/**
5365
* Rebuilds the store from scratch
5466
*
@@ -78,6 +90,7 @@ const useBuildReduxStore = (): [
7890
setStatus("loading");
7991

8092
const assets = buildAssetUrls(datacommon);
93+
8194
const response = await getModelExploreData(assets.model, assets.props)?.catch((e) => {
8295
Logger.error(e);
8396
return null;
@@ -87,19 +100,44 @@ const useBuildReduxStore = (): [
87100
return;
88101
}
89102

103+
let dictionary;
104+
const { cdeMap, data: dataList } = response;
105+
106+
if (cdeMap) {
107+
const cdeInfo: CDEInfo[] = Array.from(response.cdeMap.values());
108+
try {
109+
const CDEs = await retrieveCDEs({
110+
variables: {
111+
cdeInfo,
112+
},
113+
});
114+
115+
if (retrieveCDEsError) {
116+
dictionary = updateEnums(cdeMap, dataList, [], true);
117+
} else {
118+
const retrievedCDEs = defaultTo(CDEs.data.retrieveCDEs, []);
119+
dictionary = updateEnums(cdeMap, dataList, retrievedCDEs);
120+
}
121+
} catch (error) {
122+
dictionary = updateEnums(cdeMap, dataList, [], true);
123+
}
124+
} else {
125+
dictionary = dataList;
126+
}
127+
90128
store.dispatch({ type: "RECEIVE_VERSION_INFO", data: response.version });
91129

92130
store.dispatch({
93131
type: "REACT_FLOW_GRAPH_DICTIONARY",
94-
dictionary: response.data,
132+
dictionary,
95133
pdfDownloadConfig: datacommon.configuration.pdfConfig,
96134
graphViewConfig,
97135
});
98136

99137
store.dispatch({
100138
type: "RECEIVE_DICTIONARY",
101139
payload: {
102-
data: response.data,
140+
data: dictionary,
103141
facetfilterConfig: {
104142
...baseConfiguration,
105143
facetSearchData: datacommon.configuration.facetFilterSearchData,

src/types/CDEs.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type CDEInfo = {
2+
CDECode: string;
3+
CDEVersion: string;
4+
};

0 commit comments

Comments
 (0)