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

Introduce useResourceLabel hook #6016

Merged
merged 8 commits into from
Mar 18, 2021
Merged

Introduce useResourceLabel hook #6016

merged 8 commits into from
Mar 18, 2021

Conversation

djhi
Copy link
Contributor

@djhi djhi commented Mar 8, 2021

  • Introduce hook
  • Use the hook where possible (menu, page titles, etc.)

@djhi djhi added the RFR Ready For Review label Mar 8, 2021
@djhi djhi added this to the 3.14 milestone Mar 8, 2021
@djhi djhi added WIP Work In Progress RFR Ready For Review and removed RFR Ready For Review WIP Work In Progress labels Mar 9, 2021
const resources = useSelector(getResources);
const translate = useTranslate();

return (resource: string, pluralize = true): string => {
Copy link
Member

Choose a reason for hiding this comment

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

Why is it a higher-order function and why isn't the hook simply returning the label? This needs to be explained in the jsDoc I think.

* smart_count: 1,
* _: inflection.humanize(inflection.singularize(resource)),
* });
* const resourceName = useResourceLabel(resource, false);
Copy link
Member

Choose a reason for hiding this comment

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

bad syntax: it returns a function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


/**
* A hook which will return a translated resource name. It will use the label option of the `Resource` component if provided.
*
Copy link
Member

Choose a reason for hiding this comment

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

could you add a usage example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

packages/ra-ui-materialui/src/list/Empty.tsx Show resolved Hide resolved
Copy link
Member

@fzaninotto fzaninotto left a comment

Choose a reason for hiding this comment

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

Seing the code is use, I find the API perfectible. The second parameter, true, isn't very readable if one doesn't know the signature of the hook. Why not pass an options object instead?

-getResourceLabel(resource, true)
+getResourceLabel(resource, { smart_count: 1 })

packages/ra-ui-materialui/src/list/Empty.tsx Show resolved Hide resolved
Copy link
Member

@fzaninotto fzaninotto left a comment

Choose a reason for hiding this comment

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

Needs another rebase...

packages/ra-core/src/core/useResourceContext.ts Outdated Show resolved Hide resolved
@fzaninotto
Copy link
Member

needs rebase

@fzaninotto fzaninotto merged commit e03b3b6 into next Mar 18, 2021
@fzaninotto fzaninotto deleted the use-resource-label branch March 18, 2021 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants