Skip to content

Commit

Permalink
add import functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
kurund committed Dec 28, 2023
1 parent 58d7465 commit f0ae267
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
28 changes: 27 additions & 1 deletion src/containers/Flow/FlowTranslation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { DialogBox } from 'components/UI/DialogBox/DialogBox';
import { FormControl, RadioGroup, FormControlLabel, Radio } from '@mui/material';
import { useTranslation } from 'react-i18next';

import { AUTO_TRANSLATE_FLOW } from 'graphql/mutations/Flow';
import { AUTO_TRANSLATE_FLOW, IMPORT_FLOW_LOCALIZATIONS } from 'graphql/mutations/Flow';
import { EXPORT_FLOW_LOCALIZATIONS } from 'graphql/queries/Flow';
import { setNotification } from 'common/notification';
import { exportCsvFile } from 'common/utils';

import { ImportButton } from 'components/UI/ImportButton/ImportButton';
import { Loading } from 'components/UI/Layout/Loading/Loading';
import styles from './FlowTranslation.module.css';

export interface FlowTranslationProps {
Expand All @@ -18,6 +20,7 @@ export interface FlowTranslationProps {

export const FlowTranslation = ({ flowId, setDialog }: FlowTranslationProps) => {
const [action, setAction] = useState('auto');
const [importing, setImporting] = useState(false);

Check warning on line 23 in src/containers/Flow/FlowTranslation.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Flow/FlowTranslation.tsx#L22-L23

Added lines #L22 - L23 were not covered by tests

const { t } = useTranslation();

Check warning on line 25 in src/containers/Flow/FlowTranslation.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Flow/FlowTranslation.tsx#L25

Added line #L25 was not covered by tests

Expand Down Expand Up @@ -46,6 +49,13 @@ export const FlowTranslation = ({ flowId, setDialog }: FlowTranslationProps) =>
},
});

const [importFlow] = useMutation(IMPORT_FLOW_LOCALIZATIONS, {

Check warning on line 52 in src/containers/Flow/FlowTranslation.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Flow/FlowTranslation.tsx#L52

Added line #L52 was not covered by tests
onCompleted: (result: any) => {
const { status } = result.importFlow;
setImporting(false);

Check warning on line 55 in src/containers/Flow/FlowTranslation.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Flow/FlowTranslation.tsx#L54-L55

Added lines #L54 - L55 were not covered by tests
},
});

const handleAuto = () => {
autoTranslateFlow({ variables: { id: flowId } });

Check warning on line 60 in src/containers/Flow/FlowTranslation.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Flow/FlowTranslation.tsx#L59-L60

Added lines #L59 - L60 were not covered by tests
};
Expand All @@ -72,6 +82,20 @@ export const FlowTranslation = ({ flowId, setDialog }: FlowTranslationProps) =>
setAction((event.target as HTMLInputElement).value);

Check warning on line 82 in src/containers/Flow/FlowTranslation.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Flow/FlowTranslation.tsx#L81-L82

Added lines #L81 - L82 were not covered by tests
};

const importButton = (
<ImportButton

Check warning on line 86 in src/containers/Flow/FlowTranslation.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Flow/FlowTranslation.tsx#L86

Added line #L86 was not covered by tests
title={t('Import translations')}
onImport={() => setImporting(true)}

Check warning on line 88 in src/containers/Flow/FlowTranslation.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Flow/FlowTranslation.tsx#L88

Added line #L88 was not covered by tests
afterImport={(result: string) =>
importFlow({ variables: { localization: result, id: flowId } })

Check warning on line 90 in src/containers/Flow/FlowTranslation.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Flow/FlowTranslation.tsx#L90

Added line #L90 was not covered by tests
}
/>
);

if (importing) {
return <Loading message="Uploading" />;

Check warning on line 96 in src/containers/Flow/FlowTranslation.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Flow/FlowTranslation.tsx#L96

Added line #L96 was not covered by tests
}

const dialogContent = (
<div>

Check warning on line 100 in src/containers/Flow/FlowTranslation.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Flow/FlowTranslation.tsx#L100

Added line #L100 was not covered by tests
<FormControl>
Expand All @@ -85,6 +109,7 @@ export const FlowTranslation = ({ flowId, setDialog }: FlowTranslationProps) =>
<FormControlLabel value="export" control={<Radio />} label={t('Export translations')} />
<FormControlLabel value="import" control={<Radio />} label={t('Import translations')} />
</RadioGroup>
{action === 'import' ? importButton : ''}
</FormControl>
</div>
);
Expand All @@ -100,6 +125,7 @@ export const FlowTranslation = ({ flowId, setDialog }: FlowTranslationProps) =>
handleCancel={() => {
setDialog(false);

Check warning on line 126 in src/containers/Flow/FlowTranslation.tsx

View check run for this annotation

Codecov / codecov/patch

src/containers/Flow/FlowTranslation.tsx#L126

Added line #L126 was not covered by tests
}}
skipOk={action === 'import'}
>
{dialogContent}
</DialogBox>
Expand Down
8 changes: 2 additions & 6 deletions src/graphql/mutations/Flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,9 @@ export const AUTO_TRANSLATE_FLOW = gql`
`;

export const IMPORT_FLOW_LOCALIZATIONS = gql`
mutation importFlowLocalization($id: ID!) {
importFlowLocalization(id: $id) {
mutation importFlowLocalization($localization: String!, $id: ID!) {
importFlowLocalization(localization: $localization, id: $id) {
success
errors {
key
message
}
}
}
`;

0 comments on commit f0ae267

Please sign in to comment.