forked from redhat-developer/vscode-rhoas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes redhat-developer#1 Signed-off-by: Fred Bricon <fbricon@gmail.com>
- Loading branch information
Showing
8 changed files
with
2,753 additions
and
317 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,66 @@ | ||
import { TelemetryService } from '@redhat-developer/vscode-redhat-telemetry/lib'; | ||
import { authentication, commands, ExtensionContext, Uri, window } from 'vscode'; | ||
import { rhosakService } from './rhosakService'; | ||
import { createCluster } from './wizard'; | ||
|
||
export const OPEN_RHOSAK_DASHBOARD_CMD = 'rhoas.open.RHOSAKDashboard'; | ||
export const DELETE_RHOSAK_CLUSTER_CMD = 'rhoas.delete.RHOSAKCluster'; | ||
export const CREATE_RHOSAK_CLUSTER_CMD = 'rhoas.create.RHOSAKCluster'; | ||
const LANDING_PAGE = 'https://cloud.redhat.com/beta/application-services/streams'; | ||
|
||
export function registerCommands (context: ExtensionContext, telemetryService:TelemetryService ) { | ||
context.subscriptions.push( | ||
commands.registerCommand(OPEN_RHOSAK_DASHBOARD_CMD, (clusterItem?: any) => { | ||
let clusterId:string|undefined; | ||
if (clusterItem?.cluster?.id) { | ||
clusterId = clusterItem.cluster.id; | ||
} else if (clusterItem?.id) { | ||
clusterId = clusterItem.id; | ||
} | ||
const reason = clusterId?"Cluster page":"Manual invocation"; | ||
openRHOSAKDashboard(telemetryService, reason, clusterId); | ||
}) | ||
); | ||
context.subscriptions.push( | ||
commands.registerCommand(DELETE_RHOSAK_CLUSTER_CMD, async (clusterItem?: any) => { | ||
let clusterId:string|undefined; | ||
if (clusterItem?.cluster?.id) { | ||
clusterId = clusterItem.cluster.id; | ||
} else if (clusterItem?.id) { | ||
clusterId = clusterItem.id; | ||
} | ||
const session = await authentication.getSession('redhat-account-auth', ['openid'], { createIfNone: true }); | ||
if (session) { | ||
await rhosakService.deleteKafka(clusterId!, session.accessToken); | ||
return commands.executeCommand("vscode-kafka.api.deleteclusters", [clusterId]); | ||
} | ||
}) | ||
); | ||
context.subscriptions.push( | ||
commands.registerCommand(CREATE_RHOSAK_CLUSTER_CMD, async () => { | ||
try { | ||
const clusters = await createCluster(telemetryService); | ||
if (clusters && clusters.length > 0){ | ||
return commands.executeCommand("vscode-kafka.api.addclusters", clusters); | ||
} | ||
} catch(e) { | ||
window.showErrorMessage(e?.message); | ||
} | ||
}) | ||
); | ||
} | ||
|
||
export async function openRHOSAKDashboard(telemetryService:TelemetryService, reason: string, clusterId?:string) { | ||
let event = { | ||
name: "rhoas.open.rhosak.dashboard", | ||
properties: { | ||
"reason": reason | ||
} | ||
}; | ||
let page = LANDING_PAGE; | ||
if (clusterId) { | ||
page = `${page}/kafkas/${clusterId}`; | ||
} | ||
telemetryService.send(event); | ||
return commands.executeCommand('vscode.open', Uri.parse(page)); | ||
} |
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
Oops, something went wrong.