Skip to content

Commit

Permalink
review: alternative way
Browse files Browse the repository at this point in the history
Signed-off-by: Fernando Rijo Cedeno <[email protected]>
  • Loading branch information
zFernand0 committed Jan 10, 2025
1 parent 8e2b73a commit f31ccd9
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions packages/zowe-explorer/src/trees/dataset/DatasetActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,19 +693,35 @@ export class DatasetActions {
if (name) {
const label = parent.label as string;
const profile = parent.getProfile();
let foundNode: IZoweDatasetTreeNode;
// let foundNode: IZoweDatasetTreeNode;
let memberFound = false;
const memberUri = vscode.Uri.from({
scheme: ZoweScheme.DS,
path: path.posix.join(parent.resourceUri.path, name),
});
try {
// Make sure we have the latest children nodes, i.e. members
await parent.getChildren();
foundNode = parent.children.find((mem) => mem.getLabel().toString().toUpperCase() === name.toUpperCase());
if (foundNode != null) {
const memberFileEntry = await DatasetFSProvider.instance.fetchDatasetAtUri(memberUri);
memberFound = memberFileEntry != null;
if (memberFound) {
const replace = await DatasetActions.determineReplacement(profile, `${label}(${name})`, "mem");
if (replace === "cancel") {
await vscode.commands.executeCommand("vscode.open", foundNode.resourceUri);
await vscode.commands.executeCommand("vscode.open", memberUri);
datasetProvider.refresh();
return;
}
}

// // Make sure we have the latest children nodes, i.e. members
// await parent.getChildren();
// foundNode = parent.children.find((mem) => mem.getLabel().toString().toUpperCase() === name);
// if (foundNode != null) {
// const replace = await DatasetActions.determineReplacement(profile, `${label}(${name})`, "mem");
// if (replace === "cancel") {
// await vscode.commands.executeCommand("vscode.open", foundNode.resourceUri);
// datasetProvider.refresh();
// return;
// }
// }
await ZoweExplorerApiRegister.getMvsApi(profile).createDataSetMember(label + "(" + name + ")", {
responseTimeout: profile.profile?.responseTimeout,
});
Expand All @@ -719,16 +735,17 @@ export class DatasetActions {
}
throw err;
}
const newNode = new ZoweDatasetNode({
label: name,
collapsibleState: vscode.TreeItemCollapsibleState.None,
parentNode: parent,
profile: parent.getProfile(),
});
const theNode = foundNode ?? newNode;
await vscode.workspace.fs.writeFile(theNode.resourceUri, new Uint8Array());
if (!memberFound) {
const newNode = new ZoweDatasetNode({
label: name,
collapsibleState: vscode.TreeItemCollapsibleState.None,
parentNode: parent,
profile: parent.getProfile(),
});
parent.children.push(newNode);
}
await vscode.workspace.fs.writeFile(memberUri, new Uint8Array());

if (foundNode == null) parent.children.push(theNode);
parent.dirty = true;
datasetProvider.refreshElement(parent);

Expand All @@ -738,7 +755,7 @@ export class DatasetActions {
datasetProvider.refreshElement(otherTreeParent);
}

await vscode.commands.executeCommand("vscode.open", theNode.resourceUri);
await vscode.commands.executeCommand("vscode.open", memberUri);
datasetProvider.refresh();
}
}
Expand Down

0 comments on commit f31ccd9

Please sign in to comment.