-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement #449] Split new vocabulary import into separate tabs for…
… SKOS and Excel.
- Loading branch information
Showing
8 changed files
with
225 additions
and
47 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
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
138 changes: 138 additions & 0 deletions
138
src/component/vocabulary/importing/CreateVocabularyFromExcel.tsx
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,138 @@ | ||
import React, { useState } from "react"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import TermItState from "../../../model/TermItState"; | ||
import PromiseTrackingMask from "../../misc/PromiseTrackingMask"; | ||
import CreateVocabularyForm from "../CreateVocabularyForm"; | ||
import Routes from "../../../util/Routes"; | ||
import Routing from "../../../util/Routing"; | ||
import { ThunkDispatch } from "../../../util/Types"; | ||
import Vocabulary from "../../../model/Vocabulary"; | ||
import TermItFile from "../../../model/File"; | ||
import { trackPromise } from "react-promise-tracker"; | ||
import { | ||
createFileInDocument, | ||
createVocabulary, | ||
uploadFileContent, | ||
} from "../../../action/AsyncActions"; | ||
import Utils from "../../../util/Utils"; | ||
import VocabularyUtils from "../../../util/VocabularyUtils"; | ||
import { publishNotification } from "../../../action/SyncActions"; | ||
import NotificationType from "../../../model/NotificationType"; | ||
import IdentifierResolver from "../../../util/IdentifierResolver"; | ||
import { Col, Label, Row } from "reactstrap"; | ||
import UploadFile from "../../resource/file/UploadFile"; | ||
import { | ||
downloadExcelTemplate, | ||
importIntoExistingVocabulary, | ||
} from "../../../action/AsyncImportActions"; | ||
import { FormattedMessage } from "react-intl"; | ||
import { useI18n } from "../../hook/useI18n"; | ||
|
||
const CreateVocabularyFromExcel: React.FC = () => { | ||
const { i18n } = useI18n(); | ||
const configuredLanguage = useSelector( | ||
(state: TermItState) => state.configuration.language | ||
); | ||
const [language, setLanguage] = React.useState(configuredLanguage); | ||
const [file, setFile] = useState<File>(); | ||
const dispatch: ThunkDispatch = useDispatch(); | ||
const downloadTemplate = () => { | ||
dispatch(downloadExcelTemplate()); | ||
}; | ||
const onCreate = ( | ||
vocabulary: Vocabulary, | ||
files: TermItFile[], | ||
fileContents: File[] | ||
) => { | ||
trackPromise( | ||
dispatch(createVocabulary(vocabulary)).then((location) => { | ||
if (!location) { | ||
return; | ||
} | ||
return Promise.all( | ||
Utils.sanitizeArray(files).map((f, fIndex) => | ||
dispatch( | ||
createFileInDocument( | ||
f, | ||
VocabularyUtils.create(vocabulary.document!.iri) | ||
) | ||
) | ||
.then(() => | ||
dispatch( | ||
uploadFileContent( | ||
VocabularyUtils.create(f.iri), | ||
fileContents[fIndex] | ||
) | ||
) | ||
) | ||
.then(() => | ||
dispatch( | ||
publishNotification({ | ||
source: { type: NotificationType.FILE_CONTENT_UPLOADED }, | ||
}) | ||
) | ||
) | ||
) | ||
) | ||
.then(() => { | ||
if (file) { | ||
return dispatch( | ||
importIntoExistingVocabulary( | ||
VocabularyUtils.create(vocabulary.iri), | ||
file | ||
) | ||
); | ||
} | ||
return Promise.resolve({}); | ||
}) | ||
.then(() => | ||
Routing.transitionTo( | ||
Routes.vocabularySummary, | ||
IdentifierResolver.routingOptionsFromLocation(location) | ||
) | ||
); | ||
}), | ||
"import-excel-vocabulary" | ||
); | ||
}; | ||
|
||
return ( | ||
<> | ||
<PromiseTrackingMask area="import-excel-vocabulary" /> | ||
<CreateVocabularyForm | ||
onSave={onCreate} | ||
onCancel={() => Routing.transitionTo(Routes.vocabularies)} | ||
language={language} | ||
selectLanguage={setLanguage} | ||
childrenBefore={ | ||
<Row className="mb-3"> | ||
<Col xs={12}> | ||
<Label className="attribute-label mb-2"> | ||
<FormattedMessage | ||
id="vocabulary.summary.import.dialog.excelImport" | ||
values={{ | ||
a: (chunks: any) => ( | ||
<span | ||
role="button" | ||
className="bold btn-link link-like" | ||
onClick={downloadTemplate} | ||
title={i18n( | ||
"vocabulary.summary.import.excel.template.tooltip" | ||
)} | ||
> | ||
{chunks} | ||
</span> | ||
), | ||
}} | ||
/> | ||
</Label> | ||
<UploadFile setFile={(file) => setFile(file)} /> | ||
</Col> | ||
</Row> | ||
} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default CreateVocabularyFromExcel; |
48 changes: 48 additions & 0 deletions
48
src/component/vocabulary/importing/CreateVocabularyFromSkos.tsx
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,48 @@ | ||
import React from "react"; | ||
import { Card, CardBody, Label } from "reactstrap"; | ||
import { useI18n } from "src/component/hook/useI18n"; | ||
import PromiseTrackingMask from "../../misc/PromiseTrackingMask"; | ||
import ImportVocabularyDialog from "./ImportVocabularyDialog"; | ||
import Routing from "../../../util/Routing"; | ||
import Routes from "../../../util/Routes"; | ||
import { ThunkDispatch } from "../../../util/Types"; | ||
import { useDispatch } from "react-redux"; | ||
import { trackPromise } from "react-promise-tracker"; | ||
import { importSkosAsNewVocabulary } from "../../../action/AsyncImportActions"; | ||
import IdentifierResolver from "../../../util/IdentifierResolver"; | ||
|
||
const CreateVocabularyFromSkos: React.FC = () => { | ||
const { i18n } = useI18n(); | ||
const dispatch: ThunkDispatch = useDispatch(); | ||
const importSkos = (file: File, rename: Boolean) => | ||
trackPromise( | ||
dispatch(importSkosAsNewVocabulary(file, rename)), | ||
"import-vocabulary" | ||
).then((location?: string) => { | ||
if (location) { | ||
Routing.transitionTo( | ||
Routes.vocabularySummary, | ||
IdentifierResolver.routingOptionsFromLocation(location) | ||
); | ||
} | ||
}); | ||
|
||
return ( | ||
<Card id="vocabulary-import" className="mb-3"> | ||
<CardBody> | ||
<PromiseTrackingMask area="import-vocabulary" /> | ||
<Label className="attribute-label mb-2"> | ||
{i18n("vocabulary.import.dialog.message")} | ||
</Label> | ||
<ImportVocabularyDialog | ||
propKeyPrefix="vocabulary.import" | ||
onCreate={importSkos} | ||
onCancel={() => Routing.transitionTo(Routes.vocabularies)} | ||
allowRename={true} | ||
/> | ||
</CardBody> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default CreateVocabularyFromSkos; |
57 changes: 19 additions & 38 deletions
57
src/component/vocabulary/importing/ImportVocabularyPage.tsx
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