axa-ch-webhub-cloud / pattern-library

AXA CH UI component library. Please share, comment, create issues and work with us!
https://axa-ch-webhub-cloud.github.io/plib-feature/develop
125 stars 18 forks source link

FileUpload total file size calculation #2404

Open martinoss opened 1 year ago

martinoss commented 1 year ago

I just noticed that the total file size calculation possibly has a bug.

It seems that when adding a single file, it will be counted twice for the total size over all files.

How to reproduce

  1. Go to this storybook page: https://axa-ch-webhub-cloud.github.io/plib-feature/develop/?path=/story/components-file-upload--file-upload&args=maxSizeOfSingleFileKB:500;maxSizeOfAllFilesKB:999 Notice that max single file size is capped at 500KB and max size of all files is 999KB
  2. Add sample file (exactly 500KB) 500kb.pdf
  3. Notice the error regarding the exceeded total file size for all files
  4. Increase the limit from 999 to 1000, then it works.

A first look into the source suggests that these two lines probably needs to be flipped.

https://github.com/axa-ch-webhub-cloud/pattern-library/blob/eca9f02be6af012e649036d337cf1034afe8fc48/src/components/20-molecules/file-upload/index.js#L442-L443

On line 406, sizeOfAllFilesInBytes already has the value of 512000 when previewing the future total including the new file to be added.

https://github.com/axa-ch-webhub-cloud/pattern-library/blob/eca9f02be6af012e649036d337cf1034afe8fc48/src/components/20-molecules/file-upload/index.js#L398-L413