Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
🐛 ui updated correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
frenicohansen committed Feb 13, 2024
1 parent ebf7dd9 commit 2382211
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 36 deletions.
18 changes: 3 additions & 15 deletions web/src/components/Spreadsheet/cells.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect } from 'react'

import { type Row, type Getter, Column, Table } from '@tanstack/react-table'
import { type Row, type Getter } from '@tanstack/react-table'
import { ChevronDown, ChevronRight } from 'lucide-react'

import { useMutation } from '@redwoodjs/web'
Expand Down Expand Up @@ -67,13 +67,9 @@ const UPDATE_BUDGET = gql`
export const CEditableCurrency = ({
getValue,
row,
column,
table,
}: {
getValue: Getter<number>
row: Row<MonthlyBudget>
column: Column<MonthlyBudget>
table: Table<MonthlyBudget>
}) => {
const convertToFloat = (str: string) => {
const res = parseFloat(str.replace(/[^0-9.]/g, ''))
Expand All @@ -97,22 +93,14 @@ export const CEditableCurrency = ({
setValue(initialValue)
}, [initialValue])

const tableMeta = table.options.meta as {
updateData: (rowIndex: number[], columnId: string, value: string) => void
}
const month = useSelectedMonth()
const year = useSelectedYear()

const [updateAssignedBudgetForCategory] = useMutation(UPDATE_BUDGET, {
refetchQueries: [FIND_THIS_MONTH_BUDGET],
})
const month = useSelectedMonth()
const year = useSelectedYear()

const onBlur = () => {
tableMeta.updateData(
[row.getParentRow().index, row.index],
column.id,
value
)
setValue(format(value))
if (!row.getCanExpand()) {
updateAssignedBudgetForCategory({
Expand Down
22 changes: 1 addition & 21 deletions web/src/components/Spreadsheet/data-table.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { useState } from 'react'

import { css } from '@one-ui/styled-system/css'
import {
ColumnDef,
Expand Down Expand Up @@ -32,31 +30,13 @@ export type DataTableProps<TData> = {

export function DataTable({ columns, data }: DataTableProps<MonthlyBudget>) {
const [expanded, setExpanded] = React.useState<ExpandedState>(true)
const [tableData, setTableData] = useState(data)

const table = useReactTable({
data: tableData,
data,
columns,
state: {
expanded,
},
meta: {
updateData: (rowIndex: number[], columnId: string, value: string) => {
setTableData((old) =>
old.map((row, index) => {
if (index === rowIndex[0]) {
const subRows = old[rowIndex[0]].subRows
subRows[rowIndex[1]][columnId] = value
return {
...old[rowIndex[0]],
subRows,
}
}
return row
})
)
},
},
getCoreRowModel: getCoreRowModel(),
onExpandedChange: setExpanded,
getSubRows: (row) => row.subRows,
Expand Down

0 comments on commit 2382211

Please sign in to comment.