@truedat/dd 4.37.2 → 4.37.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.json +5 -5
- package/src/api.js +6 -7
- package/src/components/StructureSelectedFilters.js +12 -9
- package/src/components/StructureSelector.js +2 -2
- package/src/components/StructuresRoutes.js +2 -2
- package/src/components/UserSearchFiltersLoader.js +29 -0
- package/src/components/__tests__/UserSearchFiltersLoader.spec.js +27 -0
- package/src/components/__tests__/__snapshots__/StructureSelector.spec.js.snap +3 -1
- package/src/components/__tests__/__snapshots__/UserSearchFiltersLoader.spec.js.snap +3 -0
- package/src/messages/en.js +2 -2
- package/src/messages/es.js +2 -2
- package/src/reducers/__tests__/grantQuery.spec.js +0 -9
- package/src/reducers/__tests__/selectedUserSearchFilter.spec.js +62 -0
- package/src/reducers/__tests__/structureActiveFilters.spec.js +12 -12
- package/src/reducers/__tests__/structureQuery.spec.js +10 -10
- package/src/reducers/__tests__/structureUserFilters.spec.js +26 -26
- package/src/reducers/index.js +4 -4
- package/src/reducers/selectedUserSearchFilter.js +48 -0
- package/src/reducers/structureActiveFilters.js +4 -4
- package/src/reducers/structureQuery.js +2 -2
- package/src/reducers/{structureUserFilters.js → userSearchFilters.js} +11 -14
- package/src/routines.js +8 -12
- package/src/sagas/__tests__/deleteUserSearchFilter.spec.js +72 -0
- package/src/sagas/__tests__/fetchUserSearchFilters.spec.js +69 -0
- package/src/sagas/__tests__/saveUserSearchFilters.spec.js +78 -0
- package/src/sagas/deleteUserSearchFilter.js +31 -0
- package/src/sagas/fetchUserSearchFilters.js +26 -0
- package/src/sagas/index.js +9 -9
- package/src/sagas/saveUserSearchFilters.js +30 -0
- package/src/components/StructureUserFiltersLoader.js +0 -30
- package/src/components/__tests__/StructureUserFiltersLoader.spec.js +0 -27
- package/src/components/__tests__/__snapshots__/StructureUserFiltersLoader.spec.js.snap +0 -3
- package/src/reducers/__tests__/structureSelectedUserFilter.spec.js +0 -64
- package/src/reducers/structureSelectedUserFilter.js +0 -34
- package/src/sagas/__tests__/deleteStructureUserFilter.spec.js +0 -75
- package/src/sagas/__tests__/fetchStructureUserFilters.spec.js +0 -70
- package/src/sagas/__tests__/saveStructureUserFilters.spec.js +0 -73
- package/src/sagas/deleteStructureUserFilter.js +0 -34
- package/src/sagas/fetchStructureUserFilters.js +0 -29
- package/src/sagas/saveStructureUserFilters.js +0 -31
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clearRuleFilters,
|
|
3
|
+
resetRuleFilters,
|
|
4
|
+
clearImplementationFilters,
|
|
5
|
+
resetImplementationFilters,
|
|
6
|
+
} from "@truedat/dq/routines";
|
|
7
|
+
import {
|
|
8
|
+
applyUserSearchFilter,
|
|
9
|
+
clearUserSearchFilters,
|
|
10
|
+
removeStructureFilter,
|
|
11
|
+
resetStructureFilters,
|
|
12
|
+
} from "../routines";
|
|
13
|
+
|
|
14
|
+
/** @type {string} */
|
|
15
|
+
export const initialState = null;
|
|
16
|
+
|
|
17
|
+
export const selectedUserSearchFilter = (
|
|
18
|
+
state = initialState,
|
|
19
|
+
{ type, payload }
|
|
20
|
+
) => {
|
|
21
|
+
switch (type) {
|
|
22
|
+
case applyUserSearchFilter.TRIGGER:
|
|
23
|
+
const {
|
|
24
|
+
userFilter: { name: name },
|
|
25
|
+
} = payload;
|
|
26
|
+
if (state == name) {
|
|
27
|
+
return initialState;
|
|
28
|
+
} else {
|
|
29
|
+
return name;
|
|
30
|
+
}
|
|
31
|
+
case clearUserSearchFilters.TRIGGER:
|
|
32
|
+
return initialState;
|
|
33
|
+
case removeStructureFilter.TRIGGER:
|
|
34
|
+
return initialState;
|
|
35
|
+
case resetStructureFilters.TRIGGER:
|
|
36
|
+
return initialState;
|
|
37
|
+
case clearRuleFilters.TRIGGER:
|
|
38
|
+
return initialState;
|
|
39
|
+
case resetRuleFilters.TRIGGER:
|
|
40
|
+
return initialState;
|
|
41
|
+
case clearImplementationFilters.TRIGGER:
|
|
42
|
+
return initialState;
|
|
43
|
+
case resetImplementationFilters.TRIGGER:
|
|
44
|
+
return initialState;
|
|
45
|
+
default:
|
|
46
|
+
return state;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from "lodash/fp";
|
|
11
11
|
import {
|
|
12
12
|
addStructureFilter,
|
|
13
|
-
|
|
13
|
+
applyUserSearchFilter,
|
|
14
14
|
clearStructureFilters,
|
|
15
15
|
closeStructureFilter,
|
|
16
16
|
removeStructureFilter,
|
|
@@ -31,9 +31,9 @@ export const structureActiveFilters = (
|
|
|
31
31
|
const { filter } = payload;
|
|
32
32
|
return { ...state, [filter]: [] };
|
|
33
33
|
}
|
|
34
|
-
case
|
|
35
|
-
const { userFilter } = payload;
|
|
36
|
-
return prop("filters")(userFilter);
|
|
34
|
+
case applyUserSearchFilter.TRIGGER: {
|
|
35
|
+
const { userFilter, scope } = payload;
|
|
36
|
+
return scope === "data_structure" ? prop("filters")(userFilter) : state;
|
|
37
37
|
}
|
|
38
38
|
case closeStructureFilter.TRIGGER: {
|
|
39
39
|
const { filter } = payload;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
applyUserSearchFilter,
|
|
4
4
|
clearStructureFilters,
|
|
5
5
|
removeStructureFilter,
|
|
6
6
|
searchStructures,
|
|
@@ -31,7 +31,7 @@ const structureQuery = (state = initialState, { type, payload }) => {
|
|
|
31
31
|
const page = defaultPage;
|
|
32
32
|
return { ...state, page };
|
|
33
33
|
}
|
|
34
|
-
case
|
|
34
|
+
case applyUserSearchFilter.TRIGGER: {
|
|
35
35
|
const page = defaultPage;
|
|
36
36
|
return { ...state, page };
|
|
37
37
|
}
|
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
2
|
import { accentInsensitivePathOrder } from "@truedat/core/services/sort";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
fetchUserSearchFilters,
|
|
5
|
+
clearUserSearchFilters,
|
|
6
|
+
deleteUserSearchFilter,
|
|
7
|
+
saveUserSearchFilters,
|
|
8
8
|
} from "../routines";
|
|
9
9
|
|
|
10
10
|
export const initialState = [];
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
state = initialState,
|
|
14
|
-
{ type, payload, meta }
|
|
15
|
-
) => {
|
|
12
|
+
const userSearchFilters = (state = initialState, { type, payload, meta }) => {
|
|
16
13
|
switch (type) {
|
|
17
|
-
case
|
|
14
|
+
case clearUserSearchFilters.TRIGGER:
|
|
18
15
|
return initialState;
|
|
19
|
-
case
|
|
16
|
+
case fetchUserSearchFilters.SUCCESS: {
|
|
20
17
|
const userFilters = _.propOr([], "data")(payload);
|
|
21
18
|
return _.sortBy(accentInsensitivePathOrder("name"))(userFilters);
|
|
22
19
|
}
|
|
23
|
-
case
|
|
20
|
+
case fetchUserSearchFilters.FAILURE:
|
|
24
21
|
return initialState;
|
|
25
|
-
case
|
|
22
|
+
case saveUserSearchFilters.SUCCESS:
|
|
26
23
|
const userFilter = _.propOr({}, "data")(payload);
|
|
27
24
|
return _.flow(
|
|
28
25
|
_.concat([userFilter]),
|
|
29
26
|
_.sortBy(accentInsensitivePathOrder("name"))
|
|
30
27
|
)(state);
|
|
31
|
-
case
|
|
28
|
+
case deleteUserSearchFilter.SUCCESS:
|
|
32
29
|
const { id } = meta;
|
|
33
30
|
return _.reject(_.propEq("id", id))(state);
|
|
34
31
|
default:
|
|
@@ -36,4 +33,4 @@ const structureUserFilters = (
|
|
|
36
33
|
}
|
|
37
34
|
};
|
|
38
35
|
|
|
39
|
-
export {
|
|
36
|
+
export { userSearchFilters };
|
package/src/routines.js
CHANGED
|
@@ -9,9 +9,7 @@ export const applyGrantDateFilter = createRoutine("APPLY_GRANT_DATE_FILTER");
|
|
|
9
9
|
export const applyStructureDateFilter = createRoutine(
|
|
10
10
|
"APPLY_STRUCTURE_DATE_FILTER"
|
|
11
11
|
);
|
|
12
|
-
export const
|
|
13
|
-
"APPLY_STRUCTURE_USER_FILTER"
|
|
14
|
-
);
|
|
12
|
+
export const applyUserSearchFilter = createRoutine("APPLY_USER_SEARCH_FILTER");
|
|
15
13
|
export const bulkUpdateStructures = createRoutine("BULK_UPDATE_STRUCTURES");
|
|
16
14
|
export const cancelPoll = createRoutine("CANCEL_POLL");
|
|
17
15
|
export const clearGrantFilters = createRoutine("CLEAR_GRANT_FILTERS");
|
|
@@ -32,8 +30,8 @@ export const clearStructureTag = createRoutine("CLEAR_STRUCTURE_TAG");
|
|
|
32
30
|
export const clearStructureTags = createRoutine("CLEAR_STRUCTURE_TAGS");
|
|
33
31
|
export const clearStructureType = createRoutine("CLEAR_STRUCTURE_TYPE");
|
|
34
32
|
export const clearStructureTypes = createRoutine("CLEAR_STRUCTURE_TYPES");
|
|
35
|
-
export const
|
|
36
|
-
"
|
|
33
|
+
export const clearUserSearchFilters = createRoutine(
|
|
34
|
+
"CLEAR_USER_SEARCH_FILTERS"
|
|
37
35
|
);
|
|
38
36
|
export const clearStructures = createRoutine("CLEAR_STRUCTURES");
|
|
39
37
|
export const clearStructuresSort = createRoutine("CLEAR_STRUCTURES_SORT");
|
|
@@ -53,8 +51,8 @@ export const deleteLinkStructureTag = createRoutine(
|
|
|
53
51
|
"DELETE_LINK_STRUCTURE_TAG"
|
|
54
52
|
);
|
|
55
53
|
export const deleteStructureTag = createRoutine("DELETE_STRUCTURE_TAG");
|
|
56
|
-
export const
|
|
57
|
-
"
|
|
54
|
+
export const deleteUserSearchFilter = createRoutine(
|
|
55
|
+
"DELETE_USER_SEARCH_FILTER"
|
|
58
56
|
);
|
|
59
57
|
export const doStructureNoteAction = createRoutine("DO_STRUCTURE_NOTE_ACTION");
|
|
60
58
|
export const downloadCsvGraph = createRoutine("DOWNLOAD_CSV_GRAPH");
|
|
@@ -84,8 +82,8 @@ export const fetchStructureTag = createRoutine("FETCH_STRUCTURE_TAG");
|
|
|
84
82
|
export const fetchStructureTags = createRoutine("FETCH_STRUCTURE_TAGS");
|
|
85
83
|
export const fetchStructureType = createRoutine("FETCH_STRUCTURE_TYPE");
|
|
86
84
|
export const fetchStructureTypes = createRoutine("FETCH_STRUCTURE_TYPES");
|
|
87
|
-
export const
|
|
88
|
-
"
|
|
85
|
+
export const fetchUserSearchFilters = createRoutine(
|
|
86
|
+
"FETCH_USER_SEARCH_FILTERS"
|
|
89
87
|
);
|
|
90
88
|
export const fetchStructures = createRoutine("FETCH_STRUCTURES");
|
|
91
89
|
export const fetchSystem = createRoutine("FETCH_SYSTEM");
|
|
@@ -106,9 +104,7 @@ export const removeStructureSelectedFilter = createRoutine(
|
|
|
106
104
|
);
|
|
107
105
|
export const resetGrantFilters = createRoutine("RESET_GRANT_FILTERS");
|
|
108
106
|
export const resetStructureFilters = createRoutine("RESET_STRUCTURE_FILTERS");
|
|
109
|
-
export const
|
|
110
|
-
"SAVE_STRUCTURE_USER_FILTERS"
|
|
111
|
-
);
|
|
107
|
+
export const saveUserSearchFilters = createRoutine("SAVE_USER_SEARCH_FILTERS");
|
|
112
108
|
export const searchGrants = createRoutine("SEARCH_GRANTS");
|
|
113
109
|
export const searchStructures = createRoutine("SEARCH_STRUCTURES");
|
|
114
110
|
export const selectGrantPage = createRoutine("SELECT_GRANT_PAGE");
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { compile } from "path-to-regexp";
|
|
2
|
+
import { testSaga } from "redux-saga-test-plan";
|
|
3
|
+
import { apiJsonDelete, JSON_OPTS } from "@truedat/core/services/api";
|
|
4
|
+
import {
|
|
5
|
+
deleteUserSearchFilterSaga,
|
|
6
|
+
deleteUserSearchFilterRequestSaga,
|
|
7
|
+
} from "../deleteUserSearchFilter";
|
|
8
|
+
import { deleteUserSearchFilter } from "../../routines";
|
|
9
|
+
import { API_USER_SEARCH_FILTER } from "../../api";
|
|
10
|
+
|
|
11
|
+
describe("sagas: deleteUserSearchFilterRequestSaga", () => {
|
|
12
|
+
it("should invoke deleteUserSearchFilterSaga on deleteUserSearchFilter.TRIGGER", () => {
|
|
13
|
+
expect(() => {
|
|
14
|
+
testSaga(deleteUserSearchFilterRequestSaga)
|
|
15
|
+
.next()
|
|
16
|
+
.takeLatest(deleteUserSearchFilter.TRIGGER, deleteUserSearchFilterSaga)
|
|
17
|
+
.finish()
|
|
18
|
+
.isDone();
|
|
19
|
+
}).not.toThrow();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should throw exception if an unhandled action is received", () => {
|
|
23
|
+
expect(() => {
|
|
24
|
+
testSaga(deleteUserSearchFilterRequestSaga)
|
|
25
|
+
.next()
|
|
26
|
+
.takeLatest("FOO", deleteUserSearchFilterRequestSaga);
|
|
27
|
+
}).toThrow();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("sagas: deleteUserSearchFilterSaga", () => {
|
|
32
|
+
const payload = { id: 1 };
|
|
33
|
+
const { id } = payload;
|
|
34
|
+
const url = compile(API_USER_SEARCH_FILTER)({ id });
|
|
35
|
+
const meta = { id };
|
|
36
|
+
|
|
37
|
+
it("should put a success action when a response is returned", () => {
|
|
38
|
+
expect(() => {
|
|
39
|
+
testSaga(deleteUserSearchFilterSaga, { payload })
|
|
40
|
+
.next()
|
|
41
|
+
.put({ meta, ...deleteUserSearchFilter.request() })
|
|
42
|
+
.next()
|
|
43
|
+
.call(apiJsonDelete, url, JSON_OPTS)
|
|
44
|
+
.next({ data: payload })
|
|
45
|
+
.put({ meta, ...deleteUserSearchFilter.success(payload) })
|
|
46
|
+
.next()
|
|
47
|
+
.put(deleteUserSearchFilter.fulfill())
|
|
48
|
+
.next()
|
|
49
|
+
.isDone();
|
|
50
|
+
}).not.toThrow();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should put a failure action when the call returns an error", () => {
|
|
54
|
+
const message = "Request failed";
|
|
55
|
+
const error = { message };
|
|
56
|
+
const meta = { id: 1 };
|
|
57
|
+
|
|
58
|
+
expect(() => {
|
|
59
|
+
testSaga(deleteUserSearchFilterSaga, { payload })
|
|
60
|
+
.next()
|
|
61
|
+
.put({ meta, ...deleteUserSearchFilter.request() })
|
|
62
|
+
.next()
|
|
63
|
+
.call(apiJsonDelete, url, JSON_OPTS)
|
|
64
|
+
.throw(error)
|
|
65
|
+
.put(deleteUserSearchFilter.failure(message))
|
|
66
|
+
.next()
|
|
67
|
+
.put(deleteUserSearchFilter.fulfill())
|
|
68
|
+
.next()
|
|
69
|
+
.isDone();
|
|
70
|
+
}).not.toThrow();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { testSaga } from "redux-saga-test-plan";
|
|
2
|
+
import { apiJson, JSON_OPTS } from "@truedat/core/services/api";
|
|
3
|
+
import {
|
|
4
|
+
fetchUserSearchFiltersRequestSaga,
|
|
5
|
+
fetchUserSearchFiltersSaga,
|
|
6
|
+
} from "../fetchUserSearchFilters";
|
|
7
|
+
import { fetchUserSearchFilters } from "../../routines";
|
|
8
|
+
import { API_GET_USER_SEARCH_FILTERS } from "../../api";
|
|
9
|
+
|
|
10
|
+
describe("sagas: fetchUserSearchFiltersRequestSaga", () => {
|
|
11
|
+
it("should invoke fetchUserSearchFiltersSaga on fetchUserSearchFilters.TRIGGER", () => {
|
|
12
|
+
expect(() => {
|
|
13
|
+
testSaga(fetchUserSearchFiltersRequestSaga)
|
|
14
|
+
.next()
|
|
15
|
+
.takeLatest(fetchUserSearchFilters.TRIGGER, fetchUserSearchFiltersSaga)
|
|
16
|
+
.finish()
|
|
17
|
+
.isDone();
|
|
18
|
+
}).not.toThrow();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should throw exception if an unhandled action is received", () => {
|
|
22
|
+
expect(() => {
|
|
23
|
+
testSaga(fetchUserSearchFiltersRequestSaga)
|
|
24
|
+
.next()
|
|
25
|
+
.takeLatest("FOO", fetchUserSearchFiltersRequestSaga);
|
|
26
|
+
}).toThrow();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("sagas: fetchUserSearchFiltersSaga", () => {
|
|
31
|
+
const data = [{ id: 1, name: "a" }];
|
|
32
|
+
const payload = "test_scope";
|
|
33
|
+
const url = `${API_GET_USER_SEARCH_FILTERS}?scope=${payload}`;
|
|
34
|
+
|
|
35
|
+
it("should put a success action when a response is returned", () => {
|
|
36
|
+
expect(() => {
|
|
37
|
+
testSaga(fetchUserSearchFiltersSaga, { payload })
|
|
38
|
+
.next()
|
|
39
|
+
.put(fetchUserSearchFilters.request())
|
|
40
|
+
.next()
|
|
41
|
+
.call(apiJson, url, JSON_OPTS)
|
|
42
|
+
.next({ data })
|
|
43
|
+
.put(fetchUserSearchFilters.success(data))
|
|
44
|
+
.next()
|
|
45
|
+
.put(fetchUserSearchFilters.fulfill())
|
|
46
|
+
.next()
|
|
47
|
+
.isDone();
|
|
48
|
+
}).not.toThrow();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("should put a failure action when the call returns an error", () => {
|
|
52
|
+
const message = "Request failed";
|
|
53
|
+
const error = { message };
|
|
54
|
+
|
|
55
|
+
expect(() => {
|
|
56
|
+
testSaga(fetchUserSearchFiltersSaga, { payload })
|
|
57
|
+
.next()
|
|
58
|
+
.put(fetchUserSearchFilters.request())
|
|
59
|
+
.next()
|
|
60
|
+
.call(apiJson, url, JSON_OPTS)
|
|
61
|
+
.throw(error)
|
|
62
|
+
.put(fetchUserSearchFilters.failure(message))
|
|
63
|
+
.next()
|
|
64
|
+
.put(fetchUserSearchFilters.fulfill())
|
|
65
|
+
.next()
|
|
66
|
+
.isDone();
|
|
67
|
+
}).not.toThrow();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { testSaga } from "redux-saga-test-plan";
|
|
2
|
+
import { apiJsonPost, JSON_OPTS } from "@truedat/core/services/api";
|
|
3
|
+
import {
|
|
4
|
+
saveUserSearchFiltersRequestSaga,
|
|
5
|
+
saveUserSearchFiltersSaga,
|
|
6
|
+
} from "../saveUserSearchFilters";
|
|
7
|
+
import { saveUserSearchFilters } from "../../routines";
|
|
8
|
+
import { API_USER_SEARCH_FILTERS } from "../../api";
|
|
9
|
+
|
|
10
|
+
describe("sagas: saveStructureFiltersRequestSaga", () => {
|
|
11
|
+
it("should invoke saveStructureFiltersSaga on saveStructureFilters.TRIGGER", () => {
|
|
12
|
+
expect(() => {
|
|
13
|
+
testSaga(saveUserSearchFiltersRequestSaga)
|
|
14
|
+
.next()
|
|
15
|
+
.takeLatest(saveUserSearchFilters.TRIGGER, saveUserSearchFiltersSaga)
|
|
16
|
+
.finish()
|
|
17
|
+
.isDone();
|
|
18
|
+
}).not.toThrow();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should throw exception if an unhandled action is received", () => {
|
|
22
|
+
expect(() => {
|
|
23
|
+
testSaga(saveUserSearchFiltersRequestSaga)
|
|
24
|
+
.next()
|
|
25
|
+
.takeLatest("FOO", saveUserSearchFiltersRequestSaga);
|
|
26
|
+
}).toThrow();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("sagas: saveStructureFiltersSaga", () => {
|
|
31
|
+
const data = { user_search_filter: { id: 1, name: "a" } };
|
|
32
|
+
const payload = {
|
|
33
|
+
filterName: "a",
|
|
34
|
+
filters: { country: ["A"] },
|
|
35
|
+
scope: "data_structure",
|
|
36
|
+
};
|
|
37
|
+
const requestData = {
|
|
38
|
+
user_search_filter: {
|
|
39
|
+
name: "a",
|
|
40
|
+
filters: { country: ["A"] },
|
|
41
|
+
scope: "data_structure",
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
it("should put a success action when a response is returned", () => {
|
|
45
|
+
expect(() => {
|
|
46
|
+
testSaga(saveUserSearchFiltersSaga, { payload })
|
|
47
|
+
.next()
|
|
48
|
+
.put(saveUserSearchFilters.request())
|
|
49
|
+
.next()
|
|
50
|
+
.call(apiJsonPost, API_USER_SEARCH_FILTERS, requestData, JSON_OPTS)
|
|
51
|
+
.next({ data })
|
|
52
|
+
.put(saveUserSearchFilters.success(data))
|
|
53
|
+
.next()
|
|
54
|
+
.put(saveUserSearchFilters.fulfill())
|
|
55
|
+
.next()
|
|
56
|
+
.isDone();
|
|
57
|
+
}).not.toThrow();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should put a failure action when the call returns an error", () => {
|
|
61
|
+
const message = "Request failed";
|
|
62
|
+
const error = { message };
|
|
63
|
+
|
|
64
|
+
expect(() => {
|
|
65
|
+
testSaga(saveUserSearchFiltersSaga, { payload })
|
|
66
|
+
.next()
|
|
67
|
+
.put(saveUserSearchFilters.request())
|
|
68
|
+
.next()
|
|
69
|
+
.call(apiJsonPost, API_USER_SEARCH_FILTERS, requestData, JSON_OPTS)
|
|
70
|
+
.throw(error)
|
|
71
|
+
.put(saveUserSearchFilters.failure(message))
|
|
72
|
+
.next()
|
|
73
|
+
.put(saveUserSearchFilters.fulfill())
|
|
74
|
+
.next()
|
|
75
|
+
.isDone();
|
|
76
|
+
}).not.toThrow();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { compile } from "path-to-regexp";
|
|
2
|
+
import { call, put, takeLatest } from "redux-saga/effects";
|
|
3
|
+
import { apiJsonDelete, JSON_OPTS } from "@truedat/core/services/api";
|
|
4
|
+
import { deleteUserSearchFilter } from "../routines";
|
|
5
|
+
import { API_USER_SEARCH_FILTER } from "../api";
|
|
6
|
+
|
|
7
|
+
const toApiPath = compile(API_USER_SEARCH_FILTER);
|
|
8
|
+
|
|
9
|
+
export function* deleteUserSearchFilterSaga({ payload }) {
|
|
10
|
+
try {
|
|
11
|
+
const url = toApiPath(payload);
|
|
12
|
+
const { id } = payload;
|
|
13
|
+
const meta = { id };
|
|
14
|
+
yield put({ meta, ...deleteUserSearchFilter.request() });
|
|
15
|
+
const { data } = yield call(apiJsonDelete, url, JSON_OPTS);
|
|
16
|
+
yield put({ meta, ...deleteUserSearchFilter.success(data) });
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (error.response) {
|
|
19
|
+
const { status, data } = error.response;
|
|
20
|
+
yield put(deleteUserSearchFilter.failure({ status, data }));
|
|
21
|
+
} else {
|
|
22
|
+
yield put(deleteUserSearchFilter.failure(error.message));
|
|
23
|
+
}
|
|
24
|
+
} finally {
|
|
25
|
+
yield put(deleteUserSearchFilter.fulfill());
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function* deleteUserSearchFilterRequestSaga() {
|
|
30
|
+
yield takeLatest(deleteUserSearchFilter.TRIGGER, deleteUserSearchFilterSaga);
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { call, put, takeLatest } from "redux-saga/effects";
|
|
2
|
+
import { apiJson, JSON_OPTS } from "@truedat/core/services/api";
|
|
3
|
+
import { fetchUserSearchFilters } from "../routines";
|
|
4
|
+
import { API_GET_USER_SEARCH_FILTERS } from "../api";
|
|
5
|
+
|
|
6
|
+
export function* fetchUserSearchFiltersSaga({ payload }) {
|
|
7
|
+
try {
|
|
8
|
+
const url = `${API_GET_USER_SEARCH_FILTERS}?scope=${payload}`;
|
|
9
|
+
yield put(fetchUserSearchFilters.request());
|
|
10
|
+
const { data } = yield call(apiJson, url, JSON_OPTS);
|
|
11
|
+
yield put(fetchUserSearchFilters.success(data));
|
|
12
|
+
} catch (error) {
|
|
13
|
+
if (error.response) {
|
|
14
|
+
const { status, data } = error.response;
|
|
15
|
+
yield put(fetchUserSearchFilters.failure({ status, data }));
|
|
16
|
+
} else {
|
|
17
|
+
yield put(fetchUserSearchFilters.failure(error.message));
|
|
18
|
+
}
|
|
19
|
+
} finally {
|
|
20
|
+
yield put(fetchUserSearchFilters.fulfill());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function* fetchUserSearchFiltersRequestSaga() {
|
|
25
|
+
yield takeLatest(fetchUserSearchFilters.TRIGGER, fetchUserSearchFiltersSaga);
|
|
26
|
+
}
|
package/src/sagas/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { deleteStructureRequestSaga } from "./deleteStructure";
|
|
|
9
9
|
import { createSystemRequestSaga } from "./createSystem";
|
|
10
10
|
import { deleteLinkStructureTagRequestSaga } from "./deleteLinkStructureTag";
|
|
11
11
|
import { deleteStructureTagRequestSaga } from "./deleteStructureTag";
|
|
12
|
-
import {
|
|
12
|
+
import { deleteUserSearchFilterRequestSaga } from "./deleteUserSearchFilter";
|
|
13
13
|
import { doStructureNoteActionRequestSaga } from "./doStructureNoteAction";
|
|
14
14
|
import { downloadCsvGraphRequestSaga } from "./downloadCsvGraph";
|
|
15
15
|
import { downloadGrantsRequestSaga } from "./downloadGrants";
|
|
@@ -33,14 +33,14 @@ import { fetchStructureTagRequestSaga } from "./fetchStructureTag";
|
|
|
33
33
|
import { fetchStructureTagsRequestSaga } from "./fetchStructureTags";
|
|
34
34
|
import { fetchStructureTypeRequestSaga } from "./fetchStructureType";
|
|
35
35
|
import { fetchStructureTypesRequestSaga } from "./fetchStructureTypes";
|
|
36
|
-
import {
|
|
36
|
+
import { fetchUserSearchFiltersRequestSaga } from "./fetchUserSearchFilters";
|
|
37
37
|
import { fetchStructuresRequestSaga } from "./fetchStructures";
|
|
38
38
|
import { fetchSystemRequestSaga } from "./fetchSystem";
|
|
39
39
|
import { fetchSystemStructuresRequestSaga } from "./fetchSystemStructures";
|
|
40
40
|
import { fetchSystemsRequestSaga } from "./fetchSystems";
|
|
41
41
|
import { fetchUnitDomainsRequestSaga } from "./fetchUnitDomains";
|
|
42
42
|
import { linkStructureTagRequestSaga } from "./linkStructureTag";
|
|
43
|
-
import {
|
|
43
|
+
import { saveUserSearchFiltersRequestSaga } from "./saveUserSearchFilters";
|
|
44
44
|
import { updateStructureRequestSaga } from "./updateStructure";
|
|
45
45
|
import { updateStructureTagRequestSaga } from "./updateStructureTag";
|
|
46
46
|
import { updateStructureTypeRequestSaga } from "./updateStructureType";
|
|
@@ -60,7 +60,7 @@ export {
|
|
|
60
60
|
createSystemRequestSaga,
|
|
61
61
|
deleteLinkStructureTagRequestSaga,
|
|
62
62
|
deleteStructureTagRequestSaga,
|
|
63
|
-
|
|
63
|
+
deleteUserSearchFilterRequestSaga,
|
|
64
64
|
doStructureNoteActionRequestSaga,
|
|
65
65
|
downloadCsvGraphRequestSaga,
|
|
66
66
|
downloadGrantsRequestSaga,
|
|
@@ -84,14 +84,14 @@ export {
|
|
|
84
84
|
fetchStructureTagsRequestSaga,
|
|
85
85
|
fetchStructureTypeRequestSaga,
|
|
86
86
|
fetchStructureTypesRequestSaga,
|
|
87
|
-
|
|
87
|
+
fetchUserSearchFiltersRequestSaga,
|
|
88
88
|
fetchStructuresRequestSaga,
|
|
89
89
|
fetchSystemRequestSaga,
|
|
90
90
|
fetchSystemStructuresRequestSaga,
|
|
91
91
|
fetchSystemsRequestSaga,
|
|
92
92
|
fetchUnitDomainsRequestSaga,
|
|
93
93
|
linkStructureTagRequestSaga,
|
|
94
|
-
|
|
94
|
+
saveUserSearchFiltersRequestSaga,
|
|
95
95
|
updateStructureRequestSaga,
|
|
96
96
|
updateStructureTagRequestSaga,
|
|
97
97
|
updateStructureTypeRequestSaga,
|
|
@@ -112,7 +112,7 @@ export default [
|
|
|
112
112
|
createSystemRequestSaga(),
|
|
113
113
|
deleteLinkStructureTagRequestSaga(),
|
|
114
114
|
deleteStructureTagRequestSaga(),
|
|
115
|
-
|
|
115
|
+
deleteUserSearchFilterRequestSaga(),
|
|
116
116
|
doStructureNoteActionRequestSaga(),
|
|
117
117
|
downloadCsvGraphRequestSaga(),
|
|
118
118
|
downloadGrantsRequestSaga(),
|
|
@@ -136,14 +136,14 @@ export default [
|
|
|
136
136
|
fetchStructureTagsRequestSaga(),
|
|
137
137
|
fetchStructureTypeRequestSaga(),
|
|
138
138
|
fetchStructureTypesRequestSaga(),
|
|
139
|
-
|
|
139
|
+
fetchUserSearchFiltersRequestSaga(),
|
|
140
140
|
fetchStructuresRequestSaga(),
|
|
141
141
|
fetchSystemRequestSaga(),
|
|
142
142
|
fetchSystemStructuresRequestSaga(),
|
|
143
143
|
fetchSystemsRequestSaga(),
|
|
144
144
|
fetchUnitDomainsRequestSaga(),
|
|
145
145
|
linkStructureTagRequestSaga(),
|
|
146
|
-
|
|
146
|
+
saveUserSearchFiltersRequestSaga(),
|
|
147
147
|
updateStructureRequestSaga(),
|
|
148
148
|
updateStructureTagRequestSaga(),
|
|
149
149
|
updateStructureTypeRequestSaga(),
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { call, put, takeLatest } from "redux-saga/effects";
|
|
2
|
+
import { apiJsonPost, JSON_OPTS } from "@truedat/core/services/api";
|
|
3
|
+
import { saveUserSearchFilters } from "../routines";
|
|
4
|
+
import { API_USER_SEARCH_FILTERS } from "../api";
|
|
5
|
+
|
|
6
|
+
export function* saveUserSearchFiltersSaga({ payload }) {
|
|
7
|
+
try {
|
|
8
|
+
const { filterName, filters, scope } = payload;
|
|
9
|
+
const url = API_USER_SEARCH_FILTERS;
|
|
10
|
+
const requestData = {
|
|
11
|
+
user_search_filter: { name: filterName, filters, scope },
|
|
12
|
+
};
|
|
13
|
+
yield put({ ...saveUserSearchFilters.request() });
|
|
14
|
+
const { data } = yield call(apiJsonPost, url, requestData, JSON_OPTS);
|
|
15
|
+
yield put({ ...saveUserSearchFilters.success(data) });
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (error.response) {
|
|
18
|
+
const { status, data } = error.response;
|
|
19
|
+
yield put(saveUserSearchFilters.failure({ status, data }));
|
|
20
|
+
} else {
|
|
21
|
+
yield put(saveUserSearchFilters.failure(error.message));
|
|
22
|
+
}
|
|
23
|
+
} finally {
|
|
24
|
+
yield put(saveUserSearchFilters.fulfill());
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function* saveUserSearchFiltersRequestSaga() {
|
|
29
|
+
yield takeLatest(saveUserSearchFilters.TRIGGER, saveUserSearchFiltersSaga);
|
|
30
|
+
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
import PropTypes from "prop-types";
|
|
3
|
-
import { connect } from "react-redux";
|
|
4
|
-
import {
|
|
5
|
-
clearStructureUserFilters,
|
|
6
|
-
fetchStructureUserFilters,
|
|
7
|
-
} from "../routines";
|
|
8
|
-
|
|
9
|
-
export const StructureUserFiltersLoader = ({
|
|
10
|
-
clearStructureUserFilters,
|
|
11
|
-
fetchStructureUserFilters,
|
|
12
|
-
}) => {
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
fetchStructureUserFilters();
|
|
15
|
-
return () => {
|
|
16
|
-
clearStructureUserFilters();
|
|
17
|
-
};
|
|
18
|
-
}, [clearStructureUserFilters, fetchStructureUserFilters]);
|
|
19
|
-
return null;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
StructureUserFiltersLoader.propTypes = {
|
|
23
|
-
clearStructureUserFilters: PropTypes.func,
|
|
24
|
-
fetchStructureUserFilters: PropTypes.func,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export default connect(null, {
|
|
28
|
-
clearStructureUserFilters,
|
|
29
|
-
fetchStructureUserFilters,
|
|
30
|
-
})(StructureUserFiltersLoader);
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { shallow, mount } from "enzyme";
|
|
3
|
-
import { StructureUserFiltersLoader } from "../StructureUserFiltersLoader";
|
|
4
|
-
|
|
5
|
-
describe("<StructureUserFiltersLoader />", () => {
|
|
6
|
-
const fetchStructureUserFilters = jest.fn();
|
|
7
|
-
const clearStructureUserFilters = jest.fn();
|
|
8
|
-
|
|
9
|
-
it("matches the latest snapshot", () => {
|
|
10
|
-
const props = { clearStructureUserFilters, fetchStructureUserFilters };
|
|
11
|
-
const wrapper = shallow(<StructureUserFiltersLoader {...props} />);
|
|
12
|
-
expect(wrapper).toMatchSnapshot();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it("calls fetchStructureUserFilters when component mounts, clearStructureUserFilters when component unmounts", () => {
|
|
16
|
-
const fetchStructureUserFilters = jest.fn();
|
|
17
|
-
const clearStructureUserFilters = jest.fn();
|
|
18
|
-
|
|
19
|
-
const props = { fetchStructureUserFilters, clearStructureUserFilters };
|
|
20
|
-
const wrapper = mount(<StructureUserFiltersLoader {...props} />);
|
|
21
|
-
expect(clearStructureUserFilters.mock.calls.length).toBe(0);
|
|
22
|
-
expect(fetchStructureUserFilters.mock.calls.length).toBe(1);
|
|
23
|
-
wrapper.unmount();
|
|
24
|
-
expect(clearStructureUserFilters.mock.calls.length).toBe(1);
|
|
25
|
-
expect(fetchStructureUserFilters.mock.calls.length).toBe(1);
|
|
26
|
-
});
|
|
27
|
-
});
|