• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CBIIT / crdc-datahub-ui / 16658447138

31 Jul 2025 07:44PM UTC coverage: 75.728% (+0.02%) from 75.709%
16658447138

Pull #805

github

web-flow
Merge 3948c0e03 into 97f318a5f
Pull Request #805: CRDCDH-2995 Model Navigator – Use MDF CDE Data

4110 of 4554 branches covered (90.25%)

Branch coverage included in aggregate %.

70 of 79 new or added lines in 3 files covered. (88.61%)

1 existing line in 1 file now uncovered.

25607 of 34688 relevant lines covered (73.82%)

149.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/hooks/useBuildReduxStore.ts
1
import { useLazyQuery } from "@apollo/client";
×
2
import {
×
3
  ddgraph,
4
  moduleReducers as submission,
5
  versionInfo,
6
  changelogInfo,
7
  iconMapInfo,
8
  getModelExploreData,
9
  getChangelog,
10
} from "data-model-navigator";
11
import { useState } from "react";
×
12
import { createStore, combineReducers, Store } from "redux";
×
13

14
import logo from "../assets/header/Logo.jpg";
×
15
import { baseConfiguration, defaultReadMeTitle, graphViewConfig } from "../config/ModelNavigator";
×
16
import { RETRIEVE_CDEs, RetrieveCDEsInput, RetrieveCDEsResp } from "../graphql";
×
17
import {
×
18
  buildAssetUrls,
19
  buildBaseFilterContainers,
20
  buildFilterOptionsList,
21
  Logger,
22
  deleteInvalidCDEs,
23
  extractAllCDEs,
24
  populateCDEData,
25
} from "../utils";
26

27
export type ReduxStoreStatus = "waiting" | "loading" | "error" | "success";
28

29
export type ReduxStoreData = {
30
  /**
31
   * The current status of the Redux store.
32
   */
33
  status: ReduxStoreStatus;
34
  /**
35
   * The Redux store instance.
36
   */
37
  store: Store;
38
};
39

40
export type ReduxStoreResult = [ReduxStoreData, (assets: DataCommon, modelVersion: string) => void];
41

42
const makeStore = (): Store => {
×
43
  const reducers = { ddgraph, versionInfo, submission, changelogInfo, iconMapInfo };
×
44
  const newStore = createStore(combineReducers(reducers));
×
45

46
  // @ts-ignore
47
  newStore.injectReducer = (key, reducer) => {
×
48
    reducers[key] = reducer;
×
49
    newStore.replaceReducer(combineReducers(reducers));
×
50
  };
×
51

52
  return newStore;
×
53
};
×
54

55
/**
56
 * A hook to build and populate the Redux store with DMN data
57
 *
58
 * @params {void}
59
 */
60
const useBuildReduxStore = (): ReduxStoreResult => {
×
61
  const [store] = useState<Store>(makeStore());
×
62
  const [status, setStatus] = useState<ReduxStoreStatus>("waiting");
×
63

NEW
64
  const [retrieveCDEs] = useLazyQuery<RetrieveCDEsResp, RetrieveCDEsInput>(RETRIEVE_CDEs, {
×
UNCOV
65
    context: { clientName: "backend" },
×
NEW
66
    fetchPolicy: "cache-first",
×
67
  });
×
68

69
  /**
70
   * Injects the Data Model into the store
71
   *
72
   * @param datacommon The Data Model to inject assets from
73
   * @param modelVersion The version of the Data Model to inject
74
   */
75
  const populateStore = async (datacommon: DataCommon, modelVersion: string) => {
×
76
    if (
×
77
      !datacommon?.name ||
×
78
      !datacommon?.assets ||
×
79
      !datacommon?.assets["current-version"] ||
×
80
      !datacommon?.assets["model-navigator-config"]
×
81
    ) {
×
82
      setStatus("error");
×
83
      return;
×
84
    }
×
85

86
    setStatus("loading");
×
87

88
    const assets = buildAssetUrls(datacommon, modelVersion);
×
89
    const dmnConfig = datacommon.assets["model-navigator-config"];
×
90

91
    const changelogMD = await getChangelog(assets?.changelog)?.catch((e) => {
×
92
      Logger.error(e);
×
93
      return null;
×
94
    });
×
95

96
    const response = await getModelExploreData(...assets.model_files)?.catch((e) => {
×
97
      Logger.error(e);
×
98
      return null;
×
99
    });
×
100

101
    if (!response?.data || !response?.version) {
×
102
      setStatus("error");
×
103
      return;
×
104
    }
×
105

NEW
106
    const { data: dictionary } = response as { data: MDFDictionary };
×
107

NEW
108
    deleteInvalidCDEs(dictionary);
×
109

NEW
110
    const allCDEs = extractAllCDEs(dictionary);
×
NEW
111
    if (allCDEs.length > 0) {
×
112
      try {
×
113
        const CDEs = await retrieveCDEs({
×
114
          variables: {
×
NEW
115
            cdeInfo: allCDEs.map(({ CDECode, CDEVersion }) => ({ CDECode, CDEVersion })),
×
116
          },
×
117
        });
×
NEW
118
        populateCDEData(dictionary, CDEs?.data?.retrieveCDEs || []);
×
119
      } catch (error) {
×
NEW
120
        populateCDEData(dictionary, []);
×
121
      }
×
122
    }
×
123

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

126
    store.dispatch({
×
127
      type: "REACT_FLOW_GRAPH_DICTIONARY",
×
128
      dictionary,
×
129
      pdfDownloadConfig: {
×
130
        iconSrc: logo,
×
131
        ...dmnConfig.pdfConfig,
×
132
      },
×
133
      graphViewConfig,
×
134
    });
×
135

136
    store.dispatch({
×
137
      type: "RECEIVE_DICTIONARY",
×
138
      payload: {
×
139
        data: dictionary,
×
140
        facetfilterConfig: {
×
141
          ...baseConfiguration,
×
142
          facetSearchData: dmnConfig.facetFilterSearchData,
×
143
          facetSectionVariables: dmnConfig.facetFilterSectionVariables,
×
144
          baseFilters: buildBaseFilterContainers(dmnConfig),
×
145
          filterSections: dmnConfig.facetFilterSearchData.map((s) => s?.datafield),
×
146
          filterOptions: buildFilterOptionsList(dmnConfig),
×
147
        },
×
148
        pageConfig: {
×
149
          title: dmnConfig.pageTitle,
×
150
          iconSrc: assets.navigator_icon,
×
151
        },
×
152
        readMeConfig: {
×
153
          readMeUrl: assets.readme,
×
154
          readMeTitle: dmnConfig?.readMeTitle || defaultReadMeTitle,
×
155
          allowDownload: false,
×
156
        },
×
157
        pdfDownloadConfig: dmnConfig.pdfConfig,
×
158
        loadingExampleConfig: {
×
159
          type: "static",
×
160
          url: assets.loading_file,
×
161
        },
×
162
      },
×
163
    });
×
164

165
    store.dispatch({
×
166
      type: "RECEIVE_CHANGELOG_INFO",
×
167
      data: {
×
168
        changelogMD,
×
169
        changelogTabName: "Version History",
×
170
      },
×
171
    });
×
172

173
    if (datacommon?.assets?.["model-navigator-config"]?.iconMap) {
×
174
      store.dispatch({
×
175
        type: "RECEIVE_ICON_MAP",
×
176
        data: datacommon?.assets?.["model-navigator-config"]?.iconMap,
×
177
      });
×
178
    }
×
179

180
    // MVP-2 M2 NOTE: This resets the search history to prevent the data models
181
    // from overlapping on searches. A future improvement would be to isolate
182
    // the localStorage history key to the data model based on a config option.
183
    store.dispatch({ type: "SEARCH_CLEAR_HISTORY" });
×
184

185
    setStatus("success");
×
186
  };
×
187

188
  return [{ status, store }, populateStore];
×
189
};
×
190

191
export default useBuildReduxStore;
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc