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
661 additions
and
102 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,87 @@ | ||
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; | ||
} | ||
if (!clusterId) { | ||
return; | ||
} | ||
let name: string|undefined; | ||
if (clusterItem?.cluster?.name) { | ||
name = clusterItem.cluster.name; | ||
} else if (clusterItem?.name) { | ||
name = clusterItem.name; | ||
} | ||
const deleteConfirmation = await window.showWarningMessage(`Are you sure you want to delete remote cluster '${name}'?`, 'Cancel', 'Delete'); | ||
if (deleteConfirmation !== 'Delete') { | ||
return; | ||
} | ||
|
||
const session = await authentication.getSession('redhat-account-auth', ['openid'], { createIfNone: true }); | ||
if (session) { | ||
try { | ||
await rhosakService.deleteKafka(clusterId!, session.accessToken); | ||
} catch (error) { | ||
window.showErrorMessage(`Failed to delete remote cluster '${name}': ${error.message}`); | ||
} | ||
const deleteRequest = { | ||
clusterIds: [clusterId] | ||
}; | ||
return commands.executeCommand("vscode-kafka.api.deleteclusters", deleteRequest); | ||
} | ||
}) | ||
); | ||
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.