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

Bug 2167608: highlight parts #1141

Merged
merged 1 commit into from
Mar 29, 2023

Conversation

upalatucci
Copy link
Member

@upalatucci upalatucci commented Mar 14, 2023

📝 Description

Highlight editor parts in the LIVE YAML

🎥 Demo

editor-2023-03-14_12.06.57.mp4

@openshift-ci openshift-ci bot requested review from metalice and yaacov March 14, 2023 10:06
@openshift-ci openshift-ci bot added the approved This issue is something we want to fix label Mar 14, 2023
@upalatucci upalatucci force-pushed the editor-highlight branch 2 times, most recently from f91fcd8 to b42372d Compare March 14, 2023 10:31
@upalatucci upalatucci changed the title feat: highlight parts Bug 2167608: highlight parts Mar 14, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 14, 2023

@upalatucci: This pull request references Bugzilla bug 2167608, which is invalid:

  • expected the bug to target the "4.14.0" release, but it targets "4.13.0" instead

Comment /bugzilla refresh to re-evaluate validity if changes to the Bugzilla bug are made, or edit the title of this pull request to link to a different bug.

In response to this:

Bug 2167608: highlight parts

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@upalatucci
Copy link
Member Author

/retest

(line, index) => index > startPropertyRange && line.match(/^[A-z]+:/g),
);

if (endPropertyRange === -1) endPropertyRange = rangeLines.length;
Copy link
Member

Choose a reason for hiding this comment

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

can be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Considering the previous suggestion i can do something different but in general i need this.
Here i understand that the range is finished because i find another property using the regex /^[A-z]+:/g.

So for example if i want to select the property spec i know the start because it starts with spec: and i know the end because i encounter another property at the same level status: with his conditions.

In that case i know that the spec range is finished.

But if I want to select the property status, i know that the range is finished because there isn't another property after. So here endPropertyRange would be -1. the findIndex function does not find anything else after.

So at that point, i know that the end is equivalent to the last line

Copy link
Member

Choose a reason for hiding this comment

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

Ok cool. But what's wrong in the code I suggested?

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see you took part of it

@upalatucci
Copy link
Member Author

/retest

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 14, 2023

@upalatucci: This pull request references Bugzilla bug 2167608, which is invalid:

  • expected the bug to target the "4.14.0" release, but it targets "4.13.0" instead

Comment /bugzilla refresh to re-evaluate validity if changes to the Bugzilla bug are made, or edit the title of this pull request to link to a different bug.

In response to this:

Bug 2167608: highlight parts

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@upalatucci
Copy link
Member Author

/retest

@upalatucci
Copy link
Member Author

/retest

Copy link

@hstastna hstastna left a comment

Choose a reason for hiding this comment

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

The code looks good, +1 for the comments in getLineFromPath.

When I tested the code a while ago, the editor did highlight the relevant lines nicely, however when I changed something in the VM details, e.g. changed Description field (by clicking on that field and adding text to the modal and saving), the yaml updated, but didn't highlight the lines again, got stuck. I had to turn the switcher off and on again to make it displayed highlighting the lines again.
Also the description info didn't occur in the yaml the expected way - at least for me - I mean it didn't occurred there easily visible, but hidden, I had to click on > to expand the annotations in the editor to reveal that part of the yaml - and that was a bit annoying to me, especially when I edited info belonging to that part of the yaml. Not sure if this is the behavior we expect. Additionally, the description was not highlighted at all, not before, nor after editing it - that's not what I'd expect for sure.

To sum up, IMO we should highlight all the relevant lines (e.g. also Description, when being on VM Details tab), not only most of them. PTAL into that a bit. Also I think we should highlight lines also after some editing (not only before) :) And If we should display some yaml parts expanded or not - that's what I'm not sure about. Depends on the design/what user prefer. Otherwise great work, Ugo! ❇️

src/utils/resources/vm/utils/constants.ts Outdated Show resolved Hide resolved
src/utils/components/SidebarEditor/SidebarEditor.tsx Outdated Show resolved Hide resolved
showEditor: boolean,
) => {
const [editor, setEditor] = useState<YAMLEditorRef['editor']>();
const isHighlighed = useRef(false);
Copy link
Member

Choose a reason for hiding this comment

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

why do we need it? if you will use showEditor as your dependency at line 36 we will get same effect?

Copy link
Member Author

@upalatucci upalatucci Mar 16, 2023

Choose a reason for hiding this comment

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

This is because the editor would trigger the useEffect everytime editableYAML is modified.
So every time something change in the editor.

For example, while the user types something, the editor continues to unfold and fold parts for the code

@upalatucci
Copy link
Member Author

@hstastna i've addressed your issue and added metadata.annotations to the selection in the details tab.
Unfortunately, if you change something, the highlight goes away because its not really an highlight, its more like a selection.
But we can find other solutions after this pr if you want

@hstastna
Copy link

hstastna commented Mar 16, 2023

@hstastna i've addressed your issue and added metadata.annotations to the selection in the details tab. Unfortunately, if you change something, the highlight goes away because its not really an highlight, its more like a selection. But we can find other solutions after this pr if you want

I am not sure if this actual version of the solution wouldn't add just more confusion to the users, if it worked only before they change anything. Maybe we could simulate that my "quick fix" of turning off and on the YAML switcher, so the fields would be selected/highlighted again? Or to reload/rerender the whole editor somehow after the user changes something?

@metalice
Copy link
Member

ok by me , @hstastna when you are satisfied with this pr give it a go :)

@hstastna
Copy link

I am not sure if this actual version of the solution wouldn't add just more confusion to the users, if it worked only before they change anything. Maybe we could simulate that my "quick fix" of turning off and on the YAML switcher, so the fields would be selected/highlighted again? Or to reload/rerender the whole editor somehow after the user changes something?

I'd give this mentioned by me above a try at least, before I give this PR a go. WDYT, @upalatucci ?

@upalatucci
Copy link
Member Author

/retest

@upalatucci
Copy link
Member Author

upalatucci commented Mar 17, 2023

Guys i don't know. At this point, I'll contact Yifat and see what she thinks. I'll share with her what i think we can do with the editor, and let her figure out what we should do with that.

I can't re-highlight the editor when something gets edited because its a live editor, so you can edit things from the editor and also from the form. For example in the Environment tab, you can write down envs values in the yaml and also in the form and you'll see in real time the result on the other side. So i don't think we want the yaml to highlight at every char pressed.

@hstastna
Copy link

Guys i don't know. At this point, I'll contact Yifat and see what she thinks. I'll share with her what i think we can do with the editor, and let her figure out what we should do with that.

I can't re-highlight the editor when something gets edited because its a live editor, so you can edit things from the editor and also from the form. For example in the Environment tab, you can write down envs values in the yaml and also in the form and you'll see in real time the result on the other side. So i don't think we want the yaml to highlight at every char pressed.

Ok, great, so let's ask Yifat and we'll see. If she's gonna be okay with what we actually have, let's merge this. Just make sure with her. Thanks! :)

@upalatucci
Copy link
Member Author

/retest

1 similar comment
@upalatucci
Copy link
Member Author

/retest

@metalice
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm Passed code review, ready for merge label Mar 29, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 29, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: metalice, upalatucci

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [metalice,upalatucci]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 223de4f into kubevirt-ui:main Mar 29, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 29, 2023

@upalatucci: All pull requests linked via external trackers have merged:

Bugzilla bug 2167608 has been moved to the MODIFIED state.

In response to this:

Bug 2167608: highlight parts

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved This issue is something we want to fix bugzilla/severity-medium bugzilla/valid-bug lgtm Passed code review, ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants