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

CBIIT / crdc-datahub-ui / 11074479132

27 Sep 2024 04:44PM UTC coverage: 44.982% (+26.5%) from 18.435%
11074479132

Pull #479

github

web-flow
Merge a0867d25a into 3d8b55818
Pull Request #479: 3.0.0 Release

1727 of 4418 branches covered (39.09%)

Branch coverage included in aggregate %.

2612 of 5228 relevant lines covered (49.96%)

128.96 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, applyMiddleware, combineReducers, Store } from "redux";
3
import {
4
  ddgraph,
5
  moduleReducers as submission,
6
  versionInfo,
7
  getModelExploreData,
8
} from "data-model-navigator";
9
import ReduxThunk from "redux-thunk";
10
import { createLogger } from "redux-logger";
11
import { baseConfiguration, defaultReadMeTitle, graphViewConfig } from "../config/ModelNavigator";
12
import { buildAssetUrls, buildBaseFilterContainers, buildFilterOptionsList } from "../utils";
13

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

16
const makeStore = (): Store => {
×
17
  const reducers = { ddgraph, versionInfo, submission };
×
18
  const loggerMiddleware = createLogger();
×
19

20
  const newStore = createStore(
×
21
    combineReducers(reducers),
22
    applyMiddleware(ReduxThunk, loggerMiddleware)
23
  );
24

25
  // @ts-ignore
26
  newStore.injectReducer = (key, reducer) => {
×
27
    reducers[key] = reducer;
×
28
    newStore.replaceReducer(combineReducers(reducers));
×
29
  };
30

31
  return newStore;
×
32
};
33

34
/**
35
 * A hook to build and populate the Redux store with DMN data
36
 *
37
 * @params {void}
38
 */
39
const useBuildReduxStore = (): [
×
40
  { status: Status; store: Store },
41
  () => void,
42
  (assets: DataCommon) => void,
43
] => {
44
  const [status, setStatus] = useState<Status>("waiting");
×
45
  const [store, setStore] = useState<Store>(makeStore());
×
46

47
  /**
48
   * Rebuilds the store from scratch
49
   *
50
   * @params {void}
51
   */
52
  const resetStore = () => {
×
53
    setStatus("loading");
×
54
    setStore(makeStore());
×
55
  };
56

57
  /**
58
   * Injects the Data Model into the store
59
   *
60
   * @param datacommon The Data Model to inject assets from
61
   */
62
  const populateStore = async (datacommon: DataCommon) => {
×
63
    if (
×
64
      !datacommon?.name ||
×
65
      !datacommon?.assets ||
66
      !datacommon?.assets["current-version"] ||
67
      !datacommon.configuration?.pdfConfig
68
    ) {
69
      setStatus("error");
×
70
      return;
×
71
    }
72

73
    setStatus("loading");
×
74

75
    const assets = buildAssetUrls(datacommon);
×
76
    const response = await getModelExploreData(assets.model, assets.props)?.catch((e) => {
×
77
      console.error(e);
×
78
      return null;
×
79
    });
80
    if (!response?.data || !response?.version) {
×
81
      setStatus("error");
×
82
      return;
×
83
    }
84

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

87
    store.dispatch({
×
88
      type: "REACT_FLOW_GRAPH_DICTIONARY",
89
      dictionary: response.data,
90
      pdfDownloadConfig: datacommon.configuration.pdfConfig,
91
      graphViewConfig,
92
    });
93

94
    store.dispatch({
×
95
      type: "RECEIVE_DICTIONARY",
96
      payload: {
97
        data: response.data,
98
        facetfilterConfig: {
99
          ...baseConfiguration,
100
          facetSearchData: datacommon.configuration.facetFilterSearchData,
101
          facetSectionVariables: datacommon.configuration.facetFilterSectionVariables,
102
          baseFilters: buildBaseFilterContainers(datacommon),
103
          filterSections: datacommon.configuration.facetFilterSearchData.map((s) => s?.datafield),
×
104
          filterOptions: buildFilterOptionsList(datacommon),
105
        },
106
        pageConfig: {
107
          title: datacommon.configuration.pageTitle,
108
          iconSrc: datacommon.configuration?.titleIconSrc,
109
        },
110
        readMeConfig: {
111
          readMeUrl: assets.readme,
112
          readMeTitle: datacommon.configuration?.readMeTitle || defaultReadMeTitle,
×
113
          allowDownload: false,
114
        },
115
        pdfDownloadConfig: datacommon.configuration.pdfConfig,
116
        loadingExampleConfig: {
117
          type: "static",
118
          url: assets.loading_file,
119
        },
120
        graphViewConfig,
121
      },
122
    });
123

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

129
    setStatus("success");
×
130
  };
131

132
  return [{ status, store }, resetStore, populateStore];
×
133
};
134

135
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