strapi-plugin-navigation 2.0.0-beta.2 → 2.0.0-beta.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.
@@ -8,7 +8,6 @@ import {
8
8
  LoadingIndicatorPage,
9
9
  useNotification,
10
10
  useAppInfos,
11
- useStrapiApp,
12
11
  } from "@strapi/helper-plugin";
13
12
  import DataManagerContext from "../../contexts/DataManagerContext";
14
13
  import getTrad from "../../utils/getTrad";
@@ -39,7 +38,7 @@ const DataManagerProvider = ({ children }) => {
39
38
  const toggleNotification = useNotification();
40
39
  const { autoReload } = useAppInfos();
41
40
  const { formatMessage } = useIntl();
42
-
41
+
43
42
  const {
44
43
  items,
45
44
  config,
@@ -54,10 +53,8 @@ const DataManagerProvider = ({ children }) => {
54
53
  isLoadingForAdditionalDataToBeSet,
55
54
  isLoadingForSubmit,
56
55
  error
57
- } = reducerState.toJS();
56
+ } = reducerState;
58
57
  const { pathname } = useLocation();
59
- const { getPlugin } = useStrapiApp();
60
- const { apis } = getPlugin(pluginId);
61
58
  const formatMessageRef = useRef();
62
59
  formatMessageRef.current = formatMessage;
63
60
 
@@ -164,7 +161,7 @@ const DataManagerProvider = ({ children }) => {
164
161
  }
165
162
  }, [autoReload]);
166
163
 
