diff --git a/centrifuge-app/src/components/Report/BalanceSheet.tsx b/centrifuge-app/src/components/Report/BalanceSheet.tsx index fee1b7f3b..5981b08e7 100644 --- a/centrifuge-app/src/components/Report/BalanceSheet.tsx +++ b/centrifuge-app/src/components/Report/BalanceSheet.tsx @@ -13,6 +13,7 @@ import { Spinner } from '../Spinner' import { ReportContext } from './ReportContext' import { UserFeedback } from './UserFeedback' import type { TableDataRow } from './index' +import { getColumnHeader } from './utils' type Row = TableDataRow & { formatter?: (v: any) => any @@ -77,11 +78,7 @@ export function BalanceSheet({ pool }: { pool: Pool }) { poolStates.map((state, index) => ({ align: 'right', timestamp: state.timestamp, - header: new Date(state.timestamp).toLocaleDateString('en-US', { - day: 'numeric', - month: 'short', - year: 'numeric', - }), + header: getColumnHeader(state.timestamp, groupBy), cell: (row: Row) => ( {row.formatter ? row.formatter((row.value as any)[index]) : (row.value as any)[index]} diff --git a/centrifuge-app/src/components/Report/CashflowStatement.tsx b/centrifuge-app/src/components/Report/CashflowStatement.tsx index 56b100678..9647f85bd 100644 --- a/centrifuge-app/src/components/Report/CashflowStatement.tsx +++ b/centrifuge-app/src/components/Report/CashflowStatement.tsx @@ -17,6 +17,7 @@ import { Spinner } from '../Spinner' import { ReportContext } from './ReportContext' import { UserFeedback } from './UserFeedback' import type { TableDataRow } from './index' +import { getColumnHeader } from './utils' type Row = TableDataRow & { formatter?: (v: any) => any @@ -83,29 +84,6 @@ export function CashflowStatement({ pool }: { pool: Pool }) { return [] } - const getColumnHeader = (timestamp: string) => { - if (groupBy === 'day' || groupBy === 'daily') { - return new Date(timestamp).toLocaleDateString('en-US', { - day: 'numeric', - month: 'short', - year: 'numeric', - }) - } else if (groupBy === 'month') { - return new Date(timestamp).toLocaleDateString('en-US', { - month: 'long', - year: 'numeric', - }) - } else if (groupBy === 'quarter') { - const date = new Date(timestamp) - return `Q${Math.floor(date.getMonth() / 3) + 1} ${date.getFullYear()}` - } else if (groupBy === 'year') { - return new Date(timestamp).toLocaleDateString('en-US', { - year: 'numeric', - }) - } - return '' - } - return [ { align: 'left', @@ -125,7 +103,7 @@ export function CashflowStatement({ pool }: { pool: Pool }) { poolStates.map((state, index) => ({ align: 'right', timestamp: state.timestamp, - header: getColumnHeader(state.timestamp), + header: getColumnHeader(state.timestamp, groupBy), cell: (row: Row) => ( {row.formatter ? row.formatter((row.value as any)[index]) : (row.value as any)[index]} diff --git a/centrifuge-app/src/components/Report/ProfitAndLoss.tsx b/centrifuge-app/src/components/Report/ProfitAndLoss.tsx index 565178e12..cadd57ca5 100644 --- a/centrifuge-app/src/components/Report/ProfitAndLoss.tsx +++ b/centrifuge-app/src/components/Report/ProfitAndLoss.tsx @@ -16,6 +16,7 @@ import { Spinner } from '../Spinner' import { ReportContext } from './ReportContext' import { UserFeedback } from './UserFeedback' import type { TableDataRow } from './index' +import { getColumnHeader } from './utils' type Row = TableDataRow & { formatter?: (v: any) => any @@ -75,29 +76,6 @@ export function ProfitAndLoss({ pool }: { pool: Pool }) { return [] } - const getColumnHeader = (timestamp: string) => { - if (groupBy === 'day' || groupBy === 'daily') { - return new Date(timestamp).toLocaleDateString('en-US', { - day: 'numeric', - month: 'short', - year: 'numeric', - }) - } else if (groupBy === 'month') { - return new Date(timestamp).toLocaleDateString('en-US', { - month: 'long', - year: 'numeric', - }) - } else if (groupBy === 'quarter') { - const date = new Date(timestamp) - return `Q${Math.floor(date.getMonth() / 3) + 1} ${date.getFullYear()}` - } else if (groupBy === 'year') { - return new Date(timestamp).toLocaleDateString('en-US', { - year: 'numeric', - }) - } - return '' - } - return [ { align: 'left', @@ -117,7 +95,7 @@ export function ProfitAndLoss({ pool }: { pool: Pool }) { poolStates.map((state, index) => ({ align: 'right', timestamp: state.timestamp, - header: getColumnHeader(state.timestamp), + header: getColumnHeader(state.timestamp, groupBy), cell: (row: Row) => ( {row.formatter ? row.formatter((row.value as any)[index]) : (row.value as any)[index]} diff --git a/centrifuge-app/src/components/Report/utils.tsx b/centrifuge-app/src/components/Report/utils.tsx index e3564d6bd..34f364ff7 100644 --- a/centrifuge-app/src/components/Report/utils.tsx +++ b/centrifuge-app/src/components/Report/utils.tsx @@ -155,3 +155,26 @@ export function convertCSV(values: any[], columnConfig: any[]) { }) ) } + +export const getColumnHeader = (timestamp: string, groupBy: string) => { + if (groupBy === 'day' || groupBy === 'daily') { + return new Date(timestamp).toLocaleDateString('en-US', { + day: 'numeric', + month: 'short', + year: 'numeric', + }) + } else if (groupBy === 'month') { + return new Date(timestamp).toLocaleDateString('en-US', { + month: 'long', + year: 'numeric', + }) + } else if (groupBy === 'quarter') { + const date = new Date(timestamp) + return `Q${Math.floor(date.getMonth() / 3) + 1} ${date.getFullYear()}` + } else if (groupBy === 'year') { + return new Date(timestamp).toLocaleDateString('en-US', { + year: 'numeric', + }) + } + return '' +}