-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
CustomResolverRouter.js
113 lines (103 loc) · 3.05 KB
/
CustomResolverRouter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import React from 'react';
import { Route, IndexRedirect } from 'react-router';
import { rightContainerConnector } from '../../Common/Layout';
import globals from '../../../Globals';
import {
customResolverPageConnector,
landingConnector,
addConnector,
editConnector,
viewConnector,
} from '.';
import { fetchResolvers, FILTER_RESOLVER } from './customActions';
// Objective is to render list of custom resolvers on the
// left nav bar.
// Custom resolvers list is fetched from hdb_catalog/custom_resolver
// Whenever any operation happens like add resolver/delete resolver, this state should update automatically.
import { appPrefix } from './constants';
const filterItem = dispatch => {
return (dataList, searchVal) => {
// form new schema
const matchedTables = dataList.filter(data => {
return (
data.name
.toLowerCase()
.indexOf(searchVal ? searchVal.toLowerCase() : '') !== -1
);
});
dispatch({
type: FILTER_RESOLVER,
data: {
filtered: matchedTables,
searchQuery: searchVal,
},
});
};
};
const leftNavMapStateToProps = state => {
return {
...state,
dataList: [...state.customResolverData.listData.resolvers],
isError: state.customResolverData.listData.isError,
isRequesting: state.customResolverData.listData.isRequesting,
filtered: [...state.customResolverData.listData.filtered],
searchQuery: state.customResolverData.listData.searchQuery,
viewResolver: state.customResolverData.listData.viewResolver,
appPrefix,
};
};
const leftNavMapDispatchToProps = dispatch => {
return {
filterItem: filterItem(dispatch),
};
};
const fetchInitialData = ({ dispatch }) => {
return (nextState, replaceState, cb) => {
/*
const currState = getState();
const dataList = currState.customResolverData.listData.resolvers;
if (dataList.length) {
cb();
return;
}
*/
Promise.all([dispatch(fetchResolvers())]).then(
() => {
cb();
},
() => {
// alert('Could not load schema.');
replaceState(globals.urlPrefix);
cb();
}
);
};
};
const getCustomResolverRouter = (connect, store, composeOnEnterHooks) => {
return (
<Route
path="remote-schemas"
component={customResolverPageConnector(
connect,
leftNavMapStateToProps,
leftNavMapDispatchToProps
)}
onEnter={composeOnEnterHooks([fetchInitialData(store)])}
onChange={fetchInitialData(store)}
>
<IndexRedirect to="manage" />
<Route path="manage" component={rightContainerConnector(connect)}>
<IndexRedirect to="schemas" />
<Route path="schemas" component={landingConnector(connect)} />
<Route path="add" component={addConnector(connect)} />
<Route
path=":resolverName/details"
component={viewConnector(connect)}
/>
<Route path=":resolverName/modify" component={editConnector(connect)} />
</Route>
</Route>
);
};
export default getCustomResolverRouter;
export { appPrefix };