This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputCollector.tsx
155 lines (146 loc) · 6.87 KB
/
InputCollector.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import React from "react";
import { Button, FieldPickerSynced, Icon, Input, Label, TablePickerSynced, Tooltip, useBase, useGlobalConfig, ViewPickerSynced } from "@airtable/blocks/ui"
import { GCKey, get } from "./globalConfigHelpers";
import { FieldType } from "@airtable/blocks/models";
const InputCollector = () => {
const globalConfig = useGlobalConfig();
const base = useBase()
const participantsTableId = get(globalConfig, GCKey.PARTICIPANTS_TABLE_ID, base.tables[0].id)
const participantsTable = base.getTableByIdIfExists(participantsTableId)
const dimensionsCount = parseInt(get(globalConfig, GCKey.DIMENSION_FIELD_IDS_COUNT, "2"))
const addDimension = () => {
globalConfig.setAsync(GCKey.DIMENSION_FIELD_IDS_COUNT, String(dimensionsCount + 1))
}
const removeDimension = (idx: number) => {
const newDimensions = new Array(dimensionsCount).fill(0)
.map((_, i) => get(globalConfig, `${GCKey.DIMENSION_FIELD_IDS_PREFIX}${i}`, null))
.filter((_, i) => i !== idx);
globalConfig.setAsync(GCKey.DIMENSION_FIELD_IDS_COUNT, String(newDimensions.length))
globalConfig.setPathsAsync([
{ path: [GCKey.DIMENSION_FIELD_IDS_COUNT], value: String(newDimensions.length) },
...newDimensions.map((d, i) => ({ path: [`${GCKey.DIMENSION_FIELD_IDS_PREFIX}${i}`], value: d })),
{ path: [`${GCKey.DIMENSION_FIELD_IDS_PREFIX}${newDimensions.length}`], value: null },
])
}
return (<>
<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "12px" }}>
<div>
<Label htmlFor="participants-table-picker">
Participants table
<Tooltip
content="Table containing participants"
placementX={Tooltip.placements.CENTER}
placementY={Tooltip.placements.BOTTOM}>
<Icon name="help" size={12} style={{ marginLeft: "4px" }} />
</Tooltip>
</Label>
<TablePickerSynced
id="participants-table-picker"
placeholder="Pick the participants (input) table..."
globalConfigKey={GCKey.PARTICIPANTS_TABLE_ID}
/>
</div>
<div>
<Label htmlFor="participants-view-picker">
Participants view
<Tooltip
content={"Participants in this view will be bucketed"}
placementX={Tooltip.placements.CENTER}
placementY={Tooltip.placements.BOTTOM}>
<Icon name="help" size={12} style={{ marginLeft: "4px" }} />
</Tooltip>
</Label>
<ViewPickerSynced
id="participants-view-picker"
placeholder="Pick the participants (input) view..."
table={participantsTable}
globalConfigKey={GCKey.PARTICIPANTS_VIEW_ID}
/>
</div>
<div>
<Label htmlFor="buckets-table-picker">
Buckets table
<Tooltip
content="Table containing buckets"
placementX={Tooltip.placements.CENTER}
placementY={Tooltip.placements.BOTTOM}>
<Icon name="help" size={12} style={{ marginLeft: "4px" }} />
</Tooltip>
</Label>
<TablePickerSynced
id="buckets-table-picker"
placeholder="Pick the buckets (output) table..."
globalConfigKey={GCKey.BUCKETS_TABLE_ID}
/>
</div>
<div>
<Label htmlFor="buckets-field-picker">
Participant bucket field
<Tooltip
content="Field on the participant that links to bucket"
placementX={Tooltip.placements.CENTER}
placementY={Tooltip.placements.BOTTOM}>
<Icon name="help" size={12} style={{ marginLeft: "4px" }} />
</Tooltip>
</Label>
<FieldPickerSynced
id="buckets-field-picker"
placeholder="Pick the participant bucket field..."
table={participantsTable}
allowedTypes={[FieldType.MULTIPLE_RECORD_LINKS]}
globalConfigKey={GCKey.BUCKET_FIELD_ID}
/>
</div>
<div>
<Label htmlFor="bucket-size-input">
Target bucket size
<Tooltip
content="Target number of participants per bucket"
placementX={Tooltip.placements.CENTER}
placementY={Tooltip.placements.BOTTOM}>
<Icon name="help" size={12} style={{ marginLeft: "4px" }} />
</Tooltip>
</Label>
<Input
id="bucket-size-input"
placeholder="Bucket size"
value={get(globalConfig, GCKey.BUCKET_SIZE, "50")}
type="number"
step="1"
min="1"
onChange={e => globalConfig.setAsync(GCKey.BUCKET_SIZE, e.target.value)}
/>
</div>
</div>
<div style={{ display: "flex", alignItems: "center" }}>
<h2 style={{ flex: "1" }}>
Dimensions
<Tooltip
content="The features to group participants by"
placementX={Tooltip.placements.CENTER}
placementY={Tooltip.placements.BOTTOM}>
<Icon name="help" size={12} style={{ marginLeft: "4px" }} fillColor="#757575" />
</Tooltip>
</h2>
<Button size="small" icon="plus" onClick={addDimension}>Add</Button>
</div>
<div style={{ display: "grid", gap: "4px" }}>
{new Array(dimensionsCount).fill(0).map((_, i) => (
<div key={i} style={{ display: "flex", alignItems: "center", gap: "4px" }}>
<FieldPickerSynced
placeholder="Pick a dimension field..."
table={participantsTable}
allowedTypes={[FieldType.NUMBER, FieldType.PERCENT]}
globalConfigKey={`${GCKey.DIMENSION_FIELD_IDS_PREFIX}${i}`}
/>
<Button
icon="trash"
aria-label="Remove field"
onClick={() => removeDimension(i)}
/>
</div>
))}
</div>
</>)
}
export default InputCollector;