-
Notifications
You must be signed in to change notification settings - Fork 975
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
Enable cell to take functions for a query #505
Conversation
In order to be able to write dynamic queries in a cell, we need to be able to optionally pass the component props
(Almost got away with editing in the github browser 😛)
Hey @eurobob, Thanks for this, we actually have two functions that surround the execution of the query:
I don't know if that gives you the same functionality as this PR? |
It seems not, |
@eurobob Sorry for not grasping the intent of your PR initially. I think allowing a function for |
711c520
to
2341368
Compare
I broke linting here. :/ |
Changes make a lot of sense 👍🏻 |
Description
In order to be able to write dynamic queries in a cell, we need to be able to optionally pass the component props.
Motivation
I have a project with 39 tables in the database, and the files required for listing and editing that many different entities with the cell system is a little overwhelming. Since so much of that was repetitive code I figured an abstraction would be worthwhile, and could provide basis for a more cohesive built-in admin interface
Proposed usage
I managed to get this working quite well in my project. Whether or not it is aligned with the vision of Redwood is another matter. This is my first sincere attempt at OSS contribution so go easy on me please 😅
I was going to go ahead and do the work, and I'm very willing to help out with implementing this, but wanted to get the green light. All this magic can be enabled by this very small addition to the codebase and I think it will make users lives much easier!
Routes.js
Routes take the model variable in plural form
routes.entities({ model: 'posts' })
pages/Admin/EntitiesPage/EntitiesPage.js
Admin layout for my use is a Material-UI wrapper and irrelevant for this demonstration
components/admin/EntitiesCell/EntitiesCell.js
✨✨✨Where the magic happens✨✨✨
src/queries
Just an index file to keep things organized
src/queries/posts.js
✨✨✨gql fragment magic✨✨✨
This how where we create uniquely named fragments that get passed into the cell.
For each entity we create we can optionally view minimal table columns (some of my tables are big too!)
Additionally, we can specify relations that we want to know about when creating/editing entities
src/components/admin/Entities/Entities.js
And finally list them out automatically
src/components/admin/EditEntityCell/EditEntityCell.js
Ok, so things get a little messy in this file, particularly in the Success method, but this is how I was able to only use one file for editing and creating. Maybe this is over-engineering and I welcome any feedback on how this is best approached.
I've included a relations example, so that when creating a post you could choose an author from a select input
The
EntityForm
component is a custom behemoth outside the remit of this PR. I'd like to author one that uses the built in redwood form tools, but my own project has more custom requirements. Note that by passing all Success props to it, we can access the relation queries for select inputs inside the formwhew...thanks for reading. Let me know if it makes sense or doesn't!