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

CodeAction to insert expected input for renarde #form #778

Closed
angelozerr opened this issue Jan 30, 2023 · 3 comments · Fixed by #793
Closed

CodeAction to insert expected input for renarde #form #778

angelozerr opened this issue Jan 30, 2023 · 3 comments · Fixed by #793
Assignees
Milestone

Comments

@angelozerr
Copy link
Contributor

angelozerr commented Jan 30, 2023

Given the manualLogin method of renarde controller:

public class Login extends ControllerWithUser<User> {

    @POST
    public Response manualLogin(@NotBlank @RestForm String userName,
            @RestForm String password,
            @BeanParam WebAuthnLoginResponse webAuthnResponse,
            RoutingContext ctx) 
...
}

According @notblank @restform annotations:

  • userName is an input form which is required
  • password is an input form which is optional

Given this #form in qute template:

{#form uri:Login.manualLogin() id="login"}

{/form}

We should have a warning on #form location which says that some input should be defined inside the #form. After that we can bind code action of this warning:

  • Insert required input forms
  • Insert all input forms

Click on Insert required input forms code action will insert in:

{#input name="userName" /}

Click on Insert all inputinput forms code action will insert in:

{#input name="userName" /} {#input name="password" /}

@FroMage I noticed that in your sample renarde application you are using simple HTML input element (<input name=""), I wonder if it is better to use #input ?

In your parser we can get those Qute #input user tag, but we don't parse HTML content (it is a text node for us). If you think it is very important to take care of <input HTML element, it will require for our parser to have the capability to parse HTML.

@FroMage
Copy link

FroMage commented Jan 30, 2023

Well, the #input tag is not part of Renarde but the TODO app, because it's very tied to the CSS framework in use, which depends on the application.
So, probably better to generate <input name="xx"> tags, which are universal.

@angelozerr
Copy link
Contributor Author

Thanks @FroMage for your feedback. We need to implement à basic parser to collect input html element inside #form

@angelozerr
Copy link
Contributor Author

@JessicaJHee here some directive to implement this issue. In the qute diagnostic, you need to check if section is #form. In this case you need to get the first parameter of the #form (ex : uri:Login.manualLogin()) and get the RestForm of manualLogin method JavaMethodInfo.

You will need to loop for

and check if RestParam is a form. At this step you can collect all required RestForm.

To check that required restParam are defined in #form as <input html element, you will need to parse HTML which is not done today but only for #form section. Perhaps it could be interesting to create a FormSection class which extends Section.

FormSection could have a method like getHtmlInputNames() which will return all input/ @name declared inside #form. To implement that, I suggest that you implement a vistor like https://github.com/redhat-developer/quarkus-ls/blob/master/qute.ls/com.redhat.qute.ls/src/main/java/com/redhat/qute/services/inlayhint/InlayHintASTVistor.java and implement visit(Text).

At this step you will have text node. You will need to parse this content to collect name of <input name="". To be consistent will all parsing, I suggest that you implement a little scanner like our parameter scanner https://github.com/redhat-developer/quarkus-ls/blob/master/qute.ls/com.redhat.qute.ls/src/main/java/com/redhat/qute/parser/parameter/scanner/ParameterScanner.java

@JessicaJHee JessicaJHee self-assigned this Feb 3, 2023
@angelozerr angelozerr added this to the 0.14.0 milestone Feb 17, 2023
@datho7561 datho7561 added the enhancement New feature or request label Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants