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: add download template button to taxonomy list [FC-0036] #674

Merged

Conversation

rpenido
Copy link
Contributor

@rpenido rpenido commented Nov 8, 2023

Description

This PR adds a new button in the Taxonomy List to allow users to download a sample taxonomy template in the format used to import taxonomies.

download-template

Supporting Information

Testing instructions

  • Go to the taxonomy list page (http://localhost:2001/taxonomy-list)
  • Click on the Download template and then on the CSV template option
  • Check if the template.csv is correctly saved.
  • Click on the Download template and then on the JSON template option
  • Check if the template.json is correctly saved.

Private-ref: FAL-3532

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 8, 2023
@openedx-webhooks
Copy link

openedx-webhooks commented Nov 8, 2023

Thanks for the pull request, @rpenido! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

Copy link

codecov bot commented Nov 8, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (94725df) 88.96% compared to head (7f6319e) 88.96%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #674   +/-   ##
=======================================
  Coverage   88.96%   88.96%           
=======================================
  Files         472      472           
  Lines        7376     7378    +2     
  Branches     1573     1573           
=======================================
+ Hits         6562     6564    +2     
  Misses        787      787           
  Partials       27       27           

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

@rpenido rpenido force-pushed the rpenido/fal-3532-download-template branch from 80d737b to 5381f15 Compare November 9, 2023 12:44
@rpenido rpenido force-pushed the rpenido/fal-3532-download-template branch from 193cf98 to a9414cb Compare November 9, 2023 23:23
@pomegranited
Copy link
Contributor

@rpenido I think you're missing some style changes from the original PR? I'm seeing this when I run this branch:

Screenshot 2023-11-10 110939

Copy link
Contributor

@pomegranited pomegranited left a comment

Choose a reason for hiding this comment

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

👍 Looks great @rpenido !

Could you also please update the PR description and un-draft this to get it ready for upstream/CC review?

  • I tested this on my devstack
  • I read through the code
  • I checked for accessibility issues by using only my keyboard to navigate
  • Includes documentation
  • User-facing strings are extracted for translation

@rpenido
Copy link
Contributor Author

rpenido commented Nov 10, 2023

@rpenido I think you're missing some style changes from the original PR? I'm seeing this when I run this branch:

Screenshot 2023-11-10 110939

Fixed!

@rpenido rpenido marked this pull request as ready for review November 10, 2023 18:46
@pomegranited
Copy link
Contributor

@bradenmacdonald This PR is ready for upstream review -- who should we ask?

@bradenmacdonald
Copy link
Contributor

This PR is ready for upstream review -- who should we ask?

@jristau1984 has offered to coordinate reviews for us for now. @jristau1984 could you please line up a review for this small PR? Or if you folks don't have much capacity for the near future, let me know and I can find a reviewer from Axim or an OpenCraft Core Contributor (as we did on e.g. #645).

@jristau1984 jristau1984 added the jira:2u We want an issue in the 2U Jira instance label Nov 14, 2023
@openedx-webhooks
Copy link

I've created issue TNL-11202 in the private 2U Jira.

@pomegranited
Copy link
Contributor

@rpenido could you add "[FC-0036]" to the PR title here? Thanks :)

@rpenido rpenido changed the title feat: add download template button to taxonomy list feat: add download template button to taxonomy list [FC-0036] Nov 16, 2023
@rpenido
Copy link
Contributor Author

rpenido commented Dec 12, 2023

Hi, @jristau1984! 😃

The same here: do we have an estimated due date for this review?

Thank you! 😃

@jristau1984
Copy link
Contributor

Due to heavy focus on internal goal delivery before the end of the year, I cannot promise any reviews before January. Tagging @cablaa77 and @jimjohnson8 in case they are able to prioritize this earlier.

Copy link
Contributor

@xitij2000 xitij2000 left a comment

Choose a reason for hiding this comment

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

The code looks good. Just some minor suggestions.

