Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

FUSETOOLS2-725 - Removing single window limit on didact #365

Merged

Conversation

bfitzpat
Copy link
Collaborator

@bfitzpat bfitzpat commented Jan 5, 2021

Removing single-window limitation on opening Didact files. https://issues.redhat.com/browse/FUSETOOLS2-725

multi-didact

Exploring issues with caching on a per-window basis (see https://issues.redhat.com/browse/FUSETOOLS2-930)

Signed-off-by: Brian Fitzpatrick bfitzpat@redhat.com

@bfitzpat bfitzpat added the work in progress A draft PR or work in progress label Jan 5, 2021
@bfitzpat bfitzpat self-assigned this Jan 5, 2021
@bfitzpat
Copy link
Collaborator Author

bfitzpat commented Jan 5, 2021

Essentially now when the workspace shuts down we cache the details from the first Didact window closed in a given session. In this workspace's case, it opened with the Didact demo, so that's tucked away in the cache. So regardless of what you have open when the workspace closes, you get...

multi-didact-cache-problem

I think maybe we can use the vscode setState/getState API to handle things differently on a per-window basis rather than having a single cache for all windows: https://code.visualstudio.com/api/extension-guides/webview#getstate-and-setstate

@bfitzpat
Copy link
Collaborator Author

bfitzpat commented Jan 5, 2021

Definitely a work in progress, but wanted to stash the work.

@bfitzpat
Copy link
Collaborator Author

bfitzpat commented Jan 8, 2021

Improvement... now have it working and saving html state on a per-window basis.

  • Removed all the history functionality, which is no longer necessary.
  • Updated tests
  • Working on a small issue with the didact window title being reset for the first window -- only affects the first window though

multi-didact-demo

src/didactWebView.ts Outdated Show resolved Hide resolved
@bfitzpat bfitzpat force-pushed the FUSETOOLS2-725-multiple-didact-windows branch 2 times, most recently from 87e6be3 to a7c1511 Compare January 26, 2021 20:20
@bfitzpat
Copy link
Collaborator Author

Success!!
multi-didact-demo-26-JAN-2021

@bfitzpat bfitzpat added READY FOR REVIEW and removed work in progress A draft PR or work in progress labels Jan 26, 2021
@bfitzpat bfitzpat requested review from lhein and apupier January 26, 2021 20:32
@bfitzpat
Copy link
Collaborator Author

This is a large commit, but the core of the work is in DidactManager and DidactPanel.

Copy link
Member

@apupier apupier left a comment

Choose a reason for hiding this comment

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

  • I have not found tests for the new functionality
  • every time I open a new VS Code isntance, another Didact tutorial page is opened
  • The welcome page stays blank (other tutorial are loading)
  • tried the "Writing your first Didact tutorial":
    • The "Click here to open the new myfirst.didact.md file" is no more working. The erro rmessage seems to say that the dots has been removed: Unable to open 'didactmdfile.json': Unable to read file '/home/apupier/ws/test-didact/didactmdfile.json' (Error: Unable to resolve non-existing file '/home/apupier/ws/test-didact/didactmdfile.json').
    • it simplifies a lot the workflow!
  • When hitting Ctrl+Shift+V to preview a tutorial that i'm currently writing, it is opening a new tab each time. I woudl expect that for the same file, it is only refreshing the existing one (but sounds possible to have it as an improvement for another iteration)

media/main.js Outdated Show resolved Hide resolved
src/didactManager.ts Outdated Show resolved Hide resolved
src/didactPanel.ts Outdated Show resolved Hide resolved
src/didactPanelSerializer.ts Outdated Show resolved Hide resolved
this._context = context;
}

public async deserializeWebviewPanel(webviewPanel: WebviewPanel, state: any) : Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

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

I think that it will be cleaner to provide a specific type for the state.
Something like:

class DidactPanelState {
	public oldBody:string;
	   public oldTitle: string;
	   
	   constructor(oldBody:string, oldTitle: string) {
		   this.oldBody =oldBody;
		   this.oldTitle=oldTitle;
	   }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure it's needed. There are TWO items in this state, so it's very very minimal. If it was more complex, I might agree.

Copy link
Member

Choose a reason for hiding this comment

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

deactivate the eslint rule which is forbiding usage of any then

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@apupier I thought you were against deactivating eslint rules?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added the necessary rule disablement

Copy link
Member

@apupier apupier Jan 28, 2021

Choose a reason for hiding this comment

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

I prefer not deactivating them without good reasons but when the rules are not followed, it is then better to deactivate them. it avoids to have noise of rule that you choose to not follow.
It is better to introduce a type instead of disabling the rule. But you do not want. So it remains better to to disable the rule if it is not followed.
By not creatign the type, the type-safe part of TypeScript language is not leveraged. We will hit all the troubles of non-typed languages.

src/extensionFunctions.ts Outdated Show resolved Hide resolved
@bfitzpat
Copy link
Collaborator Author

