Skip to content

Commit

Permalink
FIX Reload element form when element version changes
Browse files Browse the repository at this point in the history
The form will be reloaded when the element is
saved/published/unpublished, etc - but only if its version or
versioned-state is changing.
  • Loading branch information
GuySartorelli committed May 30, 2024
1 parent 0093776 commit ee6a200
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
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,
version: PropTypes.number
});

Expand Down

0 comments on commit ee6a200

Please sign in to comment.