Skip to content

Commit

Permalink
Merge pull request #3909 from mhsdesign/feature/simplify-publish-work…
Browse files Browse the repository at this point in the history
…flow

FEATURE: Simplify publish workflow
  • Loading branch information
mhsdesign authored Jan 27, 2025
2 parents da19324 + 6189127 commit 3fb3ef5
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 59 deletions.
5 changes: 2 additions & 3 deletions Tests/IntegrationTests/Fixtures/1Dimension/syncing.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test('Publish + Syncing: Create a conflict state between two editors, then try t

test('Publish + Syncing: Create a conflict state between two editors, then try to publish the document and choose "Drop conflicting changes" as a resolution strategy during automatic rebase', async t => {
await prepareDocumentConflictBetweenAdminAndEditor(t);
await startPublishDocument(t);
await publishDocument(t);
await assertThatConflictResolutionHasStarted(t);
await chooseDropConflictingChangesAsResolutionStrategy(t);
await performResolutionStrategy(t);
Expand Down Expand Up @@ -323,9 +323,8 @@ async function startPublishAll(t) {
await t.click(Selector('#neos-PublishDialog-Confirm'));
}

async function startPublishDocument(t) {
async function publishDocument(t) {
await t.click(Selector('#neos-PublishDropDown-Publish'))
await t.click(Selector('#neos-PublishDialog-Confirm'));
}

async function finishPublish(t) {
Expand Down
23 changes: 16 additions & 7 deletions packages/neos-ui-redux-store/src/CR/Publishing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export type State = null | {
scope: PublishingScope;
process:
| { phase: PublishingPhase.START }
| { phase: PublishingPhase.ONGOING }
| {
phase: PublishingPhase.ONGOING,
autoConfirmed: boolean
}
| { phase: PublishingPhase.CONFLICTS }
| {
phase: PublishingPhase.ERROR;
Expand Down Expand Up @@ -65,8 +68,8 @@ export enum actionTypes {
/**
* Publishes or discards all changes in the given scope
*/
const start = (mode: PublishingMode, scope: PublishingScope) =>
createAction(actionTypes.STARTED, {mode, scope});
const start = (mode: PublishingMode, scope: PublishingScope, requireConfirmation: boolean) =>
createAction(actionTypes.STARTED, {mode, scope, requireConfirmation});

/**
* Cancel the ongoing publish/discard workflow
Expand Down Expand Up @@ -142,8 +145,11 @@ export const reducer = (state: State = defaultState, action: Action): State => {
return {
mode: action.payload.mode,
scope: action.payload.scope,
process: {
process: action.payload.requireConfirmation ? {
phase: PublishingPhase.START
} : {
phase: PublishingPhase.ONGOING,
autoConfirmed: true
}
};
}
Expand All @@ -166,7 +172,8 @@ export const reducer = (state: State = defaultState, action: Action): State => {
return {
...state,
process: {
phase: PublishingPhase.ONGOING
phase: PublishingPhase.ONGOING,
autoConfirmed: false
}
};
case actionTypes.CONFLICTS_OCCURRED:
Expand All @@ -180,7 +187,8 @@ export const reducer = (state: State = defaultState, action: Action): State => {
return {
...state,
process: {
phase: PublishingPhase.ONGOING
phase: PublishingPhase.ONGOING,
autoConfirmed: false
}
};
case actionTypes.FAILED:
Expand All @@ -195,7 +203,8 @@ export const reducer = (state: State = defaultState, action: Action): State => {
return {
...state,
process: {
phase: PublishingPhase.ONGOING
phase: PublishingPhase.ONGOING,
autoConfirmed: false
}
};
case actionTypes.SUCEEDED:
Expand Down
48 changes: 45 additions & 3 deletions packages/neos-ui-sagas/src/Publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
import {put, call, select, takeEvery, take, race, all} from 'redux-saga/effects';

import {AnyError} from '@neos-project/neos-ui-error';
import {AnyError, showFlashMessage} from '@neos-project/neos-ui-error';
import {DimensionCombination, 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';
Expand All @@ -21,6 +21,7 @@ import backend, {Routes} from '@neos-project/neos-ui-backend-connector';
import {makeReloadNodes} from '../CR/NodeOperations/reloadNodes';
import {updateWorkspaceInfo} from '../CR/Workspaces';
import {makeResolveConflicts, makeSyncPersonalWorkspace} from '../Sync';
import {translate} from '@neos-project/neos-ui-i18n';

const handleWindowBeforeUnload = (event: BeforeUnloadEvent) => {
event.preventDefault();
Expand All @@ -37,6 +38,21 @@ type PublishingResponse =
| { conflicts: Conflict[] }
| { error: AnyError };

const PUBLISH_SUCCESS_TRANSLATIONS = {
[PublishingScope.ALL]: {
id: 'Neos.Neos.Ui:PublishingDialog:publish.all.success.message',
fallback: 'All {numberOfChanges} change(s) in workspace "{scopeTitle}" were successfully published to workspace "{targetWorkspaceName}".'
},
[PublishingScope.SITE]: {
id: 'Neos.Neos.Ui:PublishingDialog:publish.site.success.message',
fallback: '{numberOfChanges} change(s) in site "{scopeTitle}" were successfully published to workspace "{targetWorkspaceName}".'
},
[PublishingScope.DOCUMENT]: {
id: 'Neos.Neos.Ui:PublishingDialog:publish.document.success.message',
fallback: '{numberOfChanges} change(s) in document "{scopeTitle}" were sucessfully published to workspace "{targetWorkspaceName}".'
}
}

export function * watchPublishing({routes}: {routes: Routes}) {
const {endpoints} = backend.get();
const ENDPOINT_BY_MODE_AND_SCOPE = {
Expand Down Expand Up @@ -74,7 +90,7 @@ export function * watchPublishing({routes}: {routes: Routes}) {
const resolveConflicts = makeResolveConflicts({syncPersonalWorkspace});

yield takeEvery(actionTypes.CR.Publishing.STARTED, function * publishingWorkflow(action: ReturnType<typeof actions.CR.Publishing.start>) {
const confirmed = yield * waitForConfirmation();
const confirmed = action.payload.requireConfirmation ? yield * waitForConfirmation() : true;
if (!confirmed) {
return;
}
Expand All @@ -99,7 +115,33 @@ export function * watchPublishing({routes}: {routes: Routes}) {
: yield call(endpoint!, ancestorId, workspaceName, dimensionSpacePoint);

if ('success' in result) {
yield put(actions.CR.Publishing.succeed(result.success.numberOfAffectedChanges));
if (action.payload.requireConfirmation) {
yield put(actions.CR.Publishing.succeed(result.success.numberOfAffectedChanges));
} else {
// fixme, this translation logic is duplicated from the PublishingDialog component
let scopeTitle = 'N/A';
if (scope === PublishingScope.ALL) {
scopeTitle = yield select(selectors.CR.Workspaces.personalWorkspaceNameSelector);
} else if (scope === PublishingScope.SITE) {
scopeTitle = (yield select(selectors.CR.Nodes.siteNodeSelector))?.label ?? scopeTitle;
} else if (scope === PublishingScope.DOCUMENT) {
scopeTitle = (yield select(selectors.CR.Nodes.documentNodeSelector))?.label ?? scopeTitle;
}

const parameters = {
numberOfChanges: result.success.numberOfAffectedChanges,
scopeTitle,
targetWorkspaceName: yield select(selectors.CR.Workspaces.baseWorkspaceSelector)
};

showFlashMessage({
id: 'publishing',
severity: 'success',
message: translate(PUBLISH_SUCCESS_TRANSLATIONS[scope].id, PUBLISH_SUCCESS_TRANSLATIONS[scope].fallback, parameters),
timeout: 2000
});
yield put(actions.CR.Publishing.finish());
}
yield * reloadAfterPublishing();
} else if ('conflicts' in result) {
yield put(actions.CR.Publishing.conflicts());
Expand Down
5 changes: 3 additions & 2 deletions packages/neos-ui-sagas/src/Sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ const makeDiscardAll = () => {
function * discardAll() {
yield put(actions.CR.Publishing.start(
PublishingMode.DISCARD,
PublishingScope.ALL
PublishingScope.ALL,
true
));
yield put(actions.CR.Publishing.confirm()); // todo auto-confirm this case
yield put(actions.CR.Publishing.confirm()); // we auto-confirm this case but do want to display a full result dialog
yield put(actions.CR.Syncing.finish()); // stop syncing as discarding takes now over
const {cancelled}: {
cancelled: null | ReturnType<typeof actions.CR.Publishing.cancel>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const ConfirmationDialogVariants = {
}
}
},
// NOTE that with https://github.com/neos/neos-ui/pull/3909 this variant is currently effectively not used as confirmation is not required
[PublishingScope.DOCUMENT]: {
label: {
title: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* information, please view the LICENSE file which was distributed with this
* source code.
*/
import React from 'react';
import React, {useEffect, useState} from 'react';
// @ts-ignore
import {connect} from 'react-redux';

Expand All @@ -27,9 +27,10 @@ import {ResultDialog} from './ResultDialog';
const {
publishableNodesSelector,
publishableNodesInDocumentSelector,
personalWorkspaceNameSelector
} = (selectors as any).CR.Workspaces;
const {siteNodeSelector, documentNodeSelector} = (selectors as any).CR.Nodes;
personalWorkspaceNameSelector,
baseWorkspaceSelector
} = selectors.CR.Workspaces;
const {siteNodeSelector, documentNodeSelector} = selectors.CR.Nodes;

type PublishingDialogProperties =
| { publishingState: null }
Expand Down Expand Up @@ -84,8 +85,8 @@ const PublishingDialog: React.FC<PublishingDialogProps> = (props) => {
/>
);

case PublishingPhase.ONGOING:
return (
case PublishingPhase.ONGOING: {
const ongoingScreen = (
<ProcessIndicator
mode={props.publishingState.mode}
scope={props.publishingState.scope}
Expand All @@ -96,6 +97,9 @@ const PublishingDialog: React.FC<PublishingDialogProps> = (props) => {
/>
);

return props.publishingState.process.autoConfirmed ? <DelayedDisplay component={ongoingScreen} delay={750} /> : ongoingScreen;
}

case PublishingPhase.CONFLICTS:
return null;

Expand All @@ -117,14 +121,30 @@ const PublishingDialog: React.FC<PublishingDialogProps> = (props) => {
}
};

const DelayedDisplay = (props: {component: React.ReactElement, delay: number}) => {
const [enable, setEnable] = useState(false);

useEffect(() => {
const id = setTimeout(() => {
setEnable(true);
}, props.delay)
return () => {
clearTimeout(id)
}
}, [props.delay])

return enable ? props.component : null;
}

export default connect((state: GlobalState): PublishingDialogProperties => {
const {publishing: publishingState} = state.cr;
if (publishingState === null) {
return {publishingState};
}

const {scope} = publishingState;
const {name: sourceWorkspaceName, baseWorkspace} = state.cr.workspaces.personalWorkspace;
const sourceWorkspaceName = personalWorkspaceNameSelector(state);
const baseWorkspace = baseWorkspaceSelector(state);
const targetWorkspaceName = publishingState.mode === PublishingMode.PUBLISH
? baseWorkspace
: null;
Expand All @@ -142,11 +162,11 @@ export default connect((state: GlobalState): PublishingDialogProperties => {

let scopeTitle = 'N/A';
if (scope === PublishingScope.ALL) {
scopeTitle = personalWorkspaceNameSelector(state);
scopeTitle = sourceWorkspaceName;
} else if (scope === PublishingScope.SITE) {
scopeTitle = siteNodeSelector(state).label;
scopeTitle = siteNodeSelector(state)?.label ?? scopeTitle;
} else if (scope === PublishingScope.DOCUMENT) {
scopeTitle = documentNodeSelector(state).label;
scopeTitle = documentNodeSelector(state)?.label ?? scopeTitle;
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const ResultDialogVariants = {
}
}
},
// NOTE that with https://github.com/neos/neos-ui/pull/3909 this variant is currently effectively not used as confirmation is not required
[PublishingScope.DOCUMENT]: {
label: {
title: {
Expand Down
Loading

0 comments on commit 3fb3ef5

Please sign in to comment.