Skip to content
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 wrapper to CreatibutorsModal role SelectField #1759

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import { CreatibutorsFieldItem } from "./CreatibutorsFieldItem";
import { CREATIBUTOR_TYPE } from "./type";
import { sortOptions } from "../../utils";
import { i18next } from "@translations/invenio_rdm_records/i18next";
import { OverridableContext, overrideStore } from "react-overridable";

const overriddenComponents = overrideStore.getAll();

const creatibutorNameDisplay = (value) => {
const creatibutorType = _get(value, "person_or_org.type", CREATIBUTOR_TYPE.PERSON);
Expand Down Expand Up @@ -107,21 +110,23 @@ class CreatibutorsFieldForm extends Component {
);
})}
</List>
<CreatibutorsModal
onCreatibutorChange={this.handleOnContributorChange}
action="add"
addLabel={modal.addLabel}
editLabel={modal.editLabel}
roleOptions={sortOptions(roleOptions)}
schema={schema}
autocompleteNames={autocompleteNames}
trigger={
<Button type="button" icon labelPosition="left">
<Icon name="add" />
{addButtonLabel}
</Button>
}
/>
<OverridableContext.Provider value={overriddenComponents}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By putting the context provider here, we are risking having many nested context providers and it might have unpredicted consequences (one of them being confusion). Why not having the context provider at the level of the form rendering (RDMDepositForm in invenio-app-rdm?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkloeppe Could you look into this?

<CreatibutorsModal
onCreatibutorChange={this.handleOnContributorChange}
action="add"
addLabel={modal.addLabel}
editLabel={modal.editLabel}
roleOptions={sortOptions(roleOptions)}
schema={schema}
autocompleteNames={autocompleteNames}
trigger={
<Button type="button" icon labelPosition="left">
<Icon name="add" />
{addButtonLabel}
</Button>
}
/>
</OverridableContext.Provider>
{creatibutorsError && typeof creatibutorsError == "string" && (
<Label pointing="left" prompt>
{creatibutorsError}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import * as Yup from "yup";
import { AffiliationsField } from "./../AffiliationsField";
import { CreatibutorsIdentifiers } from "./CreatibutorsIdentifiers";
import { CREATIBUTOR_TYPE } from "./type";
import Overridable from "react-overridable";

const ModalActions = {
ADD: "add",
Expand Down Expand Up @@ -679,16 +680,18 @@ export class CreatibutorsModal extends Component {
(showPersonForm &&
_get(values, typeFieldPath) === CREATIBUTOR_TYPE.PERSON)) && (
<div>
<SelectField
fieldPath={roleFieldPath}
label={i18next.t("Role")}
options={roleOptions}
placeholder={i18next.t("Select role")}
{...(this.isCreator() && { clearable: true })}
required={!this.isCreator()}
optimized
scrolling
/>
<Overridable id="InvenioRdmRecords.Deposit.CreatibutorsModalRoleSelectField.Container">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are missing passing props to this component. Without props passed to overridable you will not be able to access any props in your overridden cmp (fe. you don't want to override fieldPath, because the form will not work)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkloeppe Could you look into this?

<SelectField
fieldPath={roleFieldPath}
label={i18next.t("Role")}
options={roleOptions}
placeholder={i18next.t("Select role")}
{...(this.isCreator() && { clearable: true })}
required={!this.isCreator()}
optimized
scrolling
/>
</Overridable>
</div>
)}
</Form>
Expand Down