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

feat(file-picker): support clearing files (VIV-1995) #1983

Merged
merged 5 commits into from
Nov 11, 2024

Conversation

RichardHelm
Copy link
Contributor

No description provided.

Copy link

codecov bot commented Nov 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (d61b119) to head (58e08dc).
Report is 1150 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##              main     #1983     +/-   ##
===========================================
  Coverage   100.00%   100.00%             
===========================================
  Files          123       361    +238     
  Lines         1562      7309   +5747     
  Branches       108       971    +863     
===========================================
+ Hits          1562      7309   +5747     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@YonatanKra YonatanKra self-requested a review November 7, 2024 08:19
@YonatanKra YonatanKra self-assigned this Nov 7, 2024
Copy link
Contributor

@YonatanKra YonatanKra left a comment

Choose a reason for hiding this comment

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

Nice and very well needed feature. Thanks :)

Comment on lines 53 to 56
/**
* @internal
*/
_dropzone?: Dropzone;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to expose dropzone?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Otherwise there is an error when accessing #dropzone from valueChanged
I believe this is because FAST will call valueChanged before the constructor is completed and the private member is not ready

Copy link
Contributor

Choose a reason for hiding this comment

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

I pushed a change that reverts it. Seems to work.
The problem is that valuechanged is sent to an event listener, which fires outside the context of the element.
By changing the valueChanged to be an arrow function, it retains the context wherever it is called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's not what's happening though. With your fix valueChange will be initialised at a later point and miss the initial call that causes the error. But I'm happy to accept it like this

@@ -73,6 +73,7 @@ describe('vwc-file-picker', () => {
unmountedElement.maxFileSize = 256;
unmountedElement.maxFiles = 1;
unmountedElement.accept = '.jpg';
unmountedElement.removeAllFiles();
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't removeAllFiles tested in its own it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is just to cover the optional chain.
To ensure it doesn't throw when component is unmounted

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the full test (for some reason it was hidden in the diff), it's a very general test and an unclear spec.

  1. Would removeAllFiles cause an error in unmounted state at any point?
  2. Did removing and appending the component to the DOM (connecting/disconnecting in WC terms?) cause an error before?
    In other words, what piece of code do I delete for the expectation to fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removeAllFiles will throw an error in unmounted state without the optional chain (because dropzone is not initialised)

@YonatanKra YonatanKra force-pushed the VIV-1995-clearing-files branch from aadebe5 to f3f0145 Compare November 8, 2024 04:11
@RichardHelm RichardHelm enabled auto-merge (squash) November 11, 2024 10:06
@RichardHelm RichardHelm merged commit 94d6f49 into main Nov 11, 2024
15 checks passed
@RichardHelm RichardHelm deleted the VIV-1995-clearing-files branch November 11, 2024 10:22
@github-actions github-actions bot mentioned this pull request Nov 11, 2024
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.

2 participants