Skip to content

Commit

Permalink
feat: update batch operations
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 committed Jul 17, 2023
1 parent 68de30c commit 25ba436
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 55 deletions.
3 changes: 1 addition & 2 deletions e2e/cypress/support/dataCyType.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ declare namespace DataCy {
"batch-operation-dialog-end-status" |
"batch-operation-dialog-minimize" |
"batch-operation-dialog-ok" |
"batch-operations-delete-button" |
"batch-operations-select" |
"batch-operations-translate-button" |
"batch-operations-submit-button" |
"batch-select-item" |
"billing-actual-extra-credits" |
"billing-actual-period" |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ export const OperationAddTags = ({ disabled, onStart }: Props) => {
setTags((tags) => tags.filter((t) => t !== tag));
}

// const batchTranslate = useApiMutation({
// const batchLoadable = useApiMutation({
// url: '/v2/projects/{projectId}/start-batch-job/translate',
// method: 'post',
// });

// function handleSubmit() {
// batchTranslate.mutate(
// batchLoadable.mutate(
// {
// path: { projectId: project.id },
// content: {
Expand Down Expand Up @@ -85,8 +85,8 @@ export const OperationAddTags = ({ disabled, onStart }: Props) => {
/>
</StyledTags>
<LoadingButton
data-cy="batch-operations-translate-button"
// loading={batchTranslate.isLoading}
data-cy="batch-operations-submit-button"
// loading={batchLoadable.isLoading}
disabled={disabled || tags.length === 0}
sx={{ minWidth: 0, minHeight: 0, width: 40, height: 40 }}
// onClick={handleSubmit}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export const OperationChangeNamespace = ({ disabled, onStart }: Props) => {

const [namespace, setNamespace] = useState<string>();

// const batchTranslate = useApiMutation({
// const batchLoadable = useApiMutation({
// url: '/v2/projects/{projectId}/start-batch-job/translate',
// method: 'post',
// });

// function handleSubmit() {
// batchTranslate.mutate(
// batchLoadable.mutate(
// {
// path: { projectId: project.id },
// content: {
Expand Down Expand Up @@ -53,8 +53,8 @@ export const OperationChangeNamespace = ({ disabled, onStart }: Props) => {
SearchSelectProps={{ SelectProps: { sx: { minWidth: 200 } } }}
/>
<LoadingButton
data-cy="batch-operations-translate-button"
// loading={batchTranslate.isLoading}
data-cy="batch-operations-submit-button"
// loading={batchLoadable.isLoading}
disabled={disabled || namespace === undefined}
sx={{ minWidth: 0, minHeight: 0, width: 40, height: 40 }}
// onClick={handleSubmit}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const OperationDelete = ({ disabled, onStart }: Props) => {
const { t } = useTranslate();
const selection = useTranslationsSelector((c) => c.selection);
const project = useProject();
const batchDelete = useApiMutation({
const batchLoadable = useApiMutation({
url: '/v2/projects/{projectId}/start-batch-job/delete-keys',
method: 'post',
});
Expand All @@ -26,7 +26,7 @@ export const OperationDelete = ({ disabled, onStart }: Props) => {
count: String(selection.length),
}),
onConfirm() {
batchDelete.mutate(
batchLoadable.mutate(
{
path: { projectId: project.id },
content: {
Expand All @@ -47,9 +47,9 @@ export const OperationDelete = ({ disabled, onStart }: Props) => {

return (
<LoadingButton
data-cy="batch-operations-delete-button"
data-cy="batch-operations-submit-button"
onClick={handleSubmit}
loading={batchDelete.isLoading}
loading={batchLoadable.isLoading}
disabled={disabled}
sx={{ minWidth: 0, minHeight: 0, width: 40, height: 40 }}
variant="contained"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,55 @@ import { Box } from '@mui/material';

import { LanguagesSelect } from 'tg.component/common/form/LanguagesSelect/LanguagesSelect';
import LoadingButton from 'tg.component/common/form/LoadingButton';
import { useProject } from 'tg.hooks/useProject';
import { useApiMutation } from 'tg.service/http/useQueryApi';

import { useTranslationsSelector } from '../context/TranslationsContext';
import { OperationProps } from './types';

type Props = OperationProps;

export const OperationMarkAsReviewed = ({ disabled, onStart }: Props) => {
// const project = useProject();
const project = useProject();
const allLanguages = useTranslationsSelector((c) => c.languages) || [];

const selectedGloballyLanguages = useTranslationsSelector(
(c) => c.selectedLanguages
);
// const selection = useTranslationsSelector((c) => c.selection);
const selection = useTranslationsSelector((c) => c.selection);

const baseLang = allLanguages.find((l) => l.base);

const [selectedLangs, setSelectedLangs] = useState(
selectedGloballyLanguages?.filter((tag) => tag !== baseLang?.tag)
);

// const batchTranslate = useApiMutation({
// url: '/v2/projects/{projectId}/start-batch-job/translate',
// method: 'post',
// });
const batchLoadable = useApiMutation({
url: '/v2/projects/{projectId}/start-batch-job/set-translation-state',
method: 'post',
});

// function handleSubmit() {
// batchTranslate.mutate(
// {
// path: { projectId: project.id },
// content: {
// 'application/json': {
// keyIds: selection,
// targetLanguageIds: allLanguages
// ?.filter((l) => selectedLangs?.includes(l.tag))
// .map((l) => l.id),
// useMachineTranslation: true,
// useTranslationMemory: false,
// service: undefined,
// },
// },
// },
// {
// onSuccess(data) {
// onStart(data);
// },
// }
// );
// }
function handleSubmit() {
batchLoadable.mutate(
{
path: { projectId: project.id },
content: {
'application/json': {
keyIds: selection,
languageIds: allLanguages
?.filter((l) => selectedLangs?.includes(l.tag))
.map((l) => l.id),
state: 'REVIEWED',
},
},
},
{
onSuccess(data) {
onStart(data);
},
}
);
}

return (
<Box display="flex" gap="10px">
Expand All @@ -64,11 +64,11 @@ export const OperationMarkAsReviewed = ({ disabled, onStart }: Props) => {
context="batch-operations"
/>
<LoadingButton
data-cy="batch-operations-translate-button"
// loading={batchTranslate.isLoading}
data-cy="batch-operations-submit-button"
loading={batchLoadable.isLoading}
disabled={disabled}
sx={{ minWidth: 0, minHeight: 0, width: 40, height: 40 }}
// onClick={handleSubmit}
onClick={handleSubmit}
variant="contained"
color="primary"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export const OperationMarkAsTranslated = ({ disabled, onStart }: Props) => {
selectedGloballyLanguages?.filter((tag) => tag !== baseLang?.tag)
);

// const batchTranslate = useApiMutation({
// const batchLoadable = useApiMutation({
// url: '/v2/projects/{projectId}/start-batch-job/translate',
// method: 'post',
// });

// function handleSubmit() {
// batchTranslate.mutate(
// batchLoadable.mutate(
// {
// path: { projectId: project.id },
// content: {
Expand Down Expand Up @@ -63,8 +63,8 @@ export const OperationMarkAsTranslated = ({ disabled, onStart }: Props) => {
context="batch-operations"
/>
<LoadingButton
data-cy="batch-operations-translate-button"
// loading={batchTranslate.isLoading}
data-cy="batch-operations-submit-button"
// loading={batchLoadable.isLoading}
disabled={disabled}
sx={{ minWidth: 0, minHeight: 0, width: 40, height: 40 }}
// onClick={handleSubmit}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const OperationRemoveTags = ({ disabled, onStart }: Props) => {
/>
</StyledTags>
<LoadingButton
data-cy="batch-operations-translate-button"
data-cy="batch-operations-submit-button"
// loading={batchTranslate.isLoading}
disabled={disabled || tags.length === 0}
sx={{ minWidth: 0, minHeight: 0, width: 40, height: 40 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ export const OperationTranslate = ({ disabled, onStart }: Props) => {
selectedGloballyLanguages?.filter((tag) => tag !== baseLang?.tag)
);

const batchTranslate = useApiMutation({
const batchLoadable = useApiMutation({
url: '/v2/projects/{projectId}/start-batch-job/translate',
method: 'post',
});

function handleSubmit() {
batchTranslate.mutate(
batchLoadable.mutate(
{
path: { projectId: project.id },
content: {
Expand Down Expand Up @@ -66,8 +66,8 @@ export const OperationTranslate = ({ disabled, onStart }: Props) => {
context="batch-operations"
/>
<LoadingButton
data-cy="batch-operations-translate-button"
loading={batchTranslate.isLoading}
data-cy="batch-operations-submit-button"
loading={batchLoadable.isLoading}
disabled={disabled}
sx={{ minWidth: 0, minHeight: 0, width: 40, height: 40 }}
onClick={handleSubmit}
Expand Down

0 comments on commit 25ba436

Please sign in to comment.