Comment on lines 103 to 105
await act(async () => {
fireEvent.click(importMenu);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

These don't need to be wrapped in act since the library itself wraps them "act" internally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 7f6319e!

Comment on lines 115 to 137
it('downloads the taxonomy template json', async () => {
useIsTaxonomyListDataLoaded.mockReturnValue(true);
useTaxonomyListDataResponse.mockReturnValue({
results: [{
id: 1,
name: 'Taxonomy',
description: 'This is a description',
}],
});
const { getByTestId } = render(<RootWrapper />);
const importMenu = getByTestId('taxonomy-download-template');
expect(importMenu).toBeInTheDocument();
await act(async () => {
fireEvent.click(importMenu);
});

const importButton = getByTestId('taxonomy-download-template-json');
expect(importButton).toBeInTheDocument();
await act(async () => {
fireEvent.click(importButton);
});
expect(getTaxonomyTemplateFile).toHaveBeenCalled();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

This and the above test seem to be exactly the same with very minor differences, so we can use parametrisation here as well.

Suggested change
it('downloads the taxonomy template json', async () => {
useIsTaxonomyListDataLoaded.mockReturnValue(true);
useTaxonomyListDataResponse.mockReturnValue({
results: [{
id: 1,
name: 'Taxonomy',
description: 'This is a description',
}],
});
const { getByTestId } = render(<RootWrapper />);
const importMenu = getByTestId('taxonomy-download-template');
expect(importMenu).toBeInTheDocument();
await act(async () => {
fireEvent.click(importMenu);
});
const importButton = getByTestId('taxonomy-download-template-json');
expect(importButton).toBeInTheDocument();
await act(async () => {
fireEvent.click(importButton);
});
expect(getTaxonomyTemplateFile).toHaveBeenCalled();
});
it.each(['CSV', 'JSON'])('downloads the taxonomy template %s', async (fileFormat) => {
useIsTaxonomyListDataLoaded.mockReturnValue(true);
useTaxonomyListDataResponse.mockReturnValue({
results: [{
id: 1,
name: 'Taxonomy',
description: 'This is a description',
}],
});
const { findByRole } = render(<RootWrapper />);
const importMenu = await findByRole('button', {name: /download template/i});
fireEvent.click(importMenu);
const importButton = await findByRole('button', {name: `${fileFormat} template` });
fireEvent.click(importButton);
expect(getTaxonomyTemplateFile).toHaveBeenCalled();
});

Note that I've simplified the test somewhat.

  • Using findByRole etc is preferred to finding by test id.
  • No need for act around fireEvent
  • No need to assert the presence of a component in the document, if the component is missing for some reason then the findByRole will still cause the test 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.

Thank you for the explanation @xitij2000!
Done 7f6319e!
But I didn't manage to find a way to check that the download really started.

src/taxonomy/data/api.js Show resolved Hide resolved
Comment on lines 55 to 63

/**
* Downloads the template file for import taxonomies
* @param {('json'|'csv')} format
* @returns {void}
*/
export function getTaxonomyTemplateFile(format) {
window.location.href = getTaxonomyTemplateApiUrl(format);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of doing this, I think you can just add this URL as a link direct using the download property.

i.e.

<a href={getTaxonomyTemplateApiUrl(format)} download=taxonomy-template.${format}>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! I skipped the download attribute: the download file name is set in the backend API.

Copy link
Contributor

@xitij2000 xitij2000 left a comment

Choose a reason for hiding this comment

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

Looks good! Just one small nit.

Comment on lines +45 to +56
<Dropdown.Item
href={getTaxonomyTemplateApiUrl('csv')}
data-testid="taxonomy-download-template-csv"
>
{intl.formatMessage(messages.downloadTemplateButtonCSVLabel)}
</Dropdown.Item>
<Dropdown.Item
href={getTaxonomyTemplateApiUrl('json')}
data-testid="taxonomy-download-template-json"
>
{intl.formatMessage(messages.downloadTemplateButtonJSONLabel)}
</Dropdown.Item>
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding download=template.json/.csv or just download will also enforce that the browser will downlod the file instead of opening it in a tab.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review @xitij2000 !

We are doing it in the backend here: https://github.com/openedx/openedx-learning/blob/3e2d6a497efddfae7a1c24b361ddfd36704dbb80/openedx_tagging/core/tagging/rest_api/v1/views_import.py#L47 using Content-Disposition. Should we also do it here?

@xitij2000 xitij2000 merged commit a37d13f into openedx:master Dec 19, 2023
6 checks passed
@openedx-webhooks
Copy link

@rpenido 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@xitij2000 xitij2000 deleted the rpenido/fal-3532-download-template branch December 19, 2023 04:01
lucascalvino pushed a commit that referenced this pull request Dec 19, 2023
This commit adds a new button in the Taxonomy List to allow users to download a sample taxonomy template in the format used to import taxonomies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jira:2u We want an issue in the 2U Jira instance open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants