-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement #581] Implement vocabulary translations import.
UI is a part of the vocabulary content import dialog - using tabs to separate the two modes.
- Loading branch information
Showing
9 changed files
with
220 additions
and
110 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
86 changes: 0 additions & 86 deletions
86
src/component/vocabulary/importing/ImportBackupOfVocabulary.tsx
This file was deleted.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
src/component/vocabulary/importing/ImportTranslationsDialog.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,64 @@ | ||
import React from "react"; | ||
import UploadFile from "../../resource/file/UploadFile"; | ||
import { Button, ButtonToolbar, Col, Form, Row } from "reactstrap"; | ||
import { useI18n } from "../../hook/useI18n"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
export const ImportTranslationsDialog: React.FC<{ | ||
onSubmit: (file: File) => void; | ||
onCancel: () => void; | ||
onDownloadTemplate: () => void; | ||
}> = ({ onSubmit, onCancel, onDownloadTemplate }) => { | ||
const { i18n } = useI18n(); | ||
const [file, setFile] = React.useState<File>(); | ||
const cannotSubmit = () => !file; | ||
return ( | ||
<> | ||
<Form id="vocabulary-translations-import"> | ||
<div className="mb-3"> | ||
<FormattedMessage | ||
id="vocabulary.summary.import.translations.label" | ||
values={{ | ||
a: (chunks: any) => ( | ||
<span | ||
role="button" | ||
className="bold btn-link link-like" | ||
onClick={onDownloadTemplate} | ||
title={i18n( | ||
"vocabulary.summary.import.excel.template.tooltip" | ||
)} | ||
> | ||
{chunks} | ||
</span> | ||
), | ||
}} | ||
/> | ||
</div> | ||
<UploadFile setFile={setFile} /> | ||
<Row> | ||
<Col xs={12}> | ||
<ButtonToolbar className="d-flex justify-content-center mt-4"> | ||
<Button | ||
id="upload-translations-file-submit" | ||
onClick={() => onSubmit(file!)} | ||
color="success" | ||
size="sm" | ||
disabled={cannotSubmit()} | ||
> | ||
{i18n("vocabulary.summary.import.action")} | ||
</Button> | ||
<Button | ||
id="upload-translations-file-cancel" | ||
onClick={onCancel} | ||
color="outline-dark" | ||
size="sm" | ||
> | ||
{i18n("cancel")} | ||
</Button> | ||
</ButtonToolbar> | ||
</Col> | ||
</Row> | ||
</Form> | ||
</> | ||
); | ||
}; |
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
116 changes: 116 additions & 0 deletions
116
src/component/vocabulary/importing/LoadVocabularyFromFile.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,116 @@ | ||
import React, { useState } from "react"; | ||
import { Alert, Modal, ModalBody, ModalHeader } from "reactstrap"; | ||
import { useI18n } from "../../hook/useI18n"; | ||
import PromiseTrackingMask from "../../misc/PromiseTrackingMask"; | ||
import { trackPromise } from "react-promise-tracker"; | ||
import { FormattedMessage } from "react-intl"; | ||
import ImportVocabularyDialog from "./ImportVocabularyDialog"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { ThunkDispatch } from "../../../util/Types"; | ||
import { downloadExcelTemplate } from "../../../action/AsyncImportActions"; | ||
import TermItState from "../../../model/TermItState"; | ||
import Tabs from "../../misc/Tabs"; | ||
import { ImportTranslationsDialog } from "./ImportTranslationsDialog"; | ||
|
||
interface LoadVocabularyFromFileProps { | ||
showDialog: boolean; | ||
onImport: (file: File, translationsOnly: boolean) => Promise<any>; | ||
closeDialog: () => void; | ||
} | ||
|
||
export const LoadVocabularyFromFile: React.FC<LoadVocabularyFromFileProps> = ({ | ||
showDialog, | ||
closeDialog, | ||
onImport, | ||
}) => { | ||
const { i18n } = useI18n(); | ||
const dispatch: ThunkDispatch = useDispatch(); | ||
const [selectedTab, setSelectedTab] = useState<string>( | ||
"vocabulary.summary.import.dialog.tab.replaceContent" | ||
); | ||
const onClose = () => { | ||
closeDialog(); | ||
setSelectedTab("vocabulary.summary.import.dialog.tab.replaceContent"); | ||
}; | ||
const onImportContent = (file: File) => | ||
trackPromise(onImport(file, false), "vocabulary-import").then(onClose); | ||
const onImportTranslations = (file: File) => { | ||
trackPromise(onImport(file, true), "vocabulary-import").then(onClose); | ||
}; | ||
const downloadTemplate = () => { | ||
dispatch(downloadExcelTemplate()); | ||
}; | ||
const vocabularyNotEmpty = | ||
(useSelector((state: TermItState) => state.vocabulary.termCount) || 0) > 0; | ||
|
||
return ( | ||
<> | ||
<Modal isOpen={showDialog} toggle={onClose}> | ||
<ModalHeader> | ||
{i18n("vocabulary.summary.import.dialog.title")} | ||
</ModalHeader> | ||
<ModalBody> | ||
<PromiseTrackingMask area="vocabulary-import" /> | ||
<Tabs | ||
activeTabLabelKey={selectedTab} | ||
contentClassName="mt-3" | ||
tabs={{ | ||
"vocabulary.summary.import.dialog.tab.replaceContent": ( | ||
<> | ||
<div className="mb-1"> | ||
<FormattedMessage id="vocabulary.summary.import.dialog.label" /> | ||
</div> | ||
<ul> | ||
<li> | ||
<FormattedMessage id="vocabulary.summary.import.dialog.skosImport" /> | ||
</li> | ||
<li> | ||
<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> | ||
), | ||
}} | ||
/> | ||
</li> | ||
</ul> | ||
{vocabularyNotEmpty && ( | ||
<Alert color="warning"> | ||
<FormattedMessage id="vocabulary.summary.import.nonEmpty.warning" /> | ||
</Alert> | ||
)} | ||
<ImportVocabularyDialog | ||
propKeyPrefix="vocabulary.summary.import" | ||
onCreate={onImportContent} | ||
onCancel={onClose} | ||
allowRename={false} | ||
/> | ||
</> | ||
), | ||
"vocabulary.summary.import.dialog.tab.translations": ( | ||
<ImportTranslationsDialog | ||
onSubmit={onImportTranslations} | ||
onCancel={onClose} | ||
onDownloadTemplate={downloadTemplate} | ||
/> | ||
), | ||
}} | ||
changeTab={setSelectedTab as (t: string) => void} | ||
/> | ||
</ModalBody> | ||
</Modal> | ||
</> | ||
); | ||
}; | ||
|
||
export default LoadVocabularyFromFile; |
Oops, something went wrong.