Skip to content

Commit cc6a193

Browse files
CedricJeanOwnmarcmomgpu
authored
feat: Feature cognito s3 stagiaire (#103)
* adding aws cognito and s3 support * remove duplicate import cat and move import s3 * navigate/display S3 bucket * version ? * refetch S3 on user change * table * merge * ignore aws config * ran prettier * s3 upload * radio button onselected working * sub data table * import issue resolve * Récupération des URLs des fichiers désirés * commentaire de la tentative d'ajout des samples * Ajout des samples fonctionnel * suppression de console log * add default case and delete useless function * Transfert des images sur le serv AWS (Imparfait) * Upload des fichiers fonctionnels * Création du dossier du projet séparément * Récupéretion des annotations * Les annotations s'affichent sur transfert * video et videoannotation upload * Vérif de l'extension * Deux fois styled component * Set interface type lors d'un fetch S3 * Résolution du bug de l'upload de vidéo * Vérif des annotations * élimine les console log oubliés * Ménage + Function Recognize extension * ménage * ménage * ménage * ménage + Sauvegarde des dernières modifications correctement * fix undefined + debut gestion fileName * Vérif undefined * run prettier * nom automatiquement affiché * run Prettier * Élimination d'un effet de bord * attend le changement du fichier pour faire le second * modif pour intégration des changements provenant du fork originel * Vérif si doit updater AWS (Début) * Vérif si doit updater AWS (Suite 1) * run prettier * Fin Vérif * Prettier * Élement graphique + 1 arg de moins sur changeFile * traitement des annotations + centralisation de Storage.list * Prettier * Choix du type de fichier à télécharger * dernière date de modification * prettier * disable fichier non autorisé selon le type de projet * prettier * Disable button selon le type de fichier dans le taskData * prettier * ménage * prettier * Sauvegarde dans la cache du nav de la configImport * prettier * isoler fileHasChange * prettier * ménage * Vérif non complète * Fix config * vérif configImport * ménage * Donner un nouveau nom aux images ayant le même * Écriture du nouveau nom dans S3 * prettier * Vérif pour ne pas sauvegarder un fichier de type non testé * prettier * fix bug annotation absente * l'avant dernier conflits (non fonctionnel) * Fin merge + ménage * prettier * modification interface et possibilité de prendre juste les samples * prettier * sample with the same image * gestion des images de source différentes avec le même nom * prettier * remove yarn lock * remove json file * comment in english * isoler updateAWSStorage * prettier * Isoler S3Icon * prettier * clean update-aws-storage * prettier * console log * Isoler give-sample-name * prettier * isoler get sampleNameByURL * prettier * ménage * prettier Co-authored-by: unknown <[email protected]> Co-authored-by: marc2333 <[email protected]>
1 parent 1d9c200 commit cc6a193

File tree

36 files changed

+1912
-59
lines changed

36 files changed

+1912
-59
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,8 @@ desktop/node_modules
2929

3030
/lib
3131

32+
src/components/LocalStorageApp/myAWSconfig.js
33+
package-lock.json
34+
src/components/LocalStorageApp/myAWSconfig.js
3235
.env
3336
.cache

cypress/fixtures/example.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"name": "Using fixtures to represent data",
33
"email": "[email protected]",
44
"body": "Fixtures are a great way to mock data for responses to routes"
5-
}
5+
}

cypress/support/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// ***********************************************************
1515

1616
// Import commands.js using ES2015 syntax:
17-
import './commands'
17+
import "./commands"
1818

1919
// Alternatively you can use CommonJS syntax:
2020
// require('./commands')

desktop/main.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const menuTemplate = require("./menu-template")
55
const { format: formatUrl } = require("url")
66

