Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,31 @@

<nz-dropdown-menu #sortOptions="nzDropdownMenu">
<ul nz-menu>
@if (showEditTime) {
<li nz-menu-item>
<button
(click)="lastSort()"
nz-button>
By Edit Time
</button>
</li>
}
<li nz-menu-item>
<button
(click)="dateSort()"
nz-button>
By Create Time
</button>
</li>
@if (showExecutionTime) {
<li nz-menu-item>
<button
(click)="execSort()"
nz-button>
By Execution Time
</button>
</li>
}
<li nz-menu-item>
<button
(click)="ascSort()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,21 @@ describe("SortButtonComponent", () => {
expect(component.sortMethod).toBe(SortMethod.ExecutionTimeDesc);
expect(emitSpy).toHaveBeenCalledWith(SortMethod.ExecutionTimeDesc);
});

// Note: the sort options render inside an nz-dropdown-menu (a CDK overlay) that
// does not attach under the vitest/jsdom test environment, so we can't assert on
// the rendered menu text. We instead verify the input contract that the template's
// @if guards bind to (showEditTime / showExecutionTime).
it("shows the edit-time and execution-time options by default (e.g. for workflows)", () => {
expect(component.showEditTime).toBe(true);
expect(component.showExecutionTime).toBe(true);
});

it("can hide edit-time and execution-time options (e.g. for datasets, which have neither)", () => {
component.showEditTime = false;
component.showExecutionTime = false;
fixture.detectChanges();
expect(component.showEditTime).toBe(false);
expect(component.showExecutionTime).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { Component, EventEmitter, Output } from "@angular/core";
import { Component, EventEmitter, Input, Output } from "@angular/core";
import { SortMethod } from "../../../type/sort-method";
import { NzDropdownADirective, NzDropdownDirective, NzDropdownMenuComponent } from "ng-zorro-antd/dropdown";
import { NzSpaceCompactItemDirective } from "ng-zorro-antd/space";
Expand Down Expand Up @@ -47,6 +47,14 @@ import { NzMenuDirective, NzMenuItemComponent } from "ng-zorro-antd/menu";
export class SortButtonComponent {
@Output()
public sortMethodChange = new EventEmitter<SortMethod>();

// Some resource types (e.g. datasets) have no edit or execution timestamp; hide the
// corresponding options so they can't produce an undefined (NULL) sort order.
@Input()
public showEditTime = true;
@Input()
public showExecutionTime = true;

public sortMethod = SortMethod.EditTimeDesc;

public lastSort(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,32 @@ <h2 class="page-title">Datasets</h2>
nzTheme="outline"></i>
<span>Create Dataset</span>
</button>
<button
nz-button
title="List View"
(click)="setViewType('list')"
[nzType]="viewType === 'list' ? 'primary' : 'default'">
<i
nz-icon
nzType="bars"
nzTheme="outline"></i>
</button>
<button
nz-button
title="Card View"
(click)="setViewType('card')"
[nzType]="viewType === 'card' ? 'primary' : 'default'">
<i
nz-icon
nzType="appstore"
nzTheme="outline"></i>
</button>
<nz-space-compact class="utility-button-group">
<texera-sort-button
[showEditTime]="false"
[showExecutionTime]="false"
(sortMethodChange)="sortMethod = $event; search()"></texera-sort-button>
<button
nz-button
title="List View"
(click)="setViewType('list')"
[nzType]="viewType === 'list' ? 'primary' : 'default'">
<i
nz-icon
nzType="bars"
nzTheme="outline"></i>
</button>
<button
nz-button
title="Card View"
(click)="setViewType('card')"
[nzType]="viewType === 'card' ? 'primary' : 'default'">
<i
nz-icon
nzType="appstore"
nzTheme="outline"></i>
</button>
</nz-space-compact>
<texera-filters #filters></texera-filters>
</div>
</nz-card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ describe("UserDatasetComponent", () => {
});
});

describe("default sort", () => {
it("defaults to CreateTimeDesc so newest datasets appear first", () => {
// Datasets have no last-modified time, so EditTimeDesc would leave the sort key NULL.
expect(component.sortMethod).toBe(SortMethod.CreateTimeDesc);
});
});

describe("ngAfterViewInit", () => {
it("subscribes to userChanged and calls search on each emission", () => {
const searchSpy = vi.spyOn(component, "search").mockResolvedValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { DashboardEntry } from "../../../type/dashboard-entry";
import { SearchResultsComponent } from "../search-results/search-results.component";
import { CardItemComponent } from "../list-item/card-item/card-item.component";
import { FiltersComponent } from "../filters/filters.component";
import { SortButtonComponent } from "../sort-button/sort-button.component";
import { firstValueFrom } from "rxjs";
import { USER_DATASET } from "../../../../app-routing.constant";
import { NzModalService } from "ng-zorro-antd/modal";
Expand All @@ -36,7 +37,7 @@ import { DashboardDataset } from "../../../type/dashboard-dataset.interface";
import { NzMessageService } from "ng-zorro-antd/message";
import { map, tap } from "rxjs/operators";
import { NzCardComponent } from "ng-zorro-antd/card";
import { NzSpaceCompactItemDirective } from "ng-zorro-antd/space";
import { NzSpaceCompactItemDirective, NzSpaceCompactComponent } from "ng-zorro-antd/space";
import { NzButtonComponent } from "ng-zorro-antd/button";
import { NzWaveDirective } from "ng-zorro-antd/core/wave";
import { ɵNzTransitionPatchDirective } from "ng-zorro-antd/core/transition-patch";
Expand All @@ -53,11 +54,13 @@ import { FormsModule } from "@angular/forms";
imports: [
NzCardComponent,
NzSpaceCompactItemDirective,
NzSpaceCompactComponent,
NzButtonComponent,
NzWaveDirective,
ɵNzTransitionPatchDirective,
NzIconDirective,
FiltersComponent,
SortButtonComponent,
FiltersInstructionsComponent,
NzSelectComponent,
FormsModule,
Expand All @@ -67,7 +70,9 @@ import { FormsModule } from "@angular/forms";
})
export class UserDatasetComponent implements AfterViewInit {
private static readonly VIEW_MODE_STORAGE_KEY = "texera.userDataset.viewMode";
public sortMethod = SortMethod.EditTimeDesc;
// Datasets have no "last modified" timestamp, so EditTimeDesc leaves the sort key NULL for every
// row and produces an undefined order. Default to CreateTimeDesc so newly created datasets appear first.
public sortMethod = SortMethod.CreateTimeDesc;
lastSortMethod: SortMethod | null = null;
public isLogin = this.userService.isLogin();
public currentUid = this.userService.getCurrentUser()?.uid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
<div class="search-container">
<div class="search-section">
<div class="filter">
<texera-sort-button (sortMethodChange)="sortMethod = $event; search()"></texera-sort-button>
<texera-sort-button
[showEditTime]="searchType !== 'dataset'"
[showExecutionTime]="searchType !== 'dataset'"
(sortMethodChange)="sortMethod = $event; search()"></texera-sort-button>
<texera-filters #filters></texera-filters>
<div
*ngIf="searchType === 'dataset'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ export class HubSearchResultComponent implements OnInit, AfterViewInit {
const url = this.router.url;
if (url.includes("dataset")) {
this.searchType = "dataset";
// Datasets have no last-modified/execution time, so EditTimeDesc leaves the sort key NULL.
// Default to CreateTimeDesc so newly created datasets appear first.
this.sortMethod = SortMethod.CreateTimeDesc;
} else if (url.includes("workflow")) {
this.searchType = "workflow";
}
Expand Down
Loading