Skip to content

Commit e03d8cc

Browse files
committed
fix(InfoViewer): accept default value formatter
1 parent d11cd22 commit e03d8cc

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/components/InfoViewer/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ function formatValue<Shape, Key extends keyof Shape>(
1414
label: Key,
1515
value: Shape[Key],
1616
formatters: ValueFormatters<Shape>,
17+
defaultFormatter?: (value: Shape[Key]) => string | undefined,
1718
) {
18-
const formatter = formatters[label];
19+
const formatter = formatters[label] || defaultFormatter;
1920
const formattedValue = formatter ? formatter(value) : value;
2021

2122
return String(formattedValue ?? '');
@@ -24,14 +25,16 @@ function formatValue<Shape, Key extends keyof Shape>(
2425
interface CreateInfoFormatterOptions<Shape> {
2526
values?: ValueFormatters<Shape>,
2627
labels?: LabelMap<Shape>,
28+
defaultValueFormatter?: (value: Shape[keyof Shape]) => string | undefined,
2729
}
2830

2931
export function createInfoFormatter<Shape extends Record<string, any>>({
3032
values: valueFormatters,
3133
labels: labelMap,
34+
defaultValueFormatter,
3235
}: CreateInfoFormatterOptions<Shape>) {
3336
return <Key extends keyof Shape>(label: Key, value: Shape[Key]) => ({
3437
label: formatLabel(label, labelMap || {}),
35-
value: formatValue(label, value, valueFormatters || {}),
38+
value: formatValue(label, value, valueFormatters || {}, defaultValueFormatter),
3639
});
3740
}

0 commit comments

Comments
 (0)