Skip to content
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

Port #2768 V2 PR to V3(main) #3145

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/zowe-explorer-api/src/tree/sorting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export namespace Sorting {
export enum JobSortOpts {
Id,
DateSubmitted,
DateCompleted,
Name,
ReturnCode,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function createIJobObject() {
type: "JOB",
url: "fake/url",
"exec-member": "sampleMember",
"exec-ended": "2024-03-07T00:04:67:980z",
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function createGlobalMocks() {
collapsibleState: vscode.TreeItemCollapsibleState.None,
session: createISession(),
profile: createIProfile(),
job: settingJobObjects(createIJobObject(), "ZOWEUSR1", "JOB045123", "ABEND S222"),
job: settingJobObjects(createIJobObject(), "ZOWEUSR1", "JOB045123", "ABEND S222", "2024-03-12T10:50:08.950Z"),
}),
JobNode2: new ZoweJobNode({
label: "testProfile",
Expand All @@ -69,7 +69,7 @@ function createGlobalMocks() {
collapsibleState: vscode.TreeItemCollapsibleState.None,
session: createISession(),
profile: createIProfile(),
job: settingJobObjects(createIJobObject(), "ZOWEUSR2", "JOB045125", "CC 0000"),
job: settingJobObjects(createIJobObject(), "ZOWEUSR2", "JOB045125", "CC 0000", "2024-03-12T08:30:08.950Z"),
}),
mockJobArray: [],
testJobsTree: null as any,
Expand Down Expand Up @@ -134,10 +134,17 @@ function createGlobalMocks() {
value: jest.fn().mockReturnValue([newMocks.imperativeProfile.name]),
configurable: true,
});
function settingJobObjects(job: zosjobs.IJob, setjobname: string, setjobid: string, setjobreturncode: string): zosjobs.IJob {
function settingJobObjects(
job: zosjobs.IJob,
setjobname: string,
setjobid: string,
setjobreturncode: string,
datecompleted?: string
): zosjobs.IJob {
job.jobname = setjobname;
job.jobid = setjobid;
job.retcode = setjobreturncode;
job["exec-ended"] = datecompleted;
return job;
}

Expand Down Expand Up @@ -1438,6 +1445,26 @@ describe("sortJobs function", () => {
expect(sortbyretcodespy.mock.calls[0][0].children).toStrictEqual(expected.mSessionNodes[0].children);
});

it("sort by date completed", async () => {
const globalMocks = createGlobalMocks();
const testtree = new JobTree();
const expected = new JobTree();
testtree.mSessionNodes[0].sort = {
method: Sorting.JobSortOpts.DateCompleted,
direction: Sorting.SortDirection.Ascending,
};
testtree.mSessionNodes[0].children = [...[globalMocks.mockJobArray[0], globalMocks.mockJobArray[1], globalMocks.mockJobArray[2]]];
expected.mSessionNodes[0].children = [...[globalMocks.mockJobArray[2], globalMocks.mockJobArray[0], globalMocks.mockJobArray[1]]];
jest.spyOn(Gui, "showQuickPick").mockResolvedValueOnce({ label: "$(calendar) Date Completed" });
const sortbynamespy = jest.spyOn(JobTree.prototype, "sortBy");
//act
await JobActions.sortJobs(testtree.mSessionNodes[0], testtree);
//asert
expect(sortbynamespy).toHaveBeenCalledWith(testtree.mSessionNodes[0]);
expect(sortbynamespy).toHaveBeenCalled();
expect(sortbynamespy.mock.calls[0][0].children).toStrictEqual(expected.mSessionNodes[0].children);
});

it("updates sort options after selecting sort direction; returns user to sort selection", async () => {
const globalMocks = createGlobalMocks();
const testtree = new JobTree();
Expand Down
1 change: 1 addition & 0 deletions packages/zowe-explorer/l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@
"Retrieving response from zowe.GetJobs": "Retrieving response from zowe.GetJobs",
"$(list-ordered) Job ID (default)": "$(list-ordered) Job ID (default)",
"$(calendar) Date Submitted": "$(calendar) Date Submitted",
"$(calendar) Date Completed": "$(calendar) Date Completed",
"$(case-sensitive) Job Name": "$(case-sensitive) Job Name",
"$(symbol-numeric) Return Code": "$(symbol-numeric) Return Code",
"$(fold) Sort Direction": "$(fold) Sort Direction",
Expand Down
1 change: 1 addition & 0 deletions packages/zowe-explorer/l10n/poeditor.json
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@
"Retrieving response from zowe.GetJobs": "",
"$(list-ordered) Job ID (default)": "",
"$(calendar) Date Submitted": "",
"$(calendar) Date Completed": "",
"$(case-sensitive) Job Name": "",
"$(symbol-numeric) Return Code": "",
"$(fold) Sort Direction": "",
Expand Down
5 changes: 3 additions & 2 deletions packages/zowe-explorer/src/trees/job/JobUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
import * as vscode from "vscode";
import * as zosjobs from "@zowe/zos-jobs-for-zowe-sdk";
import { Sorting } from "@zowe/zowe-explorer-api";

export class JobUtils {
public static JOB_SORT_OPTS = [
vscode.l10n.t("$(list-ordered) Job ID (default)"),
vscode.l10n.t("$(calendar) Date Submitted"),
vscode.l10n.t("$(calendar) Date Completed"),
vscode.l10n.t("$(case-sensitive) Job Name"),
vscode.l10n.t("$(symbol-numeric) Return Code"),
vscode.l10n.t("$(fold) Sort Direction"),
];

public static JOB_SORT_KEYS: Record<Sorting.JobSortOpts, keyof (zosjobs.IJob & { "exec-submitted": string })> = {
public static JOB_SORT_KEYS: Record<Sorting.JobSortOpts, keyof (zosjobs.IJob & { "exec-submitted": string; "exec-ended": string })> = {
[Sorting.JobSortOpts.Id]: "jobid",
[Sorting.JobSortOpts.DateSubmitted]: "exec-submitted",
[Sorting.JobSortOpts.DateCompleted]: "exec-ended",
[Sorting.JobSortOpts.Name]: "jobname",
[Sorting.JobSortOpts.ReturnCode]: "retcode",
};
Expand Down
17 changes: 15 additions & 2 deletions packages/zowe-explorer/src/trees/job/ZoweJobNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,15 @@
const sortLessThan = sortOpts.direction == Sorting.SortDirection.Ascending ? -1 : 1;
const sortGreaterThan = sortLessThan * -1;

const keyToSortBy = JobUtils.JOB_SORT_KEYS[sortOpts.method];
let keyToSortBy = JobUtils.JOB_SORT_KEYS[sortOpts.method];
let xCompare, yCompare;
if (!x.job[keyToSortBy] && !y.job[keyToSortBy]) {
keyToSortBy = JobUtils.JOB_SORT_KEYS[3];

Check warning on line 287 in packages/zowe-explorer/src/trees/job/ZoweJobNode.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/trees/job/ZoweJobNode.ts#L287

Added line #L287 was not covered by tests
} else if (!x.job[keyToSortBy]) {
return 1;
} else if (!y.job[keyToSortBy]) {
return -1;
}
if (keyToSortBy === "retcode") {
// some jobs (such as active ones) will have a null retcode
// in this case, use status as the key to compare for that node only
Expand All @@ -292,7 +299,13 @@
xCompare = x.job[keyToSortBy];
yCompare = y.job[keyToSortBy];
}

if (keyToSortBy === "exec-ended") {
x.description = x.job["exec-ended"];
y.description = y.job["exec-ended"];
} else {
x.description = "";
y.description = "";
}
if (xCompare === yCompare) {
return x.job["jobid"] > y.job["jobid"] ? sortGreaterThan : sortLessThan;
}
Expand Down
Loading