Skip to content

Commit

Permalink
Improve "Open Kuberbetes YAML file" to avoid accidental opens and dup…
Browse files Browse the repository at this point in the history
…licate files redhat-developer#3919

Fixes: redhat-developer#3919

Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
  • Loading branch information
vrubezhny committed Mar 5, 2024
1 parent 2afe32b commit 5e2b508
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,24 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
loadKubernetesCore(namespace: string | null, value: string) {
const outputFormat = this.getOutputFormat();
const uri = this.kubefsUri(namespace, value, outputFormat);
workspace.openTextDocument(uri).then((doc) => {
if (doc) {
void window.showTextDocument(doc);
}
},

const query = this.getComparableQuery(uri);
const openUri = workspace.textDocuments.map((doc) => doc.uri)
.find((docUri) => {
return (docUri.scheme === uri.scheme &&
docUri.authority === uri.authority &&
docUri.fragment === uri.fragment &&
docUri.path === uri.path &&
this.getComparableQuery(docUri) === query);
});

// If open document is found for the URI provided, we use its URI to bring its editor to the front
// instead of openning a new editor
workspace.openTextDocument(openUri ? openUri : uri).then((doc) => {
if (doc) {
void window.showTextDocument(doc);
}
},
(err) => window.showErrorMessage(`Error loading document: ${err}`));
}

Expand Down Expand Up @@ -450,6 +463,10 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
return Uri.parse(uri);
}

getComparableQuery(uri: Uri): string {
return uri.query.replace(/((\&_)|(\?_)|\s_)=([0-9])+/g, '');
}

@vsCommand('openshift.resource.delete')
public static async deleteResource(component: KubernetesObject) {
await Oc.Instance.deleteKubernetesObject(component.kind, component.metadata.name);
Expand Down

0 comments on commit 5e2b508

Please sign in to comment.