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

CBIIT / crdc-datahub-ui / 14929658318

09 May 2025 01:08PM UTC coverage: 62.417% (-0.009%) from 62.426%
14929658318

push

github

web-flow
Merge pull request #696 from CBIIT/CRDCDH-2600

CRDCDH-2600 Support custom mapping of DMN icons

3461 of 5950 branches covered (58.17%)

Branch coverage included in aggregate %.

8 of 16 new or added lines in 3 files covered. (50.0%)

1 existing line in 1 file now uncovered.

4783 of 7258 relevant lines covered (65.9%)

198.82 hits per line

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

0.0
/src/hooks/useBuildReduxStore.ts
1
import { useState } from "react";
2
import { createStore, combineReducers, Store } from "redux";
3
import {
4
  ddgraph,
5
  moduleReducers as submission,
6
  versionInfo,
7
  changelogInfo,
8
  iconMapInfo,
9
  getModelExploreData,
10
  getChangelog,
11
} from "data-model-navigator";
12
import { useLazyQuery } from "@apollo/client";
13
import { defaultTo } from "lodash";
14
import { baseConfiguration, defaultReadMeTitle, graphViewConfig } from "../config/ModelNavigator";
15
import {
16
  buildAssetUrls,
17
  buildBaseFilterContainers,
18
  buildFilterOptionsList,
19
  updateEnums,
20
  Logger,
21
} from "../utils";
22
import { RETRIEVE_CDEs, RetrieveCDEsInput, RetrieveCDEsResp } from "../graphql";
23
import logo from "../assets/header/Logo.jpg";
24

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

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

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

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

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

50
  return newStore;
×
51
};
52

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

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

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

87
    setStatus("loading");
×
88

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

199
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