diff --git a/src/components/nested-table-view/common/editable-table-cell.tsx b/src/components/nested-table-view/common/editable-table-cell.tsx index 7c35f55..556bd37 100644 --- a/src/components/nested-table-view/common/editable-table-cell.tsx +++ b/src/components/nested-table-view/common/editable-table-cell.tsx @@ -3,9 +3,9 @@ import { observer } from "mobx-react-lite"; import { Editable, EditablePreview, EditableInput } from "@chakra-ui/react"; import { IResult } from "@concord-consortium/codap-plugin-api"; import { IProcessedCaseObj } from "../../../types"; +import { getDisplayValue } from "../../../utils/utils"; import css from "./editable-table-cell.scss"; -import { getDisplayValue } from "../../../utils/utils"; interface IProps { attrTitle: string; diff --git a/src/components/nested-table-view/portrait/portrait-table-row.tsx b/src/components/nested-table-view/portrait/portrait-table-row.tsx index b7fb04e..9d4dae2 100644 --- a/src/components/nested-table-view/portrait/portrait-table-row.tsx +++ b/src/components/nested-table-view/portrait/portrait-table-row.tsx @@ -3,18 +3,18 @@ import { IProcessedCaseObj, ITableProps } from "../../../types"; import { observer } from "mobx-react-lite"; import { useTableHeaderFocusContext } from "../../../hooks/useTableHeaderFocusContext"; import { TableCells } from "../common/table-cells"; +import { TableHeaders } from "../common/table-headers"; import { DraggableTableContainer, DroppableTableData, DroppableTableHeader } from "../common/draggable-table-tags"; import css from "../common/tables.scss"; -import { TableHeaders } from "../common/table-headers"; -export type PortraitViewRowProps = { +export type PortraitTableRowProps = { caseObj: IProcessedCaseObj, index?: null | number, isParent: boolean, parentLevel?: number dataSetName: string, hasFocusBeenSet?: boolean } & ITableProps; -export const PortraitTableRow = observer(function PortraitViewRow(props: PortraitViewRowProps) { +export const PortraitTableRow = observer(function PortraitTableRow(props: PortraitTableRowProps) { const { paddingStyle, showHeaders, getClassName, caseObj, index, isParent, parentLevel = 0, dataSetName, handleAddAttribute, collectionsModel, handleSortAttribute, renameAttribute, hasFocusBeenSet, editCaseValue, selectedDataSet } = props; @@ -93,7 +93,7 @@ export const PortraitTableRow = observer(function PortraitViewRow(props: Portrai {caseObj.children.map((child, i) => { - const nextProps: PortraitViewRowProps = { + const nextProps: PortraitTableRowProps = { ...props, caseObj: child, index: i, @@ -118,11 +118,11 @@ export const PortraitTableRow = observer(function PortraitViewRow(props: Portrai renameAttribute={renameAttribute} /> - + ); } else { - return ; + return ; } })} diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 39c3a2c..fea52e3 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -3,21 +3,21 @@ import { IAttribute } from "../types"; export const getDisplayValue = (cellValue: string | number, attrTitle: string, attrTypes: Record, precisions: Record) => { let displayValue: string|number; - const isNumericType = attrTypes[attrTitle] === "numeric"; - const hasValue = cellValue !== ""; + const isAttrNumberType = attrTypes[attrTitle] === "numeric"; + const cellHasValue = cellValue !== ""; + const isValueNumberType = typeof cellValue === "number"; const parsedValue: number = typeof cellValue === "string" ? parseFloat(cellValue) : NaN; - const isNumber = !isNaN(parsedValue); + const isValueNumber = !isNaN(parsedValue); const hasPrecision = precisions[attrTitle] !== undefined; const defaultValue: string | number = cellValue; - const isNumberType = typeof cellValue === "number"; - if (isNumericType && hasValue && isNumber) { + if (isAttrNumberType && cellHasValue && isValueNumber) { const cellValAsNumber = Number(cellValue); const isWholeNumber: boolean = cellValAsNumber % 1 === 0; displayValue = isWholeNumber ? parseInt(cellValue as string, 10) : parsedValue.toFixed(hasPrecision ? precisions[attrTitle] : 2); - } else if (!isNumericType && isNumberType && hasValue) { + } else if (!isAttrNumberType && isValueNumberType && cellHasValue) { displayValue = (cellValue as number).toFixed(hasPrecision ? precisions[attrTitle] : 2); } else { displayValue = defaultValue;