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

Bugfix/bai 1297 fix issue with file uploads #1338

Merged
merged 5 commits into from
Jun 28, 2024

Conversation

ARADDCC002
Copy link
Member

image

@a3957273 a3957273 merged commit 8b74263 into main Jun 28, 2024
14 checks passed
@a3957273 a3957273 deleted the bugfix/BAI-1297-fix-issue-with-file-uploads branch June 28, 2024 10:05
const failedFileList = useMemo(
() =>
failedFileUploads.map((file) => (
<div key={file.fileName}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File names are unique although If three files of the same name were uploaded two of them would fail. Would it be better using the id here instead of the fileName

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have access to the ID for failed uploads, so name is the next best thing. Worst case it'll cause a minor performance issue as react won't be able to track each item in the list (unless someone uploads a large amount of files with the same name).

Comment on lines +130 to +134
successfulFiles.forEach((file) => {
if (!successfulFileUploads.find((successfulFile) => successfulFile.fileName === file.fileName)) {
setSuccessfulFileUploads([...successfulFileUploads, file])
}
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would setSuccessfulFileUpload([...new Set([...successfulFiles, ...successfulFileUploads))]) be a little more performant?

Copy link
Member

@ARADDCC012 ARADDCC012 Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to us creating the objects in successfulFiles each time this function runs, they will have a different reference to the ones in successfulFileUploads even if the properties are the same. That being said, I think this logic can be improved, so I'll do something with it to ensure we're not calling setSuccessfulFileUpload multiple times unnecessarily.

const failedFileList = useMemo(
() =>
failedFileUploads.map((file) => (
<div key={file.fileName}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with using id instead of fileName here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -49,7 +49,7 @@ export async function postRelease(release: CreateReleaseParams) {

export type UpdateReleaseParams = Pick<
ReleaseInterface,
'modelId' | 'modelCardVersion' | 'semver' | 'notes' | 'minor' | 'draft' | 'fileIds' | 'images' | 'comments'
'modelId' | 'modelCardVersion' | 'semver' | 'notes' | 'minor' | 'draft' | 'fileIds' | 'images'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment's also seem to be optional on creation. Could I suggest adding it as optional to the ReleaseInterface. There's some conditional rendering on the Releases page that seems to break when there is no comment attribute. This could just be a result of switching branches.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would agree, but comments are now stored in a separate collection and are no longer a part of the ReleaseInterface

setLoading(false)
}
} catch (e) {
if (e instanceof Error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this assertion necessary and does setLoading(false) inside it impact if this is not carried out?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch on the setLoading(false). I've removed it from this section of the logic as we shouldn't set it until we've finished processing all files. I've ensured we set it to false at the end of this process.

As for the assertion, errors are unknown so this is a simple hack to handle it as an error. Realistically it'll always be an error, but it's not the best piece of code at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants