Skip to content

Commit ba67f2d

Browse files
committed
Send telemetry for cluster selection in Add OpenShift Cluster editor
This PR fixes #2020. Signed-off-by: Denis Golovin dgolovin@redhat.com
1 parent 7187a3c commit ba67f2d

File tree

5 files changed

+78
-14
lines changed

5 files changed

+78
-14
lines changed

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,21 @@
766766
"command": "openshift.componentType.newComponent",
767767
"title": "New Component",
768768
"category": "OpenShift"
769+
},
770+
{
771+
"command": "openshift.explorer.addCluster.openLaunchSandboxPage",
772+
"title": "Launch Developer Sandbox",
773+
"category": "OpenShift"
774+
},
775+
{
776+
"command": "openshift.explorer.addCluster.openCreateClusterPage",
777+
"title": "Deploy it in your public cloud",
778+
"category": "OpenShift"
779+
},
780+
{
781+
"command": "openshift.explorer.addCluster.openCrcAddClusterPage",
782+
"title": "Open Add CRC Cluster Wizard",
783+
"category": "OpenShift"
769784
}
770785
],
771786
"keybindings": [
@@ -963,6 +978,10 @@
963978
{
964979
"command": "clusters.openshift.build.openConsole",
965980
"when": "false"
981+
},
982+
{
983+
"command": "openshift.explorer.addCluster.openCrcAddClusterPage",
984+
"when": "false"
966985
}
967986
],
968987
"view/title": [

src/view/@types/windows/index.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22
* Copyright (c) Red Hat, Inc. All rights reserved.
33
* Licensed under the MIT License. See LICENSE file in the project root for license information.
44
*-----------------------------------------------------------------------------------------------*/
5+
interface ActionMessage {
6+
action: string;
7+
params: any;
8+
}
9+
10+
interface VscodeAPI {
11+
postMessage(message: ActionMsg): void;
12+
}
513

614
interface Window {
7-
acquireVsCodeApi(): any;
15+
acquireVsCodeApi(): VscodeAPI;
816
cmdText: string;
917
}

src/view/cluster/app/cluster.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ const clusterTypes = [
5555
}
5656
];
5757

