Skip to content

overridable: add dynamicParametrize function #300

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

palkerecsenyi
Copy link
Member

@palkerecsenyi palkerecsenyi commented Jul 17, 2025

Closes #299

Note: may cause conflicts when merging at the same time as #298, I am happy to resolve these whenever we are ready.


Description

  • Added a function to 'dynamically' parametrize a component, based on values from the context. Currently, this includes the field values stored in Formik, but we can easily add more values from the React context as needed.

  • The user can implement a function that receives these input values and returns the override props for a given Overridable component. They need to import the dynamicParametrize function from the top level of this module, as well as the component they want to override.

  • dynamicParametrize might currently throw an error if used on a component that's rendered outside of the Formik context

Usage example

import { dynamicParametrize } from "react-invenio-forms";
import { TitlesField } from "@js/invenio_rdm_records/src/deposit/fields";

export const overriddenComponents = {
  "InvenioRdmRecords.DepositForm.TitlesField": dynamicParametrize(
    TitlesField,
    (args) => {
      return {
        hidden: args.formValues.metadata.resource_type !== "dataset",
      };
    }
  ),
};
Kooha-2025-07-17-15-42-47.webm

* Added a function to 'dynamically' parametrize a component, based on
values from the context. Currently, this includes the field values
stored in Formik, but we can easily add more values from the React
context as needed.

* The user can implement a function that receives these input values and
returns the override props for a given `Overridable` component. They
need to import the `dynamicParametrize` function from the top level of
this module, as well as the component they want to override.

* `dynamicParametrize` might currently throw an error if used on a
component that's rendered outside of the Formik context
* If the user wants to base their dynamic prop override on some existing
prop values (e.g. filtering the options of a dropdown according to the
value of another field), it is significantly easier for them if these
values are available through the `propsFactory` function
@palkerecsenyi palkerecsenyi marked this pull request as ready for review July 18, 2025 12:39
Copy link
Contributor

@sakshamarora1 sakshamarora1 left a comment

Choose a reason for hiding this comment

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

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deposit: Add support for dynamic field prop overrides
4 participants