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

EDD-19: As a download app user, I want to be able to clear my download history. #28

Merged
merged 5 commits into from
Sep 13, 2023

Conversation

eudoroolivares2016
Copy link
Contributor

@eudoroolivares2016 eudoroolivares2016 commented Sep 13, 2023

Overview

What is the feature?

Adding being able to clear items in the download history with the Clear Download History and using a button on the Actions

What is the Solution?

Adding database call and supporting function to remove items from the database

What areas of the application does this impact?

The downloadHistoryPage of the application

List impacted areas.

Testing

Reproduction steps

  • Environment for testing:
  • Collection to test with:

Add downloads, use the clear downloads button on the downloads page. On the download history page remove the downloads with the clear downloads button. Clear all downloads with the clear download history button on the header

Attachments

Please include relevant screenshots or files that would be helpful in reviewing and verifying this change.

Checklist

  • I have added automated tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have bumped the version field in package.json and ran npm install

@codecov
Copy link

codecov bot commented Sep 13, 2023

Codecov Report

Merging #28 (ee10aa9) into main (ba9da56) will increase coverage by 0.09%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #28      +/-   ##
==========================================
+ Coverage   93.26%   93.36%   +0.09%     
==========================================
  Files         102      103       +1     
  Lines        1960     1988      +28     
  Branches      432      433       +1     
==========================================
+ Hits         1828     1856      +28     
  Misses        132      132              
Files Changed Coverage Δ
...ts/DownloadHistoryHeader/DownloadHistoryHeader.jsx 100.00% <100.00%> (ø)
...ownloadHistoryListItem/DownloadHistoryListItem.jsx 96.15% <100.00%> (+1.41%) ⬆️
src/main/eventHandlers/clearDownloadHistory.ts 100.00% <100.00%> (ø)
src/main/preload.ts 100.00% <100.00%> (ø)
src/main/utils/database/EddDatabase.ts 100.00% <100.00%> (ø)
src/main/utils/setupEventListeners.ts 97.82% <100.00%> (+0.04%) ⬆️

Base automatically changed from EDD-18 to main September 13, 2023 14:59
@@ -48,7 +48,7 @@ describe('DownloadHistoryHeader component', () => {
const button = screen.getByRole('button', { name: 'Clear Download History' })
await userEvent.click(button)

expect(clearDownloadHistory).toHaveBeenCalledTimes(0)
expect(clearDownloadHistory).toHaveBeenCalledTimes(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add expect(clearDownloadHistory).toHaveBeenCalledWith({})

@@ -90,6 +92,16 @@ const DownloadHistoryListItem = ({
restartDownload({ downloadId })
},
icon: FaInfoCircle
},
{
label: 'Clear Download',
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't going to show up when a download errored fetching links because of line 66 const shouldShowActions = state !== downloadStates.errorFetchingLinks. We need to ensure the user can also delete the download, but they shouldn't be able to perform the other actions if the state is errorFetchingLinks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}) => {
const { downloadId = '' } = info

if (downloadId.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The database function also has a check for if downloadId exists, I think this function can just have a single call without caring what downloadId is database.clearDownloadHistoryDownloads(downloadId)

*/
async clearDownloadHistoryDownloads(downloadId) {
if (downloadId) {
await this.db('downloads').delete().where({ id: downloadId })
Copy link
Contributor

Choose a reason for hiding this comment

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

After this.db(), put each chained call on its own line

      await this.db('downloads')
        .delete()
        .where({ id: downloadId })

@@ -344,6 +344,80 @@ describe('EddDatabase', () => {
})
})

describe('clearDownloadHistoryDownloads', () => {
describe('when a downloadId is provided', () => {
test('sets the download to inactive', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

'deletes the download, files and pauses'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

false
])

query.response([
Copy link
Contributor

Choose a reason for hiding this comment

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

This response doesn't look like what pluck does, shouldn't it be ['mock-download-id1', 'mock-download-id2']?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it was because pluck is doing that sql statement but, then its calling lodash.map underneath. I removed puck and opted to just call lodash directly

Copy link
Contributor

Choose a reason for hiding this comment

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

I think instead of including another dependency in the file, we should perform the query with joins, and also avoid the first select query. I think this would also work

    await this.db('pauses')
      .delete()
      .join('downloads', { 'pauses.downloadId': 'downloads.id' })
      .where({
        'downloads.active': false
      })

}

// Pluck documentation: https://knexjs.org/guide/query-builder.html#pluck
const inactiveDownloads = await this.db('downloads')
Copy link
Contributor

Choose a reason for hiding this comment

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

inactiveDownloadIds better describes what the variable is

@eudoroolivares2016 eudoroolivares2016 merged commit 72cb052 into main Sep 13, 2023
8 checks passed
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.

3 participants