Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/cli/src/commands/balances/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ interface BalancesListProps {
const COLUMN_GAP = ' ';
const SOURCE_ID_MIN = 16;
const SOURCE_ID_MAX = 48;
const NAME_MIN = 12;
const NAME_MAX = 30;
const TYPE_WIDTH = 12;
const CURRENT_WIDTH = 15;
const CURRENCY_WIDTH = 8;
Expand Down Expand Up @@ -51,6 +53,17 @@ function sourceIdWidth(balances: Balance[]): number {
return Math.min(SOURCE_ID_MAX, Math.max(SOURCE_ID_MIN, maxLen));
}

function accountName(balance: Balance): string {
const name = balance.name;
return typeof name === 'string' && name.length > 0 ? name : '-';
}

function nameWidth(balances: Balance[]): number {
if (balances.length === 0) return NAME_MIN;
const maxLen = Math.max(...balances.map((b) => accountName(b).length));
return Math.min(NAME_MAX, Math.max(NAME_MIN, maxLen));
}

export const BalancesList: React.FC<BalancesListProps> = ({
resource,
params,
Expand All @@ -68,7 +81,9 @@ export const BalancesList: React.FC<BalancesListProps> = ({
: null;

const idWidth = sourceIdWidth(balances);
const accountNameWidth = nameWidth(balances);
const headerRow = [
formatCell('Source name', accountNameWidth),
formatCell('Source ID', idWidth),
formatCell('Balance type', TYPE_WIDTH),
formatCell('Current balance', CURRENT_WIDTH),
Expand All @@ -77,6 +92,7 @@ export const BalancesList: React.FC<BalancesListProps> = ({
const separatorRow = '-'.repeat(headerRow.length);
const rows = balances.map((balance) =>
[
formatCell(accountName(balance), accountNameWidth),
formatCell(balance.source_id ?? '-', idWidth),
formatCell(balance.type ?? '-', TYPE_WIDTH),
formatCell(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('sources list component', () => {
});

it('renders source details', async () => {
setTerminalWidth(160);
setTerminalWidth(200);
const resource = makeResource({
data: [
{
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/sources/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function sourceRow(source: Source, index: number): SourceRow {

return {
key: sourceId(source, index),
name: source.name ?? 'Source',
name: source.name ?? '-',
type: source.type ?? '-',
id: sourceId(source, index),
capabilities,
Expand All @@ -102,7 +102,7 @@ function sourceRow(source: Source, index: number): SourceRow {

function tableColumns(): TableColumn[] {
return [
{ label: 'Name', value: (row) => row.name, minWidth: 14, maxWidth: 24 },
{ label: 'Name', value: (row) => row.name, minWidth: 14, maxWidth: 36 },
{ label: 'Type', value: (row) => row.type, minWidth: 10, maxWidth: 14 },
{ label: 'ID', value: (row) => row.id, minWidth: 16, maxWidth: 48 },
{
Expand Down
Loading