Skip to content

Commit f86d8f3

Browse files
committed
table with optional index
1 parent 1bfafbb commit f86d8f3

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

src/assets/synthetic-data.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,16 @@ def run():
213213
setResult(json.dumps(
214214
{'type': 'heading', 'data': 'Diagnostic Results:'}
215215
))
216-
setResult(json.dumps({'type': 'table', 'data': json.dumps([
217-
{
218-
'attribute': key,
219-
'ks_stat': values['ks_stat'],
220-
'p_value': values['p_value']
221-
}
222-
for key, values in results['distribution_results'].items()
223-
])}))
216+
setResult(json.dumps({'type': 'table',
217+
'showIndex' : False,
218+
'data': json.dumps([
219+
{
220+
'attribute': key,
221+
'ks_stat': values['ks_stat'],
222+
'p_value': values['p_value']
223+
}
224+
for key, values in results['distribution_results'].items()
225+
])}))
224226
225227
setResult(json.dumps(
226228
{'type': 'heading', 'data': 'Correlation difference: ' + str(results['correlation_diff']) }
@@ -229,7 +231,11 @@ def run():
229231
setResult(json.dumps(
230232
{'type': 'heading', 'data': '5. Output data'}
231233
))
232-
setResult(json.dumps({'type': 'table', 'data': synthetic_data.head().to_json(orient="records")}))
234+
setResult(json.dumps({
235+
'type': 'table',
236+
'showIndex': True,
237+
'data': synthetic_data.head().to_json(orient="records")
238+
}))
233239
234240
235241
# copy dataframe and assign NaN to all values

src/components/SimpleTable.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import { useTranslation } from 'react-i18next';
1212
export default function SimpleTable({
1313
title,
1414
data,
15+
showIndex,
1516
}: {
17+
showIndex: boolean;
1618
title?: string;
1719
data: Record<string, string | number>[];
1820
}) {
@@ -26,6 +28,7 @@ export default function SimpleTable({
2628
{title && <TableCaption>{t(title)}</TableCaption>}
2729
<TableHeader>
2830
<TableRow className="bg-aaLight">
31+
{showIndex && <TableHead></TableHead>}
2932
{Object.keys(data[0]).map(key => (
3033
<TableHead key={key} className="text-black">
3134
{key}
@@ -36,6 +39,7 @@ export default function SimpleTable({
3639
<TableBody>
3740
{data.map((row, i) => (
3841
<TableRow key={i}>
42+
{showIndex && <TableCell>{i}</TableCell>}
3943
{Object.values(row).map((value, i) => (
4044
<TableCell key={i}>{value}</TableCell>
4145
))}

src/components/componentMapper.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export default function ComponentMapper({
9090
<SimpleTable
9191
data={data.data.slice(0, 5)}
9292
title="datasetPreview"
93+
showIndex={true}
9394
/>
9495
)}
9596
</Fragment>
@@ -101,6 +102,7 @@ export default function ComponentMapper({
101102
key={index}
102103
data={JSON.parse(resultItem.data)}
103104
title={t(resultItem.title)}
105+
showIndex={resultItem.showIndex ?? false}
104106
/>
105107
);
106108

0 commit comments

Comments
 (0)