58+
const vscodeApi = window.acquireVsCodeApi();
59+
5860
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
5961
export default function Header() {
6062
const classes = useStyles();
@@ -63,6 +65,23 @@ export default function Header() {
6365
const handleView = (index) => {
6466
if (index === 0) {
6567
setShowWizard(!showWizard);
68+
vscodeApi.postMessage({
69+
action: 'openCrcAddClusterPage',
70+
});
71+
} else if (index === 1) {
72+
vscodeApi.postMessage({
73+
action: 'openLaunchSandboxPage',
74+
params: {
75+
url: clusterTypes[index].redirectLink
76+
}
77+
});
78+
} else if (index === 2) {
79+
vscodeApi.postMessage({
80+
action: 'openCreateClusterPage',
81+
params: {
82+
url: clusterTypes[index].redirectLink
83+
}
84+
});
6685
}
6786
};
6887

@@ -92,7 +111,7 @@ export default function Header() {
92111
<CardActions className={classes.cardButton}>
93112
<Tooltip title={list.tooltip} placement="top">
94113
<div>
95-
<a href={list.redirectLink} onClick={() => handleView(index)} style={{ textDecoration: 'none'}}>
114+
<a onClick={() => handleView(index)} style={{ textDecoration: 'none'}}>
96115
<Button
97116
variant="contained"
98117
color="default"
@@ -120,7 +139,7 @@ export default function Header() {
120139
<Typography variant="body2" component="p" style={{ padding: 20 }}>
121140
Red Hat CodeReady Containers brings a minimal OpenShift 4 cluster on your laptop or desktop computer.<br></br>You can use this wizard to create OpenShift cluster locally. Cluster take approximately 15 minutes to provision.
122141
</Typography>
123-
<AddClusterView />
142+
<AddClusterView vscode={vscodeApi}/>
124143
</Card>
125144
</div>)}
126145
{!showWizard && (

src/view/cluster/app/clusterView.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ import * as ClusterViewStyles from './clusterView.style';
4242
const useStyles = makeStyles(ClusterViewStyles.useStyles);
4343
const StyledBadge = withStyles(ClusterViewStyles.badgeStyles)(Badge);
4444

45-
const vscode = window.acquireVsCodeApi();
46-
4745
const crcDefaults = {
4846
DefaultCPUs: 4,
4947
DefaultMemory: 9216,
@@ -59,7 +57,7 @@ function getSteps() {
5957
}
6058

6159
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
62-
export default function addClusterView() {
60+
export default function addClusterView(props) {
6361
const classes = useStyles();
6462
const crcLatest = '1.22.0';
6563
const crcOpenShift = '4.6.15';
@@ -80,7 +78,7 @@ export default function addClusterView() {
8078
const [statusError, setStatusError] = React.useState(false);
8179

8280
React.useEffect(() => {
83-
vscode.postMessage({action: 'checksetting'});
81+
props.vscode.postMessage({action: 'checksetting'});
8482
}, []);
8583

8684
const steps = getSteps();
@@ -184,12 +182,12 @@ export default function addClusterView() {
184182
setProgress(true);
185183
setCrcStartError(false);
186184
if (settingPresent) {
187-
vscode.postMessage({action: 'start', isSetting: true });
185+
props.vscode.postMessage({action: 'start', isSetting: true });
188186
} else {
189187
const crcStartCommand = (crcNameserver === '') ? `${fileName} start -p ${pullSecretPath} -c ${cpuSize} -m ${memory} -ojson`:
190188
`${fileName} start -p ${pullSecretPath} -c ${cpuSize} -m ${memory} -n ${crcNameserver} -ojson`;
191189

192-
vscode.postMessage({action: 'start',
190+
props.vscode.postMessage({action: 'start',
193191
data: crcStartCommand,
194192
pullSecret: pullSecretPath,
195193
crcLoc: fileName,
@@ -203,23 +201,23 @@ export default function addClusterView() {
203201
const handleStopProcess = () => {
204202
setStopProgress(true);
205203
setCrcStopError(false);
206-
vscode.postMessage({action: 'stop', data: `${fileName}`});
204+
props.vscode.postMessage({action: 'stop', data: `${fileName}`});
207205
}
208206

209207
const handleCrcSetup = () => {
210-
vscode.postMessage({action: 'run', data: `${fileName}` })
208+
props.vscode.postMessage({action: 'run', data: `${fileName}` })
211209
}
212210

213211
const handleCrcLogin = (loginDetails, clusterUrl) => {
214-
vscode.postMessage({action: 'crclogin', data: loginDetails, url: clusterUrl })
212+
props.vscode.postMessage({action: 'crclogin', data: loginDetails, url: clusterUrl })
215213
}
216214

217215
const handleRefresh = () => {
218216
setStatusSkeleton(true);
219217
if (settingPresent) {
220-
vscode.postMessage({action: 'checksetting'});
218+
props.scode.postMessage({action: 'checksetting'});
221219
} else {
222-
vscode.postMessage({action: 'checkcrcstatus', data: `${fileName}`});
220+
props.vscode.postMessage({action: 'checkcrcstatus', data: `${fileName}`});
223221
}
224222
}
225223

src/view/cluster/clusterViewLoader.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { spawn, ChildProcess } from 'child_process';
99
import { ExtenisonID } from '../../util/constants';
1010
import { WindowUtil } from '../../util/windowUtils';
1111
import { CliChannel } from '../../cli';
12+
import { vsCommand } from '../../vscommand';
1213

1314
let panel: vscode.WebviewPanel;
1415

@@ -20,6 +21,21 @@ export default class ClusterViewLoader {
2021
return vscode.extensions.getExtension(ExtenisonID).extensionPath
2122
}
2223

24+
@vsCommand('openshift.explorer.addCluster.openLaunchSandboxPage')
25+
static async openLaunchSandboxPage(url: string) {
26+
await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
27+
}
28+
29+
@vsCommand('openshift.explorer.addCluster.openCreateClusterPage')
30+
static async openCreateClusterPage(url: string) {
31+
await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
32+
}
33+
34+
@vsCommand('openshift.explorer.addCluster.openCrcAddClusterPage')
35+
static async openCrcAddClusterPage(url: string) {
36+
// fake command to report crc selection through telemetry
37+
}
38+
2339
// eslint-disable-next-line @typescript-eslint/require-await
2440
static async loadView(title: string): Promise<vscode.WebviewPanel> {
2541

@@ -43,6 +59,10 @@ export default class ClusterViewLoader {
4359
panel = undefined;
4460
});
4561
panel.webview.onDidReceiveMessage(async (event) => {
62+
if (['openLaunchSandboxPage', 'openCreateClusterPage', 'openCrcAddClusterPage'].includes(event.action)) {
63+
await vscode.commands.executeCommand(`openshift.explorer.addCluster.${event.action}`, event.params?.url);
64+
}
65+
4666
if (event.action === 'run') {
4767
const terminal: vscode.Terminal = WindowUtil.createTerminal(`OpenShift: CRC Setup`, undefined);
4868
terminal.sendText(`${event.data} setup`);

0 commit comments

Comments
 (0)