Open standuprey opened 2 years ago
This would also be really helpful for Pages
We do support directories, although they seem to be buggy at times...I think the routes can up weird? I'm also not sure if you can arbitrarily nest them as deep as you want.
I don't think they're documented very well (if at all) which doesn't help!
With the generator commands though? I’ve manually reorganized my pages and components but have to rerun the types generator after making any moves. The routes file also gets needlessly verbose when pages are nested.
Hmm, maybe not...this behavior may have changed? I just ran:
yarn rw g page admin/User admin/user
Expecting it to create web/src/admin/UserPage/UserPage.js
but:
% yarn rw g page admin/user admin/user
✔ Generating page files...
✔ Successfully wrote file `./web/src/pages/AdminUserPage/AdminUserPage.stories.js`
✔ Successfully wrote file `./web/src/pages/AdminUserPage/AdminUserPage.test.js`
✔ Successfully wrote file `./web/src/pages/AdminUserPage/AdminUserPage.js`
✔ Updating routes file...
✔ Generating types...
✔ One more thing...
And the route that was generated:
<Route path="admin/user" page={AdminUserPage} name="admin/user" />
So the path was respected, but didn't put the page in my expected path. We've had a couple of updates to fix casing issues (like wanting to create APIPage instead of ApiPage) and it's possible that one of those changes caused a regression...hmmm.
@jtoar do you remember being able to generate pages in nested directories, or was that a dream I had?
There is an open issue for this. https://github.com/redwoodjs/redwood/issues/340
@cannikin what you are thinking of is scaffolds which do respect the path. https://github.com/redwoodjs/redwood/pull/423
But yes this is definitely something that the generators should be able to handle. There was more discussions on the forums about this aswell
https://community.redwoodjs.com/t/how-to-use-feature-based-folders-structure-instead-type-based/2980
If we made the scaffold generator interface the same as the others then if you did yarn rw g scaffold admin/user
it would look at the path admin/user
and take the last part user
, assume that was a model, do everything the scaffold normally does from there, but put everything in a subdirectory admin
. When scaffolding we already put everything in a subdirectory named for the model to help organize, so to compare:
yarn rw g scaffold user -> web/src/pages/User/UserPage
yarn rw g scaffold admin/user -> web/src/pages/admin/User/UserPage
But maybe it's confusing that you're mixing the name of the model and the path into one single argument. Maybe they should be split for the scaffold:
yarn rw g scaffold User admin
The other generators, like the page generator, it makes sense to just list them in one long path because it's just creating a file in the location you specify:
yarn rw g page admin/dashboard -> web/src/pages/admin/DashboardPage
For the SDLs and services, I don't think we've ever put them in subdirectories. They should probably stay flat, just like the schema file itself.
FWIW, I have nested SDLs in my project and would love to be able to nest the services to match. When you get more than a couple of SDL files it's much easier to organize them into folders.
For example, I have 8 different Stripe-related SDL files. I have them nested in a stripe folder and this works fine, but the services do not map properly unless they are flat, so that directory has become unruly. I could put all of the Stripe-related schema in a single Stripe sdl file and have a corresponding Stripe service, but those files would be huge.
Any progress on this?
For now should we just be generating top-level components and moving them into folders?
Yes, for now manually moving is the way to go.
I also left some additional comments some days ago in that discourse thread Kris linked above that you can have a look at if you want 🙂
It would be great to be able to organize components in folders, our app start to have a lot of components, and we would love to have a folder structure. This folder structure would also be reflected in storybook
Example
would generate a component inside
src/components/widget
and ColorPicker.stories.tsx would havetitle: 'Components/Widget/ColorPicker',
I could work on a PR for this if interested