167
- const getContentTypeItems = async ({ modelUID, query }, plugin = "") => {
164
+ const getContentTypeItems = async ({ modelUID, query }) => {
168
165
  dispatch({
169
166
  type: GET_CONTENT_TYPE_ITEMS,
170
167
  });
@@ -174,7 +171,7 @@ const DataManagerProvider = ({ children }) => {
174
171
  if (query) {
175
172
  queryParams.append('_q', query);
176
173
  }
177
-
174
+
178
175
  const contentTypeItems = await request(`${url}?${queryParams.toString()}`, {
179
176
  method: "GET",
180
177
  signal,
@@ -229,7 +226,7 @@ const DataManagerProvider = ({ children }) => {
229
226
  dispatch({
230
227
  type: SUBMIT_NAVIGATION,
231
228
  });
232
-
229
+
233
230
  const nagivationId = payload.id ? `/${payload.id}` : "";
234
231
  const method = payload.id ? "PUT" : "POST";
235
232
  const navigation = await request(`/${pluginId}${nagivationId}`, {
@@ -309,4 +306,4 @@ DataManagerProvider.propTypes = {
309
306
  children: PropTypes.node.isRequired,
310
307
  };
311
308
 
312
- export default memo(DataManagerProvider);
309
+ export default memo(DataManagerProvider);
@@ -1,4 +1,5 @@
1
- import { fromJS } from "immutable";
1
+ import produce from 'immer';
2
+
2
3
  import {
3
4
  GET_LIST_DATA,
4
5
  GET_LIST_DATA_SUCCEEDED,
@@ -18,7 +19,7 @@ import {
18
19
  SUBMIT_NAVIGATION_ERROR,
19
20
  } from './actions';
20
21
 
21
- const initialState = fromJS({
22
+ const initialState = {
22
23
  items: [],
23
24
  activeItem: undefined,
24
25
  changedActiveItem: undefined,
@@ -31,106 +32,94 @@ const initialState = fromJS({
31
32
  isLoadingForAdditionalDataToBeSet: false,
32
33
  isLoadingForSubmit: false,
33
34
  error: undefined,
34
- });
35
+ };
35
36
 
36
- const reducer = (state, action) => {
37
+ const reducer = (state, action) => produce(state, draftState => {
37
38
  switch (action.type) {
38
39
  case GET_CONFIG: {
39
- return state
40
- .update("isLoadingForAdditionalDataToBeSet", () => true)
41
- .removeIn("config");
40
+ draftState.isLoadingForDetailsDataToBeSet = true;
41
+ draftState.config = {};
42
+ break;
42
43
  }
43
44
  case GET_CONFIG_SUCCEEDED: {
44
- return state
45
- .update("isLoadingForAdditionalDataToBeSet", () => false)
46
- .update("config", () => fromJS(action.config));
45
+ draftState.isLoadingForDetailsDataToBeSet = false;
46
+ draftState.config = action.config;
47
+ break;
47
48
  }
48
49
  case GET_LIST_DATA: {
49
- return state
50
- .removeIn("items")
51
- .update("isLoadingForDataToBeSet", () => true);
50
+ draftState.items = [];
51
+ draftState.isLoadingForDataToBeSet = true;
52
+ break;
52
53
  }
53
54
  case GET_LIST_DATA_SUCCEEDED: {
54
- return state
55
- .update("items", () => fromJS(action.items))
56
- .update("isLoading", () => false)
57
- .update("isLoadingForDataToBeSet", () => false);
55
+ draftState.items = action.items;
56
+ draftState.isLoading = false;
57
+ draftState.isLoadingForDataToBeSet = false;
58
+ break;
58
59
  }
59
60
  case GET_NAVIGATION_DATA: {
60
- return state
61
- .removeIn("activeItem")
62
- .removeIn("changedActiveItem")
63
- .update("isLoadingForDetailsDataToBeSet", () => true);
61
+ draftState.activeItem = undefined;
62
+ draftState.changedActiveItem = undefined;
63
+ draftState.isLoadingForDetailsDataToBeSet = true;
64
+ break;
64
65
  }
65
66
  case GET_NAVIGATION_DATA_SUCCEEDED: {
66
- const { activeItem = {} } = action;
67
- return state
68
- .update("activeItem", () => fromJS(activeItem))
69
- .update("changedActiveItem", () => fromJS(activeItem))
70
- .update("isLoadingForDetailsDataToBeSet", () => false);
67
+ const activeItem = action.activeItem || {};
68
+ draftState.activeItem = activeItem;
69
+ draftState.changedActiveItem = activeItem;
70
+ draftState.isLoadingForDetailsDataToBeSet = false;
71
+ break;
71
72
  }
72
73
  case CHANGE_NAVIGATION_DATA: {
73
- return state
74
- .update("changedActiveItem", () => action.changedActiveItem)
75
- .update("navigationPopupOpened", () =>
76
- action.forceClosePopups ? false : state.navigationPopupOpened,
77
- )
78
- .update("navigationItemPopupOpened", () =>
79
- action.forceClosePopups ? false : state.navigationItemPopupOpened,
80
- );
81
- }
82
- case RESET_NAVIGATION_DATA: {
83
- const { activeItem = {} } = action;
84
- return state.update("changedActiveItem", () => activeItem);
74
+ draftState.changedActiveItem = action.changedActiveItem;
75
+ draftState.navigationPopupOpened = action.forceClosePopups ? false : state.navigationPopupOpened;
76
+ draftState.navigationItemPopupOpened = action.forceClosePopups ? false : state.navigationItemPopupOpened;
77
+ break;
78
+ }
79
+ case RESET_NAVIGATION_DATA : {
80
+ draftState.changedActiveItem = action.activeItem || {};
81
+ break;
85
82
  }
86
83
  case GET_CONTENT_TYPE_ITEMS: {
87
- return state.update("isLoadingForAdditionalDataToBeSet", () => true);
84
+ draftState.isLoadingForAdditionalDataToBeSet = true;
85
+ break;
88
86
  }
89
87
  case GET_CONTENT_TYPE_ITEMS_SUCCEEDED: {
90
- return state
91
- .update("isLoadingForAdditionalDataToBeSet", () => false)
92
- .updateIn(["config", "contentTypeItems"], () =>
93
- fromJS(action.contentTypeItems),
94
- );
88
+ draftState.isLoadingForAdditionalDataToBeSet = false;
89
+ draftState.config.contentTypeItems = action.contentTypeItems;
90
+ break;
95
91
  }
96
92
  case CHANGE_NAVIGATION_POPUP_VISIBILITY: {
97
- return state.update(
98
- "navigationPopupOpened",
99
- () => action.navigationPopupOpened,
100
- );
93
+ draftState.navigationPopupOpened = action.navigationPopupOpened;
94
+ break;
101
95
  }
102
96
  case CHANGE_NAVIGATION_ITEM_POPUP_VISIBILITY: {
103
- return state.update(
104
- "navigationItemPopupOpened",
105
- () => action.navigationItemPopupOpened,
106
- );
97
+ draftState.navigationItemPopupOpened = action.navigationItemPopupOpened;
98
+ break;
107
99
  }
108
100
  case SUBMIT_NAVIGATION: {
109
- return state
110
- .update('isLoadingForSubmit', () => true)
111
- .update('error', () => undefined);
101
+ draftState.isLoadingForSubmit = true;
102
+ draftState.error = undefined;
103
+ break;
112
104
  }
113
105
  case SUBMIT_NAVIGATION_SUCCEEDED: {
114
- const { navigation = {} } = action;
115
- return state
116
- .update("activeItem", () => fromJS(navigation))
117
- .update("changedActiveItem", () => fromJS(navigation))
118
- .update(
119
- 'isLoadingForSubmit',
120
- () => false,
121
- );
106
+ draftState.activeItem = action.navigation || {};
107
+ draftState.changedActiveItem = action.navigation || {};
108
+ draftState.isLoadingForSubmit = false;
109
+ break;
122
110
  }
123
111
  case SUBMIT_NAVIGATION_ERROR: {
124
- return state
125
- .update('isLoadingForSubmit', () => false)
126
- .update('error', () => action.error);
112
+ draftState.isLoadingForSubmit = false;
113
+ draftState.error = action.error;
114
+ break;
127
115
  }
128
- case RELOAD_PLUGIN:
116
+ case RELOAD_PLUGIN: {
129
117
  return initialState;
118
+ }
130
119
  default:
131
- return state;
120
+ return draftState;
132
121
  }
133
- };
122
+ });
134
123
 
135
124
  export default reducer;
136
125
  export { initialState };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-plugin-navigation",
3
- "version": "2.0.0-beta.2",
3
+ "version": "2.0.0-beta.3",
4
4
  "description": "Strapi - Navigation plugin",
5
5
  "strapi": {
6
6
  "name": "navigation",