-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
React-admin 3 #263
React-admin 3 #263
Conversation
@fzaninotto It would be great if you could have a look 🙂 |
src/hydra/HydraAdmin.js
Outdated
authProvider, | ||
i18nProvider, | ||
history = createHashHistory(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT about making it configurable to support also browser history?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a prop so you can pass whatever you want (for example an instance of createBrowserHistory
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add info about this change to "Things done:" because it was not possible before :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure 🙂
Thanks, looking Forward . |
Tested on a fresh project after an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job @alanpoulain 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Encouraging!
src/AdminGuesser.test.js
Outdated
loading: false, | ||
}, | ||
)} | ||
{AdminGuesserComponent({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's strange (and misleading) to call a component function instead of rendering it. See https://kentcdodds.com/blog/dont-call-a-react-function-component for details.
Why don't you do
<Provider store={store}>
<AdminGuesserComponent error="..." resources={resources} fetching={false} />
</Provider>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it has been done this way because the ShallowRenderer
from react-test-renderer
only allows to render the component "one level deep" and using the Provider
is necessary.
See: https://reactjs.org/docs/shallow-renderer.html#overview
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean in tests? Then don't use shallow rendering, use react-testing-library instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Provider
was not needed anymore so we can keep the react-test-renderer
.
src/AdminGuesser.js
Outdated
<Loading /> | ||
</TranslationProvider> | ||
); | ||
export const AdminGuesserComponent = ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"XXXComponent" is a bad name for a component. You don't name your classes "XXXClass", do you?
@@ -0,0 +1,11 @@ | |||
root = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it normal that you commit this file? It feels user based, not project based.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fzaninotto The whole purpose of this file is to define common options for files' formatting, so everyone working on the project can (with support from IDEs) enforce the same configuration without any manual work. With this you won't get unintentional whitespace diffs. It should be commited to work.
The question is: do project maintainers want this file and current configuration fits project's standards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me (we have it on every other API Platform projects).
README.md
Outdated
import ReactDOM from 'react-dom'; | ||
import { AdminGuesser, hydra } from '@api-platform/admin'; | ||
|
||
const Admin = () => <AdminGuesser dataProvider={hydra.dataProvider("https://demo.api-platform.com")} resourceSchemaAnalyzer={hydra.resourceSchemaAnalyzer()} /> // Use your custom data provider or resource schema analyzer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add line breaks to make it more readable.
Hint: ask prettier to do it for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, resourceSchemaAnalyzer
is long. Why not simply use schemaAnalyzer
?
README.md
Outdated
```javascript | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { AdminGuesser, hydra } from '@api-platform/admin'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name hydra
is very vague IMO. What does this object do? Why don't you export a hydraDataProvider
and a hydraResourceSchemaAnalyzer
directly?
src/hydra/resourceSchemaAnalyzer.js
Outdated
@@ -0,0 +1,68 @@ | |||
const getReferenceNameField = reference => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This entire file is hard to read and would greatly benefit from input/output examples in jsDoc.
src/Introspecter.js
Outdated
import {Loading, useDataProvider} from 'react-admin'; | ||
import ResourceSchemaAnalyzerContext from './ResourceSchemaAnalyzerContext'; | ||
|
||
const IntrospecterComponent = ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad name for a component. By the way, why does this file split its logic in two components that are entirely intricated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For testing purpose, IIRC.
src/Introspecter.js
Outdated
|
||
useEffect(() => { | ||
dataProvider | ||
.introspect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I understanding correctly: as Introspecter
is called in every Guesser
, this will fetch the entire hydra schema once for each resource, field, input? If so, that's a huge waste of bandwidth and a major slowdown. Especially since you've already fetched the resources in AdminGuesser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The introspection logic is only called once, then the result is stored in a local cache and reused.
admin/src/hydra/dataProvider.js
Line 351 in b022e15
if (apiSchema) return Promise.resolve({data: apiSchema}); |
|
||
render() { | ||
const {resourceSchema, fields, ...props} = this.props; | ||
setOrderParameters(resolvedOrderParameters); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why you setState here even though resolvedOrderParameters
might be empty, and you'll have to call the resourceSchema
just next line to set it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, Hydra doesn't support (yet) to expose available filters in docs.jsonld
, this information is only available in the metadata of the collection, so a call to the 1st page is needed to retrieve these parameters.
src/ListGuesser.js
Outdated
</List> | ||
); | ||
if (!children) { | ||
children = fields.map(field => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't set a new value for a function argument
The |
Supersede #257.
Upgrade the Admin for react-admin 3.
It will be a new 2.0 version because of the BC.
Things done:
AdminGuesser
can be used instead ofHydraAdmin
(to make it clear it's not related to Hydra).resourceSchemaAnalyzer
can be pass as a prop ofAdminGuesser
.history
can be pass as a prop.