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

edit / show title prop: add 'false' and callback choices #9770

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

Conversation

hiaselhans
Copy link
Contributor

follow-up from #9768 to change branch

This PR adds two more choices to the 'title' prop of edit / show views:

  • false to display no title
  • callback with signature (arg0?: RaRecord) => string

I found this to be the most flexible and efficient way to inject a title

@hiaselhans hiaselhans changed the title Page title next edit / show title prop: add 'false' and callback choices Apr 11, 2024
@djhi djhi added this to the 5.0.0 milestone Apr 12, 2024
Copy link
Contributor

@slax57 slax57 left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution 😊

Two more things I'd like to add to the following comments:

  • I saw the following warning in the console while testing: Warning: Failed prop type: Invalid prop `title` supplied to `Show`, expected a ReactNode.. You may have forgotten to update a propTypes declaration somewhere.
  • I'd like to have the approval of @fzaninotto or @djhi on the feature before merging. Guys wdyt?

@@ -71,7 +71,9 @@ That's enough to display the post show view above.
| `queryOptions` | Optional | `object` | | The options to pass to the `useQuery` hook
| `resource` | Optional | `string` | | The resource name, e.g. `posts`
| `sx` | Optional | `object` | | Override or extend the styles applied to the component
| `title` | Optional | `string | ReactElement` | | The title to display in the App Bar
| `title` | Optional | *titleType | | The title to display in the App Bar see [Edit](./Edit.md#title)
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick (non-blocking): ‏You could also add another example in the title section of this doc, just like you did for Edit.

<Title
title={newTitle}
defaultTitle={defaultTitle}
preferenceKey={`${resource}.show.title`}
Copy link
Contributor

Choose a reason for hiding this comment

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

issue:

Suggested change
preferenceKey={`${resource}.show.title`}
preferenceKey={`${resource}.edit.title`}

Comment on lines +135 to +139
it('should display a custom title', async () => {
render(<CustomTitle />);
await screen.findByText('book_1_test');
});

Copy link
Contributor

Choose a reason for hiding this comment

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

question: ‏Why not add tests for Edit too?

Comment on lines +68 to +70
export type ShowViewProps<RecordType extends RaRecord = any> = ShowProps<
RecordType
>;
Copy link
Contributor

Choose a reason for hiding this comment

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

question: ‏Why did you need that change?

| string
| ReactElement
| false
| ((arg0: RecordType | undefined) => string);
Copy link
Contributor

Choose a reason for hiding this comment

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

polish:

Suggested change
| ((arg0: RecordType | undefined) => string);
| ((record: RecordType | undefined) => string);

| string
| ReactElement
| false
| ((arg0: RecordType | undefined) => string);
Copy link
Contributor

Choose a reason for hiding this comment

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

polish:

Suggested change
| ((arg0: RecordType | undefined) => string);
| ((record: RecordType | undefined) => string);

@slax57
Copy link
Contributor

slax57 commented Apr 15, 2024

Got the approval! 🎉

Also, realizing this will also fix #9695

@slax57 slax57 added the v5 label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants