From d2a34aa8af216e9a259c73fd197e7412ada0fdb3 Mon Sep 17 00:00:00 2001 From: GomeChas Date: Wed, 17 Jul 2024 19:42:28 -0500 Subject: [PATCH 1/6] Added helper method isGalaxyFile() and gracefully handle previous galaxy file upload. --- client/src/utils/upload-payload.js | 19 +++++++++++++++++++ client/src/utils/upload-payload.test.js | 22 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/client/src/utils/upload-payload.js b/client/src/utils/upload-payload.js index 2fbca26c06da..a624bd5b4dbd 100644 --- a/client/src/utils/upload-payload.js +++ b/client/src/utils/upload-payload.js @@ -18,6 +18,17 @@ export function isUrl(content) { return URI_PREFIXES.some((prefix) => content.startsWith(prefix)); } +export function isGalaxyFile(content) { + const galaxyRegexPattern = /Galaxy\d+-\[(.*?)\](\..+)/; + const match = content.match(galaxyRegexPattern); + if (match) { + console.log(`Uploaded file has previous Galaxy annotated filename: "${content}"`); + return true; + } else { + return false; + } +} + export function uploadPayload(items, historyId, composite = false) { const files = []; const elements = items @@ -28,6 +39,14 @@ export function uploadPayload(items, historyId, composite = false) { if (fileName === DEFAULT_FILE_NAME) { fileName = null; } + if (isGalaxyFile(fileName)) { + const modifiedFileName = fileName.replace(/Galaxy\d+-\[(.*?)\](\..+)/, "$1"); + + const keepModifiedName = confirm(`This looks like a previous Galaxy file. We have renamed it.\n\nOriginal Name: ${fileName}\nModified Name: ${modifiedFileName}\n\n Do you want to keep the modified name?`) + if (keepModifiedName) { + fileName = modifiedFileName; + } + } // consolidate exclusive file content attributes const urlContent = (item.fileUri || item.filePath || item.fileContent || "").trim(); const hasFileData = item.fileData && item.fileData.size > 0; diff --git a/client/src/utils/upload-payload.test.js b/client/src/utils/upload-payload.test.js index 9a3bc946391e..ee261053b0df 100644 --- a/client/src/utils/upload-payload.test.js +++ b/client/src/utils/upload-payload.test.js @@ -66,6 +66,7 @@ describe("uploadPayload", () => { spaceToTab: false, toPosixLines: false, }, + { fileContent: " PreviousGalaxyFileContent ", fileMode: "new", fileName: "Galaxy-1[PreviousGalaxyFile].bed" }, ], "historyId" ); @@ -126,6 +127,16 @@ describe("uploadPayload", () => { to_posix_lines: false, url: "http://test.me", }, + { + dbkey: "?", + deferred: undefined, + ext: "auto", + name: "PreviousGalaxyFile", + paste_content: " PreviousGalaxyFileContent ", + space_to_tab: undefined, + src: "pasted", + to_posix_lines: undefined, + }, ], }, ], @@ -147,6 +158,7 @@ describe("uploadPayload", () => { spaceToTab: true, toPosixLines: true, }, + { fileContent: " PreviousGalaxyFileContent ", fileMode: "new", fileName: "Galaxy-1[PreviousGalaxyFile].bed" }, ], "historyId", true @@ -181,6 +193,16 @@ describe("uploadPayload", () => { src: "files", to_posix_lines: true, }, + { + dbkey: "?", + deferred: undefined, + ext: "auto", + name: "PreviousGalaxyFile", + paste_content: " PreviousGalaxyFileContent ", + space_to_tab: undefined, + src: "pasted", + to_posix_lines: undefined, + }, ], }, dbkey: "?", From d720b2ecf930b0dacb7347cf88d5abf0551173eb Mon Sep 17 00:00:00 2001 From: GomeChas Date: Wed, 17 Jul 2024 19:57:10 -0500 Subject: [PATCH 2/6] Strip surrounding text from uploaded Galaxy file - Uses a helper isGalaxyFile() to check for Galaxy file syntax. - Handles the rename gracefully with a confirmation pop-up. --- client/src/utils/upload-payload.js | 1 - 1 file changed, 1 deletion(-) diff --git a/client/src/utils/upload-payload.js b/client/src/utils/upload-payload.js index a624bd5b4dbd..c7c2329c89d8 100644 --- a/client/src/utils/upload-payload.js +++ b/client/src/utils/upload-payload.js @@ -41,7 +41,6 @@ export function uploadPayload(items, historyId, composite = false) { } if (isGalaxyFile(fileName)) { const modifiedFileName = fileName.replace(/Galaxy\d+-\[(.*?)\](\..+)/, "$1"); - const keepModifiedName = confirm(`This looks like a previous Galaxy file. We have renamed it.\n\nOriginal Name: ${fileName}\nModified Name: ${modifiedFileName}\n\n Do you want to keep the modified name?`) if (keepModifiedName) { fileName = modifiedFileName; From 0bee9c23e0c5ea8acbaff96b1a8dcfa6ac581bb5 Mon Sep 17 00:00:00 2001 From: GomeChas Date: Wed, 17 Jul 2024 20:37:41 -0500 Subject: [PATCH 3/6] Fix bug related to undefined and null fileName in isGalaxyFile() --- client/src/utils/upload-payload.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/client/src/utils/upload-payload.js b/client/src/utils/upload-payload.js index c7c2329c89d8..be61ac8a00ba 100644 --- a/client/src/utils/upload-payload.js +++ b/client/src/utils/upload-payload.js @@ -19,6 +19,9 @@ export function isUrl(content) { } export function isGalaxyFile(content) { + if (content === undefined || content === null) { + return false; + } const galaxyRegexPattern = /Galaxy\d+-\[(.*?)\](\..+)/; const match = content.match(galaxyRegexPattern); if (match) { @@ -39,10 +42,11 @@ export function uploadPayload(items, historyId, composite = false) { if (fileName === DEFAULT_FILE_NAME) { fileName = null; } - if (isGalaxyFile(fileName)) { - const modifiedFileName = fileName.replace(/Galaxy\d+-\[(.*?)\](\..+)/, "$1"); - const keepModifiedName = confirm(`This looks like a previous Galaxy file. We have renamed it.\n\nOriginal Name: ${fileName}\nModified Name: ${modifiedFileName}\n\n Do you want to keep the modified name?`) + if (isGalaxyFile(item.fileName)) { + const modifiedFileName = item.fileName.replace(/Galaxy\d+-\[(.*?)\](\..+)/, "$1"); + const keepModifiedName = confirm(`This looks like a previous Galaxy file. We have renamed it.\n\nOriginal Name: ${item.fileName}\nModified Name: ${modifiedFileName}\n\n Do you want to keep the modified name?`) if (keepModifiedName) { + item.fileName = modifiedFileName; fileName = modifiedFileName; } } From 4133a31255ee8eae4ea724694b5264024d77eaa1 Mon Sep 17 00:00:00 2001 From: GomeChas Date: Wed, 17 Jul 2024 21:07:09 -0500 Subject: [PATCH 4/6] still troubleshooting tests... --- client/src/utils/upload-payload.test.js | 53 ++++++++++++++++--------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/client/src/utils/upload-payload.test.js b/client/src/utils/upload-payload.test.js index ee261053b0df..5872d866b5ac 100644 --- a/client/src/utils/upload-payload.test.js +++ b/client/src/utils/upload-payload.test.js @@ -66,13 +66,22 @@ describe("uploadPayload", () => { spaceToTab: false, toPosixLines: false, }, - { fileContent: " PreviousGalaxyFileContent ", fileMode: "new", fileName: "Galaxy-1[PreviousGalaxyFile].bed" }, + { + dbKey: "dbKey5", + deferred: true, + extension: "extension5", + fileData: { size: 1 }, + fileMode: "local", + fileName: "Galaxy5-[PreviousGalaxyFile].bed", + spaceToTab: true, + toPosixLines: true, + }, ], "historyId" ); expect(p).toEqual({ auto_decompress: true, - files: [{ size: 1 }], + files: [{ size: 1 }, { size: 1}], history_id: "historyId", targets: [ { @@ -128,14 +137,13 @@ describe("uploadPayload", () => { url: "http://test.me", }, { - dbkey: "?", - deferred: undefined, - ext: "auto", + dbkey: "dbKey5", + deferred: true, + ext: "extension5", name: "PreviousGalaxyFile", - paste_content: " PreviousGalaxyFileContent ", - space_to_tab: undefined, - src: "pasted", - to_posix_lines: undefined, + space_to_tab: true, + src: "files", + to_posix_lines: true, }, ], }, @@ -158,14 +166,24 @@ describe("uploadPayload", () => { spaceToTab: true, toPosixLines: true, }, - { fileContent: " PreviousGalaxyFileContent ", fileMode: "new", fileName: "Galaxy-1[PreviousGalaxyFile].bed" }, + { + dbKey: "dbKey2", + deferred: true, + extension: "extension2", + fileContent: "fileContent", + fileData: "fileData", + fileMode: "local", + fileName: "Galaxy2-[PreviousGalaxyFile].bed", + spaceToTab: true, + toPosixLines: true, + }, ], "historyId", true ); expect(p).toEqual({ auto_decompress: true, - files: ["fileData"], + files: ["fileData", "fileData"], history_id: "historyId", targets: [ { @@ -194,14 +212,13 @@ describe("uploadPayload", () => { to_posix_lines: true, }, { - dbkey: "?", - deferred: undefined, - ext: "auto", + dbkey: "dbKey2", + deferred: true, + ext: "extension2", name: "PreviousGalaxyFile", - paste_content: " PreviousGalaxyFileContent ", - space_to_tab: undefined, - src: "pasted", - to_posix_lines: undefined, + space_to_tab: true, + src: "files", + to_posix_lines: true, }, ], }, From c86e256ea4ee9fa19bfd41b35255abb82c9815ab Mon Sep 17 00:00:00 2001 From: GomeChas Date: Thu, 18 Jul 2024 21:33:06 -0500 Subject: [PATCH 5/6] Format both files with Prettier. --- client/src/utils/upload-payload.js | 4 +++- client/src/utils/upload-payload.test.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client/src/utils/upload-payload.js b/client/src/utils/upload-payload.js index be61ac8a00ba..4b24aed52878 100644 --- a/client/src/utils/upload-payload.js +++ b/client/src/utils/upload-payload.js @@ -44,7 +44,9 @@ export function uploadPayload(items, historyId, composite = false) { } if (isGalaxyFile(item.fileName)) { const modifiedFileName = item.fileName.replace(/Galaxy\d+-\[(.*?)\](\..+)/, "$1"); - const keepModifiedName = confirm(`This looks like a previous Galaxy file. We have renamed it.\n\nOriginal Name: ${item.fileName}\nModified Name: ${modifiedFileName}\n\n Do you want to keep the modified name?`) + const keepModifiedName = confirm( + `This looks like a previous Galaxy file. We have renamed it.\n\nOriginal Name: ${item.fileName}\nModified Name: ${modifiedFileName}\n\n Do you want to keep the modified name?` + ); if (keepModifiedName) { item.fileName = modifiedFileName; fileName = modifiedFileName; diff --git a/client/src/utils/upload-payload.test.js b/client/src/utils/upload-payload.test.js index 5872d866b5ac..747dba290fa0 100644 --- a/client/src/utils/upload-payload.test.js +++ b/client/src/utils/upload-payload.test.js @@ -81,7 +81,7 @@ describe("uploadPayload", () => { ); expect(p).toEqual({ auto_decompress: true, - files: [{ size: 1 }, { size: 1}], + files: [{ size: 1 }, { size: 1 }], history_id: "historyId", targets: [ { From a731902582651f138f79d542cc122b457f685dee Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Thu, 9 Jan 2025 15:57:17 -0600 Subject: [PATCH 6/6] just rename Galaxy file without a confirmation --- client/src/utils/upload-payload.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/client/src/utils/upload-payload.js b/client/src/utils/upload-payload.js index 4b24aed52878..7fa7d29766d2 100644 --- a/client/src/utils/upload-payload.js +++ b/client/src/utils/upload-payload.js @@ -25,7 +25,6 @@ export function isGalaxyFile(content) { const galaxyRegexPattern = /Galaxy\d+-\[(.*?)\](\..+)/; const match = content.match(galaxyRegexPattern); if (match) { - console.log(`Uploaded file has previous Galaxy annotated filename: "${content}"`); return true; } else { return false; @@ -44,13 +43,8 @@ export function uploadPayload(items, historyId, composite = false) { } if (isGalaxyFile(item.fileName)) { const modifiedFileName = item.fileName.replace(/Galaxy\d+-\[(.*?)\](\..+)/, "$1"); - const keepModifiedName = confirm( - `This looks like a previous Galaxy file. We have renamed it.\n\nOriginal Name: ${item.fileName}\nModified Name: ${modifiedFileName}\n\n Do you want to keep the modified name?` - ); - if (keepModifiedName) { - item.fileName = modifiedFileName; - fileName = modifiedFileName; - } + item.fileName = modifiedFileName; + fileName = modifiedFileName; } // consolidate exclusive file content attributes const urlContent = (item.fileUri || item.filePath || item.fileContent || "").trim();