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

Optimize variable edition and use of Monaco editor in raw mode #191

Merged
merged 6 commits into from
Apr 18, 2023

Conversation

PaulFarault
Copy link
Contributor

@PaulFarault PaulFarault commented Mar 3, 2023

Which issue(s) this PR fixes

Fixes #96
Fixes #149
Fixes #164

Additional comments

  • Add react-hook-form to optimize state and to simplify the userInput slice. The slice now only contains dirty variables across a single service and is emptied when switching service.
  • Sync variable edition in raw and view modes, with Monaco as the raw code editor.
  • Persist user settings across pages (raw/visual mode, show unused tabs).
  • New variables can be added using raw mode. (Variable creation #65)
  • Variable deletion in raw mode.

Agreements

@PaulFarault PaulFarault force-pushed the feat/variables-edition-context branch from b4a6a26 to 85da0b4 Compare March 8, 2023 15:07
@PaulFarault
Copy link
Contributor Author

Force pushed after rebase on master.

@PaulFarault PaulFarault marked this pull request as ready for review March 8, 2023 15:11
@PaulFarault PaulFarault self-assigned this Mar 9, 2023
@mdrutel
Copy link
Contributor

mdrutel commented Mar 9, 2023

Hi,
❓ ❌ ✅ ✔️
❓ When you select the Knox service, the tdpldap variable from the group gateway_topology is empty in View mode.
But it is related to the issue #149.
❓ When you try to modify the attribute name, another variable is created instead.
❓ In Raw mode, when there's a syntax error, an unhandled error popup appears ; do we have to add a try/catch block ?
❓ If there's a syntax error, there's only an error in the console when you click on the Validate button.
❓ When you scroll down to the end of the text, only one line is displayed ; I prefer the behavior of a text editor
❓ when you add an array variable in Raw mode, in View mode you have another display :
image
image
❓ (maybe related to another issue) when you dislay an existing array, you have this : in Raw mode, then in View mode :
image
image

✔️ When you modify in Raw mode, the state is updated in View mode
✔️ The syntax error are well displayed

@PaulFarault
Copy link
Contributor Author

Overall, the raw view seems to be fixed now and the sync between view / raw is working. View mode has some problems but those are hard to solve without any JSON schema. The default mode is now the raw one. I'll add a mention on the view page that this is still a work in progress.

When you try to modify the attribute name, another variable is created instead.

Yes that normal. Renaming a variable is not possible. Hence, it is the same as deleting/creating a new one.

In Raw mode, when there's a syntax error, an unhandled error popup appears ; do we have to add a try/catch block ?

It seems to be fixed now. The problem now appear on visual mode.

If there's a syntax error, there's only an error in the console when you click on the Validate button.

It seems to be fixed now.

When you scroll down to the end of the text, only one line is displayed ; I prefer the behavior of a text editor

I'm not sure to understand this one.

when you add an array variable in Raw mode, in View mode you have another display / (maybe related to another issue) when you dislay an existing array, you have this : in Raw mode, then in View mode

Arrays are causing some troubles. I decided to treat them as object until we make use of the json schemas.

@sergkudinov
Copy link
Contributor

When you scroll down to the end of the text, only one line is displayed ; I prefer the behavior of a text editor

It is this:
image

@PaulFarault PaulFarault force-pushed the feat/variables-edition-context branch from 1ce0501 to 23095df Compare April 6, 2023 13:39
@sergkudinov
Copy link
Contributor

sergkudinov commented Apr 7, 2023

I found a bug.

To reproduce

  1. Run tdp-server with docker, enabling DO_NOT_USE_IN_PRODUCTION_DISABLE_TOKEN_CHECK=True
  2. Run tdp-ui with "skipAuth": true in config.json
  3. Go to Spark service - http://localhost:3000/services/spark
  4. Click on the "View" button of the "spark" tab
  5. It outputs errors:
Uncaught TypeError: can't convert null to object
...
The above error occurred in the <VisualEditor> component:
VisualEditor@webpack-internal:///./src/components/Services/ServiceVariables/Editor/VisualEditor/index.tsx:98:51
...

It happens also on "Spark3" (http://localhost:3000/services/spark3) and nowhere else.

Reason

The reason is it defines "spark_env_client": null as an Object variable and put it to objectVariables, later on after destructuring the object it fails with on a type check.

Solution

First we have to determine if null is an object or a primitive variable.

@PaulFarault
Copy link
Contributor Author

Thanks @sergkudinov! I fixed it on my last commit.

Copy link
Contributor

@sergkudinov sergkudinov left a comment

Choose a reason for hiding this comment

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

Looks good to me, except this is not improved.

@PaulFarault
Copy link
Contributor Author

Looks good to me, except #191 (comment) is not improved.

True, it doesn't seem to be any settings for this with Monaco.

@PaulFarault PaulFarault mentioned this pull request Apr 11, 2023
2 tasks
@PaulFarault
Copy link
Contributor Author

TODO :

  • If there is no click outside Monaco, the value is not taken into account when validating
  • Errors are display inside the console when JSON can't be parsed

@PaulFarault PaulFarault force-pushed the feat/variables-edition-context branch from 3b20f98 to 759fb6a Compare April 12, 2023 12:26
Add react-hook-form to optimize state.

Sync raw and visual modes.

Persit user settings accross pages (raw mode, show unused tabs).

Fixes  #96
Fixes #164
@PaulFarault PaulFarault force-pushed the feat/variables-edition-context branch from e76b4a4 to 9c0e3a3 Compare April 12, 2023 14:33
@PaulFarault PaulFarault changed the title Feat/variables edition context Optimize variable edition and use of Monaco editor in raw mode Apr 12, 2023
@PaulFarault
Copy link
Contributor Author

I fixed the bug that I mentioned previously.

Forced pushed to squash commits.

@mdrutel
Copy link
Contributor

mdrutel commented Apr 12, 2023

I tested the add/remove of a variable :

  • Adding a variable : ✔️
    I get my variable
  • Removing a variable : ❌
    The variable is kept, and null is set

@PaulFarault
Copy link
Contributor Author

  • Removing a variable : x
    The variable is kept, and null is set

I did it on purpose. I understood from @rpignolet that deleted variables should be set as null. Does it seems good for you Romain or am I wrong?

@rpignolet
Copy link
Collaborator

Does the server support variable deletion by setting it to null ? If not, in the UI, removing variable should not be possible until the server support it.

@PaulFarault
Copy link
Contributor Author

PaulFarault commented Apr 12, 2023

Does the server support variable deletion by setting it to null ?

In my understanding, it is not possible to delete a variable using a PUT. The only way is to POST a new config.

If not, in the UI, removing variable should not be possible until the server support it.

It's a bit weird to prevent deleting in a raw mode. I can either:

  • Continue to use PUT and ignore deleted lines for now (as you suggested)
  • Use POST instead to send the whole config at each request

@rpignolet
Copy link
Collaborator

Use POST for now.

Copy link
Contributor

@sergkudinov sergkudinov left a comment

Choose a reason for hiding this comment

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

I ran and tested the edditor, it seams it works without issues descussed above. However, I see different errors in the browser console. I propose to merge to master as is, because existing errors must disappear after my refactoring to RTK Query this week.

@PaulFarault
Copy link
Contributor Author

Use POST for now.

@rpignolet I was mistaken, there is no POST on the server (only PUT, to add new variables, and PATH, to edit existing variables). Deleting variable is not possible currently. IMO the server lacks both POST and DELETE methods.

What should I do for this PR then? Leaving the deleted variable as null as it is now?


Thanks for your test and your input @sergkudinov! I agree, some of the errors are coming from the server answer / toast which aren't directly related to this PR.

Copy link
Contributor

@mdrutel mdrutel left a comment

Choose a reason for hiding this comment

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

test of the editore : OK

@rpignolet
Copy link
Collaborator

@PaulFarault
If you put null for a variable, I don't know if it will actually write null to the YAML file for Ansible. Also how will Ansible interpret this null, will it still merge dicts?

Currently the server does not support variable deletion, setting a variable to null doesn't necessarily make sense so I would say ignore the deletion for now and display a message above the editor stating that it is not supported at this time.

When the server will officially support it we can do the implementation on the UI side. The UI must use existing features of the server and not seek to circumvent non-existent features of the server.

@PaulFarault
Copy link
Contributor Author

This PR should fix the PUT behavior to allow deletion : TOSIT-IO/tdp-server#122

I'll switch from PATCH to PUT in the next commit to handle variables deletion.

@sergkudinov
Copy link
Contributor

It is fine from my side.

@PaulFarault PaulFarault merged commit 23a9fd0 into master Apr 18, 2023
@PaulFarault PaulFarault deleted the feat/variables-edition-context branch April 18, 2023 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Variable edition state optimization Can't restitute knox/gateway_topologies Raw field using code editor
4 participants