Skip to content

Commit

Permalink
Fix date header for balance sheet
Browse files Browse the repository at this point in the history
It should only show the month of the report for monthly
  • Loading branch information
kattylucy committed Sep 6, 2024
1 parent 52a5fba commit 83bc918
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 53 deletions.
7 changes: 2 additions & 5 deletions centrifuge-app/src/components/Report/BalanceSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) => (
<Text variant={row.heading ? 'heading4' : row.bold ? 'interactive2' : 'body3'}>
{row.formatter ? row.formatter((row.value as any)[index]) : (row.value as any)[index]}
Expand Down
26 changes: 2 additions & 24 deletions centrifuge-app/src/components/Report/CashflowStatement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand All @@ -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) => (
<Text variant={row.heading ? 'heading4' : row.bold ? 'interactive2' : 'body3'}>
{row.formatter ? row.formatter((row.value as any)[index]) : (row.value as any)[index]}
Expand Down
26 changes: 2 additions & 24 deletions centrifuge-app/src/components/Report/ProfitAndLoss.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand All @@ -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) => (
<Text variant={row.heading ? 'heading4' : row.bold ? 'interactive2' : 'body3'}>
{row.formatter ? row.formatter((row.value as any)[index]) : (row.value as any)[index]}
Expand Down
23 changes: 23 additions & 0 deletions centrifuge-app/src/components/Report/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''
}

0 comments on commit 83bc918

Please sign in to comment.