forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Taxonomy export menu [FC-0036] (openedx#645)
* feat: System-defined tooltip added * feat: Taxonomy card menu added. Export menu item added * feat: Modal for export taxonomy * feat: Connect with export API * test: Tests for API and selectors * feat: Use windows.location.href to call the export endpoint * test: ExportModal.test added * style: Delete unnecessary code * docs: README updated with taxonomy feature * style: TaxonomyCard updated to a better code style * style: injectIntl replaced by useIntl on taxonomy pages and components * refactor: Move and rename taxonomy UI components to match 0002 ADR * refactor: Move api to data to match with 0002 ADR * test: Refactor ExportModal tests * chore: Fix validations * chore: Lint * refactor: Moving hooks to apiHooks * style: Nit on return null --------- Co-authored-by: Rômulo Penido <[email protected]> Co-authored-by: Christofer Chavez <[email protected]>
- Loading branch information
Showing
24 changed files
with
671 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export { default as taxonomyListMock } from './taxonomyListMock'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module.exports = { | ||
next: null, | ||
previous: null, | ||
count: 4, | ||
numPages: 1, | ||
currentPage: 1, | ||
start: 0, | ||
results: [ | ||
{ | ||
id: -2, | ||
name: 'Content Authors', | ||
description: 'Allows tags for any user ID created on the instance.', | ||
enabled: true, | ||
allowMultiple: false, | ||
allowFreeText: false, | ||
systemDefined: true, | ||
visibleToAuthors: false, | ||
}, | ||
{ | ||
id: -1, | ||
name: 'Languages', | ||
description: 'lang lang lang lang lang lang lang lang', | ||
enabled: true, | ||
allowMultiple: false, | ||
allowFreeText: false, | ||
systemDefined: true, | ||
visibleToAuthors: true, | ||
}, | ||
{ | ||
id: 1, | ||
name: 'Taxonomy', | ||
description: 'This is a Description', | ||
enabled: true, | ||
allowMultiple: false, | ||
allowFreeText: false, | ||
systemDefined: false, | ||
visibleToAuthors: true, | ||
}, | ||
{ | ||
id: 2, | ||
name: 'Taxonomy long long long long long long long long long long long long long long long long long long long', | ||
description: 'This is a Description long lon', | ||
enabled: true, | ||
allowMultiple: false, | ||
allowFreeText: false, | ||
systemDefined: false, | ||
visibleToAuthors: true, | ||
}, | ||
], | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// @ts-check | ||
import { camelCaseObject, getConfig } from '@edx/frontend-platform'; | ||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
|
||
const getApiBaseUrl = () => getConfig().STUDIO_BASE_URL; | ||
export const getTaxonomyListApiUrl = () => new URL('api/content_tagging/v1/taxonomies/?enabled=true', getApiBaseUrl()).href; | ||
export const getExportTaxonomyApiUrl = (pk, format) => new URL( | ||
`api/content_tagging/v1/taxonomies/${pk}/export/?output_format=${format}&download=1`, | ||
getApiBaseUrl(), | ||
).href; | ||
|
||
/** | ||
* Get list of taxonomies. | ||
* @returns {Promise<Object>} | ||
*/ | ||
export async function getTaxonomyListData() { | ||
const { data } = await getAuthenticatedHttpClient().get(getTaxonomyListApiUrl()); | ||
return camelCaseObject(data); | ||
} | ||
|
||
/** | ||
* Downloads the file of the exported taxonomy | ||
* @param {number} pk | ||
* @param {string} format | ||
* @returns {void} | ||
*/ | ||
export function getTaxonomyExportFile(pk, format) { | ||
window.location.href = getExportTaxonomyApiUrl(pk, format); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import { initializeMockApp } from '@edx/frontend-platform'; | ||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
|
||
import { taxonomyListMock } from '../__mocks__'; | ||
|
||
import { | ||
getTaxonomyListApiUrl, | ||
getExportTaxonomyApiUrl, | ||
getTaxonomyListData, | ||
getTaxonomyExportFile, | ||
} from './api'; | ||
|
||
let axiosMock; | ||
|
||
describe('taxonomy api calls', () => { | ||
const { location } = window; | ||
beforeEach(() => { | ||
initializeMockApp({ | ||
authenticatedUser: { | ||
userId: 3, | ||
username: 'abc123', | ||
administrator: true, | ||
roles: [], | ||
}, | ||
}); | ||
axiosMock = new MockAdapter(getAuthenticatedHttpClient()); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
beforeAll(() => { | ||
delete window.location; | ||
window.location = { | ||
href: '', | ||
}; | ||
}); | ||
|
||
afterAll(() => { | ||
window.location = location; | ||
}); | ||
|
||
it('should get taxonomy list data', async () => { | ||
axiosMock.onGet(getTaxonomyListApiUrl()).reply(200, taxonomyListMock); | ||
const result = await getTaxonomyListData(); | ||
|
||
expect(axiosMock.history.get[0].url).toEqual(getTaxonomyListApiUrl()); | ||
expect(result).toEqual(taxonomyListMock); | ||
}); | ||
|
||
it('should set window.location.href correctly', () => { | ||
const pk = 1; | ||
const format = 'json'; | ||
|
||
getTaxonomyExportFile(pk, format); | ||
|
||
expect(window.location.href).toEqual(getExportTaxonomyApiUrl(pk, format)); | ||
}); | ||
}); |
Oops, something went wrong.