Skip to content

Commit

Permalink
feat: add nested export selector
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 committed Dec 19, 2022
1 parent 8f63cf3 commit 6d03217
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
1 change: 1 addition & 0 deletions e2e/cypress/support/dataCyType.d.ts
Expand Up @@ -67,6 +67,7 @@ declare namespace DataCy {
"export-format-selector-item" |
"export-language-selector" |
"export-language-selector-item" |
"export-nested-selector" |
"export-state-selector" |
"export-state-selector-item" |
"export-submit-button" |
Expand Down
24 changes: 18 additions & 6 deletions webapp/src/views/projects/export/ExportForm.tsx
Expand Up @@ -14,6 +14,7 @@ import { StateSelector } from './StateSelector';
import { LanguageSelector } from './LanguageSelector';
import { FORMATS, FormatSelector } from './FormatSelector';
import { useUrlSearchState } from 'tg.hooks/useUrlSearchState';
import { NestedSelector } from './NestedSelector';

const messaging = container.resolve(MessageService);

Expand All @@ -39,10 +40,9 @@ const StyledForm = styled('form')`
gap: ${({ theme }) => theme.spacing(3)};
grid-template-columns: 1fr 1fr;
grid-template-areas:
'states states'
'langs format'
'. submit';
'states states'
'langs format'
'options submit';
& .states {
grid-area: states;
}
Expand All @@ -58,6 +58,10 @@ const StyledForm = styled('form')`
}
`;

const StyledOptions = styled('div')`
display: grid;
`;

export const ExportForm = () => {
const project = useProject();
const exportLoadable = useApiMutation({
Expand Down Expand Up @@ -96,6 +100,9 @@ export const ExportForm = () => {
const [format, setFormat] = useUrlSearchState('format', {
defaultVal: EXPORT_DEFAULT_FORMAT,
});
const [nested, setNested] = useUrlSearchState('nested', {
defaultVal: 'false',
});

if (languagesLoadable.isFetching) {
return (
Expand All @@ -113,6 +120,7 @@ export const ExportForm = () => {
: EXPORT_DEFAULT_STATES) as StateType[],
languages: (languages?.length ? languages : allLangs) as string[],
format: (format || EXPORT_DEFAULT_FORMAT) as typeof FORMATS[number],
nested: nested === 'true',
}}
validate={(values) => {
const errors: FormikErrors<typeof values> = {};
Expand All @@ -128,6 +136,7 @@ export const ExportForm = () => {
setStates(sortStates(values.states));
setLanguages(sortLanguages(values.languages));
setFormat(values.format);
setNested(String(values.nested));

return errors;
}}
Expand All @@ -142,8 +151,8 @@ export const ExportForm = () => {
format: values.format,
filterState: values.states,
languages: values.languages,
splitByScope: false,
splitByScopeDelimiter: '.',
splitByScope: values.nested ? true : false,
splitByScopeDelimiter: values.nested ? '.' : '',
splitByScopeDepth: 0,
zip: values.languages.length > 1,
},
Expand Down Expand Up @@ -181,6 +190,9 @@ export const ExportForm = () => {
languages={languagesLoadable.data?._embedded?.languages}
/>
<FormatSelector className="format" />
<StyledOptions className="options">
<NestedSelector />
</StyledOptions>
<div className="submit">
<LoadingButton
data-cy="export-submit-button"
Expand Down
52 changes: 52 additions & 0 deletions webapp/src/views/projects/export/NestedSelector.tsx
@@ -0,0 +1,52 @@
import { Field } from 'formik';
import { useTranslate } from '@tolgee/react';
import { Checkbox, FormControlLabel, Tooltip, styled } from '@mui/material';
import { Help } from '@mui/icons-material';

const StyledLabel = styled('div')`
display: flex;
gap: 5px;
align-items: center;
`;

const StyledHelpIcon = styled(Help)`
font-size: 17px;
`;

type Props = {
className?: string;
};

export const NestedSelector: React.FC<Props> = ({ className }) => {
const { t } = useTranslate();

return (
<Field name="nested">
{({ field }) => {
return (
<FormControlLabel
className={className}
label={
<StyledLabel>
<div>{t('export_translations_nested_label')}</div>
<Tooltip title={t('export_translations_nested_hint')}>
<StyledHelpIcon />
</Tooltip>
</StyledLabel>
}
control={
<>
<Checkbox
{...field}
checked={field.value}
data-cy="export-nested-selector"
variant="standard"
/>
</>
}
/>
);
}}
</Field>
);
};

0 comments on commit 6d03217

Please sign in to comment.