Skip to content

Commit 9be253e

Browse files
bastienhubert“Bastien
andauthored
Fix/issue 534 (#536)
* Update TableChart to use first row as titles when transposed * Fix error when column title is the same than column value * Allow the display of false values as string --------- Co-authored-by: “Bastien <“[email protected]”>
1 parent c01eb0c commit 9be253e

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ To manually run linting of all your .ts and .tsx files, run:
5050
yarn run lint
5151
```
5252

53-
To manually run linting of all your .ts and .tsx staged files, run:
53+
To manually run linting of all your .ts and .tsx staged files, run:
5454
```
5555
yarn run lint-staged
5656
```

src/chart/table/TableChart.tsx

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,19 @@ export const NeoTableChart = (props: ChartProps) => {
114114
const actionableFields = actionsRules.map((r) => r.field);
115115

116116
const columns = transposed
117-
? ['Field'].concat(records.map((r, j) => `Value${j == 0 ? '' : ` ${(j + 1).toString()}`}`)).map((key, i) => {
118-
const value = key;
117+
? [records[0].keys[0]].concat(records.map((record) => record._fields[0]?.toString() || '')).map((key, i) => {
118+
const uniqueKey = `${String(key)}_${i}`;
119119
return ApplyColumnType(
120120
{
121121
key: `col-key-${i}`,
122-
field: generateSafeColumnKey(key),
122+
field: generateSafeColumnKey(uniqueKey),
123123
headerName: generateSafeColumnKey(key),
124124
headerClassName: 'table-small-header',
125125
disableColumnSelector: true,
126126
flex: columnWidths && i < columnWidths.length ? columnWidths[i] : 1,
127127
disableClickEventBubbling: true,
128128
},
129-
value,
129+
key,
130130
actionableFields.includes(key)
131131
);
132132
})
@@ -166,15 +166,32 @@ export const NeoTableChart = (props: ChartProps) => {
166166
...columns.filter((x) => x.field.startsWith(HIDDEN_COLUMN_PREFIX)).map((x) => ({ [x.field]: false }))
167167
);
168168

169+
const getTransposedRows = (records) => {
170+
// Skip first key
171+
const rowKeys = [...records[0].keys];
172+
rowKeys.shift();
173+
174+
// Add values in rows
175+
const rowsWithValues = rowKeys.map((key, i) =>
176+
Object.assign(
177+
{ id: i, Field: key },
178+
...records.map((record, j) => ({
179+
[`${record._fields[0]}_${j + 1}`]: RenderSubValue(record._fields[i + 1]),
180+
}))
181+
)
182+
);
183+
184+
// Add field in rows
185+
const rowsWithFieldAndValues = rowsWithValues.map((row, i) => ({
186+
...row,
187+
[`${records[0].keys[0]}_${0}`]: rowKeys[i],
188+
}));
189+
190+
return rowsWithFieldAndValues;
191+
};
192+
169193
const rows = transposed
170-
? records[0].keys.map((key, i) => {
171-
return Object.assign(
172-
{ id: i, Field: key },
173-
...records.map((r, j) => ({
174-
[`Value${j == 0 ? '' : ` ${(j + 1).toString()}`}`]: RenderSubValue(r._fields[i]),
175-
}))
176-
);
177-
})
194+
? getTransposedRows(records)
178195
: records.map((record, rownumber) => {
179196
return Object.assign(
180197
{ id: rownumber },

src/report/ReportRecordProcessing.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ function RenderArray(value) {
214214
}
215215

216216
function RenderString(value) {
217-
const str = value ? value.toString() : '';
217+
const str = value?.toString() || '';
218218
if (str.startsWith('http') || str.startsWith('https')) {
219219
return (
220220
<TextLink externalLink target='_blank' href={str}>
@@ -331,6 +331,10 @@ export const rendererForType: any = {
331331
type: 'string',
332332
renderValue: (c) => RenderString(c.value),
333333
},
334+
boolean: {
335+
type: 'string',
336+
renderValue: (c) => RenderString(c.value),
337+
},
334338
};
335339

336340
export function getRendererForValue(value) {

0 commit comments

Comments
 (0)