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

[temp] feat: add download taxonomy template button #6

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 41 additions & 7 deletions src/taxonomy/TaxonomyListPage.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,58 @@
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 Header from '../header';
import SubHeader from '../generic/sub-header/SubHeader';
import { downloadTaxonomyTemplate } from './data/thunks';
import messages from './messages';
import TaxonomyCard from './taxonomy-card';
import { useTaxonomyListDataResponse, useIsTaxonomyListDataLoaded } from './hooks';

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={() => downloadTaxonomyTemplate('csv')}>
{intl.formatMessage(messages.downloadTemplateButtonCSVLabel)}
</Dropdown.Item>
<Dropdown.Item onClick={() => downloadTaxonomyTemplate('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 +63,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 +84,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);
}
13 changes: 10 additions & 3 deletions src/taxonomy/data/thunks.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
// @ts-check
import { getTaxonomyExportFile } from './api';
import { getTaxonomyExportFile, getTaxonomyTemplateFile } from './api';

/**
* Downloads the file of the exported taxonomy
* @param {number} pk
* @param {string} format
* @returns {void}
*/
const exportTaxonomy = (pk, format) => (
export const exportTaxonomy = (pk, format) => (
getTaxonomyExportFile(pk, format)
);

export default exportTaxonomy;
/**
* Downloads the template file for import taxonomies
* @param {('json'|'csv')} format
* @returns {void}
*/
export const downloadTaxonomyTemplate = (format) => (
getTaxonomyTemplateFile(format)
);
2 changes: 1 addition & 1 deletion src/taxonomy/export-modal/ExportModal.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AppProvider } from '@edx/frontend-platform/react';
import { render, fireEvent } from '@testing-library/react';
import ExportModal from '.';
import initializeStore from '../../store';
import exportTaxonomy from '../data/thunks';
import { exportTaxonomy } from '../data/thunks';

const onClose = jest.fn();
let store;
Expand Down
2 changes: 1 addition & 1 deletion src/taxonomy/export-modal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import PropTypes from 'prop-types';
import { useIntl } from '@edx/frontend-platform/i18n';
import messages from './messages';
import exportTaxonomy from '../data/thunks';
import { exportTaxonomy } from '../data/thunks';

const ExportModal = ({
taxonomyId,
Expand Down
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
Loading