Skip to content

Commit 76b0d8e

Browse files
fix: sort persistence overriding sort direction (#4048)
* fix: sort persistence overriding sort direction Signed-off-by: JWaters02 <watersjoshua2002@gmail.com> * chore: changelog Signed-off-by: JWaters02 <watersjoshua2002@gmail.com> * tests: fix that one test had incorrect assertion Signed-off-by: JWaters02 <watersjoshua2002@gmail.com> * fix: tree not updating on sort change Signed-off-by: JWaters02 <watersjoshua2002@gmail.com> --------- Signed-off-by: JWaters02 <watersjoshua2002@gmail.com> Signed-off-by: Joshua Waters <watersjoshua2002@gmail.com> Co-authored-by: Billie Simmons <BillieJean.Simmons@ibm.com>
1 parent 24c2509 commit 76b0d8e

File tree

4 files changed

+82
-13
lines changed

4 files changed

+82
-13
lines changed

packages/zowe-explorer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen
2020
- Fixed an issue where an error appeared when moving an empty PDS across LPARs. [#4001](https://github.com/zowe/zowe-explorer-vscode/pull/4001)
2121
- Fixed an issue where logical record length truncation detection failed for extenders. [#4002](https://github.com/zowe/zowe-explorer-vscode/pull/4002)
2222
- Fixed an issue with the "Create New Data Set" feature where a data set attribute's original value was deleted after the user dismissed the input box. Now, the attribute's value is preserved when the user cancels their input. [#4003](https://github.com/zowe/zowe-explorer-vscode/issues/4003)
23+
- Fixed an issue where the data set sort persistence was overriding the selected sort direction. [#4048](https://github.com/zowe/zowe-explorer-vscode/pull/4048)
2324
- Updated Zowe SDKs to `8.30.1` for technical currency. [#4079](https://github.com/zowe/zowe-explorer-vscode/pull/4079)
2425

2526
## `3.4.0`

packages/zowe-explorer/__tests__/__unit__/trees/dataset/DatasetTree.unit.test.ts

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4253,6 +4253,8 @@ describe("Dataset Tree Unit Tests - Sorting and Filtering operations", () => {
42534253
const mocks = getBlockMocks();
42544254
const nodes = nodesForSuite();
42554255

4256+
nodes.pds.sort = undefined;
4257+
42564258
const persistedSort = {
42574259
method: Sorting.DatasetSortOpts.DateCreated,
42584260
direction: Sorting.SortDirection.Descending,
@@ -4264,8 +4266,8 @@ describe("Dataset Tree Unit Tests - Sorting and Filtering operations", () => {
42644266

42654267
expect(mocks.nodeDataChanged).toHaveBeenCalled();
42664268
expect(mocks.refreshElement).not.toHaveBeenCalled();
4267-
expect(nodes.pds.sort?.method).toBe(Sorting.DatasetSortOpts.Name);
4268-
expect(nodes.pds.sort?.direction).toBe(Sorting.SortDirection.Descending);
4269+
expect((nodes.pds.sort as any)?.method).toBe(Sorting.DatasetSortOpts.Name);
4270+
expect((nodes.pds.sort as any)?.direction).toBe(Sorting.SortDirection.Descending);
42694271
});
42704272

42714273
it("falls back to default sort options when no persistence available", async () => {
@@ -4281,8 +4283,8 @@ describe("Dataset Tree Unit Tests - Sorting and Filtering operations", () => {
42814283

42824284
expect(mocks.nodeDataChanged).toHaveBeenCalled();
42834285
expect(mocks.refreshElement).not.toHaveBeenCalled();
4284-
expect(nodes.pds.sort?.method).toBe(Sorting.DatasetSortOpts.DateCreated);
4285-
expect(nodes.pds.sort?.direction).toBe(Sorting.SortDirection.Ascending);
4286+
expect((nodes.pds.sort as any)?.method).toBe(Sorting.DatasetSortOpts.DateCreated);
4287+
expect((nodes.pds.sort as any)?.direction).toBe(Sorting.SortDirection.Ascending);
42864288
});
42874289

42884290
it("saves sort settings to persistence after sorting", async () => {
@@ -4347,6 +4349,8 @@ describe("Dataset Tree Unit Tests - Sorting and Filtering operations", () => {
43474349
const mocks = getBlockMocks();
43484350
const nodes = nodesForSuite();
43494351

4352+
nodes.session.sort = undefined;
4353+
43504354
const persistedSessionSort = {
43514355
method: Sorting.DatasetSortOpts.LastModified,
43524356
direction: Sorting.SortDirection.Descending,
@@ -4358,8 +4362,8 @@ describe("Dataset Tree Unit Tests - Sorting and Filtering operations", () => {
43584362

43594363
expect(mocks.nodeDataChanged).toHaveBeenCalled();
43604364
expect(mocks.refreshElement).not.toHaveBeenCalled();
4361-
expect(nodes.session.sort?.method).toBe(Sorting.DatasetSortOpts.UserId);
4362-
expect(nodes.session.sort?.direction).toBe(Sorting.SortDirection.Descending);
4365+
expect((nodes.session.sort as any)?.method).toBe(Sorting.DatasetSortOpts.UserId);
4366+
expect((nodes.session.sort as any)?.direction).toBe(Sorting.SortDirection.Descending);
43634367
});
43644368

43654369
it("does not interfere with sort when getSortSetting returns undefined", async () => {
@@ -4413,8 +4417,8 @@ describe("Dataset Tree Unit Tests - Sorting and Filtering operations", () => {
44134417
mocks.showQuickPick.mockResolvedValueOnce({ label: "$(account) User ID" });
44144418
await tree.sortPdsMembersDialog(nodes.pds);
44154419

4416-
expect(nodes.pds.sort?.method).toBe(Sorting.DatasetSortOpts.UserId);
4417-
expect(nodes.pds.sort?.direction).toBe(Sorting.SortDirection.Descending);
4420+
expect((nodes.pds.sort as any)?.method).toBe(Sorting.DatasetSortOpts.UserId);
4421+
expect((nodes.pds.sort as any)?.direction).toBe(Sorting.SortDirection.Descending);
44184422
expect(mocks.nodeDataChanged).toHaveBeenCalled();
44194423
});
44204424

@@ -4487,6 +4491,67 @@ describe("Dataset Tree Unit Tests - Sorting and Filtering operations", () => {
44874491

44884492
expect(favPdsNode.children?.map((c: IZoweDatasetTreeNode) => c.label)).toStrictEqual(["C", "B", "A"]);
44894493
});
4494+
4495+
it("allows changing sort direction when node already has sort set and persistence exists", async () => {
4496+
const mocks = getBlockMocks();
4497+
const nodes = nodesForSuite();
4498+
4499+
nodes.pds.sort = {
4500+
method: Sorting.DatasetSortOpts.Name,
4501+
direction: Sorting.SortDirection.Descending,
4502+
};
4503+
4504+
const persistedSort = {
4505+
method: Sorting.DatasetSortOpts.Name,
4506+
direction: Sorting.SortDirection.Descending,
4507+
};
4508+
const getSortSettingSpy = jest.spyOn(DatasetTree.prototype, "getSortSetting").mockReturnValue(persistedSort);
4509+
4510+
mocks.showQuickPick.mockResolvedValueOnce({ label: "$(fold) Sort Direction" });
4511+
mocks.showQuickPick.mockResolvedValueOnce("Ascending");
4512+
mocks.showQuickPick.mockResolvedValueOnce({ label: "$(case-sensitive) Name" });
4513+
4514+
await tree.sortPdsMembersDialog(nodes.pds);
4515+
4516+
expect(nodes.pds.sort?.direction).toBe(Sorting.SortDirection.Ascending);
4517+
expect(nodes.pds.sort?.method).toBe(Sorting.DatasetSortOpts.Name);
4518+
expect(mocks.nodeDataChanged).toHaveBeenCalled();
4519+
4520+
getSortSettingSpy.mockRestore();
4521+
});
4522+
4523+
it("does not let persistence override sort direction changes by user", async () => {
4524+
const mocks = getBlockMocks();
4525+
const nodes = nodesForSuite();
4526+
4527+
nodes.pds.sort = {
4528+
method: Sorting.DatasetSortOpts.Name,
4529+
direction: Sorting.SortDirection.Ascending,
4530+
};
4531+
4532+
const persistedSort = {
4533+
method: Sorting.DatasetSortOpts.Name,
4534+
direction: Sorting.SortDirection.Ascending,
4535+
};
4536+
jest.spyOn(DatasetTree.prototype, "getSortSetting").mockReturnValue(persistedSort);
4537+
const addSortSettingSpy = jest.spyOn(DatasetTree.prototype, "addSortSetting");
4538+
4539+
mocks.showQuickPick.mockResolvedValueOnce({ label: "$(fold) Sort Direction" });
4540+
mocks.showQuickPick.mockResolvedValueOnce("Descending");
4541+
mocks.showQuickPick.mockResolvedValueOnce({ label: "$(case-sensitive) Name" });
4542+
4543+
await tree.sortPdsMembersDialog(nodes.pds);
4544+
4545+
expect(nodes.pds.sort?.direction).toBe(Sorting.SortDirection.Descending);
4546+
4547+
expect(addSortSettingSpy).toHaveBeenCalledWith(
4548+
nodes.pds,
4549+
expect.objectContaining({
4550+
method: Sorting.DatasetSortOpts.Name,
4551+
direction: Sorting.SortDirection.Descending,
4552+
})
4553+
);
4554+
});
44904555
});
44914556

44924557
describe("filterBy & filterPdsMembersDialog", () => {

packages/zowe-explorer/src/trees/dataset/DatasetTree.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,9 +1795,12 @@ Would you like to do this now?`,
17951795
SharedUtils.getDefaultSortOptions(DatasetUtils.DATASET_SORT_OPTS, Constants.SETTINGS_DS_DEFAULT_SORT, Sorting.DatasetSortOpts);
17961796

17971797
// Override the default sort method if the node already has sort setting in persistence
1798-
const sortSetting = this.getSortSetting(node);
1799-
if (sortSetting) {
1800-
sortOpts = sortSetting;
1798+
// But only do this if the user hasn't already selected a sort method for this node in the current session
1799+
if (node.sort == null) {
1800+
const sortSetting = this.getSortSetting(node);
1801+
if (sortSetting) {
1802+
sortOpts = sortSetting;
1803+
}
18011804
}
18021805

18031806
// Adapt menus to user based on the node that was interacted with

packages/zowe-explorer/src/trees/dataset/ZoweDatasetNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,8 @@ export class ZoweDatasetNode extends ZoweTreeNode implements IZoweDatasetTreeNod
470470
.filter((label) => this.children.find((c) => (c.label as string) === label) == null)
471471
.map((label) => elementChildren[label]);
472472

473-
// Determine sort options: persistence > node > session
474-
const sortOpts = this.persistence.getSortSetting(this) ?? this.sort ?? this.getSessionNode().sort;
473+
// Determine sort options: node > persistence > session
474+
const sortOpts = this.sort ?? this.persistence.getSortSetting(this) ?? this.getSessionNode().sort;
475475

476476
// use the PDS filter if one is set, otherwise try using the session filter
477477
const sessionFilter = SharedContext.isSession(this) ? this.filter : this.getSessionNode().filter;

0 commit comments

Comments
 (0)