Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app/styles/antd.less
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@
display: flex;
justify-content: space-between;
}

p:last-of-type {
margin-bottom: 0;
}
1 change: 1 addition & 0 deletions src/app/styles/variables.less
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
@picker-bg: #f1f3f5;
@tooltip-bg: #000000;

@tooltip-max-width: 300px;
@line-height-base: 1.5;
1 change: 1 addition & 0 deletions src/entities/file/@x/transfer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** Cross-import entities using public API in FSD https://feature-sliced.design/ru/docs/reference/public-api#public-api-for-cross-imports */
export type { FileFormat, Json } from '../types';
export { FileSizeUnitValue, FileSizeUnit } from '../types';
export { FileFormatParams, FileNameTemplate } from '../ui';
6 changes: 3 additions & 3 deletions src/entities/file/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FileSizeUnit } from './types';

export const FILE_SIZE_UNIT_DISPLAY = {
[FileSizeUnit.B]: 'b',
[FileSizeUnit.KB]: 'kb',
[FileSizeUnit.MB]: 'mb',
[FileSizeUnit.GB]: 'gb',
[FileSizeUnit.KiB]: 'kib',
[FileSizeUnit.MiB]: 'mib',
[FileSizeUnit.GiB]: 'gib',
} as const;
12 changes: 6 additions & 6 deletions src/entities/file/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export enum FileSizeUnit {
B = 'B',
KB = 'KB',
MB = 'MB',
GB = 'GB',
KiB = 'KiB',
MiB = 'MiB',
GiB = 'GiB',
}

export enum FileSizeUnitValue {
B = 1,
KB = 1000,
MB = 1000 * 1000,
GB = 1000 * 1000 * 1000,
KiB = 1024,
MiB = 1024 * 1024,
GiB = 1024 * 1024 * 1024,
}

