You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -18,16 +18,21 @@ For this guide, we assume that you are familiar with React and JavaScript.
18
18
The UI of InvenioRDM is composed of classic HTML web pages for mostly static content, and React web apps for very dynamic content to enhance the user experience.
19
19
While a [dedicated guide](./templates.md) describes how to override HTML web pages (Jinja templates), this guide focus on how to override React components.
20
20
21
-
InvenioRDM uses the React library [`react-overridable`](https://github.com/indico/react-overridable). The library provides a mechanism to mark React components as "overridable" by id.
22
-
Developers can define a map `{ id: Overridden React component }`, which is then applied when each React component is rendered: the overridden component is rendered instead of the default one.
21
+
InvenioRDM uses the React library [`react-overridable`](https://github.com/indico/react-overridable). The library provides a mechanism to mark React components as "overridable" by ID.
22
+
Developers can define a mapping which is then applied when each React component is rendered.
23
+
The override can be specified in one of three ways:
24
+
25
+
- completely replacing a component with a custom one
26
+
- a static override of the props passed to the component
27
+
- a 'dynamic' override of the props based on the form's state
23
28
24
29
As example for this guide, you will learn how to override the UI React component **in the upload form that marks a record as "Metadata only"**. More specifically, you will replace the "Metadata-only record" checkbox with a toggle, a "switch-like" component.
25
30
26
31

27
32
28
-
## Steps
33
+
## Guided example
29
34
30
-
### Identify how to override
35
+
### 1. Identify which component to override
31
36
32
37
At the moment, the easiest way to understand how to identify if the component that you want to override is a classic HTML component or a React component is to use the Developer Tools in your browser (e.g. [Chrome](https://developer.chrome.com/docs/devtools/) or [Firefox DevTools](https://firefox-source-docs.mozilla.org/devtools-user/)). You can inspect the code and take advantage of some useful [React browser extensions](https://beta.reactjs.org/learn/react-developer-tools) to select and inspect elements:
33
38
@@ -37,7 +42,7 @@ You can then find the component in the InvenioRDM modules source code, searching
37
42
38
43
You can always [ask for help](../../../install/troubleshoot.md#getting-help)!
39
44
40
-
### Find the React Overridable ID
45
+
### 2. Find the React Overridable ID
41
46
42
47
The easiest way to to find the ID of an overridable component is to use `react-overridable`'s built-in developer tool.
43
48
Simply open a browser console on your local instance and call the global function `reactOverridableEnableDevMode()`.
@@ -46,11 +51,11 @@ You can click a tag to copy its ID to your clipboard.
46
51
47
52

48
53
49
-
The React component's overridable ID for the '`Metadata-only record`' checkbox component is `ReactInvenioDeposit.FileUploaderToolbar.MetadataOnlyToggle.container`. It can be found in the [`invenio-rdm-records`](https://github.com/inveniosoftware/invenio-rdm-records/blob/dd72962b713f07b81699f7d5c9a8a673d585466a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/FileUploader/FileUploaderToolbar.js#L56) module.
54
+
The React component's overridable ID for the '`Metadata-only record`' checkbox component is `InvenioRdmRecords.DepositForm.FileUploaderToolbar.MetadataOnlyToggle`. It can be found in the [`invenio-rdm-records`](https://github.com/inveniosoftware/invenio-rdm-records/blob/dd72962b713f07b81699f7d5c9a8a673d585466a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/FileUploader/FileUploaderToolbar.js#L56) module.
50
55
51
-
### The mapping file
56
+
### 3. Find or create the mapping file
52
57
53
-
In a new InvenioRDM v11 or above installations, an almost empty file named `mapping.js` is available at the following path in your `assets` folder:
58
+
In new InvenioRDM v11 or above installations, a near-empty file named `mapping.js` is available at the following path in your `assets` folder:
The `const overriddenComponents` is the map that will contain all your future overridden components.
70
75
71
-
### New component creation
76
+
### 4. Create a new component creation
72
77
73
78
Let's create a new React component, very similar to the default `FileUploaderToolbar`, changing the UI component that will render. In the same file `mapping.js`, add the following code above the `const overriddenComponents`:
74
79
@@ -109,7 +114,7 @@ Now, change the map by adding your new component:
In many cases, you simply want to make a small modification to a component by changing one of its props instead of recreating the component from scratch by yourself.
136
+
This can either be done by specifying the desired prop overrides statically, or by expressing them as a function of the form state.
137
+
138
+
### Static
139
+
140
+
You can use the `parametrize` function built into `react-overridable`, into which you need to pass the component you wish to override and an object containing your props.
141
+
These props will be 'merged' with the existing props, with yours taking precedence over existing ones of the same name.
helpText:`Enter the title of your ${formValue.metadata.resource_type}`
182
+
}
183
+
}
184
+
)
185
+
}
186
+
```
187
+
188
+
The callback function is currently passed an object as its single argument, containing the following values:
189
+
190
+
-`formValues`: the raw values of the entire deposit form as given by Formik. The majority of field values are under the `metadata` key.
191
+
-`existingProps`: the props passed to the element before your override.
192
+
193
+
### Deposit form field props
194
+
195
+
The built-in fields in the deposit form (e.g. title, description, etc.) have a number of common props to make customizing basic functionality easier.
196
+
197
+
The following props may be overriden on all built-in fields:
198
+
199
+
-`label`: the user-facing short label
200
+
-`labelIcon`: the ID of the [Semantic UI Icon](https://semantic-ui.com/elements/icon.html) to include in the label
201
+
-`helpText`: a small optional text generally shown below the field, providing additional context to the user
202
+
-`placeholder`: same as the [HTML attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/placeholder)
203
+
204
+
Additionally, the following props may be overriden on fields that are not mandatory.
205
+
At the moment, this is all fields except the Resource Type, Title, Publication Date, and Creatibutors.
206
+
207
+
-`hidden`: if `true`, the field is not rendered at all
208
+
- If a field already had a value before being hidden, this will still be included in the model and will be sent to the server when the form is submitted.
209
+
- Fields retain their values when they are hidden and later re-shown.
210
+
-`disabled`: same as the [HTML attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/disabled)
211
+
-`required`: if `true`, shows a red asterisk in the field label
212
+
- This does not affect the form validation model on the frontend or the backend, and is purely a stylistic setting.
213
+
214
+
Many fields have their own props in addition to these.
215
+
Please [view the source code](https://github.com/inveniosoftware/invenio-rdm-records/tree/master/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields) for more details.
216
+
128
217
## Other examples
129
218
130
-
Let's hide completely the '`Metadata-only record`'checkbox from the upload form.
219
+
### Showing/hiding
220
+
221
+
You can completely hide a field in the deposit form, based on either a static `true`/`false` value or in response to the current state of the form.
131
222
132
-
It is possible to remove a component using the overridable strategy. In the previous example, instead of declaring a target component `MetadataToggle`you can simply change the map to:
223
+
To simply permanently hide the field, you can use something like this:
Copy file name to clipboardExpand all lines: docs/operate/customize/metadata/custom_fields/widgets.md
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,36 @@ These props are applicable to all widgets. In the reference below, only props ad
28
28
29
29
To improve consistency with the fields in the deposit form, the `icon` prop has been renamed to `labelIcon` and `description` has been renamed to `helpText`. The functionality of these props is unchanged and the old names will continue working for now, albeit with a deprecation notice.
30
30
31
+
## Dynamic behaviour
32
+
33
+
While controlling the static prop values via the [`RDM_CUSTOM_FIELDS_UI` config value](records.md#upload-deposit-form) is relatively straightforward, it doesn't allow
34
+
you to specify dynamic behaviour, such as showing/hiding the field only in specific cases, or using a different `helpText` depending on the resource type.
35
+
36
+
This can instead be done using the `dynamicParametrize` function.
37
+
For more details on its usage, [see the documentation on overriding React components](../../look-and-feel/override_components.md#dynamic).
38
+
39
+
The ID of the overridable is the internal name of your custom field (e.g. `cern:experiment`).
40
+
You can override any of the props listed on this page (except `fieldPath`), depending on the specific widget.
41
+
42
+
For example, to make the `cern:experiment` field only be shown for thesis records:
Copy file name to clipboardExpand all lines: docs/releases/vNext/upgrade-vNext.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -172,10 +172,22 @@ affected by `invenio index destroy --yes-i-know` and are totally functional afte
172
172
173
173
### Required changes
174
174
175
+
#### Overridable IDs in the deposit form
176
+
177
+
To improve consistency in naming conventions and structure, some IDs of Overridables in the deposit form have been modified. If you are overriding any of these components, you will need to change the ID in your mapping file to reflect these modifications.
178
+
179
+
The full list of ID changes [can be found here](https://github.com/inveniosoftware/invenio-rdm-records/pull/2101/files#diff-ff3c479edefad986d2fe6fe7ead575a46b086e3bbcf0ccc86d85efc4a4c63c79).
180
+
181
+
If you are not overriding any of these components, you do not need to change anything.
182
+
175
183
### Optional changes
176
184
177
185
#### Deprecations
178
186
187
+
##### Custom field widget prop names
188
+
189
+
Many [custom field widgets](../../operate/customize/metadata/custom_fields/widgets.md) used the `icon` and `description` props, which have now been deprecated and replaced with `labelIcon` and `helpText` respectively. This is to improve consistency with the naming of the built-in fields used in the deposit form and thereby avoid confusion. The old names will continue to function for now, but we recommend updating to the new names where applicable.
190
+
179
191
#### New configuration variables
180
192
181
193
These are the new configuration variables introduced in this release. Make sure that you read the related documentation before enabling them. Add them to your `invenio.cfg` as needed:
Copy file name to clipboardExpand all lines: docs/releases/vNext/version-vNext.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,10 +26,11 @@ Here is a quick summary of the myriad of other improvements in this release:
26
26
27
27
## Deprecations
28
28
29
-
29
+
- Many [custom field widgets](../../operate/customize/metadata/custom_fields/widgets.md) used the `icon` and `description` props, which have now been deprecated and replaced with `labelIcon` and `helpText` respectively. This is to improve consistency with the naming of the built-in fields used in the deposit form and thereby avoid confusion. The old names will continue to function for now.
30
30
31
31
## Breaking changes
32
32
33
+
- Overridables in the deposit form have been modified to improve consistency in structure and naming conventions. This has involved renaming the IDs of several `<Overridable>`s, but none have been removed. If you are using these IDs to override components, please see [the full list of updates](https://github.com/inveniosoftware/invenio-rdm-records/pull/2101/files#diff-ff3c479edefad986d2fe6fe7ead575a46b086e3bbcf0ccc86d85efc4a4c63c79) and change your IDs accordingly.
0 commit comments