diff --git a/src/lib/account-select-label.js b/src/lib/account-select-label.js new file mode 100644 index 0000000..545dc2e --- /dev/null +++ b/src/lib/account-select-label.js @@ -0,0 +1,13 @@ +/** + * Подпись аккаунта в select и списках: при выборе одного хостера (scopedProviderId) — только имя аккаунта, + * иначе «хостер / аккаунт» (как в фильтрах VPS). + * @param {{ name?: string, providerId?: string }} account + * @param {Map} providerById + * @param {string} [scopedProviderId] + */ +export function accountSelectLabel(account, providerById, scopedProviderId) { + const name = account.name?.trim() || '—' + if (scopedProviderId) return name + const providerName = providerById.get(account.providerId)?.name ?? '—' + return `${providerName} / ${name}` +} diff --git a/src/pages/BalancePage.jsx b/src/pages/BalancePage.jsx index 9e7b993..2c03978 100644 --- a/src/pages/BalancePage.jsx +++ b/src/pages/BalancePage.jsx @@ -8,6 +8,7 @@ import { EmptyState } from '../components/EmptyState' import { PageHeader } from '../components/PageHeader' import { ConvertedAmount } from '../components/ConvertedAmount' import { noBrowserSuggestProps } from '../lib/noBrowserSuggestProps' +import { accountSelectLabel } from '../lib/account-select-label' const emptyForm = { type: 'daily_debit', @@ -24,6 +25,11 @@ export function BalancePage({ db, actions, settings, ratesData }) { const [error, setError] = useState('') const [isModalOpen, setIsModalOpen] = useState(false) + const providerById = useMemo( + () => new Map(db.providers.map((p) => [p.id, p])), + [db.providers], + ) + const vpsOptions = useMemo( () => db.vps.filter((vps) => !form.providerAccountId || vps.providerAccountId === form.providerAccountId), [db.vps, form.providerAccountId], @@ -94,7 +100,7 @@ export function BalancePage({ db, actions, settings, ratesData }) { {accountBalances.map((account) => ( - {account.name} + {accountSelectLabel(account, providerById, '')} {billingModeLabel(account.billingMode)} -
{account?.name || '-'}
+
+ {account + ? accountSelectLabel(account, providerById, '') + : '-'} +
{vps?.dns || vps?.ip || '-'}
@@ -216,7 +226,7 @@ export function BalancePage({ db, actions, settings, ratesData }) { {db.providerAccounts.map((account) => ( ))} diff --git a/src/pages/VpsPage.jsx b/src/pages/VpsPage.jsx index b346fb7..99a82e0 100644 --- a/src/pages/VpsPage.jsx +++ b/src/pages/VpsPage.jsx @@ -29,6 +29,7 @@ import { ProjectSuggestInput } from '../components/ProjectSuggestInput' import { noBrowserSuggestProps } from '../lib/noBrowserSuggestProps' import { getPaidUntilDate as computePaidUntilForHealth } from '../lib/paid-until' import { billmanagerSyncableAccounts } from '../lib/billmanager-ui' +import { accountSelectLabel } from '../lib/account-select-label' const emptyForm = { ip: '', @@ -78,14 +79,6 @@ function loadFilterPresets() { } } -/** Подпись аккаунта в select: при фильтре по одному хостеру — только имя, иначе «хостер / аккаунт». */ -function accountSelectLabel(account, providerById, scopedProviderId) { - const name = account.name?.trim() || '—' - if (scopedProviderId) return name - const providerName = providerById.get(account.providerId)?.name ?? '—' - return `${providerName} / ${name}` -} - function vpsMonthlyEstimateInBase(item, baseCurrency, ratesData, providerById) { if (item.status !== 'active') return 0 const tariffType = item.tariffType || (Number(item.dailyRate || 0) > 0 ? 'daily' : 'monthly')