Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Fix change to go back to 'fake' modal (#62)
Browse files Browse the repository at this point in the history
* fix: rebase

* fix: tests

* fix: remove broken code button

* fix: test case with iff
  • Loading branch information
rayzhou-bit committed Apr 19, 2022
1 parent be12d11 commit 5200897
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 111 deletions.
Original file line number Diff line number Diff line change
@@ -1,87 +1,82 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EditorContainer component render snapshot: initialized. enable save and pass to header 1`] = `
<FullscreenModal
footerNode={
<InjectIntl(ShimmedIntlComponent)
disableSave={false}
onCancel={
Object {
"handleCancelClicked": Object {
"onClose": [MockFunction props.onClose],
},
}
}
onSave={
Object {
"handleSaveClicked": Object {
"dispatch": [MockFunction react-redux.dispatch],
"getContent": [MockFunction props.getContent],
},
}
}
/>
}
isOpen={true}
onClose={
Object {
"handleCancelClicked": Object {
"onClose": [MockFunction props.onClose],
},
}
}
title={
<InjectIntl(ShimmedIntlComponent)
isInitialized={true}
/>
}
variant="primary"
>
<div>
<ModalDialog.Header>
<ModalDialog.Title>
<InjectIntl(ShimmedIntlComponent)
isInitialized={true}
/>
<div
className="pgn__modal-close-container"
>
<IconButton
iconAs="Icon"
onClick={[MockFunction props.onClose]}
src={[MockFunction icons.Close]}
/>
</div>
</ModalDialog.Title>
</ModalDialog.Header>
<h1>
My test content
</h1>
</FullscreenModal>
<InjectIntl(ShimmedIntlComponent)
disableSave={false}
onCancel={
Object {
"handleCancelClicked": Object {
"onClose": [MockFunction props.onClose],
},
}
}
onSave={
Object {
"handleSaveClicked": Object {
"dispatch": [MockFunction react-redux.dispatch],
"getContent": [MockFunction props.getContent],
},
}
}
/>
</div>
`;

exports[`EditorContainer component render snapshot: not initialized. disable save and pass to header 1`] = `
<FullscreenModal
footerNode={
<InjectIntl(ShimmedIntlComponent)
disableSave={true}
onCancel={
Object {
"handleCancelClicked": Object {
"onClose": [MockFunction props.onClose],
},
}
<div>
<ModalDialog.Header>
<ModalDialog.Title>
<InjectIntl(ShimmedIntlComponent)
isInitialized={false}
/>
<div
className="pgn__modal-close-container"
>
<IconButton
iconAs="Icon"
onClick={[MockFunction props.onClose]}
src={[MockFunction icons.Close]}
/>
</div>
</ModalDialog.Title>
</ModalDialog.Header>
<InjectIntl(ShimmedIntlComponent)
disableSave={true}
onCancel={
Object {
"handleCancelClicked": Object {
"onClose": [MockFunction props.onClose],
},
}
onSave={
Object {
"handleSaveClicked": Object {
"dispatch": [MockFunction react-redux.dispatch],
"getContent": [MockFunction props.getContent],
},
}
}
onSave={
Object {
"handleSaveClicked": Object {
"dispatch": [MockFunction react-redux.dispatch],
"getContent": [MockFunction props.getContent],
},
}
/>
}
isOpen={true}
onClose={
Object {
"handleCancelClicked": Object {
"onClose": [MockFunction props.onClose],
},
}
}
title={
<InjectIntl(ShimmedIntlComponent)
isInitialized={false}
/>
}
variant="primary"
>
<h1>
My test content
</h1>
</FullscreenModal>
/>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
exports[`EditorFooter render snapshot: default args (disableSave: false, saveFailed: false) 1`] = `
<div
className="editor-footer"
style={
Object {
"bottom": 0,
"position": "sticky",
}
}
>
<ModalDialog.Footer
className="border-top-0"
Expand Down Expand Up @@ -39,6 +45,12 @@ exports[`EditorFooter render snapshot: default args (disableSave: false, saveFai
exports[`EditorFooter render snapshot: save disabled. Show button spinner 1`] = `
<div
className="editor-footer"
style={
Object {
"bottom": 0,
"position": "sticky",
}
}
>
<ModalDialog.Footer
className="border-top-0"
Expand Down Expand Up @@ -74,6 +86,12 @@ exports[`EditorFooter render snapshot: save disabled. Show button spinner 1`] =
exports[`EditorFooter render snapshot: save failed. Show error message 1`] = `
<div
className="editor-footer"
style={
Object {
"bottom": 0,
"position": "sticky",
}
}
>
<Toast
onClose={[MockFunction hooks.nullMethod]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const EditorFooter = ({
// injected
intl,
}) => (
<div className="editor-footer">
<div className="editor-footer" style={{ position: 'sticky', bottom: 0 }}>
{saveFailed && (
<Toast show onClose={nullMethod}>
<FormattedMessage {...messages.contentSaveFailed} />
Expand Down
42 changes: 23 additions & 19 deletions src/editors/containers/EditorContainer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react';
import { useDispatch } from 'react-redux';
import PropTypes from 'prop-types';

import { FullscreenModal } from '@edx/paragon';
import { Icon, ModalDialog, IconButton } from '@edx/paragon';
import { Close } from '@edx/paragon/icons';

import EditorFooter from './components/EditorFooter';
import TitleHeader from './components/TitleHeader';
Expand All @@ -18,24 +19,27 @@ export const EditorContainer = ({
const isInitialized = hooks.isInitialized();
const handleCancelClicked = hooks.handleCancelClicked({ onClose });
return (
<FullscreenModal
isOpen
onClose={handleCancelClicked}
variant="primary"
footerNode={(
<EditorFooter
onCancel={handleCancelClicked}
onSave={hooks.handleSaveClicked({ getContent, dispatch })}
disableSave={!isInitialized}
saveFailed={hooks.saveFailed()}
/>
)}
title={(
<TitleHeader isInitialized={isInitialized} />
)}
>
{children}
</FullscreenModal>
<div>
<ModalDialog.Header>
<ModalDialog.Title>
<TitleHeader isInitialized={isInitialized} />
<div className="pgn__modal-close-container">
<IconButton
src={Close}
iconAs={Icon}
onClick={onClose}
/>
</div>
</ModalDialog.Title>
</ModalDialog.Header>
{isInitialized && children}
<EditorFooter
onCancel={handleCancelClicked}
onSave={hooks.handleSaveClicked({ getContent, dispatch })}
disableSave={!isInitialized}
saveFailed={hooks.saveFailed()}
/>
</div>
);
};
EditorContainer.defaultProps = {
Expand Down
3 changes: 0 additions & 3 deletions src/editors/containers/EditorContainer/index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
.pgn__modal-layer {
z-index: 0;
}
11 changes: 6 additions & 5 deletions src/editors/containers/EditorContainer/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ describe('EditorContainer component', () => {
});
test('close behavior is linked to modal onClose and footer onCancel', () => {
const expected = hooks.handleCancelClicked({ onClose: props.onClose });
expect(el.at(0).props().onClose).toEqual(expected);
expect(el.at(0).props().footerNode.props.onCancel).toEqual(expected);
expect(el.children().at(2).props().onCancel).toEqual(expected);
});
test('save behavior is linked to footer onSave', () => {
expect(el.at(0).props().footerNode.props.onSave).toEqual(
hooks.handleSaveClicked({ dispatch: useDispatch(), getContent: props.getContent }),
);
const expected = hooks.handleSaveClicked({
getContent: props.getContent,
dispatch: useDispatch(),
});
expect(el.children().at(2).props().onSave).toEqual(expected);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/editors/containers/TextEditor/pluginConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default StrictDict({
],
[buttons.imageUploadButton, buttons.link, buttons.unlink, buttons.codesample, buttons.table],
[buttons.emoticons, buttons.charmap, buttons.hr],
[buttons.removeFormat, buttons.code],
[buttons.removeFormat],
]),
imageToolbar: mapToolbars([
// [buttons.rotate.left, buttons.rotate.right],
Expand Down
3 changes: 1 addition & 2 deletions src/editors/data/redux/app/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ export const returnUrl = createSelector(
export const isInitialized = createSelector(
[
module.simpleSelectors.unitUrl,
module.simpleSelectors.editorInitialized,
module.simpleSelectors.blockValue,
],
(unitUrl, editorInitialized, blockValue) => !!(unitUrl && blockValue && editorInitialized),
(unitUrl, blockValue) => !!(unitUrl && blockValue),
);

export const displayTitle = createSelector(
Expand Down
9 changes: 3 additions & 6 deletions src/editors/data/redux/app/selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ describe('app selectors unit tests', () => {
it('is memoized based on unitUrl, editorInitialized, and blockValue', () => {
expect(selectors.isInitialized.preSelectors).toEqual([
simpleSelectors.unitUrl,
simpleSelectors.editorInitialized,
simpleSelectors.blockValue,
]);
});
Expand All @@ -76,14 +75,12 @@ describe('app selectors unit tests', () => {
const truthy = {
url: { url: 'data' },
blockValue: { block: 'value' },
editorInitialized: true,
};

[
[[truthy.url, truthy.blockValue, false], false],
[[null, truthy.blockValue, true], false],
[[truthy.url, null, true], false],
[[truthy.url, truthy.blockValue, true], true],
[[null, truthy.blockValue], false],
[[truthy.url, null], false],
[[truthy.url, truthy.blockValue], true],
].map(([args, expected]) => expect(cb(...args)).toEqual(expected));
});
});
Expand Down

0 comments on commit 5200897

Please sign in to comment.