fix: open report cards in the same tab

Clicking a report card or "create from this report" now switches to the
report form inside the app instead of opening a new browser tab.
Ctrl+click on the copy link still opens a new tab.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Тимур Городецкий
2026-10-22 17:01:27 +05:00
parent 0ae52ccd6b
commit eb646193fa
@@ -1,6 +1,7 @@
import * as React from 'react';
import { Badge, Icon } from '@tnsu/ui-kit';
import { useRouter } from '../../app/routing/RouterContext';
import { IRoute } from '../../app/routing/routes';
import { IReportAccess, IReportCard } from './reportsTypes';
import { canCreateReport, canDeleteReport } from './reportsRules';
import { REPORTS_TEXTS } from './texts';
@@ -17,16 +18,26 @@ interface Props {
}
/**
* Карточка отчёта. Отчёт и «Создать на основе» открываются в новой вкладке — как в старом
* web part (window.open … '_blank'), но адрес теперь — раздел формы отчёта этого приложения.
* Карточка отчёта. Отчёт и «Создать на основе» открываются в этой же вкладке — переходом
* на раздел формы отчёта без перезагрузки страницы.
*/
export const ReportCard: React.FC<Props> = ({ report, access, projectId, onDelete }) => {
const { buildHref } = useRouter();
const reportHref = buildHref({ page: 'report', projectId, reportId: report.id });
const copyHref = buildHref({ page: 'report', projectId, copyFromId: report.id });
const { navigate, buildHref } = useRouter();
const reportRoute: IRoute = { page: 'report', projectId, reportId: report.id };
const copyRoute: IRoute = { page: 'report', projectId, copyFromId: report.id };
const openReport = (): void => {
window.open(reportHref, '_blank', 'noopener,noreferrer');
navigate(reportRoute);
};
// Ссылка остаётся настоящим <a href>, чтобы Ctrl+клик / средняя кнопка по-прежнему
// открывали копию в новой вкладке; обычный клик — переход внутри приложения.
const onCopyClick = (event: React.MouseEvent<HTMLAnchorElement>): void => {
event.stopPropagation();
const opensNewTab = event.ctrlKey || event.metaKey || event.shiftKey || event.button !== 0;
if (opensNewTab) return;
event.preventDefault();
navigate(copyRoute);
};
// Как в старом коде: Enter/Space внутри карточки (в том числе на её кнопках) открывают отчёт.
@@ -65,12 +76,10 @@ export const ReportCard: React.FC<Props> = ({ report, access, projectId, onDelet
{canCreateReport(access) && (
<a
className={styles.cardAction}
href={copyHref}
target="_blank"
rel="noopener noreferrer"
href={buildHref(copyRoute)}
title={TEXTS.copyTitle(report.number)}
aria-label={TEXTS.copyAriaLabel}
onClick={(event) => event.stopPropagation()}
onClick={onCopyClick}
>
<Icon name="copy" size="sm" />
</a>