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

Implement Bidirectional Sync between Go Form Rendering and KCL Schema #422

Open
riven-blade opened this issue Jun 5, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request faq question Further information is requested

Comments

@riven-blade
Copy link

riven-blade commented Jun 5, 2024

Feature Request

Is your feature request related to a problem? Please describe:

Describe the feature you'd like:

Describe alternatives you've considered:

Teachability, Documentation, Adoption, Migration Strategy:

Description:

We need to implement a feature in Go that renders the KCL schema initialized Deployment configuration into a frontend form. This will allow frontend personnel to modify the configuration, which should then be written back into the code. Additionally, we want any direct modifications in the code to be reflected back in the frontend form, achieving bidirectional synchronization between the two modification entry points.

Requirements
Initialize Configuration File:
Initialize the Deployment schema with the following example configuration:

kcl
deployment = Deployment {
name: "example-deployment",
cpu: 2,
memory: 1024,
image: "example-image",
service: "example-service",
replica: 3,
command: ["run", "example-command"]
}
Render Configuration to Form:
Implement a function in Go to parse this configuration and render it into a form for the frontend. Each attribute of the Deployment schema should be represented as a form field.

Form Modification and Sync Back to Code:
Allow modifications to the form by the frontend personnel. Once changes are made, they should be written back to the KCL configuration file.

Code Modification Sync to Form:
Implement functionality to detect changes made directly in the code and update the form accordingly to reflect these changes.

Implementation Steps
Parsing KCL Configuration:

Use a Go parser to read the KCL configuration file and extract the Deployment schema values.
Convert the parsed values into a structured format that can be rendered as a form.
Rendering Form:

Create an HTML form with fields corresponding to each attribute in the Deployment schema.
Populate the form fields with the values parsed from the KCL configuration.
Handling Form Submissions:

Implement a backend endpoint in Go to handle form submissions.
Upon form submission, validate the input values and update the KCL configuration file with the new values.
Bidirectional Sync Mechanism:

Implement a file watcher in Go to monitor changes in the KCL configuration file.
When a change is detected, update the form values to reflect the new configuration.
Similarly, ensure that changes made via the form are written back to the KCL configuration file, maintaining consistency.
Frontend-Backend Communication:

Use AJAX or WebSocket to facilitate real-time communication between the frontend form and the Go backend.
Ensure that any changes are immediately reflected on both ends.
Expected Outcome
The frontend form should be rendered based on the Deployment schema configuration.
Modifications made via the form should be accurately written back to the KCL configuration file.
Changes made directly in the KCL configuration file should be detected and reflected in the form.
Both modification entry points should stay in sync, ensuring consistency and accuracy of the configuration.

@Peefy
Copy link
Contributor

Peefy commented Jun 5, 2024

Hello @riven-blade Thanks for the detailed description.

In KCL Go SDK. We have APIs to load Schema from KCL file and convert it to the OpenAPI Type https://github.com/kcl-lang/kcl-go/blob/main/pkg/tools/gen/genopenapi.go, which is like the JsonSchema and can be used to render a HTML form. Besides, we also allow developers to define some extension information (e.g., the HTML form style) through the @info decorator.

We can use the APIs in the gen package to generate KCL code from other formats including go, JSON and YAML values.

Of course, there are also some additional features provided for the config templating

KCL focuses on the fields of configuration and automation, and its APIs are continuously supplementing and growing. Welcome to join the KCL community to build together. ❤️

Reference

KCL GitClickOps Issue: kcl-lang/backstage-kcl#2

cc @zong-zhe

@Peefy Peefy added the enhancement New feature or request label Jun 5, 2024
@Peefy Peefy assigned Peefy and zong-zhe and unassigned Peefy Jun 5, 2024
@Peefy Peefy added the question Further information is requested label Jul 19, 2024
@Peefy Peefy transferred this issue from kcl-lang/kcl Jul 19, 2024
@Peefy Peefy added the faq label Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request faq question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants