From 7b6d7ad9ee0d8d8f5da5e626db72ec90d9d6bd50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Wed, 8 Nov 2023 16:14:43 -0300 Subject: [PATCH] feat: add download taxonomy template button --- src/taxonomy/TaxonomyListPage.jsx | 49 ++++++++++++++++++++++++++----- src/taxonomy/data/api.js | 13 ++++++++ src/taxonomy/messages.js | 12 ++++++++ 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/src/taxonomy/TaxonomyListPage.jsx b/src/taxonomy/TaxonomyListPage.jsx index 98e446e45b..d54f11cf98 100644 --- a/src/taxonomy/TaxonomyListPage.jsx +++ b/src/taxonomy/TaxonomyListPage.jsx @@ -1,18 +1,59 @@ import React from 'react'; import { + Button, CardView, Container, DataTable, + Dropdown, + DropdownButton, + OverlayTrigger, Spinner, + Tooltip, } from '@edx/paragon'; +import { + Add, +} from '@edx/paragon/icons'; import { StudioFooter } from '@edx/frontend-component-footer'; import { useIntl } from '@edx/frontend-platform/i18n'; + +import { getTaxonomyTemplateFile } from './data/api'; import Header from '../header'; import SubHeader from '../generic/sub-header/SubHeader'; import messages from './messages'; import TaxonomyCard from './taxonomy-card'; import { useTaxonomyListDataResponse, useIsTaxonomyListDataLoaded } from './data/apiHooks'; +const TaxonomyListHeaderButtons = () => { + const intl = useIntl(); + return ( + <> + + {intl.formatMessage(messages.downloadTemplateButtonHint)} + + )} + > + + getTaxonomyTemplateFile('csv')}> + {intl.formatMessage(messages.downloadTemplateButtonCSVLabel)} + + getTaxonomyTemplateFile('json')}> + {intl.formatMessage(messages.downloadTemplateButtonJSONLabel)} + + + + + + ); +}; + const TaxonomyListPage = () => { const intl = useIntl(); const useTaxonomyListData = () => { @@ -23,12 +64,6 @@ const TaxonomyListPage = () => { const { taxonomyListData, isLoaded } = useTaxonomyListData(); - const getHeaderButtons = () => ( - // Download template and import buttons. - // TODO Add functionality to this buttons. - undefined - ); - const getOrgSelect = () => ( // Organization select component // TODO Add functionality to this component @@ -50,7 +85,7 @@ const TaxonomyListPage = () => { } hideBorder /> diff --git a/src/taxonomy/data/api.js b/src/taxonomy/data/api.js index 513f7fdaf9..e9236dd929 100644 --- a/src/taxonomy/data/api.js +++ b/src/taxonomy/data/api.js @@ -8,6 +8,10 @@ export const getExportTaxonomyApiUrl = (pk, format) => new URL( `api/content_tagging/v1/taxonomies/${pk}/export/?output_format=${format}&download=1`, getApiBaseUrl(), ).href; +const getTaxonomyTemplateApiUrl = (format) => new URL( + `api/content_tagging/v1/taxonomies/import/template.${format}`, + getApiBaseUrl(), +).href; /** * Get list of taxonomies. @@ -27,3 +31,12 @@ export async function getTaxonomyListData() { export function getTaxonomyExportFile(pk, format) { window.location.href = getExportTaxonomyApiUrl(pk, format); } + +/** + * Downloads the template file for import taxonomies + * @param {('json'|'csv')} format + * @returns {void} + */ +export function getTaxonomyTemplateFile(format) { + window.location.href = getTaxonomyTemplateApiUrl(format); +} diff --git a/src/taxonomy/messages.js b/src/taxonomy/messages.js index 82467e09ba..0f016db033 100644 --- a/src/taxonomy/messages.js +++ b/src/taxonomy/messages.js @@ -9,6 +9,18 @@ const messages = defineMessages({ id: 'course-authoring.taxonomy-list.button.download-template.label', defaultMessage: 'Download template', }, + downloadTemplateButtonCSVLabel: { + id: 'course-authoring.taxonomy-list.button.download-template.csv.label', + defaultMessage: 'CSV template', + }, + downloadTemplateButtonJSONLabel: { + id: 'course-authoring.taxonomy-list.button.download-template.json.label', + defaultMessage: 'JSON template', + }, + downloadTemplateButtonHint: { + id: 'course-authoring.taxonomy-list.butotn.download-template.hint', + defaultMessage: 'Download example taxonomy', + }, importButtonLabel: { id: 'course-authoring.taxonomy-list.button.import.label', defaultMessage: 'Import',