refactor: clarify frontend module ownership
Frontend verify / commits (pull_request) Failing after 1m19s
Frontend verify / security (pull_request) Skipped
Frontend verify / verify (pull_request) Skipped

This commit is contained in:
2026-09-29 07:07:36 +03:00
parent 7c28a423dd
commit f9f0f6921e
91 changed files with 1292 additions and 1050 deletions
+4
View File
@@ -1,2 +1,6 @@
export { useScreenSync } from "./model/screen-sync";
export {
InvestmentRefreshState,
type InvestmentRefreshStateProps,
} from "./ui/InvestmentRefreshState/InvestmentRefreshState.view";
export { TbankConnectionSection } from "./ui/TbankConnectionSection/TbankConnectionSection";
@@ -9,7 +9,14 @@ import {
type TbankConnectionStatus
= paths["/api/v1/tbank-connection"]["get"]["responses"][200]["content"]["application/json"];
const brokerageAccountsPath = "/api/v1/brokerage-accounts";
function isInvestmentPath(path: string) {
return [
"/api/v1/brokerage-accounts",
"/api/v1/stocks",
"/api/v1/bonds",
"/api/v1/tbank-sync",
].some(root => path === root || path.startsWith(`${root}/`));
}
const tbankConnectionQueryOptions = () =>
apiQueryClient.queryOptions("get", "/api/v1/tbank-connection");
@@ -20,13 +27,7 @@ function commitTbankConnectionBoundary(
queryClient: QueryClient,
status: TbankConnectionStatus,
) {
invalidateApiRequests(
path =>
path.startsWith("/api/v1/brokerage-accounts")
|| path.startsWith("/api/v1/stocks")
|| path.startsWith("/api/v1/bonds")
|| path.startsWith("/api/v1/tbank-sync"),
);
invalidateApiRequests(isInvestmentPath);
queryClient.setQueryData(tbankConnectionQueryKey, status);
void queryClient.resetQueries({
predicate: ({ queryKey }) => {
@@ -35,13 +36,7 @@ function commitTbankConnectionBoundary(
return (
method === "get"
&& typeof path === "string"
&& (path.startsWith("/api/v1/tbank-sync")
|| path === "/api/v1/bonds"
|| path.startsWith("/api/v1/bonds/")
|| path === "/api/v1/stocks"
|| path.startsWith("/api/v1/stocks/")
|| path === brokerageAccountsPath
|| path.startsWith(`${brokerageAccountsPath}/`))
&& isInvestmentPath(path)
);
},
});
@@ -0,0 +1,52 @@
import type { Meta, StoryObj } from "@storybook/react-vite";
import { Stack, Text } from "@mantine/core";
import { fn } from "storybook/test";
import { InvestmentRefreshState } from "./InvestmentRefreshState.view";
const meta = {
args: { labelScope: "portfolio", refreshError: false, refreshing: false, retry: fn() },
argTypes: {
refreshError: { control: "boolean" },
refreshing: { control: "boolean" },
retry: { control: false },
},
component: InvestmentRefreshState,
parameters: {
docs: {
description: {
component:
"Обновление уже показанных данных портфеля. Синтетические суммы остаются видимыми вместе с InvestmentRefreshState при refetch и его ошибке. Суммы синтетические; это presentation Client Cached Snapshot, без QueryClient и запроса API. Retry регистрирует локальное действие в Actions и не доказывает восстановление API.",
},
},
},
render: arguments_ => (
<Stack>
<Text>125 000,50 ₽ · 320 USD</Text>
<InvestmentRefreshState {...arguments_} />
</Stack>
),
tags: ["autodocs"],
title: "Product/InvestmentRefreshState",
} satisfies Meta<typeof InvestmentRefreshState>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Idle: Story = { name: "Сохранённые данные" };
export const Refreshing: Story = {
args: { refreshing: true },
name: "Фоновое обновление",
};
export const RefreshError: Story = {
args: { labelScope: "portfolio", refreshError: true },
name: "Ошибка обновления с retry",
};
export const SourceFailure: Story = {
args: { labelScope: "portfolio", refreshError: true, sourceError: true },
name: "Ошибка синхронизации сохраняет суммы",
};
@@ -0,0 +1,67 @@
import type { FC } from "react";
import { Alert, Button, Group, Loader, Stack, Text } from "@mantine/core";
import { useTranslation } from "react-i18next";
import { formatSnapshotTime } from "@/shared/lib";
type InvestmentRefreshStateProps = {
labelScope?: "accounts" | "portfolio";
lastSuccessfulAt?: null | string;
refreshError?: boolean;
refreshing?: boolean;
retry?: () => void;
sourceError?: boolean;
};
const InvestmentRefreshState: FC<InvestmentRefreshStateProps> = (props) => {
const { labelScope = "accounts", refreshError = false, refreshing = false, retry } = props;
const { t } = useTranslation();
return (
<>
{!!props.lastSuccessfulAt && (
<Text c="dimmed" size="xs">
{t("investment.sourceTime", {
date: formatSnapshotTime(props.lastSuccessfulAt),
})}
</Text>
)}
<Button
disabled={refreshing}
onClick={retry}
variant="light"
w="fit-content"
>
{t(refreshError ? "accounts.retry" : "investment.refresh")}
</Button>
{!!refreshing && (
<Group aria-label={t(`${labelScope}.refreshing`)} gap="xs" role="status">
<Loader size="sm" />
<Text c="dimmed" size="sm">
{t(`${labelScope}.refreshing`)}
</Text>
</Group>
)}
{!!refreshError && (
<Alert aria-live="polite" color="orange" role="status">
<Stack gap="sm">
<Text>
{t(
props.sourceError
? "investment.syncFailed"
: `${labelScope}.refreshError`,
)}
</Text>
</Stack>
</Alert>
)}
</>
);
};
export { InvestmentRefreshState, type InvestmentRefreshStateProps };