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 9, 2023
1 parent 78eb512 commit 5381f15
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 8 deletions.
51 changes: 43 additions & 8 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 { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import {
Add,
} from '@edx/paragon/icons';
import { injectIntl, intlShape, useIntl } from '@edx/frontend-platform/i18n';
import { StudioFooter } from '@edx/frontend-component-footer';

import { getTaxonomyTemplateFile } from './data/api';
import Header from '../header';
import SubHeader from '../generic/sub-header/SubHeader';
import messages from './messages';
import TaxonomyCard from './TaxonomyCard';
import { useTaxonomyListDataResponse, useIsTaxonomyListDataLoaded } from './api/hooks/selectors';

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')}>

Check warning on line 42 in src/taxonomy/TaxonomyListPage.jsx

View check run for this annotation

Codecov / codecov/patch

src/taxonomy/TaxonomyListPage.jsx#L42

Added line #L42 was not covered by tests
{intl.formatMessage(messages.downloadTemplateButtonCSVLabel)}
</Dropdown.Item>
<Dropdown.Item onClick={() => getTaxonomyTemplateFile('json')}>

Check warning on line 45 in src/taxonomy/TaxonomyListPage.jsx

View check run for this annotation

Codecov / codecov/patch

src/taxonomy/TaxonomyListPage.jsx#L45

Added line #L45 was not covered by tests
{intl.formatMessage(messages.downloadTemplateButtonJSONLabel)}
</Dropdown.Item>
</DropdownButton>
</OverlayTrigger>
<Button iconBefore={Add} disabled>
{intl.formatMessage(messages.importButtonLabel)}
</Button>
</>
);
};

const TaxonomyListPage = ({ intl }) => {
const useTaxonomyListData = () => {
const taxonomyListData = useTaxonomyListDataResponse();
Expand All @@ -22,12 +63,6 @@ const TaxonomyListPage = ({ intl }) => {

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 @@ -49,7 +84,7 @@ const TaxonomyListPage = ({ intl }) => {
<SubHeader
title={intl.formatMessage(messages.headerTitle)}
titleActions={getOrgSelect()}
headerActions={getHeaderButtons()}
headerActions={<TaxonomyListHeaderButtons />}
hideBorder
/>
</Container>
Expand Down
17 changes: 17 additions & 0 deletions src/taxonomy/data/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @ts-check
import { getConfig } from '@edx/frontend-platform';

const getApiBaseUrl = () => getConfig().STUDIO_BASE_URL;
const getTaxonomyTemplateApiUrl = (format) => new URL(
`api/content_tagging/v1/taxonomies/import/template.${format}`,
getApiBaseUrl(),
).href;

/**
* Downloads the template file for import taxonomies
* @param {('json'|'csv')} format
* @returns {void}
*/
export function getTaxonomyTemplateFile(format) { // eslint-disable-line import/prefer-default-export
window.location.href = getTaxonomyTemplateApiUrl(format);

Check warning on line 16 in src/taxonomy/data/api.js

View check run for this annotation

Codecov / codecov/patch

src/taxonomy/data/api.js#L15-L16

Added lines #L15 - L16 were not covered by tests
}
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 5381f15

Please sign in to comment.