Skip to content

Commit b1cca7a

Browse files
Copilothotlong
andcommitted
refactor: address code review feedback - move imports, extract regex constant
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 8d41a4b commit b1cca7a

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

packages/fields/src/__tests__/cell-renderers.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
TextCellRenderer,
1717
DateCellRenderer,
1818
BooleanCellRenderer,
19+
PercentCellRenderer,
20+
humanizeLabel,
1921
formatDate,
2022
formatRelativeDate,
2123
} from '../index';
@@ -738,7 +740,6 @@ describe('UserCellRenderer', () => {
738740
// =========================================================================
739741
// 9. humanizeLabel
740742
// =========================================================================
741-
import { humanizeLabel, PercentCellRenderer } from '../index';
742743

743744
describe('humanizeLabel', () => {
744745
it('should convert snake_case to Title Case', () => {

packages/fields/src/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ export function CurrencyCellRenderer({ value, field }: CellRendererProps): React
223223
return <span className="tabular-nums font-medium whitespace-nowrap">{formatted}</span>;
224224
}
225225

226+
// Fields that store percentage values as whole numbers (0-100) rather than fractions (0-1)
227+
const WHOLE_PERCENT_FIELD_PATTERN = /progress|completion/;
228+
226229
/**
227230
* Percent field cell renderer with mini progress bar
228231
*/
@@ -234,7 +237,7 @@ export function PercentCellRenderer({ value, field }: CellRendererProps): React.
234237
const numValue = Number(value);
235238
// Use field name to disambiguate 0-1 fraction vs 0-100 whole number:
236239
// Fields like "progress" or "completion" store values as 0-100, not 0-1
237-
const isWholePercentField = /progress|completion/.test(field?.name?.toLowerCase() || '');
240+
const isWholePercentField = WHOLE_PERCENT_FIELD_PATTERN.test(field?.name?.toLowerCase() || '');
238241
const barValue = isWholePercentField
239242
? numValue
240243
: (numValue > -1 && numValue < 1) ? numValue * 100 : numValue;

0 commit comments

Comments
 (0)