Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: HACK: 90 edit preview mode support #3411

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/neos-ui-redux-store/src/UI/ContentCanvas/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,15 @@ test(`The "stopLoading" action should set the proper loading flag.`, () => {
const nextState = reducer(state, actions.stopLoading());
expect(nextState.isLoading).toBe(false);
});

test(`contentCanvas.src selector also calculates the editPreviewMode into the uri as query param.`, () => {
const state = {
ui: {
contentCanvas: {
src: 'http://127.0.0.1:8081/neos/preview?node%5B__contextNodePath%5D=%2Fsites%2Fneosdemo%40user-admin%3Blanguage%3Den_US'
},
editPreviewMode: 'rawContent'
}
};
expect(selectors.src(state)).toBe('http://127.0.0.1:8081/neos/preview?node%5B__contextNodePath%5D=%2Fsites%2Fneosdemo%40user-admin%3Blanguage%3Den_US&editPreviewMode=rawContent');
});
12 changes: 12 additions & 0 deletions packages/neos-ui-redux-store/src/UI/ContentCanvas/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {$get} from 'plow-js';
import {GlobalState} from '../../System';
import {selectors as editPreviewModeSelectors} from '../EditPreviewMode';

export const shouldScrollIntoView = (state: GlobalState) => $get(['ui', 'contentCanvas', 'shouldScrollIntoView'], state);

Expand All @@ -9,4 +10,15 @@ export const formattingUnderCursor = (state: GlobalState) => $get(['ui', 'conten

export const isLinkEditorOpen = (state: GlobalState) => $get(['ui', 'contentCanvas', 'isLinkEditorOpen'], state);

export const src = (state: GlobalState) => {
const src = state?.ui?.contentCanvas?.src;
if (src === null || src === '') {
return src;
}
const contentCanvasUri = new URL(src);
const editPreviewMode = editPreviewModeSelectors.currentEditPreviewMode(state);
contentCanvasUri.searchParams.set('editPreviewMode', editPreviewMode);
return contentCanvasUri.toString();
};

export const selectors = {};
23 changes: 20 additions & 3 deletions packages/neos-ui-sagas/src/UI/ContentCanvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {takeLatest, put, select, take, race} from 'redux-saga/effects';
import {$get} from 'plow-js';
import {getGuestFrameDocument} from '@neos-project/neos-ui-guest-frame/src/dom';

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

/**
* Load newly created page into canvas
Expand Down Expand Up @@ -44,7 +44,8 @@ export function * watchStopLoading({globalRegistry, store}) {
export function * watchReload() {
yield takeLatest(actionTypes.UI.ContentCanvas.RELOAD, function * (action) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk but why is there no reducer of actionTypes.UI.ContentCanvas.RELOAD which updates the current iframe url (if in payload)

then we can use the same selector down in line 61 ... or we can put into the selector a modified temporal state ...

const {uri} = action.payload;
const currentIframeUrl = yield select($get('ui.contentCanvas.src'));

const currentIframeUrl = yield select(selectors.UI.ContentCanvas.src);

[].slice.call(document.querySelectorAll(`iframe[name=neos-content-main]`)).forEach(iframe => {
const iframeWindow = iframe.contentWindow || iframe;
Expand All @@ -55,7 +56,23 @@ export function * watchReload() {
// If the new uri is provided in the action payload, use that
//
if (iframeWindow.location.href === currentIframeUrl) {
iframeWindow.location.href = uri || iframeWindow.location.href;
if (uri) {
const state = yield select();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as @grebaldi noted, yield is not allowed here and we have to get the state above / or convert it to a for of loop.

// @todo fix me, idk why we dont just write the src in the reducer on UI.ContentCanvas.RELOAD
const reloadSrc = selectors.UI.ContentCanvas.src({
...state,
ui: {
...state.ui,
contentCanvas: {
...state.contentCanvas,
src: uri
}
}
});
iframeWindow.location.href = reloadSrc;
} else {
iframeWindow.location.reload();
}
}
});
});
Expand Down
6 changes: 2 additions & 4 deletions packages/neos-ui-sagas/src/UI/EditPreviewMode/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {takeLatest, select} from 'redux-saga/effects';
import {$get} from 'plow-js';

import {actionTypes} from '@neos-project/neos-ui-redux-store';
import {actionTypes, selectors} from '@neos-project/neos-ui-redux-store';
import backend from '@neos-project/neos-ui-backend-connector';
import {getGuestFrameWindow} from '@neos-project/neos-ui-guest-frame/src/dom';

Expand All @@ -11,10 +10,9 @@ import {getGuestFrameWindow} from '@neos-project/neos-ui-guest-frame/src/dom';
export function * watchEditPreviewModesChanged() {
yield takeLatest(actionTypes.UI.EditPreviewMode.SET, function * editPreviewModeSet(action) {
const {editPreviewMode} = action.payload;
const currentIframeUrl = yield select($get('ui.contentCanvas.src'));

yield backend.get().endpoints.setUserPreferences('contentEditing.editPreviewMode', editPreviewMode);

getGuestFrameWindow().location.href = currentIframeUrl;
getGuestFrameWindow().location.href = yield select(selectors.UI.ContentCanvas.src);
});
}
2 changes: 1 addition & 1 deletion packages/neos-ui/src/Containers/ContentCanvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import style from './style.css';
isFringeRight: $get('ui.rightSideBar.isHidden'),
isFullScreen: $get('ui.fullScreen.isFullScreen'),
backgroundColor: $get('ui.contentCanvas.backgroundColor'),
src: $get('ui.contentCanvas.src'),
src: selectors.UI.ContentCanvas.src,
baseNodeType: $get('ui.pageTree.filterNodeType'),
currentEditPreviewMode: selectors.UI.EditPreviewMode.currentEditPreviewMode
}), {
Expand Down