@@ -10,6 +10,7 @@ import { Select } from "@pythnetwork/component-library/Select";
10
10
import { SingleToggleGroup } from "@pythnetwork/component-library/SingleToggleGroup";
11
11
import {
12
12
type RowConfig,
13
+ type ColumnConfig,
13
14
type SortDescriptor,
14
15
Table,
15
16
} from "@pythnetwork/component-library/Table";
@@ -37,7 +38,7 @@ import { Status as StatusComponent } from "../Status";
37
38
38
39
const SCORE_WIDTH = 32;
39
40
40
- type Props<T extends PriceComponent> = {
41
+ type Props<U extends string, T extends PriceComponent & Record<U, unknown> > = {
41
42
className?: string | undefined;
42
43
priceComponents: T[];
43
44
metricsTime?: Date | undefined;
@@ -47,6 +48,8 @@ type Props<T extends PriceComponent> = {
47
48
onPriceComponentAction: (component: T) => void;
48
49
toolbarExtra?: ReactNode;
49
50
assetClass?: string | undefined;
51
+ extraColumns?: ColumnConfig<U>[] | undefined;
52
+ nameWidth?: number | undefined;
50
53
};
51
54
52
55
type PriceComponent = {
@@ -63,11 +66,14 @@ type PriceComponent = {
63
66
nameAsString: string;
64
67
};
65
68
66
- export const PriceComponentsCard = <T extends PriceComponent>({
69
+ export const PriceComponentsCard = <
70
+ U extends string,
71
+ T extends PriceComponent & Record<U, unknown>,
72
+ >({
67
73
priceComponents,
68
74
onPriceComponentAction,
69
75
...props
70
- }: Props<T>) => (
76
+ }: Props<U, T>) => (
71
77
<Suspense fallback={<PriceComponentsCardContents isLoading {...props} />}>
72
78
<ResolvedPriceComponentsCard
73
79
priceComponents={priceComponents}
@@ -77,11 +83,14 @@ export const PriceComponentsCard = <T extends PriceComponent>({
77
83
</Suspense>
78
84
);
79
85
80
- export const ResolvedPriceComponentsCard = <T extends PriceComponent>({
86
+ export const ResolvedPriceComponentsCard = <
87
+ U extends string,
88
+ T extends PriceComponent & Record<U, unknown>,
89
+ >({
81
90
priceComponents,
82
91
onPriceComponentAction,
83
92
...props
84
- }: Props<T>) => {
93
+ }: Props<U, T>) => {
85
94
const logger = useLogger();
86
95
const collator = useCollator();
87
96
const filter = useFilter({ sensitivity: "base", usage: "search" });
@@ -174,6 +183,12 @@ export const ResolvedPriceComponentsCard = <T extends PriceComponent>({
174
183
id: component.id,
175
184
data: {
176
185
name: component.name,
186
+ ...Object.fromEntries(
187
+ props.extraColumns?.map((column) => [
188
+ column.id,
189
+ component[column.id],
190
+ ]) ?? [],
191
+ ),
177
192
...(showQuality
178
193
? {
179
194
score: component.score !== undefined && (
@@ -228,7 +243,7 @@ export const ResolvedPriceComponentsCard = <T extends PriceComponent>({
228
243
onPriceComponentAction(component);
229
244
},
230
245
})),
231
- [paginatedItems, showQuality, onPriceComponentAction],
246
+ [paginatedItems, showQuality, onPriceComponentAction, props.extraColumns ],
232
247
);
233
248
234
249
const updateStatus = useCallback(
@@ -273,15 +288,20 @@ export const ResolvedPriceComponentsCard = <T extends PriceComponent>({
273
288
);
274
289
};
275
290
276
- type PriceComponentsCardProps<T extends PriceComponent> = Pick<
277
- Props<T>,
291
+ type PriceComponentsCardProps<
292
+ U extends string,
293
+ T extends PriceComponent & Record<U, unknown>,
294
+ > = Pick<
295
+ Props<U, T>,
278
296
| "className"
279
297
| "metricsTime"
280
298
| "nameLoadingSkeleton"
281
299
| "label"
282
300
| "searchPlaceholder"
283
301
| "toolbarExtra"
284
302
| "assetClass"
303
+ | "extraColumns"
304
+ | "nameWidth"
285
305
> &
286
306
(
287
307
| { isLoading: true }
@@ -306,15 +326,20 @@ type PriceComponentsCardProps<T extends PriceComponent> = Pick<
306
326
}
307
327
);
308
328
309
- export const PriceComponentsCardContents = <T extends PriceComponent>({
329
+ export const PriceComponentsCardContents = <
330
+ U extends string,
331
+ T extends PriceComponent & Record<U, unknown>,
332
+ >({
310
333
className,
311
334
metricsTime,
312
335
nameLoadingSkeleton,
313
336
label,
314
337
searchPlaceholder,
315
338
toolbarExtra,
339
+ extraColumns,
340
+ nameWidth,
316
341
...props
317
- }: PriceComponentsCardProps<T>) => {
342
+ }: PriceComponentsCardProps<U, T>) => {
318
343
const collator = useCollator();
319
344
return (
320
345
<Card
@@ -408,7 +433,9 @@ export const PriceComponentsCardContents = <T extends PriceComponent>({
408
433
isRowHeader: true,
409
434
loadingSkeleton: nameLoadingSkeleton,
410
435
allowsSorting: true,
436
+ ...(nameWidth !== undefined && { width: nameWidth }),
411
437
},
438
+ ...(extraColumns ?? []),
412
439
...otherColumns(props),
413
440
{
414
441
id: "status",
0 commit comments