Skip to content

Commit

Permalink
TASK: Replace all calls to action.UI.FlashMessages.add with new `sh…
Browse files Browse the repository at this point in the history
…owFlashMessage` API
  • Loading branch information
grebaldi committed Jun 6, 2024
1 parent 942bb36 commit 092d97d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 15 deletions.
8 changes: 7 additions & 1 deletion packages/neos-ui-sagas/src/UI/ContentCanvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {takeLatest, put, select, take, race} from 'redux-saga/effects';
import {getGuestFrameDocument} from '@neos-project/neos-ui-guest-frame/src/dom';

import {actionTypes, actions} from '@neos-project/neos-ui-redux-store';
import {showFlashMessage} from '@neos-project/neos-ui-error';

/**
* Load newly created page into canvas
Expand Down Expand Up @@ -80,7 +81,12 @@ export function * watchControlOverIFrame() {
const nextAction = Object.keys(waitForNextAction).map(k => waitForNextAction[k])[0];

if (nextAction.type === actionTypes.UI.ContentCanvas.REQUEST_REGAIN_CONTROL) {
yield put(actions.UI.FlashMessages.add('iframe access', nextAction.payload.errorMessage, 'error', 5000));
showFlashMessage({
id: 'iframe access',
severity: 'error',
message: nextAction.payload.errorMessage,
timeout: 5000
});

//
// We need to delay, so that the iframe gets cleared before we load a new src
Expand Down
7 changes: 6 additions & 1 deletion packages/neos-ui-sagas/src/UI/ContentTree/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {actionTypes, actions, selectors} from '@neos-project/neos-ui-redux-store
import {isNodeCollapsed} from '@neos-project/neos-ui-redux-store/src/CR/Nodes/helpers';

import backend from '@neos-project/neos-ui-backend-connector';
import {showFlashMessage} from '@neos-project/neos-ui-error';

export function * watchReloadTree({globalRegistry}) {
const nodeTypesRegistry = globalRegistry.get('@neos-project/neos-ui-contentrepository');
Expand Down Expand Up @@ -122,7 +123,11 @@ export function * watchRequestChildrenForContextPath({globalRegistry}) {
childNodes = yield query.neosUiFilteredChildren(nodeTypeFilter).get();
} catch (err) {
yield put(actions.UI.ContentTree.invalidate(contextPath));
yield put(actions.UI.FlashMessages.add('loadChildNodesError', err.message, 'error'));
showFlashMessage({
id: 'loadChildNodesError',
severity: 'error',
message: err.message
});
}

yield put(actions.UI.ContentTree.setAsLoaded(contextPath));
Expand Down
23 changes: 18 additions & 5 deletions packages/neos-ui-sagas/src/UI/Impersonate/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {put, call, takeEvery} from 'redux-saga/effects';
import {call, takeEvery} from 'redux-saga/effects';

import {actionTypes, actions} from '@neos-project/neos-ui-redux-store';
import {actionTypes} from '@neos-project/neos-ui-redux-store';
import backend from '@neos-project/neos-ui-backend-connector';
import {showFlashMessage} from '@neos-project/neos-ui-error';

export function * impersonateRestore({globalRegistry, routes}) {
const {impersonateRestore} = backend.get().endpoints;
Expand Down Expand Up @@ -33,14 +34,26 @@ export function * impersonateRestore({globalRegistry, routes}) {
);

if (status) {
yield put(actions.UI.FlashMessages.add('restoreUserImpersonateUser', restoreMessage, 'success'));
showFlashMessage({
id: 'restoreUserImpersonateUser',
severity: 'success',
message: restoreMessage
});
} else {
yield put(actions.UI.FlashMessages.add('restoreUserImpersonateUser', errorMessage, 'error'));
showFlashMessage({
id: 'restoreUserImpersonateUser',
severity: 'error',
message: errorMessage
});
}

window.location.href = routes?.core?.modules?.defaultModule;
} catch (error) {
yield put(actions.UI.FlashMessages.add('restoreUserImpersonateUser', errorMessage, 'error'));
showFlashMessage({
id: 'restoreUserImpersonateUser',
severity: 'error',
message: errorMessage
});
}
});
}
13 changes: 11 additions & 2 deletions packages/neos-ui-sagas/src/UI/PageTree/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {takeLatest, takeEvery, put, select} from 'redux-saga/effects';

import {actionTypes, actions, selectors} from '@neos-project/neos-ui-redux-store';
import backend from '@neos-project/neos-ui-backend-connector';
import {showFlashMessage} from '@neos-project/neos-ui-error';

import {isNodeCollapsed} from '@neos-project/neos-ui-redux-store/src/CR/Nodes/helpers';

Expand Down Expand Up @@ -42,7 +43,11 @@ export function * watchRequestChildrenForContextPath({configuration}) {
childNodes = yield query.neosUiFilteredChildren(baseNodeType).getForTree();
} catch (err) {
yield put(actions.UI.PageTree.invalidate(contextPath));
yield put(actions.UI.FlashMessages.add('loadChildNodesError', err.message, 'error'));
showFlashMessage({
id: 'loadChildNodesError',
severity: 'error',
message: err.message
});
}

yield put(actions.UI.PageTree.setAsLoaded(contextPath));
Expand Down Expand Up @@ -183,7 +188,11 @@ export function * watchSearch({configuration}) {
} catch (err) {
console.error('Error while executing a tree search: ', err);
yield put(actions.UI.PageTree.invalidate(contextPath));
yield put(actions.UI.FlashMessages.add('searchError', 'There was an error searching in the node tree. Contact your administrator for fixing this issue.', 'error'));
showFlashMessage({
id: 'searchError',
severity: 'error',
message: 'There was an error searching in the node tree. Contact your administrator for fixing this issue.'
});
return;
}
const siteNode = yield select(selectors.CR.Nodes.siteNodeSelector);
Expand Down
13 changes: 11 additions & 2 deletions packages/neos-ui/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import fetchWithErrorHandling from '@neos-project/neos-ui-backend-connector/src/
import {SynchronousMetaRegistry} from '@neos-project/neos-ui-extensibility/src/registry';
import backend from '@neos-project/neos-ui-backend-connector';
import {handleActions} from '@neos-project/utils-redux';
import {showFlashMessage} from '@neos-project/neos-ui-error';

import {
appContainer,
Expand Down Expand Up @@ -141,7 +142,11 @@ function initializeFetchWithErrorHandling() {
message = exception.textContent;
}

store.dispatch(actions.UI.FlashMessages.add('fetch error', message, 'error'));
showFlashMessage({
id: 'fetch error',
severity: 'error',
message
});
});
}

Expand Down Expand Up @@ -181,7 +186,11 @@ async function loadImpersonateStatus() {
store.dispatch(actions.User.Impersonate.fetchStatus(impersonateState));
}
} catch (error) {
store.dispatch(actions.UI.FlashMessages.add('impersonateStatusError', error.message, 'error'));
showFlashMessage({
id: 'impersonateStatusError',
severity: 'error',
message: error.message
});
}
}

Expand Down
11 changes: 7 additions & 4 deletions packages/neos-ui/src/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import initializeContentDomNode from '@neos-project/neos-ui-guest-frame/src/init
import style from '@neos-project/neos-ui-guest-frame/src/style.module.css';
import backend from '@neos-project/neos-ui-backend-connector';

import {showFlashMessage} from '@neos-project/neos-ui-error';

manifest('main', {}, (globalRegistry, {routes}) => {
//
// Create edit preview mode registry
Expand Down Expand Up @@ -191,12 +193,13 @@ manifest('main', {}, (globalRegistry, {routes}) => {
//
// Take care of message feedback
//
const flashMessageFeedbackHandler = (feedbackPayload, {store}) => {
const {message, severity} = feedbackPayload;
const timeout = severity.toLowerCase() === 'success' ? 5000 : 0;
const flashMessageFeedbackHandler = (feedbackPayload) => {
const {message} = feedbackPayload;
const severity = feedbackPayload.severity.toLowerCase();
const timeout = severity === 'success' ? 5000 : 0;
const id = uuid.v4();

store.dispatch(actions.UI.FlashMessages.add(id, message, severity, timeout));
showFlashMessage({id, message, severity, timeout});
};
serverFeedbackHandlers.set('Neos.Neos.Ui:Success/Main', flashMessageFeedbackHandler);
serverFeedbackHandlers.set('Neos.Neos.Ui:Error/Main', flashMessageFeedbackHandler);
Expand Down

0 comments on commit 092d97d

Please sign in to comment.