Skip to content

Commit

Permalink
Persist to, from and groupBy filters and fix linter warnings (#2635)
Browse files Browse the repository at this point in the history
  • Loading branch information
kattylucy authored Feb 14, 2025
1 parent a443c25 commit c6368fc
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 63 deletions.
6 changes: 3 additions & 3 deletions centrifuge-app/src/components/Report/BalanceSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export function BalanceSheet({ pool }: { pool: Pool }) {
.concat(
poolStates.map((state, index) => ({
align: 'left',
timestamp: state.timestamp,
header: new Date(state.timestamp).toLocaleDateString('en-US', {
timestamp: state?.timestamp,
header: new Date(state?.timestamp).toLocaleDateString('en-US', {
day: 'numeric',
month: 'short',
year: 'numeric',
Expand Down Expand Up @@ -111,7 +111,7 @@ export function BalanceSheet({ pool }: { pool: Pool }) {
formatter: (v: any) => (v ? formatBalance(v, 2, currency) : ''),
},
]
}, [currency, poolStates])
}, [poolStates, currency])

const trancheRecords: Row[] = React.useMemo(() => {
return [
Expand Down
4 changes: 2 additions & 2 deletions centrifuge-app/src/components/Report/CashflowStatement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export function CashflowStatement({ pool }: { pool: Pool }) {
.concat(
data.map((state, index) => ({
align: 'right',
timestamp: state.timestamp,
header: getColumnHeader(state.timestamp, groupBy),
timestamp: 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
17 changes: 14 additions & 3 deletions centrifuge-app/src/components/Report/DataFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,21 @@ export function DataFilter({ poolId }: ReportFilterProps) {
options={reportOptions}
value={report}
onChange={(event: React.ChangeEvent<HTMLSelectElement>) => {
const { value } = event.target
if (value) {
navigate(`${basePath}/${pool.id}/data/${value}`)
const newReport = event.target.value
let path = `${basePath}/${pool.id}/data/${newReport}`

if (newReport !== 'orders') {
const params = new URLSearchParams()
if (startDate) params.append('from', startDate)
if (endDate) params.append('to', endDate)
if (groupBy) params.append('groupBy', groupBy)

const queryString = params.toString()
if (queryString) {
path = `${path}?${queryString}`
}
}
navigate(path)
}}
/>

Expand Down
42 changes: 1 addition & 41 deletions centrifuge-app/src/components/Report/InvestorTransactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,47 +159,7 @@ export function InvestorTransactions({ pool }: { pool: Pool }) {
}

return transactions
?.filter((tx) => {
if (txType === 'all') {
return true
}

if (
txType === 'orders' &&
(tx.transactionType === 'INVEST_ORDER_UPDATE' ||
tx.transactionType === 'REDEEM_ORDER_UPDATE' ||
tx.transactionType === 'INVEST_ORDER_CANCEL' ||
tx.transactionType === 'REDEEM_ORDER_CANCEL')
) {
return true
}

if (
txType === 'executions' &&
(tx.transactionType === 'INVEST_EXECUTION' || tx.transactionType === 'REDEEM_EXECUTION')
) {
return true
}

if (
txType === 'transfers' &&
(tx.transactionType === 'INVEST_COLLECT' ||
tx.transactionType === 'REDEEM_COLLECT' ||
tx.transactionType === 'INVEST_LP_COLLECT' ||
tx.transactionType === 'REDEEM_LP_COLLECT' ||
tx.transactionType === 'TRANSFER_IN' ||
tx.transactionType === 'TRANSFER_OUT')
) {
return true
}

return false
})
.filter((tx) => {
if (!network || network === 'all') return true
return network === (tx.chainId || 'centrifuge')
})
.map((tx) => {
?.map((tx) => {
const token = pool.tranches.find((t) => t.id === tx.trancheTokenId)!
return {
name: '',
Expand Down
2 changes: 1 addition & 1 deletion centrifuge-app/src/components/Report/PoolBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function PoolBalance({ pool }: { pool: Pool }) {
.concat(
poolStates.map((state, index) => ({
align: 'right',
timestamp: state.timestamp,
timestamp: state?.timestamp,
header:
groupBy === 'day'
? new Date(state.timestamp).toLocaleDateString('en-US', {
Expand Down
4 changes: 2 additions & 2 deletions centrifuge-app/src/components/Report/ProfitAndLoss.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export function ProfitAndLoss({ pool }: { pool: Pool }) {
.concat(
data.map((state, index) => ({
align: 'right',
timestamp: state.timestamp,
header: getColumnHeader(state.timestamp, groupBy),
timestamp: 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
31 changes: 21 additions & 10 deletions centrifuge-app/src/components/Report/ReportFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ interface StyledButtonProps {
selected?: boolean
}

type ReportFilterProps = {
poolId: string
}

const StyledButton = styled(Button)<StyledButtonProps>`
margin-bottom: 12px;
margin-right: 12px;
Expand All @@ -40,10 +44,6 @@ const StyledButton = styled(Button)<StyledButtonProps>`
}
`

type ReportFilterProps = {
poolId: string
}

export function ReportFilter({ poolId }: ReportFilterProps) {
const { csvData, setStartDate, startDate, endDate, setEndDate, groupBy, setGroupBy, report, reportData } =
React.useContext(ReportContext)
Expand All @@ -55,26 +55,37 @@ export function ReportFilter({ poolId }: ReportFilterProps) {
if (!reportData.length) return
if (report === 'balance-sheet') {
return (reportData as BalanceSheetReport[]).map((data) => ({
name: data.timestamp,
name: data?.timestamp,
yAxis: data.totalCapital?.toDecimal(),
}))
} else if (report === 'profit-and-loss') {
return (reportData as ProfitAndLossReport[]).map((data) => ({
name: data.timestamp,
name: data?.timestamp,
yAxis: data.totalProfitAndLoss?.toDecimal(),
}))
} else {
return (reportData as CashflowReport[])
.filter((data) => !data.totalCashflow?.isZero())
.map((data) => {
return {
name: data.timestamp,
name: data?.timestamp,
yAxis: data.totalCashflow?.toDecimal(),
}
})
}
}, [report, reportData])

const changeTab = (tab: string) => {
const base = `${basePath}/${pool.id}/reporting/${tab}`

const params = new URLSearchParams()
if (startDate) params.append('from', startDate)
if (endDate) params.append('to', endDate)
if (groupBy) params.append('groupBy', groupBy)

navigate(`${base}?${params.toString()}`)
}

return (
<Shelf
padding={2}
Expand All @@ -91,23 +102,23 @@ export function ReportFilter({ poolId }: ReportFilterProps) {
selected={report === 'balance-sheet'}
variant={report === 'balance-sheet' ? 'secondary' : 'tertiary'}
icon={<IconBalanceSheet size={18} />}
onClick={() => navigate(`${basePath}/${pool.id}/reporting/balance-sheet`)}
onClick={() => changeTab('balance-sheet')}
>
Balance sheet
</StyledButton>
<StyledButton
selected={report === 'profit-and-loss'}
variant={report === 'profit-and-loss' ? 'secondary' : 'tertiary'}
icon={<IconProfitAndLoss size={18} />}
onClick={() => navigate(`${basePath}/${pool.id}/reporting/profit-and-loss`)}
onClick={() => changeTab('profit-and-loss')}
>
Profit & loss
</StyledButton>
<StyledButton
selected={report === 'cash-flow-statement'}
variant={report === 'cash-flow-statement' ? 'secondary' : 'tertiary'}
icon={<IconCashflow size={18} />}
onClick={() => navigate(`${basePath}/${pool.id}/reporting/cash-flow-statement`)}
onClick={() => changeTab('cash-flow-statement')}
>
Cash flow
</StyledButton>
Expand Down
2 changes: 1 addition & 1 deletion centrifuge-app/src/components/Report/TokenPrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function TokenPrice({ pool }: { pool: Pool }) {
.concat(
poolStates.map((state, index) => ({
align: 'right',
timestamp: state.timestamp,
timestamp: state?.timestamp,
header:
groupBy === 'day'
? new Date(state.timestamp).toLocaleDateString('en-US', {
Expand Down

0 comments on commit c6368fc

Please sign in to comment.