Skip to content

Commit 4c83655

Browse files
authored
fix: Samples-Style Refactor, Minor Fixes and Refactoring (#125)
* extra vanilla test * added udt-format dep * interfaces refactored to samples-style * completed refactor, likely broke s3 * remove credentialed file, import invalid file * partially fixes #120 scaling issue * fix errors loading aws config, fix toy dataset import * attempted to refactor s3 dialog, not sure what is supposed to be done in these lines * fix prettier * rename image classification test to segementation. fix for various refactoring errors
1 parent fa1e98e commit 4c83655

File tree

61 files changed

+4794
-5227
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+4794
-5227
lines changed

package-lock.json

+4,303-4,622
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
"seed-random": "^2.2.0",
102102
"seedrandom": "^3.0.5",
103103
"styled-components": "^5.0.0",
104+
"udt-format": "0.0.1",
104105
"use-event-callback": "^0.1.0",
105106
"wavesurfer.js": "^3.3.3",
106107
"ytdl-core": "^2.0.1"

src/components/AddAuthFromTemplateDialog/authTemplates.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default [
6363
Icon: CognitoIcon,
6464
oha: {
6565
interface: {},
66-
taskData: [],
66+
samples: [],
6767
},
6868
},
6969
]

src/components/AddAuthFromTemplateDialog/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export default ({ open, onClose, onSelect, onFinish, onAuthConfigured }) => {
137137
{isEmpty(authProvider) &&
138138
authTemplates.map((template) => (
139139
<Button
140+
key={template.name}
140141
onClick={() => {
141142
setAuthProvider(template.provider)
142143
setDialogTitle(`Add Authentification for ${template.name}`)

src/components/AudioTranscription/index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ import NLPAnnotator from "react-nlp-annotate/components/NLPAnnotator"
88
export default (props) => {
99
const [currentSampleIndex, changeCurrentSampleIndex] = useState(0)
1010

11+
const sample = props.samples[currentSampleIndex]
12+
1113
return (
1214
<SampleContainer
1315
{...props.containerProps}
1416
currentSampleIndex={currentSampleIndex}
15-
totalSamples={props.taskData.length}
16-
taskOutput={props.taskOutput}
17+
totalSamples={props.samples.length}
18+
taskOutput={props.samples.map((s) => s.annotation)}
1719
description={
18-
getTaskDescription(props.taskData[currentSampleIndex]) ||
20+
getTaskDescription(props.samples[currentSampleIndex]) ||
1921
props.interface.description
2022
}
2123
onChangeSample={(sampleIndex) => changeCurrentSampleIndex(sampleIndex)}
2224
>
2325
<NLPAnnotator
2426
key={(props.sampleIndex || 0) + currentSampleIndex}
2527
type="transcribe"
26-
audio={props.taskData[currentSampleIndex].audioUrl}
28+
audio={sample.audioUrl}
2729
phraseBank={props.phraseBank}
28-
initialTranscriptionText={
29-
(props.taskOutput || [])[currentSampleIndex] || ""
30-
}
30+
initialTranscriptionText={sample.annotation || ""}
3131
onFinish={(result) => {
3232
props.onSaveTaskOutputItem(currentSampleIndex, result)
3333
if (props.containerProps.onExit)

src/components/AudioTranscription/index.story.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ storiesOf("AudioTranscription", module).add("Basic", () => (
1414
type: "audio_transcription",
1515
description: "This is an **audio transcription** description.",
1616
}}
17-
taskData={[
17+
samples={[
1818
{
1919
audioUrl: "https://html5tutorial.info/media/vincent.mp3",
20+
annotation: "starry starry night",
2021
},
2122
]}
22-
taskOutput={["starry starry night"]}
2323
/>
2424
))

src/components/Composite/index.js

+12-19
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ export const Composite = (props) => {
3636

3737
if (!fields) throw new Error("No fields defined. Try adding a field in Setup")
3838

39+
const sample = props.samples[currentSampleIndex]
40+
3941
if (selectedField) {
4042
return (
4143
<UniversalDataViewer
4244
oha={{
4345
interface: selectedField.interface,
44-
taskOutput: [
45-
props.taskOutput
46-
? (props.taskOutput[currentSampleIndex] || {})[
47-
selectedField.fieldName
48-
]
49-
: null,
46+
samples: [
47+
{
48+
...sample,
49+
annotation: (sample.annotation || {})[selectedField.fieldName],
50+
},
5051
],
51-
taskData: [props.taskData[currentSampleIndex]],
5252
}}
5353
onSaveTaskOutputItem={(indexZero, output) => {
5454
props.onSaveTaskOutputItem(currentSampleIndex, {
55-
...(props.taskOutput ? props.taskOutput[currentSampleIndex] : {}),
55+
...sample.annotation,
5656
[selectedField.fieldName]: output,
5757
})
5858
changeSelectedField(null)
@@ -65,12 +65,9 @@ export const Composite = (props) => {
6565
<SampleContainer
6666
{...props.containerProps}
6767
currentSampleIndex={currentSampleIndex}
68-
totalSamples={props.taskData.length}
69-
taskOutput={props.taskOutput}
70-
description={
71-
getTaskDescription(props.taskData[currentSampleIndex]) ||
72-
props.interface.description
73-
}
68+
totalSamples={props.samples.length}
69+
taskOutput={props.samples.map((s) => s.annotation)}
70+
description={getTaskDescription(sample) || props.interface.description}
7471
onChangeSample={(sampleIndex) => changeCurrentSampleIndex(sampleIndex)}
7572
>
7673
<Title>Fields</Title>
@@ -90,11 +87,7 @@ export const Composite = (props) => {
9087
{field.fieldName}
9188
<Box flexGrow={1} />
9289
<Checkbox
93-
checked={Boolean(
94-
(props.taskOutput
95-
? props.taskOutput[currentSampleIndex] || {}
96-
: {})[field.fieldName]
97-
)}
90+
checked={Boolean((sample.annotation || {})[field.fieldName])}
9891
/>
9992
<KeyboardArrowRightIcon />
10093
</StyledButton>

src/components/ConfigureInterface/index.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import React, { useState, useEffect } from "react"
44
import { styled } from "@material-ui/core/styles"
5-
import templates from "../StartingPage/templates"
5+
import templates, { templateMap } from "../StartingPage/templates"
66
import Button from "@material-ui/core/Button"
77
import Box from "@material-ui/core/Box"
88
import * as colors from "@material-ui/core/colors"
@@ -132,7 +132,7 @@ export const ConfigureInterface = ({
132132
}}
133133
/>
134134
<Grid container>
135-
<Grid item hidden={isNested} xs={12} md={6}>
135+
<Grid item hidden={isNested} xs={12} lg={6}>
136136
<Heading>Preview</Heading>
137137
<PreviewContainer>
138138
<PreviewContent style={{ opacity: previewLoading ? 0.5 : 1 }}>
@@ -144,21 +144,14 @@ export const ConfigureInterface = ({
144144
onSaveTaskOutputItem={noop}
145145
oha={{
146146
interface: iface,
147-
taskData: [
148-
(
149-
templates.find(
150-
(template) =>
151-
template.oha.interface.type === iface.type
152-
) || { oha: { taskData: [{}] } }
153-
).oha.taskData[0],
154-
],
147+
samples: [templateMap[iface.type].oha.samples[0]],
155148
}}
156149
/>
157150
</LabelErrorBoundary>
158151
</PreviewContent>
159152
</PreviewContainer>
160153
</Grid>
161-
<Grid item xs={12} md={isNested ? 12 : 6}>
154+
<Grid item xs={12} lg={isNested ? 12 : 6}>
162155
<Heading>Options</Heading>
163156
<Box paddingTop={2} />
164157
{!iface.type && <NoOptions>Select a Type</NoOptions>}

src/components/DataEntry/index.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import SampleContainer from "../SampleContainer"
66
export const DataEntry = (props) => {
77
const [currentSampleIndex, changeCurrentSampleIndex] = useState(0)
88
const form =
9-
props.taskData[currentSampleIndex].surveyjs || props.interface.surveyjs
9+
props.samples[currentSampleIndex].surveyjs || props.interface.surveyjs
1010
if (!form)
1111
throw new Error("No survey/form created. Try adding some inputs in Setup")
1212
return (
1313
<SampleContainer
1414
{...props.containerProps}
1515
currentSampleIndex={currentSampleIndex}
16-
totalSamples={props.taskData.length}
17-
taskOutput={props.taskOutput}
16+
totalSamples={props.samples.length}
17+
taskOutput={props.samples.map((s) => s.annotation)}
1818
description={
19-
getTaskDescription(props.taskData[currentSampleIndex]) ||
19+
getTaskDescription(props.samples[currentSampleIndex]) ||
2020
props.interface.description
2121
}
2222
onChangeSample={(sampleIndex) => changeCurrentSampleIndex(sampleIndex)}
@@ -26,9 +26,7 @@ export const DataEntry = (props) => {
2626
variant="flat"
2727
form={form}
2828
defaultAnswers={
29-
props.taskOutput && props.taskOutput[currentSampleIndex]
30-
? props.taskOutput[currentSampleIndex]
31-
: undefined
29+
props.samples[currentSampleIndex].annotation || undefined
3230
}
3331
completeText="Save & Next"
3432
onFinish={(answers) => {

src/components/DataEntry/index.story.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ storiesOf("DataEntry", module)
4848
],
4949
},
5050
}}
51-
taskData={[
51+
samples={[
5252
{
5353
imageUrl:
5454
"https://s3.amazonaws.com/asset.workaround.online/example-jobs/sticky-notes/image1.jpg",
@@ -104,10 +104,11 @@ storiesOf("DataEntry", module)
104104
],
105105
},
106106
}}
107-
taskData={[
107+
samples={[
108108
{
109109
imageUrl:
110110
"https://s3.amazonaws.com/asset.workaround.online/example-jobs/sticky-notes/image1.jpg",
111+
annotation: { group_letter: "A", feedback: "some feedback here" },
111112
},
112113
{
113114
imageUrl:
@@ -118,7 +119,6 @@ storiesOf("DataEntry", module)
118119
"https://s3.amazonaws.com/asset.workaround.online/example-jobs/sticky-notes/image3.jpg",
119120
},
120121
]}
121-
taskOutput={[{ group_letter: "A", feedback: "some feedback here" }]}
122122
/>
123123
))
124124
.add("PDF Url", () => (
@@ -142,11 +142,11 @@ storiesOf("DataEntry", module)
142142
],
143143
},
144144
}}
145-
taskData={[
145+
samples={[
146146
{
147147
pdfUrl: "https://arxiv.org/pdf/1608.04481v1.pdf",
148+
annotation: { group_letter: "A", feedback: "some feedback here" },
148149
},
149150
]}
150-
taskOutput={[{ group_letter: "A", feedback: "some feedback here" }]}
151151
/>
152152
))

src/components/DesktopApp/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export default () => {
112112
})
113113
)
114114

115-
const collaborateError = (((file || {}).content || {}).taskData || []).some(
115+
const collaborateError = (((file || {}).content || {}).samples || []).some(
116116
(sample) =>
117117
[sample.imageUrl, sample.videoUrl, sample.pdfUrl]
118118
.filter(Boolean)

src/components/DownloadURLsDialog/index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ export default ({ open, onChangeOHA, onClose, oha }) => {
7070
return
7171
}
7272

73-
const newTaskData = [...oha.taskData]
73+
const newSamples = [...oha.samples]
7474
let errors = ""
7575

7676
// Iterate over each task datum and download the url, then convert
7777
// the path to a filesystem path
78-
for (let i = 0; i < oha.taskData.length; i++) {
79-
const td = oha.taskData[i]
78+
for (let i = 0; i < oha.samples.length; i++) {
79+
const td = oha.samples[i]
8080
let urlKey
8181
if (td.imageUrl) urlKey = "imageUrl"
8282
if (td.videoUrl) urlKey = "videoUrl"
@@ -88,17 +88,17 @@ export default ({ open, onChangeOHA, onClose, oha }) => {
8888
directoryPath,
8989
remote
9090
)
91-
newTaskData[i] = {
91+
newSamples[i] = {
9292
...td,
9393
[urlKey]: `file://${pathToFile}`,
9494
}
9595
} catch (e) {
96-
errors += `Skipping sample, error downloading taskData[${i}] (${urlToDownload}): ${e.toString()} \n`
96+
errors += `Skipping sample, error downloading samples[${i}] (${urlToDownload}): ${e.toString()} \n`
9797
}
98-
changeProgress((i / oha.taskData.length) * 100)
98+
changeProgress((i / oha.samples.length) * 100)
9999
}
100100

101-
onChangeOHA(setIn(oha, ["taskData"], newTaskData))
101+
onChangeOHA(setIn(oha, ["samples"], newSamples))
102102

103103
changeErrors(errors)
104104
changeProgress(100)

src/components/EditSampleDialog/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default ({ open, sampleIndex, sampleInput, onChange, onClose }) => {
2020
<SimpleDialog
2121
open={open}
2222
onClose={onClose}
23-
title={`taskData[${sampleIndex}]`}
23+
title={`samples[${sampleIndex}]`}
2424
>
2525
<AceEditor
2626
theme="github"

src/components/EmptySampleContainer/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import BadOHA from "../BadOHA"
66
export default () => {
77
return (
88
<BadOHA title="No Samples to Show">
9-
Make sure that <code>taskData</code> is defined and not empty.
9+
Make sure that <code>samples</code> is defined and not empty.
1010
<br />
1111
<br />
1212
Need help setting up? <a href="#">Check out this tutorial.</a>

src/components/ImageClassification/index.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ const [emptyObj, emptyArr] = [{}, []]
9898
export default ({
9999
sampleIndex: globalSampleIndex,
100100
interface: iface,
101-
taskData = emptyArr,
102-
taskOutput = emptyObj,
101+
samples = emptyArr,
103102
containerProps = emptyObj,
104103
onSaveTaskOutputItem,
105104
}) => {
@@ -126,7 +125,7 @@ export default ({
126125
})
127126
const onNext = useEventCallback((newOutput) => {
128127
onSaveTaskOutputItem(sampleIndex, newOutput || currentOutput)
129-
if (sampleIndex !== taskData.length - 1) {
128+
if (sampleIndex !== samples.length - 1) {
130129
changeSampleIndex(sampleIndex + 1)
131130
} else {
132131
if (containerProps.onExit) containerProps.onExit("go-to-next")
@@ -167,7 +166,7 @@ export default ({
167166
})
168167

169168
useEffect(() => {
170-
let newOutput = (taskOutput || [])[sampleIndex]
169+
let newOutput = samples[sampleIndex].annotation
171170
if (!newOutput) newOutput = []
172171
if (typeof newOutput === "string") newOutput = [newOutput]
173172
changeCurrentOutput(newOutput)
@@ -212,16 +211,16 @@ export default ({
212211
style={{ height: containerProps.height || "calc(100vh - 70px)" }}
213212
>
214213
<ImageContainer>
215-
<Image src={taskData[sampleIndex].imageUrl} />
214+
<Image src={samples[sampleIndex].imageUrl} />
216215
</ImageContainer>
217216
<Nav>
218217
<NavItem>
219218
<NavButton onClick={onPrev}>Prev (backspace)</NavButton>
220219
</NavItem>
221-
{taskData.length > 1 ? (
220+
{samples.length > 1 ? (
222221
<NavItem>
223222
<span>
224-
({sampleIndex + 1}/{taskData.length})
223+
({sampleIndex + 1}/{samples.length})
225224
</span>
226225
</NavItem>
227226
) : globalSampleIndex !== undefined ? (

0 commit comments

Comments
 (0)