Skip to content

Commit

Permalink
display total amount
Browse files Browse the repository at this point in the history
  • Loading branch information
quinn committed Jan 28, 2024
1 parent bc84d23 commit bec2b08
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
15 changes: 10 additions & 5 deletions electron/main/models/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ export async function fetchTransactions({
})
}

const [results, total] = await Promise.all([
const [
results,
total,
{
_sum: { amount: totalAmount },
},
] = await Promise.all([
prisma.transaction.findMany({
orderBy: {
[sortColumn]: sort,
Expand All @@ -54,13 +60,12 @@ export async function fetchTransactions({
where,
include: { account: true },
}),
prisma.transaction.count({
where,
}),
prisma.transaction.count({ where }),
prisma.transaction.aggregate({ where, _sum: { amount: true } }),
])

const pageCount = Math.ceil(total / pageSize)
return { results, total, pageCount }
return { results, total, pageCount, totalAmount }
}

export async function hideTransaction(plaidId: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export const transactionColumns: ColumnDef<TransactionType>[] = [
}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
className="translate-y-[2px]"
className="text-2xl data-[state=checked]:translate-y-[2px] data-[state=indeterminate]:translate-y-[2px]"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
aria-label="Select row"
className="translate-y-[2px]"
className="data-[state=checked]:translate-y-[2px]"
/>
),
enableSorting: false,
Expand Down
7 changes: 7 additions & 0 deletions src/components/pages/TablePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useDataTable, useDataTableInput } from '@/lib/useDataTable'
import { SelectionOverlay } from '../SelectionOverlay'
import { useEffect, useState } from 'react'
import { Transaction } from '@prisma/client'
import { formatMoney } from './ChartPage'

export function TablePage() {
const [input, setInput] = useDataTableInput()
Expand Down Expand Up @@ -51,6 +52,12 @@ export function TablePage() {
})) ?? [],
},
]}
metadata={
<>
Total Amount:{' '}
{data?.totalAmount ? formatMoney(data?.totalAmount) : 'N/A'}
</>
}
/>

{Boolean(selectedRows.length) && (
Expand Down
4 changes: 3 additions & 1 deletion src/components/ui/data-table/data-table-pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ import {

interface DataTablePaginationProps<TData> {
table: Table<TData>
metadata?: React.ReactNode
}

export function DataTablePagination<TData>({
table,
metadata,
}: DataTablePaginationProps<TData>) {
return (
<div className="flex items-center justify-between mx-3 mb-3">
<div className="flex-1 text-muted-foreground">
{table.getFilteredSelectedRowModel().rows.length} of{' '}
{table.getFilteredRowModel().rows.length} row(s) selected.
{table.getFilteredRowModel().rows.length} row(s) selected. {metadata}
</div>
<div className="flex items-center space-x-6 lg:space-x-8">
<div className="flex items-center space-x-2">
Expand Down
9 changes: 7 additions & 2 deletions src/components/ui/data-table/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ import { DataTableFilter, DataTableToolbar } from './data-table-toolbar'
interface DataTableProps<TData> {
table: Table<TData>
filters?: DataTableFilter<TData>[]
metadata?: React.ReactNode
}

export function DataTable<TData>({ table, filters }: DataTableProps<TData>) {
export function DataTable<TData>({
table,
filters,
metadata,
}: DataTableProps<TData>) {
return (
<>
<DataTableToolbar table={table} filters={filters} />
Expand Down Expand Up @@ -75,7 +80,7 @@ export function DataTable<TData>({ table, filters }: DataTableProps<TData>) {
</UITable>
</div>

<DataTablePagination table={table} />
<DataTablePagination table={table} metadata={metadata} />
</>
)
}
4 changes: 2 additions & 2 deletions src/components/ui/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const TableHead = React.forwardRef<
<th
ref={ref}
className={cn(
'h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]',
'h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0', // [&>[role=checkbox]]:translate-y-[2px]',
className,
)}
{...props}
Expand All @@ -88,7 +88,7 @@ const TableCell = React.forwardRef<
<td
ref={ref}
className={cn(
'p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]',
'p-2 align-middle [&:has([role=checkbox])]:pr-0', // [&>[role=checkbox]]:translate-y-[2px]',
className,
)}
{...props}
Expand Down

0 comments on commit bec2b08

Please sign in to comment.