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

Add new settings for default dataset & job sort orders #3369

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen
- You can now add multiple partitioned data sets or USS directories to your workspace at once using the "Add to Workspace" feature. [#3324](https://github.com/zowe/zowe-explorer-vscode/issues/3324)
- Exposed read and write access to local storage keys for Zowe Explorer extenders. [#3180](https://github.com/zowe/zowe-explorer-vscode/issues/3180)
- Added `Open with Encoding` to the context menu of Job Spool files. [#1941](https://github.com/zowe/zowe-explorer-vscode/issues/1941)
- Added two new settings, `zowe.ds.default.sort` and `zowe.jobs.default.sort`, that allow you to change the default sorting order of datasets and jobs when you open them. [#3369](https://github.com/zowe/zowe-explorer-vscode/pull/3369)

### Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
createTeamConfigMock,
createUnsecureTeamConfigMock,
createMockNode,
createGetConfigMock,
} from "../../__mocks__/mockCreators/shared";
import { createDatasetSessionNode, createDatasetTree } from "../../__mocks__/mockCreators/datasets";
import {
Expand All @@ -37,6 +38,7 @@ import {
Validation,
FileManagement,
ProfilesCache,
Sorting,
AuthHandler,
} from "@zowe/zowe-explorer-api";
import { Profiles } from "../../../src/configuration/Profiles";
Expand Down Expand Up @@ -120,6 +122,15 @@ function createGlobalMocks(): { [key: string]: any } {
configurable: true,
});

Object.defineProperty(SettingsConfig, "getDirectValue", {
value: createGetConfigMock({
"zowe.ds.default.sort": Sorting.DatasetSortOpts.Name,
"zowe.jobs.default.sort": Sorting.JobSortOpts.Id,
[Constants.SETTINGS_SECURE_CREDENTIALS_ENABLED]: false,
}),
configurable: true,
});

Object.defineProperty(vscode.window, "showInformationMessage", {
value: newMocks.mockShowInformationMessage,
configurable: true,
Expand Down Expand Up @@ -582,7 +593,15 @@ describe("Profiles Unit Tests - Function createZoweSchema", () => {
});

Object.defineProperty(SettingsConfig, "getDirectValue", {
value: jest.fn().mockReturnValue(true),
value: jest.fn((key: string) => {
if (key === "zowe.ds.default.sort") {
return Sorting.DatasetSortOpts.Name;
}
if (key === "zowe.jobs.default.sort") {
return Sorting.JobSortOpts.Id;
}
return false;
}),
configurable: true,
});
const spyConfig = jest.spyOn(Profiles.getInstance(), "openConfigFile").mockImplementation();
Expand Down Expand Up @@ -956,6 +975,8 @@ describe("Profiles Unit Tests - function deleteProfile", () => {
sessions: ["test", "test1", "test2"],
fileHistory: ["[TEST]: TEST.LIST"],
searchHistory: ["TEST.*"],
"zowe.ds.default.sort": Sorting.DatasetSortOpts.Name,
"zowe.jobs.default.sort": Sorting.JobSortOpts.Id,
});

// mock USS call to vs code settings
Expand All @@ -966,6 +987,8 @@ describe("Profiles Unit Tests - function deleteProfile", () => {
sessions: ["test", "test1", "test2"],
fileHistory: ["[TEST]: /u/test/test.txt"],
searchHistory: ["/u/test"],
"zowe.ds.default.sort": Sorting.DatasetSortOpts.Name,
"zowe.jobs.default.sort": Sorting.JobSortOpts.Id,
});

// mock Jobs call to vs code settings
Expand All @@ -976,6 +999,8 @@ describe("Profiles Unit Tests - function deleteProfile", () => {
sessions: ["test", "test1", "test2"],
fileHistory: ["TEST"],
searchHistory: ["Owner:TEST Prefix:*"],
"zowe.ds.default.sort": Sorting.DatasetSortOpts.Name,
"zowe.jobs.default.sort": Sorting.JobSortOpts.Id,
});

await expect(Profiles.getInstance().deleteProfile(datasetTree)).resolves.not.toThrow();
Expand Down Expand Up @@ -1949,7 +1974,15 @@ describe("Profiles Unit Tests - function createNonSecureProfile", () => {
const changingConfig = globalMocks.testTeamConfigProfile;
const privateProfile = Profiles.getInstance() as any;
Object.defineProperty(SettingsConfig, "getDirectValue", {
value: jest.fn().mockReturnValue(false),
value: jest.fn((key: string) => {
if (key === "zowe.ds.default.sort") {
return Sorting.DatasetSortOpts.Name;
}
if (key === "zowe.jobs.default.sort") {
return Sorting.JobSortOpts.Id;
}
return false;
}),
configurable: true,
});
expect(privateProfile.createNonSecureProfile(changingConfig)).toBeUndefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as fsextra from "fs-extra";
import * as extension from "../../src/extension";
import * as zosfiles from "@zowe/zos-files-for-zowe-sdk";
import * as zosmf from "@zowe/zosmf-for-zowe-sdk";
import { imperative, Gui, Validation, ProfilesCache, FileManagement, ZoweVsCodeExtension } from "@zowe/zowe-explorer-api";
import { imperative, Gui, Validation, ProfilesCache, FileManagement, ZoweVsCodeExtension, Sorting } from "@zowe/zowe-explorer-api";
import { createGetConfigMock, createInstanceOfProfileInfo, createIProfile, createTreeView } from "../__mocks__/mockCreators/shared";
import { Constants } from "../../src/configuration/Constants";
import { Profiles } from "../../src/configuration/Profiles";
Expand Down Expand Up @@ -349,6 +349,7 @@ async function createGlobalMocks() {
Object.defineProperty(SettingsConfig, "getDirectValue", {
value: createGetConfigMock({
"zowe.automaticProfileValidation": true,
"zowe.ds.default.sort": Sorting.DatasetSortOpts.Name,
}),
});
jest.spyOn(ProfilesUtils, "setupProfileInfo").mockResolvedValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import * as vscode from "vscode";
import { imperative, ProfilesCache, Validation, PersistenceSchemaEnum } from "@zowe/zowe-explorer-api";
import { imperative, ProfilesCache, Validation, PersistenceSchemaEnum, Sorting } from "@zowe/zowe-explorer-api";
import { ZoweLocalStorage } from "../../../src/tools/ZoweLocalStorage";
import { ZoweTreeProvider } from "../../../src/trees/ZoweTreeProvider";
import {
Expand Down Expand Up @@ -149,6 +149,7 @@ async function createGlobalMocks() {
Object.defineProperty(SettingsConfig, "getDirectValue", {
value: createGetConfigMock({
"zowe.automaticProfileValidation": true,
"zowe.ds.default.sort": Sorting.DatasetSortOpts.Name,
}),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
TableViewProvider,
TableBuilder,
Table,
Sorting,
} from "@zowe/zowe-explorer-api";
import { DatasetFSProvider } from "../../../../src/trees/dataset/DatasetFSProvider";
import { bindMvsApi, createMvsApi } from "../../../__mocks__/mockCreators/api";
Expand All @@ -34,6 +35,7 @@ import {
createTreeView,
createQuickPickContent,
createWorkspaceConfiguration,
createGetConfigMock,
} from "../../../__mocks__/mockCreators/shared";
import {
createDatasetAttributes,
Expand All @@ -53,6 +55,7 @@ import { mocked } from "../../../__mocks__/mockUtils";
import { DatasetActions } from "../../../../src/trees/dataset/DatasetActions";
import { AuthUtils } from "../../../../src/utils/AuthUtils";
import { ZoweExplorerApiRegister } from "../../../../src/extending/ZoweExplorerApiRegister";
import { SettingsConfig } from "../../../../src/configuration/SettingsConfig";

// Missing the definition of path module, because I need the original logic for tests
jest.mock("fs");
Expand Down Expand Up @@ -96,6 +99,11 @@ function createGlobalMocks() {
bindMvsApi(newMocks.mvsApi);

Object.defineProperty(vscode.window, "withProgress", { value: jest.fn(), configurable: true });
Object.defineProperty(SettingsConfig, "getDirectValue", {
value: createGetConfigMock({
"zowe.ds.default.sort": Sorting.DatasetSortOpts.Name,
}),
});
Object.defineProperty(zosfiles, "Upload", { value: jest.fn(), configurable: true });
Object.defineProperty(zosfiles.Upload, "bufferToDataSet", { value: jest.fn(), configurable: true });
Object.defineProperty(zosfiles.Upload, "pathToDataSet", { value: jest.fn(), configurable: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ function createGlobalMocks() {
Object.defineProperty(SettingsConfig, "getDirectValue", {
value: createGetConfigMock({
"zowe.automaticProfileValidation": true,
"zowe.ds.default.sort": Sorting.DatasetSortOpts.Name,
}),
});
Object.defineProperty(globalMocks.mockProfilesCache, "getConfigInstance", {
Expand Down Expand Up @@ -2927,14 +2928,15 @@ describe("Dataset Tree Unit Tests - Sorting and Filtering operations", () => {
it("does nothing if no children exist", async () => {
const mocks = getBlockMocks();
const nodes = nodesForSuite();

// case 1: called on PDS node
mocks.showQuickPick.mockResolvedValueOnce({ label: "$(case-sensitive) Name (default)" });
mocks.showQuickPick.mockResolvedValueOnce({ label: "$(case-sensitive) Name" });
nodes.pds.children = [];
await tree.sortPdsMembersDialog(nodes.pds);
expect(mocks.nodeDataChanged).not.toHaveBeenCalled();

// case 2: called on session node
mocks.showQuickPick.mockResolvedValueOnce({ label: "$(case-sensitive) Name (default)" });
mocks.showQuickPick.mockResolvedValueOnce({ label: "$(case-sensitive) Name" });
nodes.session.children = [];
await tree.sortPdsMembersDialog(nodes.session);
expect(mocks.nodeDataChanged).not.toHaveBeenCalled();
Expand All @@ -2943,7 +2945,7 @@ describe("Dataset Tree Unit Tests - Sorting and Filtering operations", () => {
it("sorts by name", async () => {
const mocks = getBlockMocks();
const nodes = nodesForSuite();
mocks.showQuickPick.mockResolvedValueOnce({ label: "$(case-sensitive) Name (default)" });
mocks.showQuickPick.mockResolvedValueOnce({ label: "$(case-sensitive) Name" });
await tree.sortPdsMembersDialog(nodes.pds);
expect(mocks.nodeDataChanged).toHaveBeenCalled();
expect(mocks.refreshElement).not.toHaveBeenCalled();
Expand Down Expand Up @@ -3107,7 +3109,7 @@ describe("Dataset Tree Unit Tests - Sorting and Filtering operations", () => {
it("sorting by session: descriptions are reset when sorted by name", async () => {
const mocks = getBlockMocks();
const nodes = nodesForSuite();
mocks.showQuickPick.mockResolvedValueOnce({ label: "$(case-sensitive) Name (default)" });
mocks.showQuickPick.mockResolvedValueOnce({ label: "$(case-sensitive) Name" });
await tree.sortPdsMembersDialog(nodes.session);
expect(mocks.nodeDataChanged).toHaveBeenCalled();
expect(mocks.refreshElement).not.toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,7 @@ describe("sortJobs function", () => {
testtree.mSessionNodes[0].children = [...[globalMocks.mockJobArray[2], globalMocks.mockJobArray[1], globalMocks.mockJobArray[0]]];
expected.mSessionNodes[0].children = [...[globalMocks.mockJobArray[1], globalMocks.mockJobArray[0], globalMocks.mockJobArray[2]]];
const sortbyidspy = jest.spyOn(JobTree.prototype, "sortBy");
jest.spyOn(Gui, "showQuickPick").mockResolvedValueOnce({ label: "$(list-ordered) Job ID (default)" });
jest.spyOn(Gui, "showQuickPick").mockResolvedValueOnce({ label: "$(list-ordered) Job ID" });
//act
await JobActions.sortJobs(testtree.mSessionNodes[0], testtree);
//asert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import * as vscode from "vscode";
import * as zosjobs from "@zowe/zos-jobs-for-zowe-sdk";
import { Gui, imperative, IZoweJobTreeNode, ProfilesCache, Validation, Poller, ZosEncoding } from "@zowe/zowe-explorer-api";
import { Gui, imperative, IZoweJobTreeNode, ProfilesCache, Validation, Poller, ZosEncoding, Sorting } from "@zowe/zowe-explorer-api";
import { createIJobFile, createIJobObject, createJobFavoritesNode, createJobSessionNode, MockJobDetail } from "../../../__mocks__/mockCreators/jobs";
import {
createIProfile,
Expand All @@ -20,6 +20,7 @@ import {
createISessionWithoutCredentials,
createTreeView,
createInstanceOfProfileInfo,
createGetConfigMock,
} from "../../../__mocks__/mockCreators/shared";
import { createJesApi } from "../../../__mocks__/mockCreators/api";
import { TreeViewUtils } from "../../../../src/utils/TreeViewUtils";
Expand Down Expand Up @@ -178,6 +179,14 @@ async function createGlobalMocks() {
configurable: true,
});

Object.defineProperty(SettingsConfig, "getDirectValue", {
value: createGetConfigMock({
"zowe.ds.default.sort": Sorting.DatasetSortOpts.Name,
"zowe.jobs.default.sort": Sorting.JobSortOpts.Id,
}),
configurable: true,
});

Object.defineProperty(vscode.window, "createTreeView", { value: globalMocks.createTreeView, configurable: true });
Object.defineProperty(vscode.window, "showQuickPick", { value: globalMocks.mockShowQuickPick, configurable: true });
Object.defineProperty(vscode, "ConfigurationTarget", { value: globalMocks.enums, configurable: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import * as vscode from "vscode";
import {
createGetConfigMock,
createInstanceOfProfile,
createIProfile,
createISessionWithoutCredentials,
Expand All @@ -20,7 +21,7 @@ import {
createTreeView,
} from "../../../__mocks__/mockCreators/shared";
import { createDatasetSessionNode, createDatasetTree } from "../../../__mocks__/mockCreators/datasets";
import { Gui, Types } from "@zowe/zowe-explorer-api";
import { Gui, Sorting, Types } from "@zowe/zowe-explorer-api";
import { Profiles } from "../../../../src/configuration/Profiles";
import { ZoweDatasetNode } from "../../../../src/trees/dataset/ZoweDatasetNode";
import { createUSSSessionNode, createUSSTree } from "../../../__mocks__/mockCreators/uss";
Expand All @@ -37,6 +38,7 @@ import { IconUtils } from "../../../../src/icons/IconUtils";
import { IconGenerator } from "../../../../src/icons/IconGenerator";
import { SharedTreeProviders } from "../../../../src/trees/shared/SharedTreeProviders";
import { TreeViewUtils } from "../../../../src/utils/TreeViewUtils";
import { SettingsConfig } from "../../../../src/configuration/SettingsConfig";

function createGlobalMocks() {
const globalMocks = {
Expand Down Expand Up @@ -94,6 +96,13 @@ function createGlobalMocks() {
value: jest.fn().mockReturnValue(createInstanceOfProfile(globalMocks.imperativeProfile)),
configurable: true,
});
Object.defineProperty(SettingsConfig, "getDirectValue", {
value: createGetConfigMock({
"zowe.ds.default.sort": Sorting.DatasetSortOpts.Name,
"zowe.jobs.default.sort": Sorting.JobSortOpts.Id,
}),
configurable: true,
});
Object.defineProperty(zosfiles, "Download", {
value: {
ussFile: jest.fn().mockReturnValue({
Expand Down
Loading
Loading