-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add overridable tags #287
Add overridable tags #287
Changes from 3 commits
8db39eb
dd898a2
3dd61ea
80a1591
908e329
55f16c5
37e7846
9c3dba9
8093de8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,6 +12,8 @@ import { TextField, RemoteSelectField } from "react-invenio-forms"; | |||||
import { i18next } from "@translations/invenio_rdm_records/i18next"; | ||||||
import _isEmpty from "lodash/isEmpty"; | ||||||
|
||||||
import Overridable from "react-overridable"; | ||||||
|
||||||
function CustomAwardForm({ deserializeFunder, selectedFunding }) { | ||||||
function deserializeFunderToDropdown(funderItem) { | ||||||
let funderName = null; | ||||||
|
@@ -48,64 +50,73 @@ function CustomAwardForm({ deserializeFunder, selectedFunding }) { | |||||
|
||||||
return ( | ||||||
<Form> | ||||||
<RemoteSelectField | ||||||
fieldPath="selectedFunding.funder.id" | ||||||
suggestionAPIUrl="/api/funders" | ||||||
suggestionAPIHeaders={{ | ||||||
Accept: "application/vnd.inveniordm.v1+json", | ||||||
}} | ||||||
placeholder={i18next.t("Search for a funder by name")} | ||||||
serializeSuggestions={(funders) => { | ||||||
return funders.map((funder) => | ||||||
deserializeFunderToDropdown(deserializeFunder(funder)) | ||||||
); | ||||||
}} | ||||||
searchInput={{ | ||||||
autoFocus: _isEmpty(selectedFunding), | ||||||
}} | ||||||
label={i18next.t("Funder")} | ||||||
noQueryMessage={i18next.t("Search for funder...")} | ||||||
clearable | ||||||
allowAdditions={false} | ||||||
multiple={false} | ||||||
selectOnBlur={false} | ||||||
selectOnNavigation={false} | ||||||
required | ||||||
search={(options) => options} | ||||||
isFocused | ||||||
onValueChange={({ formikProps }, selectedFundersArray) => { | ||||||
if (selectedFundersArray.length === 1) { | ||||||
const selectedFunder = selectedFundersArray[0]; | ||||||
if (selectedFunder) { | ||||||
const deserializedFunder = serializeFunderFromDropdown(selectedFunder); | ||||||
formikProps.form.setFieldValue( | ||||||
"selectedFunding.funder", | ||||||
deserializedFunder | ||||||
); | ||||||
<Overridable id="InvenioVocabularies.CustomAwardForm.RemoteSelectField.SelectedFundingFunderId"> | ||||||
<RemoteSelectField | ||||||
fieldPath="selectedFunding.funder.id" | ||||||
suggestionAPIUrl="/api/funders" | ||||||
suggestionAPIHeaders={{ | ||||||
Accept: "application/vnd.inveniordm.v1+json", | ||||||
}} | ||||||
placeholder={i18next.t("Search for a funder by name")} | ||||||
serializeSuggestions={(funders) => { | ||||||
return funders.map((funder) => | ||||||
deserializeFunderToDropdown(deserializeFunder(funder)) | ||||||
); | ||||||
}} | ||||||
searchInput={{ | ||||||
autoFocus: _isEmpty(selectedFunding), | ||||||
}} | ||||||
label={i18next.t("Funder")} | ||||||
noQueryMessage={i18next.t("Search for funder...")} | ||||||
clearable | ||||||
allowAdditions={false} | ||||||
multiple={false} | ||||||
selectOnBlur={false} | ||||||
selectOnNavigation={false} | ||||||
required | ||||||
search={(options) => options} | ||||||
isFocused | ||||||
onValueChange={({ formikProps }, selectedFundersArray) => { | ||||||
if (selectedFundersArray.length === 1) { | ||||||
const selectedFunder = selectedFundersArray[0]; | ||||||
if (selectedFunder) { | ||||||
const deserializedFunder = serializeFunderFromDropdown(selectedFunder); | ||||||
formikProps.form.setFieldValue( | ||||||
"selectedFunding.funder", | ||||||
deserializedFunder | ||||||
); | ||||||
} | ||||||
} | ||||||
} | ||||||
}} | ||||||
/> | ||||||
|
||||||
<Header as="h3" size="small"> | ||||||
{i18next.t("Award information")} ({i18next.t("optional")}) | ||||||
</Header> | ||||||
<Form.Group widths="equal"> | ||||||
<TextField | ||||||
label={i18next.t("Number")} | ||||||
placeholder={i18next.t("Award number")} | ||||||
fieldPath="selectedFunding.award.number" | ||||||
/> | ||||||
<TextField | ||||||
label={i18next.t("Title")} | ||||||
placeholder={i18next.t("Award Title")} | ||||||
fieldPath="selectedFunding.award.title" | ||||||
/> | ||||||
<TextField | ||||||
label={i18next.t("URL")} | ||||||
placeholder={i18next.t("Award URL")} | ||||||
fieldPath="selectedFunding.award.url" | ||||||
}} | ||||||
/> | ||||||
</Overridable> | ||||||
<Overridable id="InvenioVocabularies.CustomAwardForm.AwardInformation.Header"> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<Header as="h3" size="small"> | ||||||
{i18next.t("Award information")} ({i18next.t("optional")}) | ||||||
</Header> | ||||||
</Overridable> | ||||||
<Form.Group widths="equal"> | ||||||
<Overridable id="InvenioVocabularies.CustomAwardForm.AwardNumber.TextField"> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<TextField | ||||||
label={i18next.t("Number")} | ||||||
placeholder={i18next.t("Award number")} | ||||||
fieldPath="selectedFunding.award.number" | ||||||
/> | ||||||
</Overridable> | ||||||
<Overridable id="InvenioVocabularies.CustomAwardForm.AwardTitle.TextField"> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<TextField | ||||||
label={i18next.t("Title")} | ||||||
placeholder={i18next.t("Award Title")} | ||||||
fieldPath="selectedFunding.award.title" | ||||||
/> | ||||||
</Overridable> | ||||||
<Overridable id="InvenioVocabularies.CustomAwardForm.AwardUrl.TextField"> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<TextField | ||||||
label={i18next.t("URL")} | ||||||
placeholder={i18next.t("Award URL")} | ||||||
fieldPath="selectedFunding.award.url" | ||||||
/> | ||||||
</Overridable> | ||||||
</Form.Group> | ||||||
</Form> | ||||||
); | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -18,6 +18,8 @@ import FundingModal from "./FundingModal"; | |||||
|
||||||
import { i18next } from "@translations/invenio_rdm_records/i18next"; | ||||||
|
||||||
import Overridable from "react-overridable"; | ||||||
|
||||||
function FundingFieldForm(props) { | ||||||
const { | ||||||
label, | ||||||
|
@@ -108,46 +110,52 @@ function FundingFieldForm(props) { | |||||
); | ||||||
})} | ||||||
</List> | ||||||
<FundingModal | ||||||
searchConfig={searchConfig} | ||||||
trigger={ | ||||||
<Button | ||||||
type="button" | ||||||
key="custom" | ||||||
icon | ||||||
labelPosition="left" | ||||||
className="mb-5" | ||||||
> | ||||||
<Icon name="add" /> | ||||||
{i18next.t("Add award")} | ||||||
</Button> | ||||||
} | ||||||
onAwardChange={(selectedFunding) => { | ||||||
formikArrayPush(selectedFunding); | ||||||
}} | ||||||
mode="standard" | ||||||
action="add" | ||||||
deserializeAward={deserializeAward} | ||||||
deserializeFunder={deserializeFunder} | ||||||
computeFundingContents={computeFundingContents} | ||||||
/> | ||||||
<FundingModal | ||||||
searchConfig={searchConfig} | ||||||
trigger={ | ||||||
<Button type="button" key="custom" icon labelPosition="left"> | ||||||
<Icon name="add" /> | ||||||
{i18next.t("Add custom")} | ||||||
</Button> | ||||||
} | ||||||
onAwardChange={(selectedFunding) => { | ||||||
formikArrayPush(selectedFunding); | ||||||
}} | ||||||
mode="custom" | ||||||
action="add" | ||||||
deserializeAward={deserializeAward} | ||||||
deserializeFunder={deserializeFunder} | ||||||
computeFundingContents={computeFundingContents} | ||||||
/> | ||||||
|
||||||
<Overridable id="InvenioVocabularies.FundingField.AddAward.Button"> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I would go with a common container for the actions of this field, rather than wrapping each element separately. There might be more action buttons that can be added to this field, and common container allows for more flexibility as well as it reduces the amount of unique overridable IDs that we need to maintain in the code base There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We actually need these separate ids on individual elements since we just want to hide one of these buttons (we only want to allow adding custom awards in our project) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there would be less flexibility in wrapping the common container. You would have to override each element (including those you want to keep) and even the possible future elements, wouldn't you? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand your point, and you are right on the fact we should allow overriding each of the elements as well. In this case, however, the overridable ID should be added in the component itself - either on the
both wrapping two instantiations of I am happy to explain it more in details on how this naming convention was planned to be used over a call. |
||||||
<FundingModal | ||||||
searchConfig={searchConfig} | ||||||
trigger={ | ||||||
<Button | ||||||
type="button" | ||||||
key="custom" | ||||||
icon | ||||||
labelPosition="left" | ||||||
className="mb-5" | ||||||
> | ||||||
<Icon name="add" /> | ||||||
{i18next.t("Add award")} | ||||||
</Button> | ||||||
} | ||||||
onAwardChange={(selectedFunding) => { | ||||||
formikArrayPush(selectedFunding); | ||||||
}} | ||||||
mode="standard" | ||||||
action="add" | ||||||
deserializeAward={deserializeAward} | ||||||
deserializeFunder={deserializeFunder} | ||||||
computeFundingContents={computeFundingContents} | ||||||
/> | ||||||
</Overridable> | ||||||
|
||||||
<Overridable id="InvenioVocabularies.FundingField.AddCustom.Button"> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<FundingModal | ||||||
searchConfig={searchConfig} | ||||||
trigger={ | ||||||
<Button type="button" key="custom" icon labelPosition="left"> | ||||||
<Icon name="add" /> | ||||||
{i18next.t("Add custom")} | ||||||
</Button> | ||||||
} | ||||||
onAwardChange={(selectedFunding) => { | ||||||
formikArrayPush(selectedFunding); | ||||||
}} | ||||||
mode="custom" | ||||||
action="add" | ||||||
deserializeAward={deserializeAward} | ||||||
deserializeFunder={deserializeFunder} | ||||||
computeFundingContents={computeFundingContents} | ||||||
/> | ||||||
</Overridable> | ||||||
</Form.Field> | ||||||
</DndProvider> | ||||||
); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.