Skip to content

Commit

Permalink
Latest feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Jul 24, 2024
1 parent bfdd334 commit 56f1d2b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/core-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ the store state using `canUser()`, or resolved if missing.
_Parameters_

- _resource_ `string | EntityResource`: Entity resource to check. Accepts entity object `{ kind: 'root', name: 'media', id: 1 }` or REST base as a string - `media`.
- _id_ `IdType`: Optional ID of the resource to check, e.g. 10. Note: The argument will be ignored when using an entity object as a resource to check permissions.
- _id_ `IdType`: Optional ID of the resource to check, e.g. 10. Note: This argument is discouraged when using an entity object as a resource to check permissions and will be ignored.

_Returns_

Expand Down
9 changes: 4 additions & 5 deletions packages/core-data/src/hooks/use-resource-permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ function useResourcePermissions< IdType = void >(
*
* @param resource Entity resource to check. Accepts entity object `{ kind: 'root', name: 'media', id: 1 }`
* or REST base as a string - `media`.
* @param id Optional ID of the resource to check, e.g. 10. Note: The argument will be ignored
* when using an entity object as a resource to check permissions.
* @param id Optional ID of the resource to check, e.g. 10. Note: This argument is discouraged
* when using an entity object as a resource to check permissions and will be ignored.
*
* @example
* ```js
Expand Down Expand Up @@ -132,10 +132,9 @@ function useResourcePermissions< IdType = void >(
// We can't just pass `resource` as one of the deps, because if it is passed
// as an object literal, then it will be a different object on each call even
// if the values remain the same.
const resourceAsString =
typeof resource === 'object' ? JSON.stringify( resource ) : resource;

const isEntity = typeof resource === 'object';
const resourceAsString = isEntity ? JSON.stringify( resource ) : resource;

if ( isEntity && typeof id !== 'undefined' ) {
warning(
`When 'resource' is an entity object, passing 'id' as a separate argument isn't supported.`
Expand Down

0 comments on commit 56f1d2b

Please sign in to comment.