Skip to content

Commit

Permalink
TASK: Update WorkspaceInfo after publish/discard
Browse files Browse the repository at this point in the history
  • Loading branch information
grebaldi committed Apr 10, 2024
1 parent edac64b commit 6645c4d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
5 changes: 1 addition & 4 deletions packages/neos-ui-redux-store/src/CR/Publishing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {action as createAction, ActionType} from 'typesafe-actions';

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

import {PublishableNode} from '../Workspaces';

export enum PublishingMode {
PUBLISH,
DISCARD
Expand Down Expand Up @@ -96,7 +94,7 @@ const acknowledge = () => createAction(actionTypes.ACKNOWLEDGED);
/**
* Finish the ongoing publish/discard workflow
*/
const finish = (affectedNodes: PublishableNode[]) => createAction(actionTypes.FINISHED, {affectedNodes});
const finish = () => createAction(actionTypes.FINISHED);

//
// Export the actions
Expand All @@ -113,7 +111,6 @@ export const actions = {
};

export type Action = ActionType<typeof actions>;
export type FinishAction = ActionType<typeof actions.finish>;

//
// Export the reducer
Expand Down
12 changes: 1 addition & 11 deletions packages/neos-ui-redux-store/src/CR/Workspaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {NodeContextPath} from '@neos-project/neos-ts-interfaces';
import {WorkspaceName} from '@neos-project/neos-ts-interfaces';

import {actionTypes as system, InitAction} from '../../System';
import {actionTypes as publishing, FinishAction} from '../Publishing';

import * as selectors from './selectors';

Expand Down Expand Up @@ -79,7 +78,7 @@ export const actions = {
//
// Export the reducer
//
export const reducer = (state: State = defaultState, action: InitAction | FinishAction | Action) => produce(state, draft => {
export const reducer = (state: State = defaultState, action: InitAction | Action) => produce(state, draft => {
switch (action.type) {
case system.INIT: {
draft.personalWorkspace = action.payload.cr.workspaces.personalWorkspace;
Expand All @@ -89,15 +88,6 @@ export const reducer = (state: State = defaultState, action: InitAction | Finish
draft.personalWorkspace = assignIn(draft.personalWorkspace, action.payload);
break;
}
case publishing.FINISHED: {
draft.personalWorkspace.publishableNodes =
state.personalWorkspace.publishableNodes.filter(
(publishableNode) => !action.payload.affectedNodes.some(
(affectedNode) => affectedNode.contextPath === publishableNode.contextPath
)
);
break;
}
}
});

Expand Down
20 changes: 20 additions & 0 deletions packages/neos-ui-sagas/src/CR/Workspaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* This file is part of the Neos.Neos.Ui package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
import {put, call} from 'redux-saga/effects';

import {actions} from '@neos-project/neos-ui-redux-store';
import {WorkspaceInformation} from '@neos-project/neos-ui-redux-store/src/CR/Workspaces';
import backend from '@neos-project/neos-ui-backend-connector';

export function * updateWorkspaceInfo() {
const {getWorkspaceInfo} = backend.get().endpoints;
const workspaceInfo: WorkspaceInformation = yield call(getWorkspaceInfo);
yield put(actions.CR.Workspaces.update(workspaceInfo));
}
25 changes: 13 additions & 12 deletions packages/neos-ui-sagas/src/Publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
* information, please view the LICENSE file which was distributed with this
* source code.
*/
import {put, call, select, takeEvery, take, race} from 'redux-saga/effects';
import {put, call, select, takeEvery, take, race, all} from 'redux-saga/effects';

import {AnyError} from '@neos-project/neos-ui-error';
import {NodeContextPath, WorkspaceName} from '@neos-project/neos-ts-interfaces';
import {actionTypes, actions, selectors} from '@neos-project/neos-ui-redux-store';
import {GlobalState} from '@neos-project/neos-ui-redux-store/src/System';
import {FeedbackEnvelope} from '@neos-project/neos-ui-redux-store/src/ServerFeedback';
import {PublishingMode, PublishingScope} from '@neos-project/neos-ui-redux-store/src/CR/Publishing';
import {PublishableNode, WorkspaceInformation} from '@neos-project/neos-ui-redux-store/src/CR/Workspaces';
import {WorkspaceInformation} from '@neos-project/neos-ui-redux-store/src/CR/Workspaces';
import backend, {Routes} from '@neos-project/neos-ui-backend-connector';

import {makeReloadNodes} from '../CR/NodeOperations/reloadNodes';
import {updateWorkspaceInfo} from '../CR/Workspaces';

const handleWindowBeforeUnload = (event: BeforeUnloadEvent) => {
event.preventDefault();
Expand Down Expand Up @@ -48,12 +49,10 @@ export function * watchPublishing({routes}: {routes: Routes}) {
};
const SELECTORS_BY_SCOPE = {
[PublishingScope.SITE]: {
ancestorIdSelector: selectors.CR.Nodes.siteNodeContextPathSelector,
publishableNodesSelector: selectors.CR.Workspaces.publishableNodesSelector
ancestorIdSelector: selectors.CR.Nodes.siteNodeContextPathSelector
},
[PublishingScope.DOCUMENT]: {
ancestorIdSelector: selectors.CR.Nodes.documentNodeContextPathSelector,
publishableNodesSelector: selectors.CR.Workspaces.publishableNodesInDocumentSelector
ancestorIdSelector: selectors.CR.Nodes.documentNodeContextPathSelector
}
};

Expand All @@ -67,24 +66,23 @@ export function * watchPublishing({routes}: {routes: Routes}) {

const {scope, mode} = action.payload;
const endpoint = ENDPOINT_BY_MODE_AND_SCOPE[mode][scope];
const {ancestorIdSelector, publishableNodesSelector} = SELECTORS_BY_SCOPE[scope];
const {ancestorIdSelector} = SELECTORS_BY_SCOPE[scope];

const workspaceName: WorkspaceName = yield select(selectors.CR.Workspaces.personalWorkspaceNameSelector);
const ancestorId: NodeContextPath = yield select(ancestorIdSelector);
const publishableNodes: PublishableNode[] = yield select(publishableNodesSelector);

let affectedNodes: PublishableNode[] = [];
do {
try {
window.addEventListener('beforeunload', handleWindowBeforeUnload);
const result: PublishingResponse = yield call(endpoint, ancestorId, workspaceName);

if ('success' in result) {
affectedNodes = publishableNodes;
yield put(actions.CR.Publishing.succeed());

if (mode === PublishingMode.DISCARD) {
yield * reloadAfterDiscard();
} else {
yield * updateWorkspaceInfo();
}
} else if ('error' in result) {
yield put(actions.CR.Publishing.fail(result.error));
Expand All @@ -98,7 +96,7 @@ export function * watchPublishing({routes}: {routes: Routes}) {
}
} while (yield * waitForRetry());

yield put(actions.CR.Publishing.finish(affectedNodes));
yield put(actions.CR.Publishing.finish());
});
}

Expand Down Expand Up @@ -132,7 +130,10 @@ const makeReloadAfterDiscard = (deps: {
const reloadNodes = makeReloadNodes(deps);

function * reloadAfterDiscard() {
yield * reloadNodes();
yield all([
call(updateWorkspaceInfo),
call(reloadNodes)
]);
}

return reloadAfterDiscard;
Expand Down

0 comments on commit 6645c4d

Please sign in to comment.