  • I have not found tests for the new functionality

There really isn't new functionality. All we did was remove the limit on a single window. Not quite sure what kind of tests you expect for that.

  • every time I open a new VS Code isntance, another Didact tutorial page is opened

Can you clarify what's going on here? In my local testing, it doesn't open additional pages. Is this with the default setting in place to open the default tutorial set in settings?

  • The welcome page stays blank (other tutorial are loading)

Can you clarify what this means? Maybe provide a video/gif?

  • The "Click here to open the new myfirst.didact.md file" is no more working. The erro rmessage seems to say that the dots has been removed: Unable to open 'didactmdfile.json': Unable to read file '/home/apupier/ws/test-didact/didactmdfile.json' (Error: Unable to resolve non-existing file '/home/apupier/ws/test-didact/didactmdfile.json').

Will investigate.

  • it simplifies a lot the workflow!

Great!

  • When hitting Ctrl+Shift+V to preview a tutorial that i'm currently writing, it is opening a new tab each time. I woudl expect that for the same file, it is only refreshing the existing one (but sounds possible to have it as an improvement for another iteration)

Interesting quirk with this implementation. I will see if there's a way to work around that, perhaps by storing the uri and comparing that when opening a new window so we only open the same one. But let's spin that off into a separate issue I think. Related, but separate.

@apupier
Copy link
Member

apupier commented Jan 27, 2021

  • I have not found tests for the new functionality

There really isn't new functionality. All we did was remove the limit on a single window. Not quite sure what kind of tests you expect for that.

that's a big functionality to be able to open 2 didact tutorial at the same time. Also that they keep the state. A test that is openign 2 tutorials and checkign that they both open with correct state woudl very useful.

@apupier
Copy link
Member

apupier commented Jan 27, 2021

  • The welcome page stays blank (other tutorial are loading)

Can you clarify what this means? Maybe provide a video/gif?

  • Open VS code with Didact installed
  • wait that the welcome page opens
  • the page is blank

Screenshot from 2021-01-27 15-24-24

@bfitzpat
Copy link
Collaborator Author

that's a big functionality to be able to open 2 didact tutorial at the same time. Also that they keep the state. A test that is openign 2 tutorials and checkign that they both open with correct state woudl very useful.

I don't disagree with you. However, unless you know how to shut down a vscode instance during a test and re-open it, I'm afraid we're kind of out of luck there.

@apupier
Copy link
Member

apupier commented Jan 27, 2021

that's a big functionality to be able to open 2 didact tutorial at the same time. Also that they keep the state. A test that is openign 2 tutorials and checkign that they both open with correct state woudl very useful.

I don't disagree with you. However, unless you know how to shut down a vscode instance during a test and re-open it, I'm afraid we're kind of out of luck there.

we can have at least teh check that 2 tutorials can be opened side by side.

Doe it really need a shutdown? Can it be a "reload window"? (for whcih VS Code has a command is used when some installation are installed)

@bfitzpat
Copy link
Collaborator Author

I believe this latest commit addresses all of the suggestions and issues raised except for the one where if you open a single didact more than once, it opens more than one window so you can have duplicates. Working on that next.

@bfitzpat
Copy link
Collaborator Author

Ok, with the last two commits we have a couple of things:

  • now using the uri effectively to ensure that we don't open more than one window for a given URI
  • now testing to ensure that the we avoid duplicates
  • renaming the old webview tests to panel tests to better reflect the refactored work

My question though is this: If I have a Didact tutorial open and re-open it, it overwrites any of the html changes that may have happened since the initial open. For instance, if I checked requirements, those requirements are now green or red with indications of whether the requirements are met. Those html changes are persisted behind the scenes, so if you close the workbench and come back it remembers what was green and red. If you open the tutorial a second time, it just resets the tutorial to its initial html.

Should there be a "Are you sure?" moment in there to ensure that it doesn't overwrite anything they've done without their knowledge? Or is that too much of an intrusion? I mean, we're just talking the state of some html here but still it could be annoying to redo some of those state changes.

@bfitzpat
Copy link
Collaborator Author

On the plus side, doing things like writing tutorials and previewing the work is a little easier. Each Ctrl+Alt+V refreshes the window so it automatically updates from the Didact adoc/md to a HTML rendering. You just have to save the file (Ctrl+S) and hit preview again (Ctrl+Alt+V) and it reflects those changes in the same place you dragged the window to.

Not quite as good as a live preview, but close.
previewdemo

@bfitzpat bfitzpat requested a review from apupier January 27, 2021 21:22
@apupier
Copy link
Member

apupier commented Jan 28, 2021

Should there be a "Are you sure?" moment in there to ensure that it doesn't overwrite anything they've done without their knowledge? Or is that too much of an intrusion? I mean, we're just talking the state of some html here but still it could be annoying to redo some of those state changes.

I think the are you sure step could be nice if their is also a checkbox to disable it fo rnext time. I think this can be handled in another iteration.

Comment on lines 111 to 112
if (testUri && originalUri) {
if (originalUri.toString() === testUri.toString()) {
Copy link
Member

Choose a reason for hiding this comment

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

the two if conditions can be merged

this._context = context;
}

public async deserializeWebviewPanel(webviewPanel: WebviewPanel, state: any) : Promise<void> {
Copy link
Member

@apupier apupier Jan 28, 2021

Choose a reason for hiding this comment

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

I prefer not deactivating them without good reasons but when the rules are not followed, it is then better to deactivate them. it avoids to have noise of rule that you choose to not follow.
It is better to introduce a type instead of disabling the rule. But you do not want. So it remains better to to disable the rule if it is not followed.
By not creatign the type, the type-safe part of TypeScript language is not leveraged. We will hit all the troubles of non-typed languages.

@bfitzpat
Copy link
Collaborator Author

I prefer not deactivating them without good reasons but when the rules are not followed, it is then better to deactivate them. it avoids to have noise of rule that you choose to not follow.
It is better to introduce a type instead of disabling the rule. But you do not want. So it remains better to to disable the rule if it is not followed.
By not creatign the type, the type-safe part of TypeScript language is not leveraged. We will hit all the troubles of non-typed languages

Though I don't disagree with you in principle, I definitely disagree as a practical matter here. Taking a look around github for other examples (even Microsoft https://github.com/search?q=deserializeWebviewPanel+user%3Amicrosoft+language%3ATypeScript+language%3ATypeScript&type=Code&ref=advsearch&l=TypeScript&l=TypeScript) nobody is making it harder than it needs to be by avoiding the any type. In our case, this typescript file is < 25 lines of code, the purpose is clear, and overcomplicating things to avoid eslinter rules doesn't buy us anything from a practical matter since typescript boils down to javascript in the end.

So the fact that I "do not want" to overcomplicate things is correct. If we truly want to deal with adding a type, that can be done in a follow-on code change, but at this time it seems like a lot more trouble than it's worth.

@bfitzpat bfitzpat force-pushed the FUSETOOLS2-725-multiple-didact-windows branch from a1b5e8a to ea70b33 Compare January 28, 2021 15:52
Signed-off-by: Brian Fitzpatrick <bfitzpat@redhat.com>
Signed-off-by: Brian Fitzpatrick <bfitzpat@redhat.com>
Signed-off-by: Brian Fitzpatrick <bfitzpat@redhat.com>
Signed-off-by: Brian Fitzpatrick <bfitzpat@redhat.com>
Signed-off-by: Brian Fitzpatrick <bfitzpat@redhat.com>
Signed-off-by: Brian Fitzpatrick <bfitzpat@redhat.com>
Signed-off-by: Brian Fitzpatrick <bfitzpat@redhat.com>
Signed-off-by: Brian Fitzpatrick <bfitzpat@redhat.com>
Signed-off-by: Brian Fitzpatrick <bfitzpat@redhat.com>
Signed-off-by: Brian Fitzpatrick <bfitzpat@redhat.com>
Signed-off-by: Brian Fitzpatrick <bfitzpat@redhat.com>
also reuse old panels (based on uri) to avoid opening a
new window each time

Signed-off-by: Brian Fitzpatrick <bfitzpat@redhat.com>
and add test to ensure that if we open the same didact URI twice
we only end up with one panel open and not two of them

Signed-off-by: Brian Fitzpatrick <bfitzpat@redhat.com>
Signed-off-by: Brian Fitzpatrick <bfitzpat@redhat.com>
@bfitzpat bfitzpat force-pushed the FUSETOOLS2-725-multiple-didact-windows branch from ea70b33 to b29aa41 Compare January 29, 2021 13:29
@bfitzpat bfitzpat requested a review from apupier January 29, 2021 13:30
Copy link
Member

@apupier apupier left a comment

Choose a reason for hiding this comment

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

good feature. The removal of the in-house history is a very good improvement from a maintenance point of view.
The downside of the new code is the non-typed state that is used which is nto optimizing the maintainability.

@apupier
Copy link
Member

apupier commented Jan 29, 2021

In our case, this typescript file is < 25 lines of code, the purpose is clear

It is softly linked to another file where the setState is used. The day the expected inout is modified, the setStates won't be detected at compile time.

@bfitzpat bfitzpat merged commit 98c40e5 into redhat-developer:master Jan 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants