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

feat(ds): Move PDS members without stats to bottom of list #2766

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

### New features and enhancements

- Updated sorting of PDS members to show items without stats at bottom of list [#2660](https://github.com/zowe/vscode-extension-for-zowe/issues/2660)

### Bug fixes

## `2.15.0`

### New features and enhancements

- Implemented sorting of PDS members by date created [#2707](https://github.com/zowe/vscode-extension-for-zowe/pull/2707)
- Added the capability for extenders to contribute new profile types to the Zowe schema during extender activation. [#2508](https://github.com/zowe/vscode-extension-for-zowe/issues/2508)
- Sort encoding by the latest encoding and filter any duplicate encoding if it already exists.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3097,6 +3097,17 @@ describe("Dataset Tree Unit Tests - Sorting and Filtering operations", () => {
expect(mocks.refreshElement).not.toHaveBeenCalled();
});

it("sorts by created date: handling node with undefined property", async () => {
const mocks = getBlockMocks();
const nodes = nodesForSuite();
delete (nodes.pds.children as any)[1].stats.createdDate;
mocks.showQuickPick.mockResolvedValueOnce({ label: "$(calendar) Date Created" });
await tree.sortPdsMembersDialog(nodes.pds);
expect(mocks.nodeDataChanged).toHaveBeenCalled();
expect(mocks.refreshElement).not.toHaveBeenCalled();
expect(nodes.pds.children?.map((c: IZoweDatasetTreeNode) => c.label)).toStrictEqual(["C", "A", "B"]);
});

it("sorts by last modified date", async () => {
const mocks = getBlockMocks();
const nodes = nodesForSuite();
Expand Down Expand Up @@ -3128,6 +3139,17 @@ describe("Dataset Tree Unit Tests - Sorting and Filtering operations", () => {
expect(nodes.pds.children?.map((c: IZoweDatasetTreeNode) => c.label)).toStrictEqual(["A", "D", "C", "B"]);
});

it("sorts by last modified date: handling node with undefined property", async () => {
const mocks = getBlockMocks();
const nodes = nodesForSuite();
delete (nodes.pds.children as any)[1].stats.modifiedDate;
mocks.showQuickPick.mockResolvedValueOnce({ label: "$(calendar) Date Modified" });
await tree.sortPdsMembersDialog(nodes.pds);
expect(mocks.nodeDataChanged).toHaveBeenCalled();
expect(mocks.refreshElement).not.toHaveBeenCalled();
expect(nodes.pds.children?.map((c: IZoweDatasetTreeNode) => c.label)).toStrictEqual(["C", "A", "B"]);
});

it("sorts by user ID", async () => {
const mocks = getBlockMocks();
const nodes = nodesForSuite();
Expand All @@ -3138,6 +3160,17 @@ describe("Dataset Tree Unit Tests - Sorting and Filtering operations", () => {
expect(nodes.pds.children?.map((c: IZoweDatasetTreeNode) => c.label)).toStrictEqual(["B", "A", "C"]);
});

it("sorts by user ID: handling node with undefined property", async () => {
const mocks = getBlockMocks();
const nodes = nodesForSuite();
delete (nodes.pds.children as any)[0].stats.user;
mocks.showQuickPick.mockResolvedValueOnce({ label: "$(account) User ID" });
await tree.sortPdsMembersDialog(nodes.pds);
expect(mocks.nodeDataChanged).toHaveBeenCalled();
expect(mocks.refreshElement).not.toHaveBeenCalled();
expect(nodes.pds.children?.map((c: IZoweDatasetTreeNode) => c.label)).toStrictEqual(["B", "C", "A"]);
});

it("returns to sort selection dialog when sort direction selection is canceled", async () => {
const sortPdsMembersDialog = jest.spyOn(tree, "sortPdsMembersDialog");
const mocks = getBlockMocks();
Expand Down
115 changes: 50 additions & 65 deletions packages/zowe-explorer/src/dataset/ZoweDatasetNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
*
* @returns {Promise<ZoweDatasetNode[]>}
*/
public async getChildren(): Promise<ZoweDatasetNode[]> {

Check warning on line 137 in packages/zowe-explorer/src/dataset/ZoweDatasetNode.ts

View workflow job for this annotation

GitHub Actions / lint

Async method 'getChildren' has a complexity of 35. Maximum allowed is 15
ZoweLogger.trace("ZoweDatasetNode.getChildren called.");
if (!this.pattern && contextually.isSessionNotFav(this)) {
return [
Expand Down Expand Up @@ -311,91 +311,76 @@
* @param method The sorting method to use
* @returns A function that sorts 2 nodes based on the given sorting method
*/
public static sortBy(sort: NodeSort): (a: IZoweDatasetTreeNode, b: IZoweDatasetTreeNode) => number {
public static sortBy(sort: NodeSort): (a: ZoweDatasetNode, b: ZoweDatasetNode) => number {
return (a, b): number => {
const aParent = a.getParent();
if (aParent == null || !contextually.isPds(aParent)) {
return (a.label as string) < (b.label as string) ? -1 : 1;
return a.compareByName(b);
}

const sortLessThan = sort.direction == SortDirection.Ascending ? -1 : 1;
const sortGreaterThan = sortLessThan * -1;

const sortByName = (nodeA: IZoweDatasetTreeNode, nodeB: IZoweDatasetTreeNode): number =>
(nodeA.label as string) < (nodeB.label as string) ? sortLessThan : sortGreaterThan;

const sortDirection = sort.direction == SortDirection.Ascending ? 1 : -1;
if (!a.stats && !b.stats) {
return sortByName(a, b);
return a.compareByName(b, sortDirection);
}

switch (sort.method) {
case DatasetSortOpts.DateCreated: {
const dateA = dayjs(a.stats?.createdDate ?? null);
const dateB = dayjs(b.stats?.createdDate ?? null);

const aVaild = dateA.isValid();
const bValid = dateB.isValid();

a.description = aVaild ? dateA.format("YYYY/MM/DD") : undefined;
b.description = bValid ? dateB.format("YYYY/MM/DD") : undefined;

if (!aVaild) {
return sortGreaterThan;
}

if (!bValid) {
return sortLessThan;
}
case DatasetSortOpts.DateCreated:
return a.compareByDateStat(b, "createdDate", sortDirection);
case DatasetSortOpts.LastModified:
return a.compareByDateStat(b, "modifiedDate", sortDirection);
case DatasetSortOpts.UserId:
return a.compareByStat(b, "user", sortDirection);
default:
return a.compareByName(b, sortDirection);
}
};
}

if (dateA.isSame(dateB, "second")) {
return sortByName(a, b);
}
private compareByName(otherNode: IZoweDatasetTreeNode, sortDirection = 1): number {
return (this.label as string).localeCompare(otherNode.label as string) * sortDirection;
}

return dateA.isBefore(dateB, "second") ? sortLessThan : sortGreaterThan;
}
case DatasetSortOpts.LastModified: {
const dateA = dayjs(a.stats?.modifiedDate ?? null);
const dateB = dayjs(b.stats?.modifiedDate ?? null);
private compareByStat(otherNode: IZoweDatasetTreeNode, statName: keyof DatasetStats, sortDirection = 1): number {
const valueA = (this.stats?.[statName] as string) ?? "";
const valueB = (otherNode.stats?.[statName] as string) ?? "";

const aValid = dateA.isValid();
const bValid = dateB.isValid();
this.description = valueA;
otherNode.description = valueB;

a.description = aValid ? dateA.format("YYYY/MM/DD HH:mm:ss") : undefined;
b.description = bValid ? dateB.format("YYYY/MM/DD HH:mm:ss") : undefined;
if (!valueA && !valueB) {
return this.compareByName(otherNode, sortDirection);

Check warning on line 351 in packages/zowe-explorer/src/dataset/ZoweDatasetNode.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/dataset/ZoweDatasetNode.ts#L351

Added line #L351 was not covered by tests
} else if (!valueA) {
return 1;

Check warning on line 353 in packages/zowe-explorer/src/dataset/ZoweDatasetNode.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/dataset/ZoweDatasetNode.ts#L353

Added line #L353 was not covered by tests
} else if (!valueB) {
return -1;
}

if (!aValid) {
return sortGreaterThan;
}
return (valueA.localeCompare(valueB) || this.compareByName(otherNode)) * sortDirection;
}

if (!bValid) {
return sortLessThan;
}
private compareByDateStat(otherNode: IZoweDatasetTreeNode, statName: "createdDate" | "modifiedDate", sortDirection = 1): number {
const dateA = dayjs(this.stats?.[statName] ?? null);
const dateB = dayjs(otherNode.stats?.[statName] ?? null);

// for dates that are equal down to the second, fallback to sorting by name
if (dateA.isSame(dateB, "second")) {
return sortByName(a, b);
}
const aValid = dateA.isValid();
const bValid = dateB.isValid();

return dateA.isBefore(dateB, "second") ? sortLessThan : sortGreaterThan;
}
case DatasetSortOpts.UserId: {
const userA = a.stats?.user ?? "";
const userB = b.stats?.user ?? "";
this.description = aValid ? dateA.format("YYYY/MM/DD") : undefined;
otherNode.description = bValid ? dateB.format("YYYY/MM/DD") : undefined;

a.description = userA;
b.description = userB;
if (!aValid && !bValid) {
return this.compareByName(otherNode, sortDirection);

Check warning on line 372 in packages/zowe-explorer/src/dataset/ZoweDatasetNode.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/dataset/ZoweDatasetNode.ts#L372

Added line #L372 was not covered by tests
} else if (!aValid) {
return 1;
} else if (!bValid) {
return -1;
}

if (userA === userB) {
return sortByName(a, b);
}
if (dateA.isSame(dateB, "second")) {
return this.compareByName(otherNode, sortDirection);
}

return userA < userB ? sortLessThan : sortGreaterThan;
}
default: {
return sortByName(a, b);
}
}
};
return dateA.isBefore(dateB, "second") ? -sortDirection : sortDirection;
}

/**
Expand Down Expand Up @@ -496,7 +481,7 @@
return responses;
}

public async openDs(forceDownload: boolean, previewMember: boolean, datasetProvider: IZoweTree<IZoweDatasetTreeNode>): Promise<void> {

Check warning on line 484 in packages/zowe-explorer/src/dataset/ZoweDatasetNode.ts

View workflow job for this annotation

GitHub Actions / lint

Async method 'openDs' has a complexity of 21. Maximum allowed is 15
ZoweLogger.trace("ZoweDatasetNode.openDs called.");
await datasetProvider.checkCurrentProfile(this);

Expand Down
Loading