Often when I create (generate) a new Cell I also want a new Page to put that Cell in.
A while ago I added support to the Page generator to also take a parameter. rw g page Category {categoryId} will generate a page, and update the routes, so that you can go to /category/54 and 54 will automatically be passed as categoryId to your page. For me, this parameter is often just passed on to a Cell to fetch some data using apollo/gql
So, my question is, would a rw g cellpage Category generator be useful to anyone else but me?
It would:
Generate a CategoryPage that takes categoryId as a parameter
Add <Route path="/category/{categoryId:Int}" page={CategoryPage} name="category" /> to my routes
Generate a CategoryCell, with a query that takes categoryId as a parameter
Interesting idea for sure @Tobbe. I think my immediate reaction is trying to intuit the amount this generator would be 1) saving time and 2) useful. The amount of code to tie together a Page and Cell is fairly minimal.
But, you raise a good point that a Cell is almost always going to need a Page, correct?
To help me understand what prompted you to consider this, could you tell me more about your personal experience and workflow? Specifically how this process has been happening for you in your project(s).
Not a lot per invocation, but so far in my project(s) I would have reached for this generator pretty much every time where I have previously used the cell generator had it existed.
To me it would have been useful, but I’m also curious to hear what others think. That’s why I posted this topic
Yes, exactly!
Most recently I wanted to fetch all of the products that belong to a specific category in my web shop. So I created a CategoryCell, and so I also needed a CategoryPage to display that cell on.
Previously it has been a ProductsCell and ProductsPage to display a (paginated) list of all products.
Yes, to the point where I’m constantly thinking “This is such repetitive work, why can’t the generators just do this for me as well?!”
I’m working on the Tutorial II right now and I just generated a cell that doesn’t need a page! I definitely wouldn’t make it a default—cells are definitely a standalone “thing” that you should be able to generate on their own.
I’m not in love with a generator called cellpage…what about a --page option you can pass to the existing cell generator? We’re going to start having more of those soon, like --javascript, --typescript, flags for skipping tests or stories…
On a related note we also discussed (on Discord) maybe having a --withLayout LayoutName option for the Page generator to make it wrap the generated page in a (already existing) layout. And --withLoading LoadingComponent--withEmpty EmptyComponent options for the cell generator to use those components as defaults for the various states.
About the --javascript and --typescript flags. I know they’re useful right now when RW is a bit of a mixed bag when it comes to TS/JS. But later, when RW is 100% TS I’m thinking those should be flags to Create-Redwood-App, and then the generators should just use whatever the entire project is using. No? Or do you see a usecase for ever generating js cells/pages/layouts in a TS project?
Yeah, this is the unix tool philosophy, but it also stipulates that you can chain the atomic things together, which we can’t do with the generators.
Just to be clear, this would only work with creating new pages. It would not try to add the cell to an existing page. At least that was my initial plan.