Skip to content
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

[legacy-framework] Subtemplate management #2134

Closed

Conversation

maastrich
Copy link
Collaborator

@maastrich maastrich commented Mar 22, 2021

Closes: #2038

What are the changes and their implications?

Addition of template comment management for the generator

Checklist

  • Changes covered by tests (tests added if needed)
  • PR submitted to blitzjs.com for any user facing changes

@flybayer
Copy link
Member

Hey @maastrich just an update here, I got swamped this week with client work and haven't had much time on Blitz. Reviewing #2101 is first in line. Once I finish that I'll give a thorough review and testing of this.

I appreciate your patience!

@maastrich
Copy link
Collaborator Author

No problem it's not a hurry ;)

Copy link
Member

@flybayer flybayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome, thank you!!

Let's adjust this to support multiple subtemplate types.

  • change the template: keyword to fieldTemplate: which makes also makes it more clear what it does
  • change getTemplateValues.subTemplateValues: {...} to be getTemplateValues.fieldTemplate: {...}

And one other sort of big thing to address is we want to be able to update files with subtemplates without overwriting the whole file. Currently if you generate some code, customize it, then add a new model field, it will overwrite your customizations. So instead of existing files, we need to just insert the new field above the template comment. I think probably we should only do this custom insertion if the file has a subtemplate comment. If it doesn't, then use the current overwrite behavior.

Comment on lines +48 to +49
fieldName: singleCamel(valueName),
FieldName: singlePascal(valueName).replace(/(?!^)([A-Z])/g, " $1"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add the following which will put spaces between the words.

  • field_name
  • Field_name
  • Field_Name - ex: myFirstName -> My First Name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still todo

@@ -6,7 +6,7 @@ export {FORM_ERROR} from "app/core/components/Form"
export function __ModelName__Form<S extends z.ZodType<any, any>>(props: FormProps<S>) {
return (
<Form<S> {...props}>
<LabeledTextField name="name" label="Name" placeholder="Name" />
{/* template: <LabeledTextField name="__fieldName__" label="__FieldName__" placeholder="__FieldName__" /> */}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{/* template: <LabeledTextField name="__fieldName__" label="__FieldName__" placeholder="__FieldName__" /> */}
{/* template: <LabeledTextField name="__fieldName__" label="__Field_Name__" placeholder="__Field_Name__" /> */}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still todo

Comment on lines 50 to 59
modelNames: this.options.modelNames,
ModelName: this.options.ModelName,
ModelNames: this.options.ModelNames,
subTemplateValues: this.options.extraArgs?.map((arg: string) => {
const [valueName, typeName] = arg.split(":")
return {
attributeName: singleCamel(valueName),
zodTypeName: this.getZodTypeName(typeName),
}
}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Let's abstract out all these getTemplateValues into the base Generator class. Currently all our generators provide the same basic values, so we need to centralize it so they stay consistant. We'll want subTemplateValues available in all our generators
    • But we should allow subclasses to add or override the default values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still todo

@flybayer
Copy link
Member

I just thought of something kind of important. Currently we have

{/* fieldTemplate: <LabeledTextField name="__fieldName__" label="__Field_Name__" */}

But we don't want to always use LabeledTextField. We may want LabeledDateField, LabeledCheckboxField, etc.

We don't need to add this in this PR, but we should consider how we can add it later. My first thought is something like this:

{/* fieldTemplate: <__FieldComponent__ name="__fieldName__" label="__Field_Name__" */}

// And then provide a map in blitz.config.js or in templates/config or something
{
  fieldComponents: {
    LabeledTextField: ['string'],
    LabeledCheckboxField: ['boolean'],
    LabeledDateField: ['date'],
  } 
}

@maastrich
Copy link
Collaborator Author

maastrich commented Mar 27, 2021

Thanks @flybayer for your review

I'll change the vars names, for the rest of what you propose I thought quite the same but I was thinking that those are more new brand features but this PR is just an "upgrade" of existing features.

Anyway, what you proposed is exactly what I thought too add.

May be we should call each other on Monday or something to plan what is the first feat to add etc...

@flybayer
Copy link
Member

Hey @maastrich any update on this? :)

@flybayer
Copy link
Member

@maastrich sweet! Can you also fix the merge conflicts?

@roshan-sama
Copy link
Collaborator

@maastrich , I was wondering if you were still free to work (or are working) on this one? I was thinking of picking it up if you have other commitments at the moment

@maastrich
Copy link
Collaborator Author

Hello @roesh, I am (un)fortunately really busy with my job and cannot spend time on Blitz those days, it would be a pleasure to see this work going to an end.
Thanks for your interest in this feature and enjoy working on it ;)

@flybayer flybayer added this to the v1.0 milestone Aug 26, 2021
@beerose beerose removed this from the v1.0 milestone Oct 20, 2021
@flybayer
Copy link
Member

Superseded by #2679

@flybayer flybayer closed this Oct 20, 2021
@itsdillon itsdillon changed the title Subtemplate management [legacy-framework] Subtemplate management Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple fields forms using templates during generation
5 participants