Skip to content

Commit df7dc2c

Browse files
Merge pull request #483 from CedricProfessionnel/RefactorImport
Refactor import (Feature Aws Part)
2 parents 7db8a32 + 0a10209 commit df7dc2c

File tree

4 files changed

+54
-29
lines changed

4 files changed

+54
-29
lines changed

src/components/ImportFromCognitoS3Dialog/header-table-import.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Button, IconButton } from "@material-ui/core/"
88

99
const selectedStyle = { color: "DodgerBlue" }
1010

11-
export default ({ configImport, setConfigImport }) => {
11+
const HeaderTable = ({ configImport, setConfigImport }) => {
1212
const { t } = useTranslation()
1313
const loadAssetsOrAnnotations = () => {
1414
setConfigImport({
@@ -52,11 +52,12 @@ export default ({ configImport, setConfigImport }) => {
5252
}}
5353
>
5454
{configImport.contentDialogBoxIsSetting ? (
55-
<StorageIcon></StorageIcon>
55+
<StorageIcon id="StorageIcon" />
5656
) : (
57-
<SettingsIcon></SettingsIcon>
57+
<SettingsIcon id="SettingIcon" />
5858
)}
5959
</IconButton>
6060
</div>
6161
)
6262
}
63+
export default HeaderTable

src/components/ImportFromCognitoS3Dialog/index.js

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import HeaderTableImport from "./header-table-import"
1515
import { Radio, Grid } from "@material-ui/core/"
1616
import importConfigIsReady from "./config-import-is-ready"
1717
import WarningHeader from "./warning-header"
18-
import getSources from "./get-sources"
1918
import { useTranslation } from "react-i18next"
2019

2120
export default ({ open, onClose, onAddSamples }) => {
@@ -107,12 +106,8 @@ export default ({ open, onClose, onAddSamples }) => {
107106
dataFolder.map(async (obj, index) => {
108107
const folder = obj
109108
var isSelected = false
110-
const rowAnnotationsContent = await dm.getListSamples({
111-
projectName: obj,
112-
})
113-
const rowAssetsContent = await dm.getListAssets({
114-
projectName: obj,
115-
})
109+
const rowAnnotationsContent = await dm.getListSamples(obj)
110+
const rowAssetsContent = await dm.getListAssets(obj)
116111
if (projectToFetch && projectToFetch.folder === folder)
117112
isSelected = true
118113
return {
@@ -173,38 +168,57 @@ export default ({ open, onClose, onAddSamples }) => {
173168
)
174169
})
175170
)
176-
onAddSamples(jsons)
171+
return jsons
177172
}
178173

179174
const createJsonFromUrlAWS = async (projectName, imageName) => {
180175
var url = await dm.getAssetUrl(imageName, projectName)
181176
var json = await setUrl(url, configImport, dm)
182-
if (json) json = setIn(json, ["_id"], imageName)
183-
if (json) json = setIn(json, ["source"], projectName)
177+
if (json)
178+
json = await setIn(
179+
json,
180+
["_id"],
181+
"s" + Math.random().toString(36).slice(-8)
182+
)
183+
if (json) json = await setIn(json, ["sampleName"], imageName)
184+
if (json) json = await setIn(json, ["source"], projectName)
184185
return json
185186
}
186187

187188
const createJsonFromAnnotation = async () => {
188189
var jsons = await dm.readJSONAllSamples(projectToFetch.rowAnnotationsUrl)
189-
var sources = getSources(jsons)
190-
if (sources) {
191-
jsons = await Promise.all(
192-
jsons.map(async (json) => {
193-
if (json.source)
194-
json = await createJsonFromUrlAWS(json.source, json._id)
195-
return json
196-
})
197-
)
198-
}
199-
onAddSamples(jsons)
190+
return jsons
191+
}
192+
193+
const checkIfJsonsContainsDouble = (jsons) => {
194+
var newJsons = []
195+
var oldUrl = oldData.samples.map((json) => {
196+
var url = dm.getSampleUrl(json)
197+
if (url) return url.match("(http.*)\\?|(http.*)$")[1]
198+
return url
199+
})
200+
201+
newJsons = jsons.filter((json) => {
202+
var url = dm.getSampleUrl(json)
203+
if (url && oldUrl.includes(url.match("(http.*)\\?|(http.*)$")[1]))
204+
return false
205+
return true
206+
})
207+
208+
return newJsons
200209
}
201210

202211
const handleAddSample = async () => {
212+
if (!dm) return
213+
var jsons
203214
if (configImport.loadAssetsIsSelected) {
204-
createJsonFromAsset()
215+
jsons = await createJsonFromAsset()
205216
} else {
206-
createJsonFromAnnotation()
217+
jsons = await createJsonFromAnnotation()
207218
}
219+
jsons = await checkIfJsonsContainsDouble(jsons)
220+
221+
onAddSamples(jsons)
208222
}
209223

210224
return (

src/components/ImportFromCognitoS3Dialog/interface-setting-import.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from "react"
2+
import { useTranslation } from "react-i18next"
23
import {
34
Radio,
45
RadioGroup,
@@ -7,8 +8,7 @@ import {
78
FormLabel,
89
Grid,
910
} from "@material-ui/core/"
10-
import { useTranslation } from "react-i18next"
11-
export default ({ configImport, setConfigImport }) => {
11+
const Setting = ({ configImport, setConfigImport, tableStyle }) => {
1212
const { t } = useTranslation()
1313
return (
1414
<Grid container item xs={12} spacing={0} justify="center">
@@ -35,12 +35,14 @@ export default ({ configImport, setConfigImport }) => {
3535
control={<Radio />}
3636
label={t("keep-incoming-annotations")}
3737
checked={configImport.annotationToKeep === "incoming"}
38+
disabled={true}
3839
/>
3940
<FormControlLabel
4041
value="current"
4142
control={<Radio />}
4243
label={t("keep-current-annotations")}
4344
checked={configImport.annotationToKeep === "current"}
45+
disabled={true}
4446
/>
4547
</RadioGroup>
4648
</FormControl>
@@ -91,9 +93,17 @@ export default ({ configImport, setConfigImport }) => {
9193
disabled={configImport.typeOfFileToDisable.Text}
9294
checked={configImport.typeOfFileToLoad === "Text"}
9395
/>
96+
<FormControlLabel
97+
value="Time"
98+
control={<Radio />}
99+
label="Load time file"
100+
disabled={configImport.typeOfFileToDisable.Time}
101+
checked={configImport.typeOfFileToLoad === "Time"}
102+
/>
94103
</RadioGroup>
95104
</FormControl>
96105
)}
97106
</Grid>
98107
)
99108
}
109+
export default Setting

src/components/ImportFromCognitoS3Dialog/warning-header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react"
22
const WarningHeader = ({ configImport, projectToFetch }) => {
3-
const orangeText = { color: "orange" }
3+
const orangeText = { color: "orange", textAlign: "center" }
44
var text = ``
55
if (!configImport.isReady) text += `Warning :`
66
else return <p style={orangeText}>{text}</p>

0 commit comments

Comments
 (0)