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

View File

@ -51,7 +51,13 @@ const WysiwygNav = ({
<Box padding={2} background="neutral100"> <Box padding={2} background="neutral100">
<Row justifyContent="space-between"> <Row justifyContent="space-between">
<Row> <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="h1">h1</Option>
<Option value="h2">h2</Option> <Option value="h2">h2</Option>
<Option value="h3">h3</Option> <Option value="h3">h3</Option>

View File

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

View File

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

View File

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