Skip to content

Commit

Permalink
Fix order of imports + var names in utility function.
Browse files Browse the repository at this point in the history
  • Loading branch information
lublagg committed Oct 2, 2024
1 parent 02ca66b commit faf8f2f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/components/nested-table-view/portrait/portrait-table-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,7 +93,7 @@ export const PortraitTableRow = observer(function PortraitViewRow(props: Portrai
<table style={paddingStyle} className={`${css.subTable} ${css[getClassName(children[0])]}`}>
<tbody className={`table-body ${css[getClassName(children[0])]}`}>
{caseObj.children.map((child, i) => {
const nextProps: PortraitViewRowProps = {
const nextProps: PortraitTableRowProps = {
...props,
caseObj: child,
index: i,
Expand All @@ -118,11 +118,11 @@ export const PortraitTableRow = observer(function PortraitViewRow(props: Portrai
renameAttribute={renameAttribute}
/>
</tr>
<PortraitViewRow {...nextProps} />
<PortraitTableRow {...nextProps} />
</React.Fragment>
);
} else {
return <PortraitViewRow key={child.id} {...nextProps} />;
return <PortraitTableRow key={child.id} {...nextProps} />;
}
})}
</tbody>
Expand Down
12 changes: 6 additions & 6 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import { IAttribute } from "../types";
export const getDisplayValue = (cellValue: string | number, attrTitle: string,
attrTypes: Record<string, string | undefined | null>, precisions: Record<string, number>) => {
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;
Expand Down

0 comments on commit faf8f2f

Please sign in to comment.