[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`. Деньги и доля — строки. */
|
||||
export interface Ref {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
import type { ReadOnlyReason, Ref } from '../corrections';
|
||||
|
||||
export interface GoodwillWarning {
|
||||
code: 'CAPITAL_SOURCE_MISSING' | 'CAPITAL_SOURCE_AMBIGUOUS' | 'OWNERSHIP_TOTAL_EXCEEDED' | string;
|
||||
@ -42,13 +39,11 @@ export interface GoodwillGroup {
|
||||
totals: GoodwillTotals;
|
||||
}
|
||||
|
||||
export type GoodwillReadOnlyReason = 'VERSION_NOT_EDITABLE' | 'LOCK_REQUIRED' | 'LOCKED_BY_OTHER';
|
||||
|
||||
export interface GoodwillTableResponse {
|
||||
version_id: string;
|
||||
goodwill_enabled: boolean;
|
||||
editable: boolean;
|
||||
read_only_reason: GoodwillReadOnlyReason | null;
|
||||
read_only_reason: ReadOnlyReason | null;
|
||||
rows: GoodwillRow[];
|
||||
groups: GoodwillGroup[];
|
||||
totals: GoodwillTotals;
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
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 { useParams } from 'react-router-dom';
|
||||
import { ApiError } from '../../../api/client';
|
||||
import { ConsolidationFormatTableFilter } from '../../../components/ConsolidationFormatTableFilter/ConsolidationFormatTableFilter';
|
||||
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 type { VersionCard } from '../../../types/consolidations/version_members';
|
||||
import type { GoodwillEdit, GoodwillSign, GoodwillTableResponse } from '../../../types/goodwill/goodwill';
|
||||
import { saveBlob, xlsxFilename } from '../../../utils/download';
|
||||
import { changedRows, effectiveRow, matchesSign, parseShare, rowKey } from '../../../utils/goodwill';
|
||||
import { useNotificationApi } from '../../../utils/useNotification';
|
||||
import { readOnlyHint } from '../../CorrectionTable/readOnly';
|
||||
import { errorOutcome, readOnlyHint } from '../../CorrectionTable/readOnly';
|
||||
import { ConsolidationGoodwillTable } from '../ConsolidationGoodwillTable/ConsolidationGoodwillTable';
|
||||
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 [loading, setLoading] = useState(false);
|
||||
const [loadError, setLoadError] = useState<string | null>(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [settingsSaving, setSettingsSaving] = useState(false);
|
||||
const [decimals, setDecimals] = useState(2);
|
||||
@ -60,10 +61,14 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
|
||||
const loadData = useCallback(
|
||||
async (vId: string) => {
|
||||
setLoading(true);
|
||||
setLoadError(null);
|
||||
try {
|
||||
setData(await fetchGoodwillTable(vId));
|
||||
} 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 {
|
||||
setLoading(false);
|
||||
}
|
||||
@ -158,6 +163,16 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
|
||||
setIsEditMode(false);
|
||||
};
|
||||
|
||||
// сервер закрыл правки (перечитали после 409, версию забрали или закрыли) — выходим из редактирования:
|
||||
// иначе экран остаётся редактируемым и каждое «Сохранить» снова получает 409
|
||||
useEffect(() => {
|
||||
if (data && !data.editable) {
|
||||
setEdits({});
|
||||
setServerIssues({});
|
||||
setIsEditMode(false);
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!version_id || !data) return;
|
||||
if (pending.length === 0) {
|
||||
@ -170,13 +185,21 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
|
||||
closeEditing();
|
||||
notification.success({ description: 'Изменения сохранены' });
|
||||
} 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);
|
||||
if (detail) {
|
||||
const key = `${detail.head_legal_entity_id}:${detail.subsidiary_legal_entity_id}`;
|
||||
const field = ERROR_FIELD[detail.code ?? ''] ?? 'ownership_share';
|
||||
setServerIssues((prev) => ({ ...prev, [key]: { ...prev[key], [field]: detail.message } }));
|
||||
}
|
||||
if (e instanceof ApiError) notification.error({ description: e.message });
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
@ -188,7 +211,9 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
|
||||
try {
|
||||
setData(await saveGoodwillSettings(version_id, { goodwill_enabled: enabled }));
|
||||
} 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 {
|
||||
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
|
||||
ref={tableRef}
|
||||
style={{
|
||||
@ -314,6 +345,7 @@ export const GoodwillContent = ({ card }: { card: VersionCard | null }) => {
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</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 {
|
||||
border-end-end-radius: 8px !important;
|
||||
border-end-start-radius: 8px !important;
|
||||
}
|
||||
|
||||
.goodwillTable .ant-table-cell-fix {
|
||||
background-color: #f8fafc !important;
|
||||
}
|
||||
.goodwillTable .resRow {
|
||||
background-color: #e6f4ea !important ;
|
||||
}
|
||||
|
||||
@ -57,6 +57,10 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
|
||||
isFullscreen = false,
|
||||
}) => {
|
||||
const treeData = useMemo(() => buildTree(data, rows), [data, rows]);
|
||||
const expandIconColumnIndex = Math.max(
|
||||
0,
|
||||
columns.findIndex((col) => col.key === 'name'),
|
||||
);
|
||||
|
||||
return (
|
||||
<Table<GoodwillTreeRow>
|
||||
@ -72,7 +76,7 @@ export const ConsolidationGoodwillTable: React.FC<ConsolidationGoodwillTableI> =
|
||||
bordered
|
||||
title={() => toolbar}
|
||||
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} />}
|
||||
rowClassName={rowClassName}
|
||||
/>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user