-
Notifications
You must be signed in to change notification settings - Fork 75
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
feat: add import taxonomy feature [FC-0036] #675
Merged
xitij2000
merged 48 commits into
openedx:master
from
open-craft:rpenido/fal-3532-import-taxonomy
Jan 8, 2024
Merged
Changes from 12 commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
0c60c37
feat: add import taxonomy feature
rpenido c273af1
test: add api.test.js
rpenido 047530d
test: add import button click test
rpenido 303e7ba
test: add action.test.js
rpenido 3955e91
test: add more tests to action.tests.js
rpenido 8176973
test: add more tests to action.tests.js 2
rpenido 4f31714
Merge branch 'openedx:master' into rpenido/fal-3532-import-taxonomy
rpenido df441fb
fix: import
rpenido a0e92f0
test: simplify import test
rpenido dc8ed9e
fix: remove undefined var
rpenido 120154e
refactor: rename actions.js -> utils.js
rpenido 318bbb7
revert: change in the jest.config
rpenido a8c2fd5
Merge branch 'master' into rpenido/fal-3532-import-taxonomy
pomegranited 70ac2a7
Merge branch 'openedx:master' into rpenido/fal-3532-import-taxonomy
rpenido adacf23
chore: trigger CD/CI
rpenido 5983953
Merge branch 'master' into rpenido/fal-3532-import-taxonomy
rpenido 7756c7f
feat: import tags to existing taxonomy
rpenido 4202c27
Merge branch 'master' into rpenido/fal-3532-import-taxonomy
rpenido 6bcd924
refactor: merges TaxonomyCardMenu and TaxonomyDetailMenu (#13)
rpenido f318dfc
refactor: improve menu organization
rpenido 204b2b9
fix: types
rpenido 5e0f599
Merge branch 'master' into rpenido/fal-3532-import-taxonomy
rpenido f888ecf
refactor: merging conflicts
rpenido 3c8da66
refactor: change export syntax
rpenido 40479c1
fix: eslint
rpenido 46e5d1b
fix: export TaxonomyDetail
rpenido db8ba58
fix: eslint
rpenido 8fe8c07
Merge branch 'openedx:master' into rpenido/fal-3532-import-taxonomy
rpenido 1440215
fix: TaxonomyContext types
rpenido e5b8e58
Merge branch 'master' into rpenido/fal-3532-import-taxonomy
rpenido fafcb9b
chore: rebasing
rpenido e80194f
fix: types
rpenido 1e0dde3
fix: remove typo
rpenido 7cae57b
test: cleaning test removing useMutation mock
rpenido 1002fc6
style: cleaning code and fix lint
rpenido fdc74c7
Merge branch 'master' into rpenido/fal-3532-import-taxonomy
rpenido e9893dc
fix: change expect getBy toThrow pattern to queryBy not.toBeInDocument
rpenido a8b4197
test: add jest-each
rpenido a3c40fd
fix: remove getTaxonomyMenuItems function
rpenido 1a31aa9
fix: remove tests from temp code
rpenido c6d39e5
Merge branch 'openedx:master' into rpenido/fal-3532-import-taxonomy
rpenido 583ab51
test: improve coverage
rpenido 151ba9e
test: refactor import button test
rpenido df9f2a0
fix: eslint
rpenido 67c42cb
Merge branch 'master' into rpenido/fal-3532-import-taxonomy
rpenido 793810f
fix: errors fixing merge conflicts
rpenido 70954b3
Merge branch 'master' into rpenido/fal-3532-import-taxonomy
pomegranited 68e820d
fixup!: remove jest-each in favour of inbuilt functionality
xitij2000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 taxonomyImportMock } from './taxonomyImportMock'; |
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,4 @@ | ||
export default { | ||
name: 'Taxonomy name', | ||
description: 'Taxonomy description', | ||
}; |
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,31 @@ | ||
// @ts-check | ||
import { camelCaseObject, getConfig } from '@edx/frontend-platform'; | ||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
|
||
const getApiBaseUrl = () => getConfig().STUDIO_BASE_URL; | ||
|
||
export const getTaxonomyImportApiUrl = () => new URL( | ||
'api/content_tagging/v1/taxonomies/import/', | ||
getApiBaseUrl(), | ||
).href; | ||
|
||
/** | ||
* Import a new taxonomy | ||
* @param {string} taxonomyName | ||
* @param {string} taxonomyDescription | ||
* @param {File} file | ||
* @returns {Promise<Object>} | ||
*/ | ||
export async function importNewTaxonomy(taxonomyName, taxonomyDescription, file) { | ||
const formData = new FormData(); | ||
formData.append('taxonomy_name', taxonomyName); | ||
formData.append('taxonomy_description', taxonomyDescription); | ||
formData.append('file', file); | ||
|
||
const { data } = await getAuthenticatedHttpClient().post( | ||
getTaxonomyImportApiUrl(), | ||
formData, | ||
); | ||
|
||
return camelCaseObject(data); | ||
} |
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,38 @@ | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import { initializeMockApp } from '@edx/frontend-platform'; | ||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
|
||
import { taxonomyImportMock } from '../__mocks__'; | ||
|
||
import { | ||
getTaxonomyImportApiUrl, | ||
importNewTaxonomy, | ||
} from './api'; | ||
|
||
let axiosMock; | ||
|
||
describe('import taxonomy api calls', () => { | ||
beforeEach(() => { | ||
initializeMockApp({ | ||
authenticatedUser: { | ||
userId: 3, | ||
username: 'abc123', | ||
administrator: true, | ||
roles: [], | ||
}, | ||
}); | ||
axiosMock = new MockAdapter(getAuthenticatedHttpClient()); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should call import taxonomy', async () => { | ||
axiosMock.onPost(getTaxonomyImportApiUrl()).reply(201, taxonomyImportMock); | ||
const result = await importNewTaxonomy('Taxonomy name', 'Taxonomy description'); | ||
|
||
expect(axiosMock.history.post[0].url).toEqual(getTaxonomyImportApiUrl()); | ||
expect(result).toEqual(taxonomyImportMock); | ||
}); | ||
}); |
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,82 @@ | ||
import messages from '../messages'; | ||
import { importNewTaxonomy } from './api'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const importTaxonomy = async (intl) => { | ||
/* | ||
* This function is a temporary "Barebones" implementation of the import | ||
* functionality with `prompt` and `alert`. It is intended to be replaced | ||
* with a component that shows a `ModalDialog` in the future. | ||
* See: https://github.com/openedx/modular-learning/issues/116 | ||
*/ | ||
/* eslint-disable no-alert */ | ||
/* eslint-disable no-console */ | ||
|
||
const selectFile = async () => new Promise((resolve) => { | ||
/* | ||
* This function get a file from the user. It does this by creating a | ||
* file input element, and then clicking it. This allows us to get a file | ||
* from the user without using a form. The file input element is created | ||
* and appended to the DOM, then clicked. When the user selects a file, | ||
* the change event is fired, and the file is resolved. | ||
* The file input element is then removed from the DOM. | ||
*/ | ||
const fileInput = document.createElement('input'); | ||
fileInput.type = 'file'; | ||
fileInput.accept = '.json,.csv'; | ||
fileInput.addEventListener('change', (event) => { | ||
const file = event.target.files[0]; | ||
if (!file) { | ||
resolve(null); | ||
} | ||
resolve(file); | ||
document.body.removeChild(fileInput); | ||
}); | ||
|
||
document.body.appendChild(fileInput); | ||
fileInput.click(); | ||
}); | ||
|
||
const getTaxonomyName = () => { | ||
let taxonomyName = null; | ||
while (!taxonomyName) { | ||
taxonomyName = prompt(intl.formatMessage(messages.promptTaxonomyName)); | ||
|
||
if (taxonomyName == null) { | ||
break; | ||
} | ||
|
||
if (!taxonomyName) { | ||
alert(intl.formatMessage(messages.promptTaxonomyNameRequired)); | ||
} | ||
} | ||
return taxonomyName; | ||
}; | ||
|
||
const getTaxonomyDescription = () => prompt(intl.formatMessage(messages.promptTaxonomyDescription)); | ||
|
||
const file = await selectFile(); | ||
|
||
if (!file) { | ||
return; | ||
} | ||
|
||
const taxonomyName = getTaxonomyName(); | ||
if (taxonomyName == null) { | ||
return; | ||
} | ||
|
||
const taxonomyDescription = getTaxonomyDescription(); | ||
if (taxonomyDescription == null) { | ||
return; | ||
} | ||
|
||
importNewTaxonomy(taxonomyName, taxonomyDescription, file) | ||
.then(() => { | ||
alert(intl.formatMessage(messages.importTaxonomySuccess)); | ||
}) | ||
.catch((error) => { | ||
alert(intl.formatMessage(messages.importTaxonomyError)); | ||
console.error(error.response); | ||
}); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ Just flagging this in particular in case any reviewers are concerned about
alert()
andprompt()
:) . This is just a temporary state during development to help get more PRs out faster and more iteratively, and will be replaced before any users ever see this (other than early beta testers).