export enum FileCompression {
Expand Down
12 changes: 6 additions & 6 deletions src/entities/file/utils/parseFileSize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { ParseFileSizeReturn } from './types';

/** Util for parsing file size in bytes to appropriate unit and value */
export const parseFileSize = (bytes: number): ParseFileSizeReturn => {
if (bytes >= FileSizeUnitValue.GB) {
return { value: bytes / FileSizeUnitValue.GB, unit: FileSizeUnit.GB };
if (bytes >= FileSizeUnitValue.GiB) {
return { value: bytes / FileSizeUnitValue.GiB, unit: FileSizeUnit.GiB };
}
if (bytes >= FileSizeUnitValue.MB) {
return { value: bytes / FileSizeUnitValue.MB, unit: FileSizeUnit.MB };
if (bytes >= FileSizeUnitValue.MiB) {
return { value: bytes / FileSizeUnitValue.MiB, unit: FileSizeUnit.MiB };
}
if (bytes >= FileSizeUnitValue.KB) {
return { value: bytes / FileSizeUnitValue.KB, unit: FileSizeUnit.KB };
if (bytes >= FileSizeUnitValue.KiB) {
return { value: bytes / FileSizeUnitValue.KiB, unit: FileSizeUnit.KiB };
}
return { value: bytes, unit: FileSizeUnit.B };
};
7 changes: 7 additions & 0 deletions src/entities/transfer/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface Transfer {
strategy_params: TransferStrategyParams;
is_scheduled: boolean;
schedule: string;
resources: TransferResources;
transformations: Transformations;
}

Expand All @@ -35,6 +36,12 @@ export interface TransferStrategyParams {
increment_by?: TransferConnectionFileIncrementBy | string;
}

export interface TransferResources {
max_parallel_tasks: number;
cpu_cores_per_task: number;
ram_bytes_per_task: number | string;
}

export interface TransferSourceConnectionFileType {
type:
| ConnectionType.FTP
Expand Down
1 change: 1 addition & 0 deletions src/entities/transfer/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './api';
export * from './ui';
export * from './utils';
2 changes: 2 additions & 0 deletions src/entities/transfer/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './prepareTransferResourcesForm';
export * from './prepareTransferResourcesRequest';
10 changes: 10 additions & 0 deletions src/entities/transfer/utils/prepareTransferResourcesForm/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { FileSizeUnitValue } from '@entities/file/@x/transfer';
import { TransferResources } from '@entities/transfer';

/** Util for mapping of transfer resources data from backend to appropriate form value */
export const prepareTransferResourcesForm = (data: TransferResources): TransferResources => {
return {
...data,
ram_bytes_per_task: +data.ram_bytes_per_task / FileSizeUnitValue.GiB,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { FileSizeUnit } from '@entities/file/@x/transfer';
import { TransferResources } from '@entities/transfer';

/** Util for mapping of transfer resources data from form value to appropriate value for backend */
export const prepareTransferResourcesRequest = (data: TransferResources): TransferResources => {
return {
...data,
ram_bytes_per_task: `${data.ram_bytes_per_task}${FileSizeUnit.GiB}`,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Form, Input } from 'antd';
import { useTranslation } from 'react-i18next';

import { MutateTransferFormProps } from './types';
import { StrategyParams, TransferConnections, TransferSchedule } from './components';
import { StrategyParams, TransferConnections, TransferResources, TransferSchedule } from './components';

export const MutateTransferForm = ({ group, onCancel }: MutateTransferFormProps) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -39,6 +39,8 @@ export const MutateTransferForm = ({ group, onCancel }: MutateTransferFormProps)

<StrategyParams />

<TransferResources />

<TransferSchedule />

<ControlButtons onCancel={onCancel} />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { useTranslation } from 'react-i18next';

import { TooltipTextProps } from './types';

export const TooltipText = ({ minValue, maxValue }: TooltipTextProps) => {
const { t } = useTranslation('transfer');

return (
<>
<p>
{t('minValue')} = {minValue}
</p>
<p>
{t('maxValue')} = {maxValue}
</p>
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface TooltipTextProps {
minValue: string | number;
maxValue: string | number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './TooltipText';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const MIN_PARALLEL_TASKS = 1;
export const MAX_PARALLEL_TASKS = 100;

export const MIN_CPU_CORES_PER_TASKS = 1;
export const MAX_CPU_CORES_PER_TASKS = 32;

export const MIN_RAM_PER_TASK = 0.5;
export const MAX_RAM_PER_TASK = 64;
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Fieldset } from '@shared/ui';
import { Form, InputNumber } from 'antd';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { validateFormFieldByPattern } from '@shared/utils';
import { INTEGER_ERROR_DISPLAY, INTEGER_REGEXP } from '@shared/constants';

import {
MAX_PARALLEL_TASKS,
MAX_CPU_CORES_PER_TASKS,
MIN_PARALLEL_TASKS,
MIN_CPU_CORES_PER_TASKS,
MIN_RAM_PER_TASK,
MAX_RAM_PER_TASK,
} from './constants';
import { TooltipText } from './components';

export const TransferResources = () => {
const { t } = useTranslation('error');

return (
<Fieldset title={t('resources', { ns: 'transfer' })}>
<Form.Item
label={t('maxParallelTasks', { ns: 'transfer' })}
name={['resources', 'max_parallel_tasks']}
rules={[
{
required: true,
pattern: INTEGER_REGEXP,
message: t(INTEGER_ERROR_DISPLAY),
validator: (rule, value) => validateFormFieldByPattern(rule, value, t),
},
]}
tooltip={<TooltipText minValue={MIN_PARALLEL_TASKS} maxValue={MAX_PARALLEL_TASKS} />}
>
<InputNumber size="large" min={MIN_PARALLEL_TASKS} max={MAX_PARALLEL_TASKS} />
</Form.Item>
<Form.Item
label={t('cpuCoresPerTask', { ns: 'transfer' })}
name={['resources', 'cpu_cores_per_task']}
rules={[
{
required: true,
pattern: INTEGER_REGEXP,
message: t(INTEGER_ERROR_DISPLAY),
validator: (rule, value) => validateFormFieldByPattern(rule, value, t),
},
]}
tooltip={<TooltipText minValue={MIN_CPU_CORES_PER_TASKS} maxValue={MAX_CPU_CORES_PER_TASKS} />}
>
<InputNumber size="large" min={MIN_CPU_CORES_PER_TASKS} max={MAX_CPU_CORES_PER_TASKS} />
</Form.Item>
<Form.Item
label={t('ramPerTask', { ns: 'transfer' })}
name={['resources', 'ram_bytes_per_task']}
rules={[{ required: true }]}
tooltip={
<TooltipText
minValue={`${MIN_RAM_PER_TASK} ${t('gib', { ns: 'file' })}`}
maxValue={`${MAX_RAM_PER_TASK} ${t('gib', { ns: 'file' })}`}
/>
}
>
<InputNumber size="large" min={MIN_RAM_PER_TASK} max={MAX_RAM_PER_TASK} />
</Form.Item>
</Fieldset>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './TransferSchedule';
export * from './TransferConnections';
export * from './StrategyParams';
export * from './TransferConnectionsCanvas';
export * from './TransferResources';
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { Descriptions } from 'antd';
import { useTranslation } from 'react-i18next';
import { FileSizeUnitValue } from '@entities/file';

import { TransferResourcesProps } from './types';

export const TransferResources = ({ data, ...props }: TransferResourcesProps) => {
const { t } = useTranslation('transfer');

return (
<Descriptions {...props}>
<Descriptions.Item label={t('maxParallelTasks')} span={3}>
{data.max_parallel_tasks}
</Descriptions.Item>
<Descriptions.Item label={t('cpuCoresPerTask')} span={3}>
{data.cpu_cores_per_task}
</Descriptions.Item>
<Descriptions.Item label={t('ramPerTask')} span={3}>
{+data.ram_bytes_per_task / FileSizeUnitValue.GiB} {t('gib', { ns: 'file' })}
</Descriptions.Item>
</Descriptions>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Transfer } from '@entities/transfer';
import { DescriptionsProps } from 'antd';

export interface TransferResourcesProps extends DescriptionsProps {
data: Transfer['resources'];
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './TransferParams';
export * from './TransferFileFormatData';
export * from './TransferStrategyParams';
export * from './TransferResources';
5 changes: 4 additions & 1 deletion src/features/transfer/TransferDetailInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next';

import { TransferDetailInfoProps } from './types';
import classes from './styles.module.less';
import { TransferParams, TransferStrategyParams } from './components';
import { TransferParams, TransferResources, TransferStrategyParams } from './components';

export const TransferDetailInfo = ({
transfer,
Expand Down Expand Up @@ -45,6 +45,9 @@ export const TransferDetailInfo = ({
<Descriptions.Item className={classes.subDescription} label={t('strategyParams', { ns: 'transfer' })} span={3}>
<TransferStrategyParams data={transfer.strategy_params} />
</Descriptions.Item>
<Descriptions.Item className={classes.subDescription} label={t('resources', { ns: 'transfer' })} span={3}>
<TransferResources data={transfer.resources} />
</Descriptions.Item>
<Descriptions.Item label={t('sourceConnection', { ns: 'connection' })} span={3}>
<Link to={`/connections/${connectionSource.id}`}>{connectionSource.name}</Link>
</Descriptions.Item>
Expand Down
17 changes: 12 additions & 5 deletions src/shared/config/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"formErrorHasOccurred": "Form error has occurred",
"fieldIsRequired": "Field is required",
"fieldPatternInvalid": "Field value does not match the pattern",
"invalidRegularExpression": "Invalid regular expressions"
"invalidRegularExpression": "Invalid regular expressions",
"integerError": "Field value must be integer"
},
"auth": {
"auth": "Authorization",
Expand Down Expand Up @@ -83,9 +84,9 @@
},
"file": {
"b": "B",
"kb": "KB",
"mb": "MB",
"gb": "GB",
"kib": "KiB",
"mib": "MiB",
"gib": "GiB",
"fileFormat": "File format",
"selectFileFormat": "Select file format",
"compression": "Compression",
Expand Down Expand Up @@ -179,7 +180,13 @@
"incremental": "incremental",
"target": "Target",
"basic": "Basic",
"advanced": "Advanced"
"advanced": "Advanced",
"resources": "Resources",
"minValue": "Min. value",
"maxValue": "Max. value",
"maxParallelTasks": "Max parallel tasks",
"cpuCoresPerTask": "CPU cores per task",
"ramPerTask": "RAM per task (GiB)"
},
"transformation": {
"transformations": "Transformations:",
Expand Down
17 changes: 12 additions & 5 deletions src/shared/config/i18n/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"formErrorHasOccurred": "Произошла ошибка формы",
"fieldIsRequired": "Поле обязательно",
"fieldPatternInvalid": "Значение поля не соответствует шаблону",
"invalidRegularExpression": "Некорректное регулярное выражение"
"invalidRegularExpression": "Некорректное регулярное выражение",
"integerError": "Значение поля должно быть целым числом"
},
"auth": {
"auth": "Авторизация",
Expand Down Expand Up @@ -83,9 +84,9 @@
},
"file": {
"b": "Б",
"kb": "КБ",
"mb": "МБ",
"gb": "ГБ",
"kib": "КиБ",
"mib": "МиБ",
"gib": "ГиБ",
"fileFormat": "Формат файла",
"selectFileFormat": "Выбрать формат файла",
"compression": "Сжатие",
Expand Down Expand Up @@ -179,7 +180,13 @@
"incremental": "инкрементальная",
"target": "Цель",
"basic": "Обычный",
"advanced": "Продвинутый"
"advanced": "Продвинутый",
"resources": "Ресурсы",
"minValue": "Мин. значение",
"maxValue": "Макс. значение",
"maxParallelTasks": "Макс. количество параллельных задач",
"cpuCoresPerTask": "Количество процессорных ядер на задачу",
"ramPerTask": "Количество оперативной памяти на задачу (ГиБ)"
},
"transformation": {
"transformations": "Трансформации:",
Expand Down
1 change: 1 addition & 0 deletions src/shared/constants/errorMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const INTEGER_ERROR_DISPLAY = 'integerError';
1 change: 1 addition & 0 deletions src/shared/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './storage';
export * from './antd';
export * from './regexp';
export * from './role';
export * from './errorMessage';
3 changes: 3 additions & 0 deletions src/shared/constants/regexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ export const ABSOLUTE_PATH_REGEXP = /^(?:[a-zA-Z]:\\|\/)/;

/** Regexp to input only digits and digits with fractional part (e.g. 123.22) */
export const NUMBER_REGEXP = /\d*\.?\d+$/;

/** Regexp to input only digits and (e.g. 354) */
export const INTEGER_REGEXP = /^\d+$/;
Loading