Skip to content

Commit

Permalink
fix(ds/sort): update stats on existing nodes
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Oct 31, 2023
1 parent db09e31 commit db82aac
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions packages/zowe-explorer/src/dataset/ZoweDatasetNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ export class ZoweDatasetNode extends ZoweTreeNode implements IZoweDatasetTreeNod
return;
}

const updateStats = (node: IZoweDatasetTreeNode, item: any): void => {
if ("m4date" in item) {
const { m4date, mtime, msec }: { m4date: string; mtime: string; msec: string } = item;
node.stats = {
user: item.user,
modifiedDate: dayjs(`${m4date} ${mtime}:${msec}`).toDate(),
};
} else if ("id" in item || "changed" in item) {
// missing keys from API response; check for FTP keys
node.stats = {
user: item.id,
modifiedDate: item.changed ? dayjs(item.changed).toDate() : undefined,
};
}
}

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (97% of all statements in
the enclosing function
have an explicit semicolon).

// push nodes to an object with property names to avoid duplicates
const elementChildren: { [k: string]: ZoweDatasetNode } = {};
for (const response of responses) {
Expand All @@ -169,6 +185,7 @@ export class ZoweDatasetNode extends ZoweTreeNode implements IZoweDatasetTreeNod
for (const item of response.apiResponse.items ?? response.apiResponse) {
const existing = this.children.find((element) => element.label.toString() === item.dsname);
if (existing) {
updateStats(existing, item);
elementChildren[existing.label.toString()] = existing;
// Creates a ZoweDatasetNode for a PDS
} else if (item.dsorg === "PO" || item.dsorg === "PO-E") {
Expand Down Expand Up @@ -262,19 +279,7 @@ export class ZoweDatasetNode extends ZoweTreeNode implements IZoweDatasetTreeNod
}

// get user and last modified date for sorting, if available
if ("m4date" in item) {
const { m4date, mtime, msec }: { m4date: string; mtime: string; msec: string } = item;
temp.stats = {
user: item.user,
modifiedDate: dayjs(`${m4date} ${mtime}:${msec}`).toDate(),
};
} else if ("id" in item || "changed" in item) {
// missing keys from API response; check for FTP keys
temp.stats = {
user: item.id,
modifiedDate: item.changed ? dayjs(item.changed).toDate() : undefined,
};
}
updateStats(temp, item);
elementChildren[temp.label.toString()] = temp;
}
}
Expand Down

0 comments on commit db82aac

Please sign in to comment.