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 3 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/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to the "zowe-explorer-api" extension will be documented in t
- Deprecated the methods `ZoweVsCodeExtension.loginWithBaseProfile` and `ZoweVsCodeExtension.logoutWithBaseProfile`. Use `ZoweVsCodeExtension.ssoLogin` and `ZoweVsCodeExtension.ssoLogout` instead, which use the `BaseProfileAuthOptions` interface and allow you to choose whether the token value in the base profile should have precedence in case there are conflicts. [#3076](https://github.com/zowe/zowe-explorer-vscode/pull/3076)
- Fixed bug in `ProfilesCache` class where old profiles were still accessible after deleting a Team configuration file. [#3124](https://github.com/zowe/zowe-explorer-vscode/issues/3124)
- Added `extensionRemovedFromPath` private function to the `DsEntry` class to allow removing the extension from a data set before making API calls. [#3121](https://github.com/zowe/zowe-explorer-vscode/issues/3121)
- Added "Date Completed" attribute to JobSortOpts enum type. [#1685](https://github.com/zowe/vscode-extension-for-zowe/issues/1685)

### Bug fixes

Expand Down
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
2 changes: 2 additions & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen

### New features and enhancements

- Implemented sorting of jobs by timestamp(on last job ran) [#1685](https://github.com/zowe/vscode-extension-for-zowe/issues/1685)

### Bug fixes

- The "Zowe Resources" panel is now hidden by default until Zowe Explorer reveals it to display a table or other data. [#3113](https://github.com/zowe/zowe-explorer-vscode/issues/3113)
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
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