@adriansteffan/reactive 0.0.30 → 0.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +9 -1
- package/dist/{mod-BY9yD0Pz.js → mod-OYK5S6rI.js} +94 -88
- package/dist/mod.d.ts +5 -2
- package/dist/reactive.es.js +1 -1
- package/dist/reactive.umd.js +12 -12
- package/dist/{web-D4yetCSC.js → web-D0E0X8r4.js} +1 -1
- package/dist/{web-Crj4uOnK.js → web-GcUUyn5k.js} +1 -1
- package/package.json +1 -1
- package/src/components/upload.tsx +30 -12
package/package.json
CHANGED
|
@@ -88,22 +88,39 @@ function convertArrayOfObjectsToCSV(data: DataObject[]): string {
|
|
|
88
88
|
return [headerRow, ...dataRows].join('\n');
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
// TODO: for better cohesion move this into the components on registration
|
|
92
|
+
const defaultFlatteningFunctions = {
|
|
93
|
+
'CanvasBlock': (item: TrialData) => {
|
|
94
|
+
const responseData = item.responseData;
|
|
95
|
+
if (Array.isArray(responseData)) {
|
|
96
|
+
return responseData.map((i) => ({
|
|
97
|
+
block: item.name,
|
|
98
|
+
...i,
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const transform = ({responseData, ...obj}: any) => ({ ...obj, ...Object.entries(responseData || {}).reduce((acc, [k, v]) => ({...acc, [`data_${k}`]: v}), {}) });
|
|
106
|
+
|
|
91
107
|
function combineTrialsToCsv(
|
|
92
108
|
data: any[],
|
|
93
109
|
filename: string,
|
|
94
110
|
names: string[],
|
|
111
|
+
flatteningFunctions: Record<string, (item: any) => any[]>,
|
|
95
112
|
fun?: (obj: any) => any,
|
|
96
113
|
) {
|
|
114
|
+
|
|
97
115
|
const processedData = names
|
|
98
116
|
.flatMap((name) => {
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
return [];
|
|
117
|
+
const matchingItems = data.filter((d) => d.name === name);
|
|
118
|
+
|
|
119
|
+
return matchingItems.flatMap((item) => {
|
|
120
|
+
const flattener = item.type && flatteningFunctions[item.type];
|
|
121
|
+
|
|
122
|
+
return flattener ? flattener(item) : transform(item);
|
|
123
|
+
});
|
|
107
124
|
})
|
|
108
125
|
.map((x) => (fun ? fun(x) : x));
|
|
109
126
|
|
|
@@ -256,7 +273,7 @@ export default function Upload({
|
|
|
256
273
|
sessionID,
|
|
257
274
|
generateFiles,
|
|
258
275
|
sessionCSVBuilder,
|
|
259
|
-
|
|
276
|
+
trialCSVBuilder,
|
|
260
277
|
uploadRaw = true,
|
|
261
278
|
autoUpload = false,
|
|
262
279
|
androidFolderName,
|
|
@@ -264,7 +281,7 @@ export default function Upload({
|
|
|
264
281
|
sessionID?: string | null;
|
|
265
282
|
generateFiles: (sessionID: string, data: TrialData[], store?: Store) => FileUpload[];
|
|
266
283
|
sessionCSVBuilder: CSVBuilder;
|
|
267
|
-
|
|
284
|
+
trialCSVBuilder: {flatteners: Record<string, ((item: TrialData) => Record<string, any>[])>, builders: CSVBuilder[]};
|
|
268
285
|
uploadRaw: boolean;
|
|
269
286
|
autoUpload: boolean;
|
|
270
287
|
androidFolderName?: string;
|
|
@@ -396,13 +413,14 @@ export default function Upload({
|
|
|
396
413
|
});
|
|
397
414
|
}
|
|
398
415
|
|
|
399
|
-
if (
|
|
400
|
-
for (const builder of
|
|
416
|
+
if (trialCSVBuilder) {
|
|
417
|
+
for (const builder of trialCSVBuilder.builders) {
|
|
401
418
|
files.push(
|
|
402
419
|
combineTrialsToCsv(
|
|
403
420
|
data,
|
|
404
421
|
`${sessionIDUpload}${builder.filename}.csv`,
|
|
405
422
|
builder.trials ?? [],
|
|
423
|
+
{...defaultFlatteningFunctions, ...trialCSVBuilder.flatteners},
|
|
406
424
|
builder.fun,
|
|
407
425
|
),
|
|
408
426
|
);
|