Skip to content
Open
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 @@ -26,7 +26,7 @@ import { EntityType } from "../../../../../../hub/service/hub.service";
import { NotificationService } from "../../../../../../common/service/notification/notification.service";
import { DomSanitizer } from "@angular/platform-browser";
import { commonTestProviders } from "../../../../../../common/testing/test-utils";
import { of } from "rxjs";
import { of, Subject, throwError } from "rxjs";
import * as Papa from "papaparse";
import JSZip from "jszip";
import readXlsxFile from "read-excel-file";
Expand Down Expand Up @@ -108,6 +108,40 @@ describe("UserDatasetFileRendererComponent", () => {
expect(component.isLoading).toBe(false);
});

it("shows the loading error when the file cannot be fetched", () => {
vi.spyOn(TestBed.inject(DatasetService), "retrieveDatasetVersionSingleFile").mockReturnValue(
throwError(() => new Error("download failed"))
);
component.resourceId = 1;
component.versionId = 2;
component.filePath = "notes.txt";

component.reloadFileContent();

expect(component.isLoading).toBe(false);
expect(component.isFileLoadingError).toBe(true);
});

it("drops a slow file once another file is selected", () => {
const slowFile = new Subject<Blob>();
const notes = new Blob(["notes"], { type: "text/plain" });
vi.spyOn(TestBed.inject(DatasetService), "retrieveDatasetVersionSingleFile").mockImplementation(path =>
path === "data.csv" ? slowFile : of(notes)
);
component.resourceId = 1;
component.versionId = 2;
component.filePath = "data.csv";
component.reloadFileContent();

component.filePath = "notes.txt";
component.reloadFileContent();
slowFile.next(new Blob(["a,b\n1,2"], { type: "text/csv" }));

expect(slowFile.observed).toBe(false);
expect(component.displayCSV).toBe(false);
expect(component.currentFile?.size).toBe(notes.size);
});

it("fetches from the model endpoint when the file belongs to a model", () => {
const datasetSpy = vi.spyOn(TestBed.inject(DatasetService), "retrieveDatasetVersionSingleFile");
const modelSpy = vi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges } from "@
import { ResourceRegistryService } from "../../../../../service/user/resource-registry/resource-registry.service";
import { EntityType } from "../../../../../../hub/service/hub.service";
import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
import { Subscription } from "rxjs";
import * as Papa from "papaparse";
import { ParseResult } from "papaparse";
import { DomSanitizer, SafeUrl } from "@angular/platform-browser";
Expand Down Expand Up @@ -139,6 +140,7 @@ export class UserDatasetFileRendererComponent implements OnInit, OnChanges, OnDe

// control flags
public isLoading: boolean = false;
private fileLoad?: Subscription;
public isFileSizeUnloadable = false;
public isFileLoadingError: boolean = false;
public isFileTypePreviewUnsupported: boolean = false;
Expand Down Expand Up @@ -195,6 +197,7 @@ export class UserDatasetFileRendererComponent implements OnInit, OnChanges, OnDe
}

reloadFileContent() {
this.fileLoad?.unsubscribe();
this.turnOffAllDisplay();

// Pre-check - file size
Expand All @@ -213,7 +216,7 @@ export class UserDatasetFileRendererComponent implements OnInit, OnChanges, OnDe
this.isLoading = true;
const retrieveSingleFile = this.resourceRegistry.get(this.resourceType).retrieveSingleFile;
if (retrieveSingleFile && this.resourceId && this.versionId && this.filePath != "") {
retrieveSingleFile(this.filePath, this.isLogin)
this.fileLoad = retrieveSingleFile(this.filePath, this.isLogin)
.pipe(untilDestroyed(this))
.subscribe({
next: blob => {
Expand Down Expand Up @@ -295,6 +298,7 @@ export class UserDatasetFileRendererComponent implements OnInit, OnChanges, OnDe
break;
}
},
error: () => this.onFileLoadingError(),
});
}
}
Expand Down
Loading