From fa91adbdbed9bf6b30e2b0a05ca3bf6ad987c296 Mon Sep 17 00:00:00 2001 From: Buckminsterfullerene02 Date: Sun, 22 Dec 2024 01:02:10 +0000 Subject: [PATCH] Add new settings for default dataset & job sort orders Added two new settings: - zowe.ds.default.sort - zowe.jobs.default.sort They use the same defaults as is currently hardcoded. The '(default)' is no longer hardcoded and is changed based on the settings. TODO: Tests need to be edited/written to reflect new feature/changes. Perhaps include sort order persistence in the feature? Signed-off-by: Buckminsterfullerene02 Refactor code Signed-off-by: Buckminsterfullerene02 --- .../trees/dataset/DatasetTree.unit.test.ts | 8 +- .../trees/job/JobActions.unit.test.ts | 2 +- packages/zowe-explorer/l10n/bundle.l10n.json | 17 +++- packages/zowe-explorer/l10n/poeditor.json | 70 ++++++++++++++- packages/zowe-explorer/package.json | 90 +++++++++++++++++-- packages/zowe-explorer/package.nls.json | 21 +++++ .../src/configuration/Constants.ts | 2 + .../src/trees/dataset/DatasetTree.ts | 8 +- .../src/trees/dataset/DatasetUtils.ts | 31 ++++++- .../src/trees/dataset/ZoweDatasetNode.ts | 9 +- .../zowe-explorer/src/trees/job/JobUtils.ts | 31 ++++++- .../src/trees/job/ZoweJobNode.ts | 7 +- 12 files changed, 263 insertions(+), 33 deletions(-) diff --git a/packages/zowe-explorer/__tests__/__unit__/trees/dataset/DatasetTree.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/trees/dataset/DatasetTree.unit.test.ts index cb1aab8f98..d0ce6bd770 100644 --- a/packages/zowe-explorer/__tests__/__unit__/trees/dataset/DatasetTree.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/trees/dataset/DatasetTree.unit.test.ts @@ -2928,13 +2928,13 @@ describe("Dataset Tree Unit Tests - Sorting and Filtering operations", () => { 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(); @@ -2943,7 +2943,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(); @@ -3107,7 +3107,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(); diff --git a/packages/zowe-explorer/__tests__/__unit__/trees/job/JobActions.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/trees/job/JobActions.unit.test.ts index 23afc0a0db..38478c4d49 100644 --- a/packages/zowe-explorer/__tests__/__unit__/trees/job/JobActions.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/trees/job/JobActions.unit.test.ts @@ -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 diff --git a/packages/zowe-explorer/l10n/bundle.l10n.json b/packages/zowe-explorer/l10n/bundle.l10n.json index 19c344f0bc..d0446fd3ff 100644 --- a/packages/zowe-explorer/l10n/bundle.l10n.json +++ b/packages/zowe-explorer/l10n/bundle.l10n.json @@ -389,7 +389,7 @@ "No spool files found": "No spool files found", "No jobs found": "No jobs found", "Retrieving response from JES list API": "Retrieving response from JES list API", - "Job ID (default)": "Job ID (default)", + "Job ID": "Job ID", "Date Submitted": "Date Submitted", "Date Completed": "Date Completed", "Job Name": "Job Name", @@ -397,6 +397,7 @@ "Sort Direction": "Sort Direction", "Go to Local Filtering": "Go to Local Filtering", "Clear filter for profile": "Clear filter for profile", + "(default)": "(default)", "Create new...": "Create new...", "Submit this query": "Submit this query", "Enter job owner ID": "Enter job owner ID", @@ -577,7 +578,6 @@ "No data sets found": "No data sets found", "Retrieving response from MVS list API": "Retrieving response from MVS list API", "Cannot download, item invalid.": "Cannot download, item invalid.", - "Name (default)": "Name (default)", "Date Created": "Date Created", "Date Modified": "Date Modified", "User ID": "User ID", @@ -898,7 +898,6 @@ "The number of data sets that are about to be searched" ] }, - "Percent Complete": "Percent Complete", "Failed to upload changes for {0}: {1}/Build file hyperlinkError message": { "message": "Failed to upload changes for {0}: {1}", "comment": [ @@ -907,6 +906,18 @@ ] }, "Error encountered while activating and initializing logger": "Error encountered while activating and initializing logger", + "Insufficient read permissions for {0} in local storage./Local storage key": { + "message": "Insufficient read permissions for {0} in local storage.", + "comment": [ + "Local storage key" + ] + }, + "Insufficient write permissions for {0} in local storage./Local storage key": { + "message": "Insufficient write permissions for {0} in local storage.", + "comment": [ + "Local storage key" + ] + }, "Add Credentials": "Add Credentials", "Add username and password for basic authentication": "Add username and password for basic authentication", "Update stored username and password": "Update stored username and password", diff --git a/packages/zowe-explorer/l10n/poeditor.json b/packages/zowe-explorer/l10n/poeditor.json index 48f053d259..0031674ffe 100644 --- a/packages/zowe-explorer/l10n/poeditor.json +++ b/packages/zowe-explorer/l10n/poeditor.json @@ -224,6 +224,36 @@ "zowe.ds.default.ps": { "Default values of Sequential data set creation": "" }, + "zowe.ds.default.sort": { + "Default sort order of data set tree": "" + }, + "zowe.ds.default.sort.method.name": { + "Sort by name": "" + }, + "zowe.ds.default.sort.method.dateCreated": { + "Sort by date created": "" + }, + "zowe.ds.default.sort.method.lastModified": { + "Sort by last modified": "" + }, + "zowe.ds.default.sort.method.userId": { + "Sort by user ID": "" + }, + "zowe.ds.default.sort.method.description": { + "Default method to sort datasets": "" + }, + "zowe.ds.default.sort.direction.ascending": { + "Sort in ascending order": "" + }, + "zowe.ds.default.sort.direction.descending": { + "Sort in descending order": "" + }, + "zowe.ds.default.sort.direction.description": { + "Default direction to sort datasets": "" + }, + "zowe.ds.default.sort.description": { + "Default sort order for datasets": "" + }, "zowe.ds.history": { "Toggle if favorite files persist locally": "" }, @@ -239,6 +269,39 @@ "zowe.jobs.history": { "Toggle if Jobs favorite files persist locally": "" }, + "zowe.jobs.default.sort": { + "Default sort order of job tree": "" + }, + "zowe.jobs.default.sort.method.id": { + "Sort by job ID": "" + }, + "zowe.jobs.default.sort.method.dateSubmitted": { + "Sort by date submitted": "" + }, + "zowe.jobs.default.sort.method.dateCompleted": { + "Sort by date completed": "" + }, + "zowe.jobs.default.sort.method.name": { + "Sort by name": "" + }, + "zowe.jobs.default.sort.method.returnCode": { + "Sort by return code": "" + }, + "zowe.jobs.default.sort.method.description": { + "Default method to sort jobs": "" + }, + "zowe.jobs.default.sort.direction.ascending": { + "Sort in ascending order": "" + }, + "zowe.jobs.default.sort.direction.descending": { + "Sort in descending order": "" + }, + "zowe.jobs.default.sort.direction.description": { + "Default direction to sort jobs": "" + }, + "zowe.jobs.default.sort.description": { + "Default sort order for jobs": "" + }, "zowe.jobs.confirmSubmission": { "Require user confirmation before submitting a job": "" }, @@ -623,7 +686,7 @@ "No spool files found": "", "No jobs found": "", "Retrieving response from JES list API": "", - "Job ID (default)": "", + "Job ID": "", "Date Submitted": "", "Date Completed": "", "Job Name": "", @@ -631,6 +694,7 @@ "Sort Direction": "", "Go to Local Filtering": "", "Clear filter for profile": "", + "(default)": "", "Create new...": "", "Submit this query": "", "Enter job owner ID": "", @@ -696,7 +760,6 @@ "No data sets found": "", "Retrieving response from MVS list API": "", "Cannot download, item invalid.": "", - "Name (default)": "", "Date Created": "", "Date Modified": "", "User ID": "", @@ -813,9 +876,10 @@ "Contents": "", "Open": "", "Are you sure you want to search {0} data sets and members?": "", - "Percent Complete": "", "Failed to upload changes for {0}: {1}": "", "Error encountered while activating and initializing logger": "", + "Insufficient read permissions for {0} in local storage.": "", + "Insufficient write permissions for {0} in local storage.": "", "Add Credentials": "", "Add username and password for basic authentication": "", "Update stored username and password": "", diff --git a/packages/zowe-explorer/package.json b/packages/zowe-explorer/package.json index 9310a620f8..f85432c849 100644 --- a/packages/zowe-explorer/package.json +++ b/packages/zowe-explorer/package.json @@ -1688,6 +1688,50 @@ "description": "%zowe.ds.default.ps%", "scope": "resource" }, + "zowe.ds.templates": { + "type": "array", + "default": [], + "description": "%zowe.ds.templates%", + "scope": "window" + }, + "zowe.ds.default.sort": { + "type": "object", + "default": { + "method": "Name", + "direction": "Ascending" + }, + "properties": { + "method": { + "type": "string", + "enum": [ + "Name", + "DateCreated", + "LastModified", + "UserId" + ], + "enumDescriptions": [ + "%zowe.ds.default.sort.method.name%", + "%zowe.ds.default.sort.method.dateCreated%", + "%zowe.ds.default.sort.method.lastModified%", + "%zowe.ds.default.sort.method.userId%" + ], + "description": "%zowe.ds.default.sort.method.description%" + }, + "direction": { + "type": "string", + "enum": [ + "Ascending", + "Descending" + ], + "enumDescriptions": [ + "%zowe.ds.default.sort.direction.ascending%", + "%zowe.ds.default.sort.direction.descending%" + ], + "description": "%zowe.ds.default.sort.direction.description%" + } + }, + "description": "%zowe.ds.default.sort.description%" + }, "zowe.ds.history": { "default": { "persistence": true, @@ -1699,12 +1743,6 @@ "scope": "application", "deprecationMessage": "%zowe.history.deprecationMsg%" }, - "zowe.ds.templates": { - "type": "array", - "default": [], - "description": "%zowe.ds.templates%", - "scope": "window" - }, "zowe.files.logsFolder.path": { "type": "string", "default": "", @@ -1722,6 +1760,46 @@ "scope": "application", "deprecationMessage": "%zowe.history.deprecationMsg%" }, + "zowe.jobs.default.sort": { + "type": "object", + "default": { + "method": "Name", + "direction": "Ascending" + }, + "properties": { + "method": { + "type": "string", + "enum": [ + "Id", + "DateSubmitted", + "DateCompleted", + "Name", + "ReturnCode" + ], + "enumDescriptions": [ + "%zowe.jobs.default.sort.method.id%", + "%zowe.jobs.default.sort.method.dateSubmitted%", + "%zowe.jobs.default.sort.method.dateCompleted%", + "%zowe.jobs.default.sort.method.name%", + "%zowe.jobs.default.sort.method.returnCode%" + ], + "description": "%zowe.jobs.default.sort.method.description%" + }, + "direction": { + "type": "string", + "enum": [ + "Ascending", + "Descending" + ], + "enumDescriptions": [ + "%zowe.jobs.default.sort.direction.ascending%", + "%zowe.jobs.default.sort.direction.descending%" + ], + "description": "%zowe.jobs.default.sort.direction.description%" + } + }, + "description": "%zowe.jobs.default.sort.description%" + }, "zowe.jobs.history": { "default": { "persistence": true, diff --git a/packages/zowe-explorer/package.nls.json b/packages/zowe-explorer/package.nls.json index 3c5142cf04..5806b4e741 100644 --- a/packages/zowe-explorer/package.nls.json +++ b/packages/zowe-explorer/package.nls.json @@ -74,11 +74,32 @@ "zowe.ds.default.pds": "Default values of Partitioned data set creation", "zowe.ds.default.extended": "Default values of Partitioned data set extended creation", "zowe.ds.default.ps": "Default values of Sequential data set creation", + "zowe.ds.default.sort": "Default sort order of data set tree", + "zowe.ds.default.sort.method.name": "Sort by name", + "zowe.ds.default.sort.method.dateCreated": "Sort by date created", + "zowe.ds.default.sort.method.lastModified": "Sort by last modified", + "zowe.ds.default.sort.method.userId": "Sort by user ID", + "zowe.ds.default.sort.method.description": "Default method to sort datasets", + "zowe.ds.default.sort.direction.ascending": "Sort in ascending order", + "zowe.ds.default.sort.direction.descending": "Sort in descending order", + "zowe.ds.default.sort.direction.description": "Default direction to sort datasets", + "zowe.ds.default.sort.description": "Default sort order for datasets", "zowe.ds.history": "Toggle if favorite files persist locally", "zowe.ds.templates": "Zowe Explorer saved data set templates", "zowe.files.logsFolder.path": "Path to Zowe Explorer logs folder", "zowe.uss.history": "Toggle if USS favorite files persist locally", "zowe.jobs.history": "Toggle if Jobs favorite files persist locally", + "zowe.jobs.default.sort": "Default sort order of job tree", + "zowe.jobs.default.sort.method.id": "Sort by job ID", + "zowe.jobs.default.sort.method.dateSubmitted": "Sort by date submitted", + "zowe.jobs.default.sort.method.dateCompleted": "Sort by date completed", + "zowe.jobs.default.sort.method.name": "Sort by name", + "zowe.jobs.default.sort.method.returnCode": "Sort by return code", + "zowe.jobs.default.sort.method.description": "Default method to sort jobs", + "zowe.jobs.default.sort.direction.ascending": "Sort in ascending order", + "zowe.jobs.default.sort.direction.descending": "Sort in descending order", + "zowe.jobs.default.sort.direction.description": "Default direction to sort jobs", + "zowe.jobs.default.sort.description": "Default sort order for jobs", "zowe.jobs.confirmSubmission": "Require user confirmation before submitting a job", "zowe.jobs.confirmSubmission.yourJobs": "Your Jobs", "zowe.jobs.confirmSubmission.otherUserJobs": "Other user Jobs", diff --git a/packages/zowe-explorer/src/configuration/Constants.ts b/packages/zowe-explorer/src/configuration/Constants.ts index e55309adfb..0b111bb28a 100644 --- a/packages/zowe-explorer/src/configuration/Constants.ts +++ b/packages/zowe-explorer/src/configuration/Constants.ts @@ -70,6 +70,8 @@ export class Constants { public static readonly SETTINGS_DS_DEFAULT_EXTENDED = "zowe.ds.default.extended"; public static readonly SETTINGS_DS_DEFAULT_PS = "zowe.ds.default.ps"; public static readonly SETTINGS_DS_TEMPLATES = "zowe.ds.templates"; + public static readonly SETTINGS_DS_DEFAULT_SORT = "zowe.ds.default.sort"; + public static readonly SETTINGS_JOBS_DEFAULT_SORT = "zowe.jobs.default.sort"; public static readonly SETTINGS_COMMANDS_ALWAYS_EDIT = "zowe.commands.alwaysEdit"; public static readonly SETTINGS_AUTOMATIC_PROFILE_VALIDATION = "zowe.automaticProfileValidation"; public static readonly SETTINGS_SECURE_CREDENTIALS_ENABLED = "zowe.security.secureCredentialsEnabled"; diff --git a/packages/zowe-explorer/src/trees/dataset/DatasetTree.ts b/packages/zowe-explorer/src/trees/dataset/DatasetTree.ts index ee4cd7960f..e10fbab117 100644 --- a/packages/zowe-explorer/src/trees/dataset/DatasetTree.ts +++ b/packages/zowe-explorer/src/trees/dataset/DatasetTree.ts @@ -1303,11 +1303,8 @@ export class DatasetTree extends ZoweTreeProvider implemen public async sortPdsMembersDialog(node: IZoweDatasetTreeNode): Promise { const isSession = SharedContext.isSession(node); - // Assume defaults if a user hasn't selected any sort options yet - const sortOpts = node.sort ?? { - method: Sorting.DatasetSortOpts.Name, - direction: Sorting.SortDirection.Ascending, - }; + // Read default options from settings if a user hasn't selected any sort options yet + const sortOpts = node.sort ?? DatasetUtils.getDefaultSortOptions(); // Adapt menus to user based on the node that was interacted with const specifier = isSession @@ -1348,6 +1345,7 @@ export class DatasetTree extends ZoweTreeProvider implemen ...sortOpts, direction: Constants.SORT_DIRS.indexOf(dir), }; + // TODO: Update sort order as persistence setting maybe } await this.sortPdsMembersDialog(node); return; diff --git a/packages/zowe-explorer/src/trees/dataset/DatasetUtils.ts b/packages/zowe-explorer/src/trees/dataset/DatasetUtils.ts index 7c04fefab7..67a70751f3 100644 --- a/packages/zowe-explorer/src/trees/dataset/DatasetUtils.ts +++ b/packages/zowe-explorer/src/trees/dataset/DatasetUtils.ts @@ -10,13 +10,14 @@ */ import * as vscode from "vscode"; -import { DS_EXTENSION_MAP, Types } from "@zowe/zowe-explorer-api"; +import { DS_EXTENSION_MAP, Types, Sorting } from "@zowe/zowe-explorer-api"; import { Constants } from "../../configuration/Constants"; +import { SettingsConfig } from "../../configuration/SettingsConfig"; import { ZoweLogger } from "../../tools/ZoweLogger"; export class DatasetUtils { - public static readonly DATASET_SORT_OPTS = [ - `$(case-sensitive) ${vscode.l10n.t("Name (default)")}`, + public static DATASET_SORT_OPTS = [ + `$(case-sensitive) ${vscode.l10n.t("Name")}`, `$(calendar) ${vscode.l10n.t("Date Created")}`, `$(calendar) ${vscode.l10n.t("Date Modified")}`, `$(account) ${vscode.l10n.t("User ID")}`, @@ -26,6 +27,30 @@ export class DatasetUtils { // eslint-disable-next-line no-magic-numbers public static readonly DATASET_FILTER_OPTS = [this.DATASET_SORT_OPTS[2], this.DATASET_SORT_OPTS[3]]; + public static updateSortOptionsWithDefault(sortMethod: Sorting.DatasetSortOpts): void { + this.DATASET_SORT_OPTS = this.DATASET_SORT_OPTS.map((opt, index) => { + if (index === sortMethod) { + return `${opt} ${vscode.l10n.t("(default)")}`; + } + return opt; + }); + } + + public static getDefaultSortOptions(): Sorting.NodeSort { + const sortSetting = SettingsConfig.getDirectValue(Constants.SETTINGS_DS_DEFAULT_SORT); + if (typeof sortSetting.method === "string") { + sortSetting.method = Sorting.DatasetSortOpts[sortSetting.method as keyof typeof Sorting.DatasetSortOpts]; + DatasetUtils.updateSortOptionsWithDefault(sortSetting.method); + } + if (typeof sortSetting.direction === "string") { + sortSetting.direction = Sorting.SortDirection[sortSetting.direction as keyof typeof Sorting.SortDirection]; + } + return { + method: sortSetting?.method ?? Sorting.DatasetSortOpts.Name, + direction: sortSetting?.direction ?? Sorting.SortDirection.Ascending, + }; + } + public static getProfileAndDataSetName(node: Types.IZoweNodeType): { profileName: string; dataSetName: string; diff --git a/packages/zowe-explorer/src/trees/dataset/ZoweDatasetNode.ts b/packages/zowe-explorer/src/trees/dataset/ZoweDatasetNode.ts index 03f2ae18d4..077d797de0 100644 --- a/packages/zowe-explorer/src/trees/dataset/ZoweDatasetNode.ts +++ b/packages/zowe-explorer/src/trees/dataset/ZoweDatasetNode.ts @@ -38,7 +38,7 @@ import { ZoweLogger } from "../../tools/ZoweLogger"; import { SharedContext } from "../shared/SharedContext"; import { AuthUtils } from "../../utils/AuthUtils"; import type { Definitions } from "../../configuration/Definitions"; -import type { DatasetTree } from "./DatasetTree"; +import { DatasetTree } from "./DatasetTree"; import { SharedTreeProviders } from "../shared/SharedTreeProviders"; import { DatasetUtils } from "./DatasetUtils"; @@ -88,10 +88,11 @@ export class ZoweDatasetNode extends ZoweTreeNode implements IZoweDatasetTreeNod } if (this.getParent() == null || this.getParent().label === vscode.l10n.t("Favorites")) { - // set default sort options for session nodes + // read sort options from settings file + const sortSetting = DatasetUtils.getDefaultSortOptions(); this.sort = { - method: Sorting.DatasetSortOpts.Name, - direction: Sorting.SortDirection.Ascending, + method: sortSetting.method, + direction: sortSetting.direction, }; } diff --git a/packages/zowe-explorer/src/trees/job/JobUtils.ts b/packages/zowe-explorer/src/trees/job/JobUtils.ts index 02611e2db5..81f1aa6ce8 100644 --- a/packages/zowe-explorer/src/trees/job/JobUtils.ts +++ b/packages/zowe-explorer/src/trees/job/JobUtils.ts @@ -12,9 +12,12 @@ import * as vscode from "vscode"; import * as zosjobs from "@zowe/zos-jobs-for-zowe-sdk"; import { Sorting } from "@zowe/zowe-explorer-api"; +import { SettingsConfig } from "../../configuration/SettingsConfig"; +import { Constants } from "../../configuration/Constants"; + export class JobUtils { - public static readonly JOB_SORT_OPTS = [ - `$(list-ordered) ${vscode.l10n.t("Job ID (default)")}`, + public static JOB_SORT_OPTS = [ + `$(list-ordered) ${vscode.l10n.t("Job ID")}`, `$(calendar) ${vscode.l10n.t("Date Submitted")}`, `$(calendar) ${vscode.l10n.t("Date Completed")}`, `$(case-sensitive) ${vscode.l10n.t("Job Name")}`, @@ -31,4 +34,28 @@ export class JobUtils { }; public static readonly JOB_FILTER_OPTS = [vscode.l10n.t("Go to Local Filtering"), `$(clear-all) ${vscode.l10n.t("Clear filter for profile")}`]; + + public static updateSortOptionsWithDefault(sortMethod: Sorting.JobSortOpts): void { + this.JOB_SORT_OPTS = this.JOB_SORT_OPTS.map((opt, index) => { + if (index === sortMethod) { + return `${opt} ${vscode.l10n.t("(default)")}`; + } + return opt; + }); + } + + public static getDefaultSortOptions(): Sorting.NodeSort { + const sortSetting = SettingsConfig.getDirectValue(Constants.SETTINGS_JOBS_DEFAULT_SORT); + if (typeof sortSetting.method === "string") { + sortSetting.method = Sorting.JobSortOpts[sortSetting.method as keyof typeof Sorting.JobSortOpts]; + JobUtils.updateSortOptionsWithDefault(sortSetting.method); + } + if (typeof sortSetting.direction === "string") { + sortSetting.direction = Sorting.SortDirection[sortSetting.direction as keyof typeof Sorting.SortDirection]; + } + return { + method: sortSetting?.method ?? Sorting.JobSortOpts.Id, + direction: sortSetting?.direction ?? Sorting.SortDirection.Ascending, + }; + } } diff --git a/packages/zowe-explorer/src/trees/job/ZoweJobNode.ts b/packages/zowe-explorer/src/trees/job/ZoweJobNode.ts index abb52708f0..72bcfba04b 100644 --- a/packages/zowe-explorer/src/trees/job/ZoweJobNode.ts +++ b/packages/zowe-explorer/src/trees/job/ZoweJobNode.ts @@ -105,10 +105,13 @@ export class ZoweJobNode extends ZoweTreeNode implements IZoweJobTreeNode { } if (SharedContext.isSession(this)) { + // read sort options from settings file + const sortSetting = JobUtils.getDefaultSortOptions(); this.sort = { - method: Sorting.JobSortOpts.Id, - direction: Sorting.SortDirection.Ascending, + method: sortSetting.method, + direction: sortSetting.direction, }; + if (this.getParent()?.label !== vscode.l10n.t("Favorites") && !SharedContext.isFavorite(this)) { this.id = this.label as string; }