Skip to content

Commit 4e989b7

Browse files
committed
Add export button support to ComponentMapper and update BiasDetection component
1 parent 2e79a2c commit 4e989b7

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

src/assets/bias-detection-python-code.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,10 @@ def run():
647647
'key': 'biasAnalysis.conclusionDescriptionHigherAverage' if p_val < 0.05 else 'biasAnalysis.conclusionNoSignificance'
648648
}))
649649
650+
setResult(json.dumps({
651+
'type': 'export-button',
652+
}))
653+
650654
651655
setResult(json.dumps({
652656
'type': 'heading',

src/components/componentMapper.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import TextValueSelect from './composed-components/TextValueSelect';
1414
import { createArrayFromPythonDictionary } from './createArrayFromPythonDictionary';
1515
import ClusterCategoriesDistributionAccordeonContent from './composed-components/ClusterCategoriesDistributionAccordeonContent';
1616
import ClusterNumericalVariableDistributionAccordeonContent from './composed-components/ClusterNumericalVariableDistributionAccordeonContent';
17+
import { ReactNode } from 'react';
1718

1819
interface Comparison {
1920
key: string;
@@ -23,9 +24,11 @@ interface Comparison {
2324
export default function ComponentMapper({
2425
items,
2526
data,
27+
exportButton,
2628
}: {
2729
items: string[];
2830
data: CSVData;
31+
exportButton?: ReactNode;
2932
}) {
3033
const { t } = useTranslation();
3134
const components = items
@@ -34,6 +37,14 @@ export default function ComponentMapper({
3437
const resultItem = JSON.parse(r);
3538

3639
switch (resultItem.type) {
40+
case 'export-button': {
41+
if (exportButton) {
42+
return (
43+
<Fragment key={index}>{exportButton}</Fragment>
44+
);
45+
}
46+
return null;
47+
}
3748
case 'data-set-preview':
3849
return (
3950
<Fragment key={index}>

src/components/composed-components/ClusterCategoriesDistributionAccordeonContent.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from 'react';
1+
import { Fragment, useEffect, useState } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import ErrorBoundary from '../ErrorBoundary';
44
import FilterSelect from '../ui/FilterSelect';
@@ -71,7 +71,7 @@ const ClusterCategoriesDistributionAccordeonContent = ({
7171
}
7272
);
7373
return (
74-
<>
74+
<Fragment key={index}>
7575
{categorieFilter === chart.selectFilterGroup ||
7676
(!categorieFilter &&
7777
chart.selectFilterGroup === defaultCategory) ||
@@ -98,7 +98,7 @@ const ClusterCategoriesDistributionAccordeonContent = ({
9898
/>
9999
</>
100100
) : null}
101-
</>
101+
</Fragment>
102102
);
103103
})}
104104
</ErrorBoundary>

src/routes/BiasDetection.tsx

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,21 @@ export default function BiasDetection() {
156156
loading && 'overflow-hidden'
157157
)}
158158
>
159-
{initialised && data.data.length > 0 && result.length > 0 && (
160-
<div className="ml-auto flex flex-row gap-2 hideonprint">
161-
<ExportButton
162-
buttonAlign={'right'}
163-
clusterInfo={clusterInfo}
164-
reactToPrintFn={reactToPrintFn}
165-
data={data}
166-
/>
167-
</div>
168-
)}
169-
170159
{result.length > 0 ? (
171-
<ComponentMapper items={result} data={data} />
160+
<ComponentMapper
161+
items={result}
162+
data={data}
163+
exportButton={
164+
<div className="flex flex-row gap-2 hideonprint justify-start">
165+
<ExportButton
166+
buttonAlign={'left'}
167+
clusterInfo={clusterInfo}
168+
reactToPrintFn={reactToPrintFn}
169+
data={data}
170+
/>
171+
</div>
172+
}
173+
/>
172174
) : loading ? (
173175
<LoadingState
174176
loadingMessageKey={loadingMessage}
@@ -185,17 +187,6 @@ export default function BiasDetection() {
185187
<div className="flex-1" />
186188
</>
187189
)}
188-
189-
{initialised && data.data.length > 0 && result.length > 0 && (
190-
<div className="flex flex-row gap-2 hideonprint">
191-
<ExportButton
192-
buttonAlign={'center'}
193-
clusterInfo={clusterInfo}
194-
reactToPrintFn={reactToPrintFn}
195-
data={data}
196-
/>
197-
</div>
198-
)}
199190
</div>
200191
</main>
201192
);

0 commit comments

Comments
 (0)