Skip to content

Commit e67f669

Browse files
committed
Record export options
1 parent e70f2cf commit e67f669

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/main/webapp/ui/src/stores/models/PersonModel.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export default class PersonModel implements Person {
151151
link.setAttribute("rel", downloadLink.rel);
152152
link.setAttribute("download", fileName);
153153
link.click(); // trigger download
154-
trackingStore.trackEvent("user:export:allTheirItems:Inventory");
154+
trackingStore.trackEvent("user:export:allTheirItems:Inventory", exportOptions);
155155
} catch (error) {
156156
uiStore.addAlert(
157157
mkAlert({

src/main/webapp/ui/src/stores/models/Search.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
doNotAwait,
77
omitNull,
88
sameKeysAndValues,
9+
mapObject,
910
} from "../../util/Util";
1011
import * as ArrayUtils from "../../util/ArrayUtils";
1112
import {
@@ -21,7 +22,10 @@ import {
2122
type GlobalId,
2223
getSavedGlobalId,
2324
} from "../definitions/BaseRecord";
24-
import { type InventoryRecord } from "../definitions/InventoryRecord";
25+
import {
26+
type InventoryRecord,
27+
type ApiRecordType,
28+
} from "../definitions/InventoryRecord";
2529
import { type AdjustableTableRowLabel } from "../definitions/Tables";
2630
import getRootStore from "../stores/RootStore";
2731
import { mkAlert } from "../contexts/Alert";
@@ -349,7 +353,8 @@ export default class Search implements SearchInterface {
349353
return this.editLoading === "batch" && !this.batchEditingRecords;
350354
}
351355

352-
get batchEditingRecordsByType(): | null
356+
get batchEditingRecordsByType():
357+
| null
353358
| {| type: "container", records: RsSet<ContainerModel> |}
354359
| {| type: "sample", records: RsSet<SampleModel> |}
355360
| {| type: "subSample", records: RsSet<SubSampleModel> |}
@@ -1168,7 +1173,16 @@ export default class Search implements SearchInterface {
11681173
link.setAttribute("rel", downloadLink.rel);
11691174
link.setAttribute("download", fileName);
11701175
link.click(); // trigger download
1171-
trackingStore.trackEvent("user:export:selection:Inventory");
1176+
trackingStore.trackEvent("user:export:selection:Inventory", {
1177+
...exportOptions,
1178+
count: {
1179+
...mapObject(
1180+
(_type: ApiRecordType, list) => list.length,
1181+
ArrayUtils.groupBy(({ type }) => type, records)
1182+
),
1183+
total: records.length,
1184+
},
1185+
});
11721186
} catch (error) {
11731187
uiStore.addAlert(
11741188
mkAlert({

src/main/webapp/ui/src/util/ArrayUtils.js

+12
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ export const partition = <T>(
108108
[[], []]
109109
);
110110

111+
/**
112+
* Group the elements of an array based on the result of the passed function.
113+
*/
114+
export const groupBy = <T, K: string>(
115+
f: (T) => K,
116+
list: $ReadOnlyArray<T>
117+
): { [K]: Array<T> } =>
118+
list.reduce((acc, element) => {
119+
const key = f(element);
120+
return { ...acc, [key]: [...(acc[key] || []), element] };
121+
}, ({}: { [K]: Array<T> }));
122+
111123
/**
112124
* Just like normal filter, but specifically just to check whether the elements
113125
* of the array are instances of the passed class. Useful where Flow would not

0 commit comments

Comments
 (0)