-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Scaffolds: Don't generate unused methods #6221
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit b29f87d. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this branch
✅ Successfully ran 8 targetsSent with 💌 from NxCloud. |
✅ Deploy Preview for redwoodjs-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
I always thought it would be good to have those so that if/when you expand on the model that's backing that scaffold, you have those functions ready to go. Otherwise you need to write your own or find a lib on NPM. We could move them to an internal lib and |
Here are some counter points 🙂 I think the chances that you're going to need/want those exact implementations are rather slim. When you update your underlaying model you either re-run the scaffold generator, or you know you're going to have to update a whole lot of code in a whole lot of places. Including writing whatever custom display method you might need. And also, especially for a super basic one like |
From @dac09:
(Content in square brackets added by me for context) |
I don't mind exploring the |
In a more general sense, I have been wanting to make the generators more composable so that we have a set of defaults and then you can use something like CLI args to turn on or off certain parts of the code-gen at a much more fine grained level then we currently do ( e.g. Not sure if/how it fits in here, so in the immediate I am in favor of leaving the unused methods out. |
I think that most people who add a field to a model -- and use scaffolds -- are most likely to regenerate the scaffold than to edit the components manually to add the field in the form ... and if they didn't they would have to know how use use the util functions. Yes, they may see them ... but there's no guarantee they will use them when manually adding the field. And they will remain unused. Alternatively, if they regenerate the scaffold, then the util function knows it is needed and then is applied. I think that leaving them out delivers initially cleaner code -- but the utils could be in the user's app so they can reference them later ... or replace with other validators/formatters. If fact, I anticipate that when certain urls can be shared across web/api a little easier, then these formatters and validations will be that shared url that both the api and web form sides could use. |
So I implemented the idea of having a separate file for all these display methods. A few observations
(I didn't bother updating any of the tests. Didn't want to spend time on it until we've decided what to do here) |
rob: put them in a separate file @dthyresson I'm not sure I know what way you're leaning currently. Did my latest comments above change your reasoning at all? |
For reference, and I'm not necessarily saying it has to be this way, I have it currently in a web/src/utils folder - but I think lib is better because consistency with the api side. I'd probably just call it formatters.tsx though, so it reads like
I also (personally) like putting extensions in my file names for this stuff, not sure if there's any appetite for it - so for example
|
@Tobbe My take is that if we leave them in (a separate file) or leave out -- we will have to document both cases. If the are in a file, the docs will say - if you manually add an Enum or a DateTime, then "use these helpers". If they are not in the file, then the docs will have to suggest a way to format them -- or ask the developer to come up with his/her own method. Given those two options, I now think that they should be in a separate file that can be easily documented in the Scaffolding or Form docs to point to each method and what it does and when to use. |
Bumping this - shouldn't fall of our radar. @cannikin - you had another PR with scaffold changes. Worth coordinating the two! |
Yeah, mine is ready to go #6385 but I thought we could review in the next core meeting to see if it's worth it. I'd really like to get @mojombo's opinion of having all the text/labels for the scaffold inside the route itself...we've been trying to keep that as concise and readable as possible, but this maybe starts mixing concerns a little bit (routing and content). |
…e-scaffold-unused-methods
…bbe/redwood into tobbe-scaffold-unused-methods
@@ -0,0 +1,50 @@ | |||
import React from 'react' | |||
|
|||
import humanize from 'humanize-string' |
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.
Isn't this dependency going to be a problem? I know it probably was there before, just not something I hadn't seen.
It looks like its a dependency on cli, but not web, so we might get away with it.
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.
Since the import is explicitly in the users's project, the dependency should probably also be explicit in the project's package.json, right? Should I make the scaffold generator run yarn add
?
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 is a weird one... maybe we should add it as a dependency on rwjs/web? It feels like a hammer, but atleast its "backwards compatible"
The reason it may not be an issue is because webpack will bundle dependencies anyway. So the other option is to not do anything, since its part of the cli dependencies anyway.
const listFormattersImports = columns | ||
.map((column) => column.listDisplayFunction) | ||
.sort() | ||
.filter((v, i, a) => a.indexOf(v) === i) |
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.
using variable names here would be super helpful :)
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.
ugh. 100% agree!
When using the scaffold generator you often end up with unused methods like this
This PR looks at what methods will be needed, and only includes those that are used.