Closed PawelSuwinski closed 2 years ago
This is intended: ResourceGuesser.registerResource
is a static call used to register the resource at the boot of React Admin.
It is mainly used to list the resources in the menu.
Once registered the first time, when the resource guesser component is mounted, it will be reregistered (in the useEffect
) with the right parameters.
Everything should work as expected, please test it.
Hmm, so it seems that it does not work that way, every resource despite its api definition has complete of operation links: For example:
# config/schema.yaml
Language:
parent: false
attributes:
ApiResource:
collectionOperations: ["get"]
itemOperations: ["get"]
localhost/admin#/languages
localhost/docs
api-platform/admin: 3.3.3
I have discovered so far that some components (toolbar/ button/ ?) are rendered multiple times before all is completed and first renders have correct setting (hasEdit
etc) but the last one is set to defaults all true
(?).
Problem solves registering ResourceDefinition Context on every render:
diff --git a/src/ResourceGuesser.tsx b/src/ResourceGuesser.tsx
index 58d3d08..0cec4a7 100644
--- a/src/ResourceGuesser.tsx
+++ b/src/ResourceGuesser.tsx
@@ -57,7 +57,7 @@ export const IntrospectedResourceGuesser = ({
useEffect(() => {
register(resourceDefinition);
- }, [register, resourceDefinition]);
+ });
return (
<Resource
But as I guess it is just symptomatic treatment (?) and it needs diving deeper.
It should be solved by https://github.com/api-platform/admin/pull/471.
Description
Default ResourceGuesser does not take the operation into account, only midware component used by it does: https://github.com/api-platform/admin/blob/363d33ccd0a488b05aea450347cd2d0ab164f468/src/ResourceGuesser.tsx#L32-L44
but all setting (
hasEdit
etc) again set to true at the end at resourceDeinition: https://github.com/api-platform/admin/blob/363d33ccd0a488b05aea450347cd2d0ab164f468/src/ResourceGuesser.tsx#L84-L94Is it intend so and I should use IntrospecedResourceGueser component by explicit manually to have this feature on or it is kind of unfinished feature?