Skip to content

Commit

Permalink
feat: add download taxonomy template button
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Nov 8, 2023
1 parent 080b03e commit 7b6d7ad
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
49 changes: 42 additions & 7 deletions src/taxonomy/TaxonomyListPage.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<OverlayTrigger
placement="top"
overlay={(
<Tooltip>
{intl.formatMessage(messages.downloadTemplateButtonHint)}
</Tooltip>
)}
>
<DropdownButton
variant="outline-primary"
title={intl.formatMessage(messages.downloadTemplateButtonLabel)}
>
<Dropdown.Item onClick={() => getTaxonomyTemplateFile('csv')}>
{intl.formatMessage(messages.downloadTemplateButtonCSVLabel)}
</Dropdown.Item>
<Dropdown.Item onClick={() => getTaxonomyTemplateFile('json')}>
{intl.formatMessage(messages.downloadTemplateButtonJSONLabel)}
</Dropdown.Item>
</DropdownButton>
</OverlayTrigger>
<Button iconBefore={Add} disabled>
{intl.formatMessage(messages.importButtonLabel)}
</Button>
</>
);
};

const TaxonomyListPage = () => {
const intl = useIntl();
const useTaxonomyListData = () => {
Expand All @@ -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
Expand All @@ -50,7 +85,7 @@ const TaxonomyListPage = () => {
<SubHeader
title={intl.formatMessage(messages.headerTitle)}
titleActions={getOrgSelect()}
headerActions={getHeaderButtons()}
headerActions={<TaxonomyListHeaderButtons />}
hideBorder
/>
</Container>
Expand Down
13 changes: 13 additions & 0 deletions src/taxonomy/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
12 changes: 12 additions & 0 deletions src/taxonomy/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 7b6d7ad

Please sign in to comment.