Skip to content

Commit

Permalink
refactor(ui-raw): update getRawFile to return File instance instead…
Browse files Browse the repository at this point in the history
… of custom RawFile type
  • Loading branch information
hdinia committed Dec 20, 2024
1 parent 60cf750 commit 6c1713a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ function Json({ filePath, filename, studyId, canEdit }: DataCompProps) {
////////////////////////////////////////////////////////////////

const handleDownload = async () => {
const { data, filename } = await getRawFile({ studyId, path: filePath });
downloadFile(data, filename);
const file = await getRawFile({ studyId, path: filePath });
return downloadFile(file, file.name);
};

const handleSave: JSONEditorProps["onSave"] = (json) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ function Text({
////////////////////////////////////////////////////////////////

const handleDownload = async () => {
const { data, filename } = await getRawFile({ studyId, path: filePath });
downloadFile(data, filename);
const file = await getRawFile({ studyId, path: filePath });
return downloadFile(file, file.name);
};

const handleUploadSuccessful = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function Unsupported({ studyId, filePath, filename, canEdit }: DataCompProps) {
////////////////////////////////////////////////////////////////

const handleDownload = async () => {
const { data, filename } = await getRawFile({ studyId, path: filePath });
downloadFile(data, filename);
const file = await getRawFile({ studyId, path: filePath });
return downloadFile(file, file.name);
};

////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/common/buttons/DownloadMatrixButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ function DownloadMatrixButton(props: DownloadMatrixButtonProps) {
}

if (format === "raw") {
const { data, filename } = await getRawFile({ studyId, path });
return downloadFile(data, filename);
const file = await getRawFile({ studyId, path });
return downloadFile(file, file.name);
}

const isXlsx = format === "xlsx";
Expand Down
10 changes: 5 additions & 5 deletions webapp/src/services/api/studies/raw/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export async function deleteFile(params: DeleteFileParams) {
* @param params.path - Path to the file within the study
* @returns Promise containing the file data and metadata
*/
export async function getRawFile(params: GetRawFileParams): Promise<RawFile> {
export async function getRawFile(params: GetRawFileParams) {
const { studyId, path } = params;

const { data, headers } = await client.get<RawFile["data"]>(
Expand All @@ -119,8 +119,8 @@ export async function getRawFile(params: GetRawFileParams): Promise<RawFile> {
}
}

return {
data,
filename,
};
return new File([data], filename, {
type: data.type, // Preserve the MIME type from the Blob
lastModified: new Date().getTime(),
});
}
4 changes: 0 additions & 4 deletions webapp/src/services/api/studies/raw/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,3 @@ export interface GetRawFileParams {
studyId: string;
path: string;
}
export interface RawFile {
data: Blob;
filename: string;
}

0 comments on commit 6c1713a

Please sign in to comment.