Skip to content

Commit

Permalink
Show field type on edit in schemawidget.
Browse files Browse the repository at this point in the history
  • Loading branch information
robgietema committed Dec 17, 2024
1 parent 2f993ce commit 27ec419
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions packages/volto/src/components/manage/Widgets/SchemaWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { compose } from 'redux';
import PropTypes from 'prop-types';
import {
concat,
find,
findIndex,
isString,
keys,
Expand All @@ -23,6 +24,7 @@ import { defineMessages, injectIntl } from 'react-intl';
import config from '@plone/volto/registry';
import { injectLazyLibs } from '@plone/volto/helpers/Loadable/Loadable';
import { slugify } from '@plone/volto/helpers/Utils/Utils';
import { getVocabulary } from '@plone/volto/actions';

import SchemaWidgetFieldset from '@plone/volto/components/manage/Widgets/SchemaWidgetFieldset';
import { Field, ModalForm } from '@plone/volto/components/manage/Form';
Expand Down Expand Up @@ -897,6 +899,10 @@ class SchemaWidget extends Component {
* On change handler
*/
onChange: PropTypes.func.isRequired,
/**
* Get vocabulary action
*/
getVocabulary: PropTypes.func.isRequired,
};

/**
Expand Down Expand Up @@ -951,6 +957,19 @@ class SchemaWidget extends Component {
};
}

/**
* Component did mount
* @method componentDidMount
* @returns {undefined}
*/
componentDidMount() {
this.props.getVocabulary({
vocabNameOrURL: 'Fields',
size: -1,
subrequest: 'schemawidget',
});
}

/**
* Add field handler
* @method onAddField
Expand Down Expand Up @@ -1480,6 +1499,17 @@ class SchemaWidget extends Component {
if (!this.props.value) {
return '';
}
const choices = [...this.props.fields, ...this.props.additionalFactory];
let editFieldType = '';
if (this.state.editField) {
const fieldType = find(choices, {
value: this.props.value.properties[this.state.editField.id].factory,
});
editFieldType = this.props.intl.formatMessage({
id: fieldType.value,
defaultMessage: fieldType.label,
});
}
const nonUserCreatedFields = this.props.value.fieldsets[
this.state.currentFieldset
].fields.filter(
Expand Down Expand Up @@ -1748,7 +1778,7 @@ class SchemaWidget extends Component {
<ModalForm
onSubmit={this.onEditField}
onCancel={this.onCancel}
title={this.props.intl.formatMessage(messages.editField)}
title={`${this.props.intl.formatMessage(messages.editField)}: ${editFieldType}`}
formData={{
...this.props.value.properties[this.state.editField.id],
id: this.state.editField.id,
Expand Down Expand Up @@ -1825,7 +1855,9 @@ export default compose(
connect(
(state, props) => ({
value: isString(props.value) ? JSON.parse(props.value) : props.value,
fields:
state.vocabularies?.Fields?.subrequests?.schemawidget?.items || [],
}),
{},
{ getVocabulary },
),
)(SchemaWidget);

0 comments on commit 27ec419

Please sign in to comment.