[AURORA-2006] - Гудвилл (вкладка): мелкие дефекты после ревью
- Ответы 404/409 при «Сохранить» перечитывают таблицу - Исправлено поведение Стрелки раскрытия блока - Вывод сообщения об ошибке - Убран лишние лишний CSS из шахматки - hooks/useFullScreen.tsx => hooks/useFullScreen.ts, убрано удблирование типов
This commit is contained in:
parent
ab46262bd9
commit
64284a2917
@ -1,8 +1,5 @@
|
|||||||
/** DTO таблицы гудвилла — по `api/src/schemas/goodwill.py` и `../docs/dev/api-contract-goodwill.md`. Деньги и доля — строки. */
|
/** DTO таблицы гудвилла — по `api/src/schemas/goodwill.py` и `../docs/dev/api-contract-goodwill.md`. Деньги и доля — строки. */
|
||||||
export interface Ref {
|
import type { ReadOnlyReason, Ref } from '../corrections';
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GoodwillWarning {
|
export interface GoodwillWarning {
|
||||||
code: 'CAPITAL_SOURCE_MISSING' | 'CAPITAL_SOURCE_AMBIGUOUS' | 'OWNERSHIP_TOTAL_EXCEEDED' | string;
|
code: 'CAPITAL_SOURCE_MISSING' | 'CAPITAL_SOURCE_AMBIGUOUS' | 'OWNERSHIP_TOTAL_EXCEEDED' | string;
|
||||||
@ -42,13 +39,11 @@ export interface GoodwillGroup {
|
|||||||
totals: GoodwillTotals;
|
totals: GoodwillTotals;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type GoodwillReadOnlyReason = 'VERSION_NOT_EDITABLE' | 'LOCK_REQUIRED' | 'LOCKED_BY_OTHER';
|
|
||||||
|
|
||||||
export interface GoodwillTableResponse {
|
export interface GoodwillTableResponse {
|
||||||
version_id: string;
|
version_id: string;
|
||||||
goodwill_enabled: boolean;
|
goodwill_enabled: boolean;
|
||||||
editable: boolean;
|
editable: boolean;
|
||||||
read_only_reason: GoodwillReadOnlyReason | null;
|
read_only_reason: ReadOnlyReason | null;
|
||||||
rows: GoodwillRow[];
|
rows: GoodwillRow[];
|
||||||
groups: GoodwillGroup[];
|
groups: GoodwillGroup[];
|
||||||
totals: GoodwillTotals;
|
totals: GoodwillTotals;
|
||||||
|
|||||||
@ -1,18 +1,18 @@
|
|||||||
import { DownloadOutlined, EditOutlined, FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons';
|
import { DownloadOutlined, EditOutlined, FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons';
|
||||||
import { Alert, Button, ConfigProvider, Select, Space, Switch, Tooltip, Typography } from 'antd';
|
import { Alert, Button, ConfigProvider, Flex, Select, Space, Switch, Tooltip, Typography } from 'antd';
|
||||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { ApiError } from '../../../api/client';
|
import { ApiError } from '../../../api/client';
|
||||||
import { ConsolidationFormatTableFilter } from '../../../components/ConsolidationFormatTableFilter/ConsolidationFormatTableFilter';
|
import { ConsolidationFormatTableFilter } from '../../../components/ConsolidationFormatTableFilter/ConsolidationFormatTableFilter';
|
||||||
import { type ColumnDef, ColumnSettings, useVisibleColumns } from '../../../components/GenericTable';
|
import { type ColumnDef, ColumnSettings, useVisibleColumns } from '../../../components/GenericTable';
|
||||||
import { useFullscreen } from '../../../hooks/useFullScreen';
|
import { useFullscreen } from '../../../hooks/useFullscreen';
|
||||||
import { exportGoodwillTable, fetchGoodwillTable, saveGoodwillRows, saveGoodwillSettings } from '../../../services/api/goodwill';
|
import { exportGoodwillTable, fetchGoodwillTable, saveGoodwillRows, saveGoodwillSettings } from '../../../services/api/goodwill';
|
||||||
import type { VersionCard } from '../../../types/consolidations/version_members';
|
import type { VersionCard } from '../../../types/consolidations/version_members';
|
||||||
import type { GoodwillEdit, GoodwillSign, GoodwillTableResponse } from '../../../types/goodwill/goodwill';
|
import type { GoodwillEdit, GoodwillSign, GoodwillTableResponse } from '../../../types/goodwill/goodwill';
|
||||||
import { saveBlob, xlsxFilename } from '../../../utils/download';
|
import { saveBlob, xlsxFilename } from '../../../utils/download';
|
||||||
import { changedRows, effectiveRow, matchesSign, parseShare, rowKey } from '../../../utils/goodwill';
|
import { changedRows, effectiveRow, matchesSign, parseShare, rowKey } from '../../../utils/goodwill';
|
||||||
import { useNotificationApi } from '../../../utils/useNotification';
|
import { useNotificationApi } from '../../../utils/useNotification';
|
||||||
import { readOnlyHint } from '../../CorrectionTable/readOnly';
|
import { errorOutcome, readOnlyHint } from '../../CorrectionTable/readOnly';
|
||||||
import { ConsolidationGoodwillTable } from '../ConsolidationGoodwillTable/ConsolidationGoodwillTable';
|
import { ConsolidationGoodwillTable } from '../ConsolidationGoodwillTable/ConsolidationGoodwillTable';
|
||||||
import { type GoodwillTreeRow, type RowIssues, formatMoney, getGoodwillColumns } from '../ConsolidationGoodwillTable/config';
|
import { type GoodwillTreeRow, type RowIssues, formatMoney, getGoodwillColumns } from '../ConsolidationGoodwillTable/config';
|
||||||
|
|
||||||
@ -45,6 +45,7 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
|
|||||||
|
|
||||||
const [data, setData] = useState<GoodwillTableResponse | null>(null);
|
const [data, setData] = useState<GoodwillTableResponse | null>(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [loadError, setLoadError] = useState<string | null>(null);
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [settingsSaving, setSettingsSaving] = useState(false);
|
const [settingsSaving, setSettingsSaving] = useState(false);
|
||||||
const [decimals, setDecimals] = useState(2);
|
const [decimals, setDecimals] = useState(2);
|
||||||
@ -60,10 +61,14 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
|
|||||||
const loadData = useCallback(
|
const loadData = useCallback(
|
||||||
async (vId: string) => {
|
async (vId: string) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
setLoadError(null);
|
||||||
try {
|
try {
|
||||||
setData(await fetchGoodwillTable(vId));
|
setData(await fetchGoodwillTable(vId));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof ApiError) notification.error({ description: e.message });
|
const message = e instanceof ApiError ? e.message : 'Не удалось загрузить таблицу гудвилла';
|
||||||
|
setData(null);
|
||||||
|
setLoadError(message);
|
||||||
|
notification.error({ description: message });
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
@ -158,6 +163,16 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
|
|||||||
setIsEditMode(false);
|
setIsEditMode(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// сервер закрыл правки (перечитали после 409, версию забрали или закрыли) — выходим из редактирования:
|
||||||
|
// иначе экран остаётся редактируемым и каждое «Сохранить» снова получает 409
|
||||||
|
useEffect(() => {
|
||||||
|
if (data && !data.editable) {
|
||||||
|
setEdits({});
|
||||||
|
setServerIssues({});
|
||||||
|
setIsEditMode(false);
|
||||||
|
}
|
||||||
|
}, [data]);
|
||||||
|
|
||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
if (!version_id || !data) return;
|
if (!version_id || !data) return;
|
||||||
if (pending.length === 0) {
|
if (pending.length === 0) {
|
||||||
@ -170,13 +185,21 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
|
|||||||
closeEditing();
|
closeEditing();
|
||||||
notification.success({ description: 'Изменения сохранены' });
|
notification.success({ description: 'Изменения сохранены' });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
// 409 (версию закрыли, блокировку забрали) и 404 (пары уже нет) — перечитываем
|
||||||
|
// таблицу, строку не подсвечиваем; правки в несуществующих парах при пересчёте cбрасываем
|
||||||
|
const out = errorOutcome(e, 'Не удалось сохранить изменения');
|
||||||
|
notification.error({ description: out.message });
|
||||||
|
if (out.reload) {
|
||||||
|
setServerIssues({});
|
||||||
|
loadData(version_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const detail = rowErrorDetail(e);
|
const detail = rowErrorDetail(e);
|
||||||
if (detail) {
|
if (detail) {
|
||||||
const key = `${detail.head_legal_entity_id}:${detail.subsidiary_legal_entity_id}`;
|
const key = `${detail.head_legal_entity_id}:${detail.subsidiary_legal_entity_id}`;
|
||||||
const field = ERROR_FIELD[detail.code ?? ''] ?? 'ownership_share';
|
const field = ERROR_FIELD[detail.code ?? ''] ?? 'ownership_share';
|
||||||
setServerIssues((prev) => ({ ...prev, [key]: { ...prev[key], [field]: detail.message } }));
|
setServerIssues((prev) => ({ ...prev, [key]: { ...prev[key], [field]: detail.message } }));
|
||||||
}
|
}
|
||||||
if (e instanceof ApiError) notification.error({ description: e.message });
|
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false);
|
setSaving(false);
|
||||||
}
|
}
|
||||||
@ -188,7 +211,9 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
|
|||||||
try {
|
try {
|
||||||
setData(await saveGoodwillSettings(version_id, { goodwill_enabled: enabled }));
|
setData(await saveGoodwillSettings(version_id, { goodwill_enabled: enabled }));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof ApiError) notification.error({ description: e.message });
|
const out = errorOutcome(e, 'Не удалось изменить настройку гудвилла');
|
||||||
|
notification.error({ description: out.message });
|
||||||
|
if (out.reload) loadData(version_id);
|
||||||
} finally {
|
} finally {
|
||||||
setSettingsSaving(false);
|
setSettingsSaving(false);
|
||||||
}
|
}
|
||||||
@ -229,6 +254,12 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{loadError && !loading ? (
|
||||||
|
<Flex vertical align='center' gap={8} style={{ padding: 48 }}>
|
||||||
|
<span>{loadError}</span>
|
||||||
|
<Button onClick={() => version_id && loadData(version_id)}>Повторить</Button>
|
||||||
|
</Flex>
|
||||||
|
) : (
|
||||||
<div
|
<div
|
||||||
ref={tableRef}
|
ref={tableRef}
|
||||||
style={{
|
style={{
|
||||||
@ -314,6 +345,7 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</ConfigProvider>
|
</ConfigProvider>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,18 +1,8 @@
|
|||||||
.goodwillTable .empty-cell {
|
|
||||||
background-color: #f2f4f7;
|
|
||||||
}
|
|
||||||
.goodwillTable .ant-table-tbody > tr:hover > td.empty-cell {
|
|
||||||
background-color: #f2f4f7 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.goodwillTable .ant-table-summary {
|
.goodwillTable .ant-table-summary {
|
||||||
border-end-end-radius: 8px !important;
|
border-end-end-radius: 8px !important;
|
||||||
border-end-start-radius: 8px !important;
|
border-end-start-radius: 8px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.goodwillTable .ant-table-cell-fix {
|
|
||||||
background-color: #f8fafc !important;
|
|
||||||
}
|
|
||||||
.goodwillTable .resRow {
|
.goodwillTable .resRow {
|
||||||
background-color: #e6f4ea !important ;
|
background-color: #e6f4ea !important ;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,6 +57,10 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
|
|||||||
isFullscreen = false,
|
isFullscreen = false,
|
||||||
}) => {
|
}) => {
|
||||||
const treeData = useMemo(() => buildTree(data, rows), [data, rows]);
|
const treeData = useMemo(() => buildTree(data, rows), [data, rows]);
|
||||||
|
const expandIconColumnIndex = Math.max(
|
||||||
|
0,
|
||||||
|
columns.findIndex((col) => col.key === 'name'),
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table<GoodwillTreeRow>
|
<Table<GoodwillTreeRow>
|
||||||
@ -72,7 +76,7 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
|
|||||||
bordered
|
bordered
|
||||||
title={() => toolbar}
|
title={() => toolbar}
|
||||||
key={treeData.map((g) => g.key).join('|')}
|
key={treeData.map((g) => g.key).join('|')}
|
||||||
expandable={{ defaultExpandAllRows: true, expandIconColumnIndex: 1 }}
|
expandable={{ defaultExpandAllRows: true, expandIconColumnIndex }}
|
||||||
summary={() => <ConsolidationGoodwillSummary totals={data?.totals ?? null} columns={columns} units={units} decimals={decimals} />}
|
summary={() => <ConsolidationGoodwillSummary totals={data?.totals ?? null} columns={columns} units={units} decimals={decimals} />}
|
||||||
rowClassName={rowClassName}
|
rowClassName={rowClassName}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user