Fix rich text editor content not being saved (#1202)

* Fix rich text editor content not being saved

* Add a temporary workaround to EditorJS issue
This commit is contained in:
Jakub Majorek 2021-07-01 13:23:36 +02:00 committed by GitHub
parent 88e5e75563
commit df7ac2dd45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 5 deletions

View file

@ -70,6 +70,7 @@ interface AttributeRowProps extends AttributeRowHandlers {
disabled: boolean;
error: ProductErrorWithAttributesFragment | PageErrorWithAttributesFragment;
loading: boolean;
entityId: string;
}
const AttributeRow: React.FC<AttributeRowProps> = ({
@ -85,7 +86,8 @@ const AttributeRow: React.FC<AttributeRowProps> = ({
onReferencesReorder,
onChange,
fetchAttributeValues,
fetchMoreAttributeValues
fetchMoreAttributeValues,
entityId
}) => {
const intl = useIntl();
const classes = useStyles({});
@ -160,6 +162,7 @@ const AttributeRow: React.FC<AttributeRowProps> = ({
return (
<BasicAttributeRow label={attribute.label}>
<RichTextEditor
key={entityId} // temporary workaround, TODO: refactor rich text editor
name={`attribute:${attribute.label}`}
disabled={disabled}
error={!!error}

View file

@ -44,6 +44,7 @@ export interface AttributesProps extends AttributeRowHandlers {
ProductErrorWithAttributesFragment | PageErrorWithAttributesFragment
>;
title?: React.ReactNode;
entityId?: string;
}
const useStyles = makeStyles(
@ -116,6 +117,7 @@ const Attributes: React.FC<AttributesProps> = ({
attributeValues,
errors,
title,
entityId = "_defaultId",
...props
}) => {
const intl = useIntl();
@ -162,6 +164,7 @@ const Attributes: React.FC<AttributesProps> = ({
<React.Fragment key={attribute.id}>
{attributeIndex > 0 && <Hr />}
<AttributeRow
entityId={entityId}
attribute={attribute}
attributeValues={attributeValues}
error={error}

View file

@ -42,10 +42,8 @@ const RichTextEditor: React.FC<RichTextEditorProps> = ({
holder: editorContainer.current,
logLevel: "ERROR" as LogLevels,
onChange: async api => {
if (!api.readOnly) {
const savedData = await api.saver.save();
onChange(savedData);
}
const savedData = await api.saver.save();
onChange(savedData);
},
onReady: () => {
// FIXME: This throws an error and is not working

View file

@ -227,6 +227,7 @@ const ProductVariantPage: React.FC<ProductVariantPageProps> = ({
<div>
<VariantDetailsChannelsAvailabilityCard variant={variant} />
<Attributes
entityId={variant?.id}
title={intl.formatMessage(messages.nonSelectionAttributes)}
attributes={data.attributes.filter(
attribute =>
@ -248,6 +249,7 @@ const ProductVariantPage: React.FC<ProductVariantPageProps> = ({
/>
<CardSpacer />
<Attributes
entityId={variant?.id}
title={intl.formatMessage(
messages.selectionAttributesHeader
)}