Skip to content

Conversation

djhi
Copy link
Collaborator

@djhi djhi commented Sep 25, 2025

Problem

<ReferenceInputBase> and <ReferenceArrayInputBase> are essential components that are not documented on https://marmelab.com/ra-core/

Solution

Document them

How To Test

  • make doc-headless
  • check the menu show the two components in the Inputs section
  • check their documentation pages

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • The documentation is up to date

Also, please make sure to read the contributing guidelines.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds documentation for two headless React Admin components, <ReferenceInputBase> and <ReferenceArrayInputBase>, to the headless documentation site. These are essential components for handling foreign key relationships in forms but were previously undocumented.

  • Creates comprehensive documentation for <ReferenceInputBase> and <ReferenceArrayInputBase> components
  • Adds both components to the navigation menu under the "Inputs" section
  • Provides detailed examples, props documentation, and usage patterns for each component

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
docs_headless/src/content/docs/ReferenceInputBase.md Complete documentation for the <ReferenceInputBase> component including usage examples, props table, and performance notes
docs_headless/src/content/docs/ReferenceArrayInputBase.md Complete documentation for the <ReferenceArrayInputBase> component with array-specific examples and configuration options
docs_headless/astro.config.mjs Updates navigation menu to include the two new documentation pages in the "Inputs" section

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

<ReferenceInputBase
source="company_id"
reference="companies"
enableGetChoices={({ q }) => !!(q && q.length >= 2)}
Copy link
Preview

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

The double negation !! is unnecessary here since the function should return a boolean. The expression q && q.length >= 2 already evaluates to a boolean-like value that can be returned directly.

Suggested change
enableGetChoices={({ q }) => !!(q && q.length >= 2)}
enableGetChoices={({ q }) => q && q.length >= 2}

Copilot uses AI. Check for mistakes.

<ReferenceArrayInputBase
source="tag_ids"
reference="tags"
enableGetChoices={({ q }) => q && q.length >= 2}
Copy link
Preview

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

This implementation is inconsistent with the same pattern in ReferenceInputBase.md (line 199) which uses !!(q && q.length >= 2). Consider using the same pattern in both files for consistency.

Suggested change
enableGetChoices={({ q }) => q && q.length >= 2}
enableGetChoices={({ q }) => !!(q && q.length >= 2)}

Copilot uses AI. Check for mistakes.

Comment on lines 44 to 45
const { choices, isLoading, error } = useChoicesContext();
const { field, id } = useInput();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const { choices, isLoading, error } = useChoicesContext();
const { field, id } = useInput();
const { choices, isLoading, error, source } = useChoicesContext();
const { field, id } = useInput({ source });

Not tested but I'm pretty sure you need that.

A story would have helped identify this mistake.

});
```

`<ReferenceInputBase>` handles the data fetching and provides the choices through a [`ChoicesContext`](./useChoicesContext.md). It's up to the child components to render the selection interface.
Copy link
Contributor

Choose a reason for hiding this comment

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

dead link

Comment on lines 119 to 120
const { choices, isLoading, error } = useChoicesContext();
const { field, id } = useInput();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const { choices, isLoading, error } = useChoicesContext();
const { field, id } = useInput();
const { choices, isLoading, error, source } = useChoicesContext();
const { field, id } = useInput({ source });

| `source` | Required | `string` | - | Name of the entity property to use for the input value |
| `reference` | Required | `string` | '' | Name of the reference resource, e.g. 'companies'. |
| `children` | Optional | `ReactNode` | - | The actual selection component |
| `render` | Optional | `(context) => ReactNode` | - | Function that takes the choices context and renders the selection interface |
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there is a render prop, is it? 🤔

Comment on lines 42 to 43
const { choices, isLoading, error } = useChoicesContext();
const { field, id } = useInput();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const { choices, isLoading, error } = useChoicesContext();
const { field, id } = useInput();
const { choices, isLoading, error, source } = useChoicesContext();
const { field, id } = useInput({ source });

<label key={choice.id} style={{ display: 'block' }}>
<input
type="checkbox"
name={field.name}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
name={field.name}
name={choice.name}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope, we want the field name here

});
```

`<ReferenceArrayInputBase>` handles the data fetching and provides the choices through a [`ChoicesContext`](./useChoicesContext.md). It's up to the child components to render the selection interface.
Copy link
Contributor

Choose a reason for hiding this comment

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

dead link

Comment on lines 129 to 130
const { choices, isLoading, error } = useChoicesContext();
const { field, id } = useInput();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const { choices, isLoading, error } = useChoicesContext();
const { field, id } = useInput();
const { choices, isLoading, error, source } = useChoicesContext();
const { field, id } = useInput({ source });

<label key={choice.id} style={{ display: 'block' }}>
<input
type="checkbox"
name={field.name}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
name={field.name}
name={choice.name}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Development

Successfully merging this pull request may close these issues.

2 participants