-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'vscode-kafka.api.saveclusters' and 'vscode-kafka.api.deleteclusters' commands #189
Conversation
src/wizards/clusters.ts
Outdated
@@ -231,4 +205,35 @@ export async function configureDefaultClusters(clusterSettings: ClusterSettings) | |||
]; | |||
} | |||
|
|||
export async function addClusters(clusters: Cluster[], clusterSettings: ClusterSettings, explorer: KafkaExplorer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should prolly move that out from the wizard namespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me addCluster should be renamed to saveCluster and it's a command handler. I suggest that you create in commands/clusters.ts a new class
export class SaveClusterCommandHandler {
constructor(private clusterSettings: ClusterSettings, private explorer: KafkaExplorer) {
}
async execute(clusters: Cluster[]): Promise<void> {
try {
// Save collected clusters in settings.
let createdClusterNames = '';
for (const cluster of clusters) {
this.clusterSettings.upsert(cluster);
if (createdClusterNames !== '') {
createdClusterNames += '\', \'';
}
createdClusterNames += cluster.name;
}
vscode.window.showInformationMessage(`${clusters.length > 1 ? `${clusters.length} clusters` : 'Cluster'} '${createdClusterNames}' created successfully`);
// Refresh the explorer
this.explorer.refresh();
// Selecting the created cluster is done with TreeView#reveal
// 1. Show the treeview of the explorer (otherwise reveal will not work)
this.explorer.show();
// 2. the reveal() call must occur within a timeout(),
// while waiting for a fix in https://github.com/microsoft/vscode/issues/114149
setTimeout(() => {
if (clusters) {
this.explorer.selectClusterByName(clusters[0].name);
}
}, 1000);
}
catch (error) {
showErrorMessage(`Error while creating cluster`, error);
}
}
}
and you consume it in extension.ts and wizard both.
We should really add a Developer section to explain how to extend vscode-kafka with #129 and you new command. |
a3f77ff
to
171b6c3
Compare
7289a8f
to
b280e14
Compare
b280e14
to
cd5b51e
Compare
src/wizards/clusters.ts
Outdated
} | ||
createdClusterNames += cluster.name; | ||
} | ||
let createdClusterNames = getNames(clusters); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think wizard création should wait for SaveClusterCommandHandler command and after we could consume it to savez clusters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I had something like that before the new wizard, but after rebasing, I just wanted to push something that compiles
905eaba
to
3ccc52a
Compare
@@ -196,7 +197,7 @@ function createEditClusterForm(cluster: Cluster | undefined, clusterSettings: Cl | |||
cluster = createCluster(data); | |||
} | |||
// Save cluster | |||
saveCluster(true, data, cluster, clusterSettings, clientAccessor, explorer, selectCluster); | |||
await saveCluster(data, cluster); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have managed select cluster in SaveCommandHandler, it's nice, but you should remove all method which use selectCluster
parameter;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You missed some code.
- in commons.ts => addClusterCommandHandler.execute(); (line 48)
- Add 'vscode-kafka.api.saveclusters' and 'vscode-kafka.api.deleteclusters' commands #189 (comment)
3ccc52a
to
9eb0298
Compare
@@ -19,34 +65,51 @@ export class AddClusterCommandHandler { | |||
} | |||
|
|||
async execute(selectCluster = false): Promise<void> { | |||
openClusterWizard(this.clusterSettings, this.clientAccessor, this.explorer, this.context, selectCluster); | |||
openClusterWizard(this.clusterSettings, this.clientAccessor, this.explorer, this.context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async execute(): Promise<void> {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
9eb0298
to
d5e60b6
Compare
…ers' command Signed-off-by: Fred Bricon <[email protected]>
d5e60b6
to
4f75b10
Compare
It works great, thanks @fbricon ! |
Signed-off-by: Fred Bricon [email protected]