#2745: categories.js
projectforge-webapp/src/reducers/list/categories.js JavaScript module, projectforge-webapp/src/reducers/list/categories.js 206 lines · 195 code · 2 comments · 9 blank
Purpose: React webapp: categories.js. categories.js is part of the ProjectForge open-source project management application.
Source (first 100 lines)
import {
LIST_CALL_SUCCESS,
LIST_CATEGORY_RESET,
LIST_DISMISS_ERROR,
LIST_FAVORITES_RECEIVED,
LIST_FETCH_DATA_BEGIN,
LIST_FETCH_FAILURE,
LIST_FILTER_ADD,
LIST_FILTER_REMOVE,
LIST_FILTER_RESET,
LIST_FILTER_SEARCH_STRING_CHANGED,
LIST_FILTER_SET,
LIST_FILTER_SORT,
LIST_INITIAL_CALL_BEGIN,
LIST_SWITCH_CATEGORY, USER_LOGIN_BEGIN,
} from '../../actions';
const initialState = {};
const initialCategoryState = {
isFetching: false,
ui: { translations: {} },
data: {},
filter: {
entries: [],
extended: {},
},
filterFavorites: [],
variables: {},
};
const categoryReducer = (state = initialCategoryState, { type, payload } = {}) => {
switch (type) {
case LIST_DISMISS_ERROR:
return {
...state,
error: undefined,
};
case LIST_INITIAL_CALL_BEGIN:
return {
...state,
isFetching: true,
search: payload.search,
error: undefined,
};
case LIST_FETCH_DATA_BEGIN:
return {
...state,
isFetching: true,
error: undefined,
variables: {
...state.variables,
...payload.variables,
},
};
case LIST_CALL_SUCCESS:
return {
...state,
isFetching: false,
lastQueriedFilter: JSON.stringify(payload.response.filter || state.filter),
newlySwitched: false,
...payload.response,
};
case LIST_FETCH_FAILURE:
return {
...state,
isFetching: false,
error: payload.error,
};
case LIST_FILTER_ADD: {
const { filter } = state;
return {
...state,
filter: {
...filter,
entries: [
...filter.entries,
{
field: payload.fieldId,
isNew: true,
},
],
},
newlySwitched: false,
};
}
case LIST_FILTER_REMOVE: {
const { filter } = state;
return {
...state,
filter: {
...filter,
entries: filter.entries
.filter(({ field }) => field !== payload.fieldId),
},
newlySwitched: false,
};
}
case LIST_FILTER_RESET:
Git History
b3f6d19b3 WIP: address vcards import: image handling.
a5be6fdda Fix endless spinner after 2FA redirect on list pages
253b9f38b update some deps and fix eslint errors
bbd81edc3 es-lint, new js versions.
c192e80fc #86 reset redux states
b3f6d19b3
WIP: address vcards import: image handling.b3f6d19b3cf17aa380ae2ae5343534500e94e127
diff --git a/projectforge-webapp/src/reducers/list/categories.js b/projectforge-webapp/src/reducers/list/categories.js
index baf55ffb4..c9fcb8abc 100644
--- a/projectforge-webapp/src/reducers/list/categories.js
+++ b/projectforge-webapp/src/reducers/list/categories.js
@@ -174,6 +174,7 @@ const reducer = (state = initialState, action = {}) => {
case LIST_CATEGORY_RESET: {
// Remove category from state to force fresh initialCall on next load
const { category } = payload;
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
const { [category]: _removed, ...rest } = state;
return rest;
} a5be6fdda
Fix endless spinner after 2FA redirect on list pagesa5be6fdda4dd21f1b91eedc251245dc950dc29c2
diff --git a/projectforge-webapp/src/reducers/list/categories.js b/projectforge-webapp/src/reducers/list/categories.js
index f9df802ff..baf55ffb4 100644
--- a/projectforge-webapp/src/reducers/list/categories.js
+++ b/projectforge-webapp/src/reducers/list/categories.js
@@ -1,5 +1,6 @@
import {
LIST_CALL_SUCCESS,
+ LIST_CATEGORY_RESET,
LIST_DISMISS_ERROR,
LIST_FAVORITES_RECEIVED,
LIST_FETCH_DATA_BEGIN,
@@ -170,6 +171,12 @@ const reducer = (state = initialState, action = {}) => {
switch (type) {
case USER_LOGIN_BEGIN:
return initialState;
+ case LIST_CATEGORY_RESET: {
+ // Remove category from state to force fresh initialCall on next load
+ const { category } = payload;
+ const { [category]: _removed, ...rest } = state;
+ return rest;
+ }
case LIST_DISMISS_ERROR:
case LIST_INITIAL_CALL_BEGIN:
case LIST_FETCH_DATA_BEGIN: 253b9f38b
update some deps and fix eslint errors253b9f38b25268fbe922dbe9e4ddca94b13b98aa
diff --git a/projectforge-webapp/src/reducers/list/categories.js b/projectforge-webapp/src/reducers/list/categories.js
index 704327196..f9df802ff 100644
--- a/projectforge-webapp/src/reducers/list/categories.js
+++ b/projectforge-webapp/src/reducers/list/categories.js
@@ -27,7 +27,7 @@ const initialCategoryState = {
variables: {},
};
-const categoryReducer = (state = initialCategoryState, { type, payload }) => {
+const categoryReducer = (state = initialCategoryState, { type, payload } = {}) => {
switch (type) {
case LIST_DISMISS_ERROR:
return {
@@ -165,7 +165,7 @@ const categoryReducer = (state = initialCategoryState, { type, payload }) => {
}
};
-const reducer = (state = initialState, action) => {
+const reducer = (state = initialState, action = {}) => {
const { type, payload } = action;
switch (type) {
case USER_LOGIN_BEGIN: bbd81edc3
es-lint, new js versions.bbd81edc3f6b2fd975756421148651d4d75eaf33
diff --git a/projectforge-webapp/src/reducers/list/categories.js b/projectforge-webapp/src/reducers/list/categories.js
index fa7ab5389..704327196 100644
--- a/projectforge-webapp/src/reducers/list/categories.js
+++ b/projectforge-webapp/src/reducers/list/categories.js
@@ -118,7 +118,6 @@ const categoryReducer = (state = initialCategoryState, { type, payload }) => {
case LIST_FILTER_SET: {
const { filter } = state;
-
return {
...state,
filter: {
@@ -145,9 +144,9 @@ const categoryReducer = (state = initialCategoryState, { type, payload }) => {
sortProperties: [
payload.sortProperty,
...(filter.sortProperties || [])
- .filter(entry => entry.property !== payload.column)
+ .filter((entry) => entry.property !== payload.column)
.slice(0, 2),
- ].filter(entry => entry !== undefined),
+ ].filter((entry) => entry !== undefined),
},
};
} c192e80fc
#86 reset redux statesc192e80fc4213657f3e21b81a8d7fac8eb5bf340
diff --git a/projectforge-webapp/src/reducers/list/categories.js b/projectforge-webapp/src/reducers/list/categories.js
index efeafd451..fa7ab5389 100644
--- a/projectforge-webapp/src/reducers/list/categories.js
+++ b/projectforge-webapp/src/reducers/list/categories.js
@@ -11,7 +11,7 @@ import {
LIST_FILTER_SET,
LIST_FILTER_SORT,
LIST_INITIAL_CALL_BEGIN,
- LIST_SWITCH_CATEGORY,
+ LIST_SWITCH_CATEGORY, USER_LOGIN_BEGIN,
} from '../../actions';
const initialState = {};
@@ -169,6 +169,8 @@ const categoryReducer = (state = initialCategoryState, { type, payload }) => {
const reducer = (state = initialState, action) => {
const { type, payload } = action;
switch (type) {
+ case USER_LOGIN_BEGIN:
+ return initialState;
case LIST_DISMISS_ERROR:
case LIST_INITIAL_CALL_BEGIN:
case LIST_FETCH_DATA_BEGIN: