Skip to content

Commit

Permalink
fix: job tree not creating new nodes
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Jul 7, 2023
1 parent 6ae3d57 commit 0bb2c1a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
2 changes: 2 additions & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen

### Bug fixes

- Fixed issue where job session nodes were not adding new job nodes when refreshed. [#2370](https://github.com/zowe/vscode-extension-for-zowe/issues/2370)

## `2.9.1`

### Bug fixes
Expand Down
2 changes: 0 additions & 2 deletions packages/zowe-explorer/src/job/ZosJobsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,6 @@ export class ZosJobsProvider extends ZoweTreeProvider implements IZoweTree<IZowe
node.label = node.getProfileName();
node.description = searchCriteria;
this.addSearchHistory(searchCriteria);
node.dirty = true;
this.refreshElement(node);
}
} else {
if (isExpanded) {
Expand Down
33 changes: 23 additions & 10 deletions packages/zowe-explorer/src/job/ZoweJobNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ export class Job extends ZoweTreeNode implements IZoweJobTreeNode {
}
if (this.dirty) {
const elementChildren: Record<string, ZoweJobNode> = {};
let unmodifiedCount = this.children.length;
if (contextually.isJob(this)) {
// Fetch spool files under job node
const cachedProfile = Profiles.getInstance().loadNamedProfile(this.getProfileName());
Expand Down Expand Up @@ -159,7 +158,6 @@ export class Job extends ZoweTreeNode implements IZoweJobTreeNode {
const existing = this.children.find((element) => element.label?.includes(`${spool.stepname}:${spool.ddname}${spoolSuffix}`));
if (existing) {
existing.label = newLabel;
unmodifiedCount--;
} else {
const spoolNode = new Spool(newLabel, vscode.TreeItemCollapsibleState.None, this, this.session, spool, this.job, this);
const icon = getIconByNode(spoolNode);
Expand All @@ -177,6 +175,19 @@ export class Job extends ZoweTreeNode implements IZoweJobTreeNode {
} else {
// Fetch jobs under session node
const jobs = await this.getJobs(this._owner, this._prefix, this._searchId, this._jobStatus);
if (!jobs.length) {
const noJobsNode = new Spool(
localize("getChildren.noJobs", "There are no jobs to display"),
vscode.TreeItemCollapsibleState.None,
this,
null,
null,
null,
this
);
noJobsNode.iconPath = null;
return [noJobsNode];
}
jobs.forEach((job) => {
let nodeTitle: string;
if (job.retcode) {
Expand All @@ -189,7 +200,6 @@ export class Job extends ZoweTreeNode implements IZoweJobTreeNode {
if (existing) {
// If matched, update the label to reflect latest retcode/status
existing.label = nodeTitle;
unmodifiedCount--;
} else {
const jobNode = new Job(nodeTitle, vscode.TreeItemCollapsibleState.Collapsed, this, this.session, job, this.getProfile());
jobNode.contextValue = globals.JOBS_JOB_CONTEXT;
Expand All @@ -207,18 +217,21 @@ export class Job extends ZoweTreeNode implements IZoweJobTreeNode {
});
}

// Child nodes already exist and every node was updated.
// Return cached list of child nodes
if (this.children.length && unmodifiedCount === 0) {
return this.children;
}

// Only add new children that are not in the list of existing child nodes
const newChildren = Object.values(elementChildren)
.sort((a, b) => a.job.jobid - b.job.jobid)
.filter((c) => this.children.find((ch) => ch.label === c.label) == null);

// If there are no new children to add, return the cached list
if (Object.keys(elementChildren).length > 0 && newChildren.length == 0) {
this.dirty = false;
return this.children;
}

// Remove any children that are no longer present in the built record
this.children = this.children.concat(newChildren).filter((ch) => ch.label in elementChildren);
this.children = this.children
.concat(newChildren)
.filter((ch) => Object.values(elementChildren).find((recordCh) => recordCh.jobid === ch.job.jobid) == null);
}
this.dirty = false;
return this.children;
Expand Down

0 comments on commit 0bb2c1a

Please sign in to comment.