diff --git a/package-lock.json b/package-lock.json
index 3a60d280..b36d0ffb 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -6,7 +6,7 @@
"packages": {
"": {
"name": "react-invenio-forms",
- "version": "2.8.4",
+ "version": "3.0.0",
"license": "MIT",
"devDependencies": {
"@babel/cli": "^7.5.0",
diff --git a/src/lib/forms/widgets/custom_fields/Extensions.js b/src/lib/forms/widgets/custom_fields/AddDiscoverableFieldsModal.js
similarity index 78%
rename from src/lib/forms/widgets/custom_fields/Extensions.js
rename to src/lib/forms/widgets/custom_fields/AddDiscoverableFieldsModal.js
index 7e745095..ef7bb208 100644
--- a/src/lib/forms/widgets/custom_fields/Extensions.js
+++ b/src/lib/forms/widgets/custom_fields/AddDiscoverableFieldsModal.js
@@ -6,6 +6,7 @@
// under the terms of the MIT License; see LICENSE file for more details.
import React, { Component } from "react";
+import { RemoveField } from "./RemoveField";
import { ListAndFilterCustomFields } from "./ListAndFilterCustomFields";
import { importWidget } from "../loader";
@@ -13,7 +14,7 @@ import { Button, Icon, Modal, Divider } from "semantic-ui-react";
import PropTypes from "prop-types";
-export class Extensions extends Component {
+export class AddDiscoverableFieldsModal extends Component {
constructor(props) {
super(props);
const { existingFields } = props;
@@ -61,20 +62,26 @@ export class Extensions extends Component {
} = this.state;
const { fieldPath, templateLoaders, addFieldCallback } = this.props;
this.setState({ loading: true });
+ selectedField["props"]["label"] = (
+
+ );
+
const field = await importWidget(templateLoaders, {
...selectedField,
fieldPath: `${fieldPath}.${selectedField.field}`,
});
-
- const performCallback = (selectedFieldTarget) => {
+ const performCallback = () => {
const { addFields } = this.state;
-
- if (withClose) {
- addFieldCallback(addFields);
- this.setState({ addFields: [], existingFields: [] });
- this.handleModalClosed();
- }
+ addFieldCallback(addFields);
+ this.setState({ addFields: [] });
+ this.handleModalClosed();
};
+
selectedFieldTarget.classList.toggle("selected-background");
this.setState(
{
@@ -84,7 +91,7 @@ export class Extensions extends Component {
selectedFieldTarget: undefined,
loading: false,
},
- () => performCallback(selectedFieldTarget)
+ () => (withClose ? performCallback() : null)
);
};
@@ -96,6 +103,13 @@ export class Extensions extends Component {
this.handleModalClosed();
};
+ handleRemoveField = (field) => {
+ const { existingFields: prevExisting } = this.state;
+ const { removeFieldCallback } = this.props;
+ const updatedFields = prevExisting.filter((n) => field.key !== n);
+ this.setState({ existingFields: [...updatedFields] });
+ removeFieldCallback(field);
+ };
render() {
const {
fieldPath, // injected by the custom field loader via the `field` config property
@@ -104,14 +118,14 @@ export class Extensions extends Component {
record,
templateLoaders,
addFieldCallback,
+ removeFieldCallback,
sections,
- existingFields: selected,
+ existingFields: _,
...fieldsList
} = this.props;
- const { modalOpen, existingFields, loading } = this.state;
+ const { modalOpen, existingFields, loading, selectedField } = this.state;
return (
<>
-
+ }
+ />
+ >
+ );
+ }
+}
+
+RemoveField.propTypes = {
+ field: PropTypes.object.isRequired,
+ fieldPath: PropTypes.string.isRequired,
+ label: PropTypes.string.isRequired,
+ removeFieldCallback: PropTypes.func.isRequired,
+};
diff --git a/src/lib/forms/widgets/custom_fields/index.js b/src/lib/forms/widgets/custom_fields/index.js
index a8c85b78..b57a438d 100644
--- a/src/lib/forms/widgets/custom_fields/index.js
+++ b/src/lib/forms/widgets/custom_fields/index.js
@@ -1,2 +1 @@
export { CustomFields } from "./CustomFields";
-export { Extensions } from "./Extensions";