77
function createWindow() {
8-
console.log("Creating window...")
98
// Create the browser window.
109
const mainWindow = new BrowserWindow({
1110
width: 1200,

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"@semantic-release/git": "^9.0.0",
7575
"@sentry/browser": "^5.15.4",
7676
"any-shell-escape": "^0.1.1",
77+
"aws-amplify": "^3.0.6",
7778
"axios": "^0.19.2",
7879
"bent": "^7.1.0",
7980
"brace": "^0.11.1",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// @flow
2+
import React from "react"
3+
4+
import SvgIcon from "@material-ui/core/SvgIcon"
5+
6+
const CognitoIcon = (props) => {
7+
return (
8+
<SvgIcon {...props} viewBox="0 0 75 75">
9+
<g id="Reference">
10+
<rect
11+
id="Red_Light_BG"
12+
data-name="Red Light BG"
13+
style={{ fill: "#d6242d" }}
14+
width="75"
15+
height="75"
16+
/>
17+
<g id="Product_Icon" data-name="Product Icon">
18+
<path
19+
style={{ fill: "#fff" }}
20+
d="M55,15H16.46a3.92,3.92,0,0,0-3.71,4.1v24.8A3.92,3.92,0,0,0,16.46,48H37.75V46H16.46a2,2,0,0,1-1.71-2.1V27h18V42a1,1,0,0,0,1,1h8V41H35.2V40.7a7.74,7.74,0,0,1,5.53-7.43,5.91,5.91,0,0,0,4.92,0,7.82,7.82,0,0,1,4.42,3.42l1.7-1v0a9.8,9.8,0,0,0-4.34-3.82,5.4,5.4,0,0,0,1.27-3.48,5.5,5.5,0,0,0-11,0A5.42,5.42,0,0,0,39,31.8a9.67,9.67,0,0,0-4.22,3.62V22h17v13.7h0V36h2V27h3V37h2l0-17.9A3.92,3.92,0,0,0,55,15ZM43.2,24.87a3.48,3.48,0,0,1,3.5,3.46,3.43,3.43,0,0,1-1.81,3,3.57,3.57,0,0,1-3.39,0,3.44,3.44,0,0,1-1.8-3A3.48,3.48,0,0,1,43.2,24.87ZM53.75,25V21a1,1,0,0,0-1-1h-19a1,1,0,0,0-1,1v4h-18v-5.9A2,2,0,0,1,16.46,17H55a2,2,0,0,1,1.73,2.1V25Z"
21+
/>
22+
<rect
23+
style={{ fill: "#fff" }}
24+
x="16.77"
25+
y="31.95"
26+
width="10.98"
27+
height="2"
28+
/>
29+
<rect
30+
style={{ fill: "#fff" }}
31+
x="16.77"
32+
y="36.95"
33+
width="6.98"
34+
height="2"
35+
/>
36+
<rect
37+
style={{ fill: "#fff" }}
38+
x="25.77"
39+
y="36.95"
40+
width="2.98"
41+
height="2"
42+
/>
43+
<path style={{ fill: "#fff" }} d="M51.78,35.65h0v0Z" />
44+
<path
45+
style={{ fill: "#fff" }}
46+
d="M52.14,60.05a10.11,10.11,0,1,1,1.22-20.14h0a10.12,10.12,0,0,1,6.46,16.61,10.47,10.47,0,0,1-3.37,2.57A10.19,10.19,0,0,1,52.14,60.05Zm0-18.22a8,8,0,0,0-3.69.9,8.11,8.11,0,0,0,7.16,14.55,8.2,8.2,0,0,0,2.71-2.07,8.11,8.11,0,0,0-5.19-13.32h0A8.22,8.22,0,0,0,52.12,41.83Z"
47+
/>
48+
<path
49+
style={{ fill: "#fff" }}
50+
d="M50.55,54.2h0a1,1,0,0,1-.71-.29l-3.23-3.23L48,49.27l2.52,2.52,5.7-5.71,1.42,1.42-6.42,6.41A1,1,0,0,1,50.55,54.2Z"
51+
/>
52+
<path style={{ fill: "#fff" }} d="M51.78,35.65h0v0Z" />
53+
</g>
54+
</g>
55+
</SvgIcon>
56+
)
57+
}
58+
59+
export default [
60+
{
61+
name: "AWS - Cognito",
62+
provider: "AWS",
63+
Icon: CognitoIcon,
64+
oha: {
65+
interface: {},
66+
taskData: [],
67+
},
68+
},
69+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// @flow
2+
3+
import React, { useState } from "react"
4+
import Button from "@material-ui/core/Button"
5+
import Dialog from "@material-ui/core/Dialog"
6+
import DialogTitle from "@material-ui/core/DialogTitle"
7+
import DialogContent from "@material-ui/core/DialogContent"
8+
import DialogActions from "@material-ui/core/DialogActions"
9+
import { makeStyles } from "@material-ui/core/styles"
10+
import authTemplates from "./authTemplates"
11+
import { grey } from "@material-ui/core/colors"
12+
import SimpleDialog from "../SimpleDialog"
13+
import isEmpty from "../../utils/isEmpty"
14+
import Survey from "material-survey/components/Survey"
15+
import ErrorToasts from "../ErrorToasts"
16+
import useErrors from "../../utils/use-errors.js"
17+
import Amplify, { Auth } from "aws-amplify"
18+
19+
const useStyles = makeStyles({
20+
bigButton: {
21+
padding: 10,
22+
width: 150,
23+
height: 120,
24+
border: "1px solid #ccc",
25+
margin: 10,
26+
},
27+
bigIcon: {
28+
width: 48,
29+
height: 48,
30+
},
31+
cognitoIcon: {
32+
width: 48,
33+
height: 48,
34+
},
35+
})
36+
37+
const forms = {
38+
AWS: {
39+
questions: [
40+
{
41+
name: "identityPoolId",
42+
title: "Amazon Cognito Identity Pool ID",
43+
placeholder: "XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab",
44+
type: "text",
45+
isRequired: true,
46+
},
47+
{
48+
name: "region",
49+
title: "AWS Region",
50+
placeholder: "XX-XXXX-X",
51+
type: "text",
52+
isRequired: true,
53+
},
54+
{
55+
name: "userPoolId",
56+
title: "Amazon Cognito User Pool ID",
57+
placeholder: "XX-XXXX-X_12ab34cd9",
58+
type: "text",
59+
isRequired: true,
60+
},
61+
{
62+
name: "userPoolWebClientId",
63+
title: "Amazon Cognito Web Client ID",
64+
placeholder: "26-char alphanumeric string",
65+
type: "text",
66+
isRequired: true,
67+
},
68+
],
69+
},
70+
}
71+
72+
export default ({ open, onClose, onSelect, onFinish, onAuthConfigured }) => {
73+
const c = useStyles()
74+
const [authProvider, setAuthProvider] = useState(null)
75+
const [dialogTitle, setDialogTitle] = useState("Add Authentification")
76+
const [errors, addError] = useErrors()
77+
78+
const validateAuthProvider = (answers) => {
79+
if (answers.provider === "AWS") {
80+
const config = {
81+
Auth: {
82+
identityPoolId: answers.identityPoolId,
83+
region: answers.region,
84+
userPoolId: answers.userPoolId,
85+
userPoolWebClientId: answers.userPoolWebClientId,
86+
mandatorySignIn: true,
87+
authenticationFlowType: "USER_PASSWORD_AUTH",
88+
},
89+
}
90+
try {
91+
Amplify.configure(config)
92+
Auth.currentAuthenticatedUser()
93+
.then((user) => {
94+
onAuthConfigured(config)
95+
onClose()
96+
})
97+
.catch((err) => {
98+
onAuthConfigured(config)
99+
onClose()
100+
})
101+
} catch (err) {
102+
addError("Invalid Cognito config")
103+
}
104+
}
105+
}
106+
107+
return (
108+
<>
109+
<SimpleDialog
110+
title={dialogTitle}
111+
open={open}
112+
onClose={() => {
113+
onClose()
114+
}}
115+
onFinish={onFinish}
116+
>
117+
{isEmpty(authProvider) &&
118+
authTemplates.map((template) => (
119+
<Button
120+
onClick={() => {
121+
setAuthProvider(template.provider)
122+
setDialogTitle(`Add Authentification for ${template.name}`)
123+
}}
124+
className={c.bigButton}
125+
>
126+
<div>
127+
<div>{template.name}</div>
128+
<div>
129+
<template.Icon className={c.cognitoIcon} />
130+
</div>
131+
</div>
132+
</Button>
133+
))}
134+
135+
{!isEmpty(authProvider) && forms[authProvider] && (
136+
<Survey
137+
variant="flat"
138+
form={forms[authProvider]}
139+
onFinish={(answers) => {
140+
answers["provider"] = authProvider
141+
validateAuthProvider(answers)
142+
}}
143+
/>
144+
)}
145+
<ErrorToasts errors={errors} />
146+
</SimpleDialog>
147+
</>
148+
)
149+
}

src/components/Composite/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export const Composite = (props) => {
3333
interface: { fields },
3434
} = props
3535
const [selectedField, changeSelectedField] = useState()
36-
const [taskOutput, changeTaskOutput] = useState(props.taskOutput)
3736

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

src/components/ConfigureInterface/index.story.js

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ storiesOf("ConfigureInterface", module).add("Data Entry", () => {
1414
iface={iface}
1515
onChange={(...args) => {
1616
action("onChange")(...args)
17-
console.log(args[0])
1817
changeIFace(args[0])
1918
}}
2019
/>

src/components/DesktopApp/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ export default () => {
7979
.require("fs")
8080
.promises.writeFile(filePath, toUDTCSV(file.content))
8181
}
82-
const onOpenFileFromToolbar = (e, file) => (
83-
console.log(file), openFile(file)
84-
)
82+
const onOpenFileFromToolbar = (e, file) => openFile(file)
8583

8684
ipcRenderer.on("open-welcome-page", onOpenWelcomePage)
8785
ipcRenderer.on("new-file", onNewFile)

src/components/Header/index.js

+16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import React, { useState, createContext, useContext, useCallback } from "react"
44
import useMediaQuery from "@material-ui/core/useMediaQuery"
5+
import CollaborateButton from "../CollaborateButton"
6+
import DownloadButton from "../DownloadButton"
7+
import LoginDrawer from "../LoginDrawer"
58

69
import HeaderToolbar from "../HeaderToolbar"
710
import HeaderDrawer from "../HeaderDrawer"
@@ -22,6 +25,10 @@ export const HeaderContext = createContext({
2225
changeSessionBoxOpen: () => null,
2326
fileOpen: false,
2427
onDownload: () => null,
28+
authConfig: null,
29+
onUserChange: () => null,
30+
user: null,
31+
logoutUser: () => null,
2532
})
2633

2734
const emptyArray = []
@@ -34,6 +41,7 @@ export default ({
3441
tabs = emptyArray,
3542
}) => {
3643
const [drawerOpen, changeDrawerOpen] = useState(false)
44+
const [loginDrawerOpen, changeLoginDrawerOpen] = useState(false)
3745
let headerContext = useContext(HeaderContext)
3846
if (!headerContext.recentItems) headerContext.recentItems = []
3947

@@ -52,6 +60,7 @@ export default ({
5260
onOpenDrawer={onOpenDrawer}
5361
isSmall={isSmall}
5462
{...headerContext}
63+
changeLoginDrawerOpen={changeLoginDrawerOpen}
5564
title={title}
5665
/>
5766
<HeaderDrawer
@@ -64,6 +73,13 @@ export default ({
6473
onClickTemplate={headerContext.onClickTemplate}
6574
onOpenRecentItem={headerContext.onOpenRecentItem}
6675
/>
76+
<LoginDrawer
77+
authConfig={headerContext.authConfig}
78+
loginDrawerOpen={loginDrawerOpen}
79+
onClose={() => changeLoginDrawerOpen(false)}
80+
onUserChange={headerContext.onUserChange}
81+
logoutUser={headerContext.logoutUser}
82+
/>
6783
</>
6884
)
6985
}

src/components/HeaderDrawer/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export default ({
3131
onClickTemplate,
3232
}) => {
3333
const c = useStyles()
34-
let classTrashCan = ""
3534

3635
const onDrop = useCallback((acceptedFiles) => {
3736
onOpenFile(acceptedFiles[0])

src/components/HeaderToolbar/index.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import Toolbar from "@material-ui/core/Toolbar"
66
import Tabs from "@material-ui/core/Tabs"
77
import Tab from "@material-ui/core/Tab"
88
import { makeStyles } from "@material-ui/core/styles"
9-
import CodeIcon from "@material-ui/icons/Code"
109
import SettingsIcon from "@material-ui/icons/Settings"
1110
import StorageIcon from "@material-ui/icons/Storage"
1211
import BorderColorIcon from "@material-ui/icons/BorderColor"
@@ -15,8 +14,8 @@ import CollaborateButton from "../CollaborateButton"
1514
import DownloadButton from "../DownloadButton"
1615
import Button from "@material-ui/core/Button"
1716
import GithubIcon from "../Header/GithubIcon"
18-
import * as colors from "@material-ui/core/colors"
1917
import IconButton from "@material-ui/core/IconButton"
18+
import isEmpty from "../../utils/isEmpty"
2019
import packageJSON from "../../../package.json"
2120
import BrushButton from "../BrushButton"
2221

@@ -84,6 +83,10 @@ const HeaderToolbar = ({
8483
selectedBrush,
8584
onChangeSelectedBrush,
8685
isSmall,
86+
authConfig,
87+
user,
88+
changeLoginDrawerOpen,
89+
logoutUser,
8790
collaborateError,
8891
}) => {
8992
const c = useStyles()
@@ -132,6 +135,21 @@ const HeaderToolbar = ({
132135
))}
133136
</Tabs>
134137
)}
138+
{!isEmpty(authConfig) && isEmpty(user) && (
139+
<Button
140+
onClick={() => {
141+
changeLoginDrawerOpen(true)
142+
}}
143+
className={c.headerButton}
144+
>
145+
Login
146+
</Button>
147+
)}
148+
{!isEmpty(authConfig) && !isEmpty(user) && (
149+
<Button onClick={logoutUser} className={c.headerButton}>
150+
Logout
151+
</Button>
152+
)}
135153
{!isSmall && (
136154
<IconButton
137155
href="https://github.com/openhumanannotation/universal-data-tool"

0 commit comments

Comments
 (0)