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

NO-ISSUE: add form-generation-tool README.md #1935

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions packages/form-generation-tool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
## Form Generation Tool

This is a utility CLI to help generating forms in differents formats for BPMN processes and User Tasks in your Kogito projects.

### How does it work?

When building a Kogito project, Kogito generates JSON schemas to represent the data models for both Processes and User Tasks.

This tool locates those JSON Schemas in the project and taking advantage of the [Uniforms](https://uniforms.tools) APIs, processes them and generate static forms as a resources in the project `src/main/resoures/form` folder.

### Form Types

There are two types of form supported with differnt styling and output format:

- **Patternfly**: generates a React (`.tsx`) forms using Patternfly 4 components. Implementation can be found in `@kie-tools/uniforms-patternfly-codegen`
Copy link
Contributor

Choose a reason for hiding this comment

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

I was not able to use patternfly for the basic process-quarkus-example is that expected, known issues or new issue?

log

Project path: /home/jomarko/github/kogito-examples/kogito-quarkus-examples/process-quarkus-example
Form type: patternfly

? Do you want to continue? Yes

Starting Form generation:

Found 5 schemas

Generating form "demo#orderItems"
Cannot generate form "demo#orderItems":  ',' expected. (3:17)
  1 | import React, { useCallback, useEffect, useState }  from "react";
  2 |     import { TextInput, FormGroup, Card, CardBody, Checkbox } from "@patternfly/react-core";
> 3 | const Form__demo#orderItems: React.FC<any> = ( props:any ) => {
    |                 ^
  4 |   const [formApi, setFormApi] = useState<any>();
  5 |   const [ item, set__item ] = useState<string>("");
  6 | const [ order__orderNumber, set__order__orderNumber ] = useState<string>("");

Generating form "demo#orderItems_Verify_order"
Cannot generate form "demo#orderItems_Verify_order":  ',' expected. (3:17)
  1 | import React, { useCallback, useEffect, useState }  from "react";
  2 |     import { Card, CardBody, TextInput, FormGroup, Checkbox } from "@patternfly/react-core";
> 3 | const Form__demo#orderItems_Verify_order: React.FC<any> = ( props:any ) => {
    |                 ^
  4 |   const [formApi, setFormApi] = useState<any>();
  5 |   const [ input1__orderNumber, set__input1__orderNumber ] = useState<string>("");
  6 | const [ input1__shipped, set__input1__shipped ] = useState<boolean>(false);

Generating form "demo#orders"
Cannot generate form "demo#orders":  ',' expected. (3:17)
  1 | import React, { useCallback, useEffect, useState }  from "react";
  2 |     import { TextInput, FormGroup, Card, CardBody, Checkbox } from "@patternfly/react-core";
> 3 | const Form__demo#orders: React.FC<any> = ( props:any ) => {
    |                 ^
  4 |   const [formApi, setFormApi] = useState<any>();
  5 |   const [ approver, set__approver ] = useState<string>("");
  6 | const [ order__orderNumber, set__order__orderNumber ] = useState<string>("");

Generating form "persons"
Successfully generated form "persons.tsx"

Generating form "persons_ChildrenHandling"
Successfully generated form "persons_ChildrenHandling.tsx"

Good bye!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jomarko ok, I think this is a new issue. Looks like the problem is because some processes in the example have an id like demo.order and that generates a schema file with a name like demo#orders.json... the tool uses the schema file name as a formId when building the react forms, probably sanityze the id to avoid that issue (at least to generate the form code)

Copy link
Contributor

Choose a reason for hiding this comment

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

@pefernan please report a separate issue, or let me know I should do it, then I can approve this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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


- **Bootstrap 4**: generates a HTML (`.html`) forms using Bootstrap 4 styling.

Each generated form consist in two files, the source code (`.tsx` or `.html`) and a companion `.config` file that defines the external resources (`css` / `js`) the form may need.

## Build

In order to build the CLI you must run the following command in the root folder of the repository:

```shell script
pnpm -F @kie-tools/form-generation-tool... build:prod
```

After the command has finished, go to `packages/form-generation-tool/dist` folder and you'll find the CLI binary (`form-generation-cli-macos`, `form-generation-cli-linux` or `form-generation-cli-win.exe` depending on your OS).

## Running the CLI

In the command line just execute the CLI binary:

```shell script
./form-generation-cli-linux
```

This command will start a wizard to help you generate the forms:

1. First set the path to your Kogito Project.

![Step 1: Set the Kogito Project path](./docs/form-generation-1.png)

> **ℹ️ NOTE:** Make sure your Kogito project has been compiled, otherwhise the CLI won't be able to find all the form schemas.

2. Select one of the availables the Form types (Patternfly or Bootstrap 4).

![Step 2: Select the Form type](./docs/form-generation-2.png)

3. Confirm Selection to start the Form Generation process.

![Step 3: Select the Form type](./docs/form-generation-3.png)

4. If the Form generation process is succesful, you'll get a confirmation message.

![Form generation succesfully finished](./docs/form-generation-4.png)

The generated forms will be stored in the `src/main/resources/forms` folder of the Kogito project.

![List of generated forms in project](./docs/form-generation-5.png)

## Using the Custom Forms with Runtime Tools Quarkus Extension
Copy link
Contributor

Choose a reason for hiding this comment

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

I was able to start and open runtime tools quarkus extension for process-quarkus-example, however when I try to open a form, I got this error, is that expected, known
Screenshot 2023-08-30 120501
issue or new issue please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jomarko this one is related to apache/incubator-kie-issues#525


If your project is a Quarkus based Kogito project, you can use and test them by using the **Runtime Tools Quarkus Extension**.

To do so, just add the following dependency in your project `pom.xml`:

```xml
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>runtime-tools-quarkus-extension</artifactId>
<version>${version}</version>
</dependency>
```

And start the project in Dev mode with the command:

```shell script
mvn clean quarkus:dev
```

For more information on how to setup the **Runtime Tools Quarkus Extension** in your project look at the oficial Kogito [documentation](https://docs.kogito.kie.org/latest/html_single/#con-runtime-tools-dev-ui_kogito-developing-process-services).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/form-generation-tool/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function run() {
console.log("Kogito Form Generation CLI");
console.log("===========================");
console.log();
console.log("This tool will help you generate forms for User Tasks in your Kogito Projects.");
console.log("This tool will help you generate forms for the Processes and User Tasks in your Kogito Projects.");
console.log(
"The tool will search for the User Tasks JSON schemas generated in your project, so make sure the project is build."
);
Expand Down
3 changes: 3 additions & 0 deletions packages/uniforms-bootstrap4-codegen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Uniforms Bootstrap 4 Codegen

This module contains the [Uniforms](https://uniforms.tools) theme contain to generate Bootstrap 4 forms for the `@kie-tools/form-generation-tool`.
3 changes: 3 additions & 0 deletions packages/uniforms-patternfly-codegen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Uniforms Patternfly Codegen

This module contains the [Uniforms](https://uniforms.tools) theme contain to generate Patternfly forms for the `@kie-tools/form-generation-tool`.