-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV2-1691 - add "Getting Started" functionality (#979)
* - open getting-started webview after installation - remove the hub welcome opening - add "Getting Started guide" action to the side panel * - open getting-started webview after installation - remove the hub welcome opening - add "Getting Started guide" action to the side panel * code review
- Loading branch information
1 parent
b24346e
commit 86201b7
Showing
14 changed files
with
159 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { EventEmitter } from "vscode"; | ||
|
||
const onPluginInstalledEmitter = new EventEmitter<void>(); | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export { onPluginInstalledEmitter }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Disposable } from "vscode"; | ||
import { onPluginInstalledEmitter } from "./events/onPluginInstalledEmitter"; | ||
import { openGettingStartedWebview } from "./webview/openGettingStartedWebview"; | ||
import { isAlreadyOpenedGettingStarted } from "./state/gettingStartedOpenedState"; | ||
import { ExtensionContext } from "./preRelease/types"; | ||
|
||
export default function handlePluginInstalled( | ||
context: ExtensionContext | ||
): Disposable { | ||
return onPluginInstalledEmitter.event(() => { | ||
if (isAlreadyOpenedGettingStarted(context)) return; | ||
openGettingStartedWebview(context); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ExtensionContext } from "../preRelease/types"; | ||
|
||
export const ALREADY_OPENED_GETTING_STARTED_KEY = | ||
"already-opened-getting-started"; | ||
|
||
export async function setAlreadyOpenedGettingStarted( | ||
context: ExtensionContext | ||
): Promise<void> { | ||
await context.globalState.update(ALREADY_OPENED_GETTING_STARTED_KEY, true); | ||
} | ||
|
||
export function isAlreadyOpenedGettingStarted( | ||
context: ExtensionContext | ||
): boolean { | ||
return context.globalState.get<boolean>( | ||
ALREADY_OPENED_GETTING_STARTED_KEY, | ||
false | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as assert from "assert"; | ||
import { afterEach } from "mocha"; | ||
import * as sinon from "sinon"; | ||
import { onPluginInstalledEmitter } from "../../events/onPluginInstalledEmitter"; | ||
import { getContext } from "./utils/preReleaseInstaller.utils"; | ||
import handlePluginInstalled from "../../handlePluginInstalled"; | ||
import { ALREADY_OPENED_GETTING_STARTED_KEY } from "../../state/gettingStartedOpenedState"; | ||
import * as gettingStartedWebview from "../../webview/openGettingStartedWebview"; | ||
|
||
suite("Getting started tests", () => { | ||
afterEach(() => { | ||
sinon.verifyAndRestore(); | ||
}); | ||
|
||
test("Should open the webview if the user hasn't seen it yet", () => { | ||
const openGettingStartedWebviewStub = sinon.spy( | ||
gettingStartedWebview, | ||
"openGettingStartedWebview" | ||
); | ||
const handler = handlePluginInstalled(getContext({})); | ||
onPluginInstalledEmitter.fire(); | ||
handler.dispose(); | ||
|
||
assert(openGettingStartedWebviewStub.calledOnce); | ||
}); | ||
|
||
test("Should not open the webview if the user has already seen it", () => { | ||
const openGettingStartedWebviewStub = sinon.spy( | ||
gettingStartedWebview, | ||
"openGettingStartedWebview" | ||
); | ||
const handler = handlePluginInstalled( | ||
getContext({ | ||
[ALREADY_OPENED_GETTING_STARTED_KEY]: true, | ||
}) | ||
); | ||
onPluginInstalledEmitter.fire(); | ||
handler.dispose(); | ||
|
||
assert(openGettingStartedWebviewStub.notCalled); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ViewColumn, WebviewPanel, window } from "vscode"; | ||
import { fireEvent } from "../binary/requests/requests"; | ||
import { createIFrameTemplate } from "./webviewTemplates"; | ||
import { setAlreadyOpenedGettingStarted } from "../state/gettingStartedOpenedState"; | ||
import { TABNINE_GETTING_STARTED_FOR_VSCODE_URL } from "../globals/consts"; | ||
import { ExtensionContext } from "../preRelease/types"; | ||
|
||
let panel: WebviewPanel | undefined; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export function openGettingStartedWebview(context: ExtensionContext): void { | ||
if (!panel) { | ||
panel = window.createWebviewPanel( | ||
"tabnine.getting-started", | ||
"Tabnine - Getting Started", | ||
{ viewColumn: ViewColumn.Beside, preserveFocus: false }, | ||
{ | ||
retainContextWhenHidden: true, | ||
enableFindWidget: true, | ||
enableCommandUris: true, | ||
enableScripts: true, | ||
} | ||
); | ||
panel.onDidDispose(() => { | ||
panel = undefined; | ||
void fireEvent({ | ||
name: "getting-started-closed", | ||
}); | ||
}); | ||
panel.webview.html = createIFrameTemplate( | ||
TABNINE_GETTING_STARTED_FOR_VSCODE_URL | ||
); | ||
void setAlreadyOpenedGettingStarted(context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export const createIFrameTemplate = (url: string): string => ` | ||
<!DOCTYPE html> | ||
<html lang="en" style="margin: 0; padding: 0; min-width: 100%; min-height: 100%"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Tabnine Hub</title> | ||
</head> | ||
<body style="margin: 0; padding: 0; min-width: 100%; min-height: 100%"> | ||
<iframe src="${url}" id="config" frameborder="0" style="display: block; margin: 0; padding: 0; position: absolute; min-width: 100%; min-height: 100%; visibility: visible;"></iframe> | ||
</body> | ||
</html>`; |