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

CBIIT / crdc-datahub-ui / 15856667353

24 Jun 2025 04:55PM UTC coverage: 70.795% (-0.009%) from 70.804%
15856667353

push

github

web-flow
Merge pull request #745 from CBIIT/CRDCDH-2816

CRDCDH-2816 ESLint Rule Updates

3530 of 3890 branches covered (90.75%)

Branch coverage included in aggregate %.

555 of 705 new or added lines in 157 files covered. (78.72%)

20 existing lines in 16 files now uncovered.

22470 of 32836 relevant lines covered (68.43%)

110.86 hits per line

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

0.0
/src/hooks/useBuildReduxStore.ts
NEW
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 { defaultTo } from "lodash";
×
NEW
12
import { useState } from "react";
×
NEW
13
import { createStore, combineReducers, Store } from "redux";
×
14

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

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

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

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

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

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

51
  return newStore;
×
52
};
×
53

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

63
  const [retrieveCDEs, { error: retrieveCDEsError }] = useLazyQuery<
×
64
    RetrieveCDEsResp,
65
    RetrieveCDEsInput
66
  >(RETRIEVE_CDEs, {
×
67
    context: { clientName: "backend" },
×
68
    fetchPolicy: "cache-and-network",
×
69
  });
×
70

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

88
    setStatus("loading");
×
89

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

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

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

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

108
    let dictionary;
×
109
    const { cdeMap, data: dataList } = response;
×
110

111
    if (cdeMap) {
×
112
      const cdeInfo: CDEInfo[] = Array.from(response.cdeMap.values());
×
113
      try {
×
114
        const CDEs = await retrieveCDEs({
×
115
          variables: {
×
116
            cdeInfo: cdeInfo.map(({ CDECode, CDEVersion }) => ({ CDECode, CDEVersion })),
×
117
          },
×
118
        });
×
119

120
        if (retrieveCDEsError) {
×
121
          dictionary = updateEnums(cdeMap, dataList, [], true);
×
122
        } else {
×
123
          const retrievedCDEs = defaultTo(CDEs.data.retrieveCDEs, []);
×
124
          dictionary = updateEnums(cdeMap, dataList, retrievedCDEs);
×
125
        }
×
126
      } catch (error) {
×
127
        dictionary = updateEnums(cdeMap, dataList, [], true);
×
128
      }
×
129
    } else {
×
130
      dictionary = dataList;
×
131
    }
×
132

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

135
    store.dispatch({
×
136
      type: "REACT_FLOW_GRAPH_DICTIONARY",
×
137
      dictionary,
×
138
      pdfDownloadConfig: {
×
139
        iconSrc: logo,
×
140
        ...dmnConfig.pdfConfig,
×
141
      },
×
142
      graphViewConfig,
×
143
    });
×
144

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

174
    store.dispatch({
×
175
      type: "RECEIVE_CHANGELOG_INFO",
×
176
      data: {
×
177
        changelogMD,
×
178
        changelogTabName: "Version History",
×
179
      },
×
180
    });
×
181

182
    if (datacommon?.assets?.["model-navigator-config"]?.iconMap) {
×
183
      store.dispatch({
×
184
        type: "RECEIVE_ICON_MAP",
×
185
        data: datacommon?.assets?.["model-navigator-config"]?.iconMap,
×
186
      });
×
187
    }
×
188

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

194
    setStatus("success");
×
195
  };
×
196

197
  return [{ status, store }, populateStore];
×
198
};
×
199

200
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

© 2026 Coveralls, Inc