Fix props

Signed-off-by: soupette <cyril@strapi.io>
This commit is contained in:
soupette 2021-09-22 07:39:04 +02:00
parent 88f8931e9b
commit a63441757e
5 changed files with 28 additions and 9 deletions

View File

@ -15,6 +15,7 @@ const Editor = ({
name,
onChange,
placeholder,
shouldSetValueAfterExpand,
textareaRef,
value,
}) => {
@ -34,15 +35,20 @@ const Editor = ({
if (initialValueRef.current) {
editorRef.current.setValue(initialValueRef.current);
// initialValueRef.current = value;
}
CodeMirror.commands.newlineAndIndentContinueMarkdownList = newlineAndIndentContinueMarkdownList;
editorRef.current.on('change', doc =>
onChangeRef.current({ target: { name, value: doc.getValue(), type: 'wysiwyg' } })
);
editorRef.current.on('change', doc => {
onChangeRef.current({ target: { name, value: doc.getValue(), type: 'wysiwyg' } });
});
}, [editorRef, textareaRef, name]);
useEffect(() => {
if (shouldSetValueAfterExpand && value) {
editorRef.current.setValue(value);
}
}, [editorRef, shouldSetValueAfterExpand, value]);
useEffect(() => {
if (isPreviewMode || disabled) {
editorRef.current.setOption('readOnly', 'nocursor');
@ -75,6 +81,7 @@ Editor.defaultProps = {
error: undefined,
isPreviewMode: false,
placeholder: '',
shouldSetValueAfterExpand: false,
value: '',
};
@ -86,6 +93,7 @@ Editor.propTypes = {
name: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
placeholder: PropTypes.string,
shouldSetValueAfterExpand: PropTypes.bool,
textareaRef: PropTypes.shape({ current: PropTypes.any }).isRequired,
value: PropTypes.string,
};

View File

@ -51,7 +51,13 @@ const WysiwygNav = ({
<Box padding={2} background="neutral100">
<Row justifyContent="space-between">
<Row>
<Select disabled id="selectTitle" placeholder={selectPlaceholder} size="S">
<Select
disabled
id="selectTitle"
placeholder={selectPlaceholder}
size="S"
aria-label={selectPlaceholder}
>
<Option value="h1">h1</Option>
<Option value="h2">h2</Option>
<Option value="h3">h3</Option>

View File

@ -67,6 +67,7 @@ const Wysiwyg = ({
const [isPreviewMode, setIsPreviewMode] = useState(false);
const [mediaLibVisible, setMediaLibVisible] = useState(false);
const [isExpandMode, setIsExpandMode] = useState(false);
const [shouldSetValueAfterExpand, setShouldSetValueAfterExpand] = useState(false);
const handleToggleMediaLib = () => setMediaLibVisible(prev => !prev);
const handleTogglePopover = () => setVisiblePopover(prev => !prev);
@ -121,9 +122,10 @@ const Wysiwyg = ({
const handleToggleExpand = collapse => {
setIsExpandMode(prev => !prev);
setShouldSetValueAfterExpand(false);
if (collapse === 'collapse' && value !== undefined) {
editorRef.current.setValue(value);
if (collapse === 'collapse' && value) {
setShouldSetValueAfterExpand(true);
}
};
@ -151,6 +153,7 @@ const Wysiwyg = ({
name={name}
onChange={onChange}
placeholder={formattedPlaceholder}
shouldSetValueAfterExpand={shouldSetValueAfterExpand}
textareaRef={textareaRef}
value={value}
/>

View File

@ -43,6 +43,7 @@ const Informations = () => {
<Text bold>
{formatMessage({
id: getTrad('containers.Edit.information.lastUpdate'),
defaultMessage: 'Last update',
})}
</Text>
<Text>{formatRelativeTime(value, unit, { numeric: 'auto' })}</Text>
@ -51,6 +52,7 @@ const Informations = () => {
<Text bold>
{formatMessage({
id: getTrad('containers.Edit.information.by'),
defaultMessage: 'By',
})}
</Text>
<Text>{isCreatingEntry ? '-' : updatedBy}</Text>

View File

@ -160,7 +160,7 @@ describe('CONTENT MANAGER | EditView | Header', () => {
<span
class="c8"
>
content-manager.containers.Edit.information.lastUpdate
Last update
</span>
<span
class="c9"
@ -174,7 +174,7 @@ describe('CONTENT MANAGER | EditView | Header', () => {
<span
class="c8"
>
content-manager.containers.Edit.information.by
By
</span>
<span
class="c9"