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

FIX Reload element form when element version changes #1200

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
4 changes: 2 additions & 2 deletions client/dist/js/bundle.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions client/src/components/ElementEditor/Content.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { elementType } from 'types/elementType';
import { inject } from 'lib/Injector';
import { compose } from 'redux';
import { connect } from 'react-redux';
Expand All @@ -10,7 +11,7 @@ import getFormState from 'lib/getFormState';
class Content extends PureComponent {
render() {
const {
id,
element,
fileUrl,
fileTitle,
content,
Expand Down Expand Up @@ -40,7 +41,7 @@ class Content extends PureComponent {
<InlineEditFormComponent
extraClass={{ 'element-editor-editform--collapsed': !previewExpanded }}
onClick={(event) => event.stopPropagation()}
elementId={id}
element={element}
activeTab={activeTab}
onFormInit={onFormInit}
handleLoadingError={handleLoadingError}
Expand All @@ -60,7 +61,7 @@ class Content extends PureComponent {
}

Content.propTypes = {
id: PropTypes.string,
element: elementType,
content: PropTypes.string,
fileUrl: PropTypes.string,
fileTitle: PropTypes.string,
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/ElementEditor/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class Element extends Component {
{
!childRenderingError &&
<ContentComponent
id={element.id}
element={element}
fileUrl={element.blockSchema.fileURL}
fileTitle={element.blockSchema.fileTitle}
content={this.getSummary(element, type)}
Expand Down
12 changes: 8 additions & 4 deletions client/src/components/ElementEditor/InlineEditForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { elementType } from 'types/elementType';
import FormBuilderLoader from 'containers/FormBuilderLoader/FormBuilderLoader';
import { loadElementSchemaValue } from 'state/editor/loadElementSchemaValue';
import i18n from 'i18n';
Expand Down Expand Up @@ -42,17 +43,20 @@ class InlineEditForm extends PureComponent {
}

render() {
const { elementId, extraClass, onClick, onFormInit, formHasState } = this.props;
const { element, extraClass, onClick, onFormInit, formHasState } = this.props;
const { loadingError } = this.state;

const classNames = classnames('element-editor-editform', extraClass);
const schemaUrl = loadElementSchemaValue('schemaUrl', elementId);
const schemaUrl = loadElementSchemaValue('schemaUrl', element.id);

const formProps = {
formTag: 'div',
schemaUrl,
identifier: 'element',
refetchSchemaOnMount: !formHasState,
// Reload the form any time the element version changes, so other react components
// within the form have their state completely recreated
refetchSchemaCriteria: JSON.stringify([element.version, element.isPublished, element.isLiveVersion]),
onLoadingError: this.handleLoadingError,
};

Expand All @@ -75,12 +79,12 @@ class InlineEditForm extends PureComponent {
InlineEditForm.propTypes = {
extraClass: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
onClick: PropTypes.func,
elementId: PropTypes.string,
element: elementType,
handleLoadingError: PropTypes.func,
};

function mapStateToProps(state, ownProps) {
const formName = loadElementFormStateName(ownProps.elementId);
const formName = loadElementFormStateName(ownProps.element.id);

return {
formHasState: state.form.formState && state.form.formState.element &&
Expand Down
4 changes: 2 additions & 2 deletions client/src/types/elementType.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const elementType = PropTypes.shape({
title: PropTypes.string,
blockSchema: PropTypes.object,
inlineEditable: PropTypes.bool,
published: PropTypes.bool,
liveVersion: PropTypes.bool,
isPublished: PropTypes.bool,
isLiveVersion: PropTypes.bool,
Comment on lines -9 to +10
Copy link
Member Author

@GuySartorelli GuySartorelli May 30, 2024

Choose a reason for hiding this comment

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

sort-of-unrelated refactoring - I noticed these were wrong when I tried to use the old keys but they kept showing undefined

version: PropTypes.number
});

Expand Down
Loading