#2478: index.js
projectforge-webapp/src/actions/list/index.js JavaScript module, projectforge-webapp/src/actions/list/index.js 208 lines · 174 code · 9 comments · 25 blank
Purpose: React webapp: index.js. index.js is part of the ProjectForge open-source project management application.
Source (first 100 lines)
import history from '../../utilities/history';
import { fetchJsonPost, getObjectFromQuery, getServiceURL, handleHTTPErrors } from '../../utilities/rest';
export const LIST_DISMISS_ERROR = 'LIST_DISMISS_ERROR';
export const LIST_SWITCH_CATEGORY = 'LIST_SWITCH_CATEGORY';
export const LIST_FETCH_FAILURE = 'LIST_FETCH_FAILURE';
export const LIST_INITIAL_CALL_BEGIN = 'LIST_INITIAL_CALL_BEGIN';
export const LIST_FETCH_DATA_BEGIN = 'LIST_FETCH_DATA_BEGIN';
export const LIST_CALL_SUCCESS = 'LIST_CALL_SUCCESS';
export const LIST_CATEGORY_RESET = 'LIST_CATEGORY_RESET';
const dismissError = (category) => ({
type: LIST_DISMISS_ERROR,
payload: { category },
});
const switchCategory = (category) => ({
type: LIST_SWITCH_CATEGORY,
payload: { category },
});
const resetCategory = (category) => ({
type: LIST_CATEGORY_RESET,
payload: { category },
});
export const fetchFailure = (category, error) => ({
type: LIST_FETCH_FAILURE,
payload: {
category,
error,
},
});
const initialCallBegin = (category, search) => ({
type: LIST_INITIAL_CALL_BEGIN,
payload: {
category,
search,
},
});
const fetchDataBegin = (category, variables) => ({
type: LIST_FETCH_DATA_BEGIN,
payload: {
category,
variables,
},
});
const callSuccess = (category, response) => ({
type: LIST_CALL_SUCCESS,
payload: {
category,
response,
},
});
const initialCall = (category, dispatch) => {
dispatch(initialCallBegin(category, history.location.search));
return fetch(
getServiceURL(
`${category}/initialList`,
getObjectFromQuery(history.location.search),
),
{
method: 'GET',
credentials: 'include',
},
)
.then(handleHTTPErrors)
.then((response) => response.json())
.then((json) => {
const { targetType, url: redirectUrl } = json;
if (targetType === 'REDIRECT' && redirectUrl) {
// Reset category state completely before redirect
// This ensures fresh data load when returning to the page
dispatch(resetCategory(category));
history.push(redirectUrl);
return;
}
dispatch(callSuccess(category, json));
})
.catch((error) => dispatch(fetchFailure(category, error.message)));
};
const fetchData = (category, dispatch, listState, variables) => {
dispatch(fetchDataBegin(category, variables));
return fetch(
getServiceURL(`${category}/list`),
{
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(listState.categories[category].filter),
},
Git History
a5be6fdda Fix endless spinner after 2FA redirect on list pages
7a2807af1 WIP: Address campaign values
c527aa3a9 wip: dependency lift edit pages
c3331c88e WIP: Banking plugin (and new import module). DynamicDropArea: copy&paste bug fixed (function renamed)
3eac1c792 Rest version of ProjectPagesRest (list view) including multi selection (not yet finished).
a5be6fdda
Fix endless spinner after 2FA redirect on list pagesa5be6fdda4dd21f1b91eedc251245dc950dc29c2
diff --git a/projectforge-webapp/src/actions/list/index.js b/projectforge-webapp/src/actions/list/index.js
index 9f42abdbe..6b0c5c37b 100644
--- a/projectforge-webapp/src/actions/list/index.js
+++ b/projectforge-webapp/src/actions/list/index.js
@@ -7,6 +7,7 @@ export const LIST_FETCH_FAILURE = 'LIST_FETCH_FAILURE';
export const LIST_INITIAL_CALL_BEGIN = 'LIST_INITIAL_CALL_BEGIN';
export const LIST_FETCH_DATA_BEGIN = 'LIST_FETCH_DATA_BEGIN';
export const LIST_CALL_SUCCESS = 'LIST_CALL_SUCCESS';
+export const LIST_CATEGORY_RESET = 'LIST_CATEGORY_RESET';
const dismissError = (category) => ({
type: LIST_DISMISS_ERROR,
@@ -18,6 +19,11 @@ const switchCategory = (category) => ({
payload: { category },
});
+const resetCategory = (category) => ({
+ type: LIST_CATEGORY_RESET,
+ payload: { category },
+});
+
export const fetchFailure = (category, error) => ({
type: LIST_FETCH_FAILURE,
payload: {
@@ -68,6 +74,9 @@ const initialCall = (category, dispatch) => {
.then((json) => {
const { targetType, url: redirectUrl } = json;
if (targetType === 'REDIRECT' && redirectUrl) {
+ // Reset category state completely before redirect
+ // This ensures fresh data load when returning to the page
+ dispatch(resetCategory(category));
history.push(redirectUrl);
return;
} 7a2807af1
WIP: Address campaign values7a2807af1dde56bee7339dee02fb793546a76fcf
diff --git a/projectforge-webapp/src/actions/list/index.js b/projectforge-webapp/src/actions/list/index.js
index bffca1e35..9f42abdbe 100644
--- a/projectforge-webapp/src/actions/list/index.js
+++ b/projectforge-webapp/src/actions/list/index.js
@@ -92,7 +92,14 @@ const fetchData = (category, dispatch, listState, variables) => {
)
.then(handleHTTPErrors)
.then((response) => response.json())
- .then((data) => dispatch(callSuccess(category, { data })))
+ .then((data) => {
+ if (data.reloadUI) {
+ // Campaign or UI definitions changed - reload initial list
+ // to get updated filter definitions
+ return initialCall(category, dispatch);
+ }
+ return dispatch(callSuccess(category, { data }));
+ })
.catch((error) => dispatch(fetchFailure(category, error.message)));
};
c527aa3a9
wip: dependency lift edit pagesc527aa3a95b05e84e642e5181a314cf1a034b093
diff --git a/projectforge-webapp/src/actions/list/index.js b/projectforge-webapp/src/actions/list/index.js
index a2329133c..bffca1e35 100644
--- a/projectforge-webapp/src/actions/list/index.js
+++ b/projectforge-webapp/src/actions/list/index.js
@@ -190,8 +190,3 @@ export const startMultiSelection = () => (dispatch, getState) => {
},
);
};
-
-export const openEditPage = (id) => (_, getState) => {
- const state = getState().list;
- history.push(`/${state.categories[state.currentCategory].standardEditPage.replace(':id', id)}`);
-}; c3331c88e
WIP: Banking plugin (and new import module). DynamicDropArea: copy&paste bug fixed (function renamed)c3331c88e9049edefa60c0ee3535d208a33fe07f
diff --git a/projectforge-webapp/src/actions/list/index.js b/projectforge-webapp/src/actions/list/index.js
index a8fb0ef67..a2329133c 100644
--- a/projectforge-webapp/src/actions/list/index.js
+++ b/projectforge-webapp/src/actions/list/index.js
@@ -1,4 +1,3 @@
-import fileDownload from 'js-file-download';
import history from '../../utilities/history';
import { fetchJsonPost, getObjectFromQuery, getServiceURL, handleHTTPErrors } from '../../utilities/rest';
3eac1c792
Rest version of ProjectPagesRest (list view) including multi selection (not yet finished).3eac1c79281040e1206da9fa4c94c700edefec0d
diff --git a/projectforge-webapp/src/actions/list/index.js b/projectforge-webapp/src/actions/list/index.js
index 43130e055..a8fb0ef67 100644
--- a/projectforge-webapp/src/actions/list/index.js
+++ b/projectforge-webapp/src/actions/list/index.js
@@ -1,6 +1,6 @@
import fileDownload from 'js-file-download';
import history from '../../utilities/history';
-import { getObjectFromQuery, getServiceURL, handleHTTPErrors } from '../../utilities/rest';
+import { fetchJsonPost, getObjectFromQuery, getServiceURL, handleHTTPErrors } from '../../utilities/rest';
export const LIST_DISMISS_ERROR = 'LIST_DISMISS_ERROR';
export const LIST_SWITCH_CATEGORY = 'LIST_SWITCH_CATEGORY';
@@ -179,6 +179,19 @@ export const exportCurrentList = () => (dispatch, getState) => {
.catch((error) => dispatch(fetchFailure(category, error.message)));
};
+export const startMultiSelection = () => (dispatch, getState) => {
+ const { list } = getState();
+ const category = list.currentCategory;
+ return fetchJsonPost(
+ `${category}/startMultiSelection`,
+ list.categories[category].filter,
+ (json) => {
+ const { url } = json;
+ history.push(url);
+ },
+ );
+};
+
export const openEditPage = (id) => (_, getState) => {
const state = getState().list;
history.push(`/${state.categories[state.currentCategory].standardEditPage.replace(':id', id)}`);