diff --git a/src/components/IOC/IOCDeployDialog.js b/src/components/IOC/IOCDeployDialog.js index 0af58f46827377f07b4e616052a4b022b5c2577f..085a2ac930e2aaa95609dbc238d0b154150012f5 100644 --- a/src/components/IOC/IOCDeployDialog.js +++ b/src/components/IOC/IOCDeployDialog.js @@ -16,6 +16,7 @@ export function IOCDeployDialog({ open, setOpen, submitCallback, init = {}}) { const [host, setHost] = useState(null); const [query, onHostKeyUp] = useTypingTimer({interval: 500}); const [tagOrCommitId, getTagOrCommitId] = useTagsAndCommitIds([]); + const [gitRepo, setGitRepo] = useState(init.git || ""); const handleClose = () => { setOpen(false); @@ -49,17 +50,19 @@ export function IOCDeployDialog({ open, setOpen, submitCallback, init = {}}) { <DialogTitle id="form-dialog-title">Deploy IOC</DialogTitle> <DialogContent> <TextField autoComplete="off" className={classes.textField} id="comment" label="Deployment comment" variant="outlined" fullWidth required/> - <TextField autoComplete="off" className={classes.textField} id="git" label="Git repository" variant="outlined" defaultValue={init.git || ""} fullWidth required/> + <TextField autoComplete="off" className={classes.textField} id="git" label="Git repository" variant="outlined" defaultValue={init.git || ""} fullWidth + onChange={(event) => setGitRepo(event.target.value)} required/> <Autocomplete className={classes.textField} autoHighlight id="version" options={tagOrCommitId} + defaultValue = { init.version || "" } onFocus={(event) => {getTagOrCommitId(gitRepo);}} getOptionLabel={(option) => {return option}} disabled={(!gitRepo) || (gitRepo.trim() === "")} - renderInput={(params) => <TextField {...params} label="Git reference" variant="outlined" defaultValue={init.version || ""} fullWidth required />} + renderInput={(params) => <TextField {...params} label="Git reference" variant="outlined" fullWidth required />} /> <Autocomplete diff --git a/src/components/IOC/IOCDialog.js b/src/components/IOC/IOCDialog.js deleted file mode 100644 index 6a2e53839a0c5fbefe7a200d7a1c055933a133b8..0000000000000000000000000000000000000000 --- a/src/components/IOC/IOCDialog.js +++ /dev/null @@ -1,113 +0,0 @@ -import React, { useEffect, useState } from "react"; -import { Button, TextField, Dialog, DialogActions, DialogContent, DialogTitle, makeStyles } from "@material-ui/core"; -import { Autocomplete } from "@material-ui/lab"; -import { useCSEntrySearch, useNamingNames, useTagsAndCommitIds } from "../../api/SwaggerApi"; -import { useTypingTimer } from "../common/SearchBoxFilter/TypingTimer"; - -const useStyles = makeStyles((theme) => ({ - textField: { - marginBottom: theme.spacing(1), - }, -})); - -export function IOCDialog({ open, setOpen, isUpdateIoc, submitCallback, title, buttonText, init = {}}) { - const classes = useStyles(); - const [hosts, getHosts] = useCSEntrySearch(); - const [host, setHost] = useState(init.host); - const [query, onHostKeyUp] = useTypingTimer({interval: 500}); - const [names, getNames] = useNamingNames(); - const [name, setName] = useState(""); - const [nameQuery, onNameKeyUp] = useTypingTimer({interval: 500}); - const [tagOrCommitId, getTagOrCommitId] = useTagsAndCommitIds([]); - const [gitRepo, setGitRepo] = useState(""); - - const handleClose = () => { - setOpen(false); - }; - - console.log({...init}); - console.log(hosts); - console.log(host); - - useEffect(() => getHosts(`fqdn:"${query}"`), [query, getHosts, getTagOrCommitId]); - - useEffect(() => getNames(nameQuery), [nameQuery, getNames, getTagOrCommitId]); - - const onSubmit = (event) => { - event.preventDefault(); - const { description: descriptionText, git: gitText, version: versionText } = event.currentTarget.elements; - const description = descriptionText.value; - const git = gitText.value; - const version = versionText.value; - console.log(host); - - if (isUpdateIoc === true) { - submitCallback({ - description: description, - owner: "dummyOwner", - sourceUrl: git, - sourceVersion: version, - hostCSEntryId: host ? parseInt(host.csEntryHost.id) : undefined}); - - } else { - submitCallback({ - description: description, - owner: "dummyOwner", - sourceUrl: git, - sourceVersion: version, - hostCSEntryId: host ? parseInt(host.csEntryHost.id) : undefined, - externalNameId: name ? parseInt(name.id) : undefined }); - } - }; - - return ( - <Dialog open={open} onClose={handleClose}> - <form onSubmit={onSubmit}> - <DialogTitle id="form-dialog-title">{title}</DialogTitle> - <DialogContent> - {isUpdateIoc === false && - <Autocomplete - className={classes.textField} - autoHighlight - id="nameAutocomplete" - options={names} - getOptionLabel={(option) => {console.log(option?.name); return option?.name}} - renderInput={(params) => <TextField {...params} label="IOC name" variant="outlined" required/>} - onChange={(event, value, reason) => setName(value)} - onInputChange={(event, value, reason) => {event && onNameKeyUp(event.nativeEvent)}} - /> - } - - <TextField autoComplete="off" className={classes.textField} id="description" label="description" variant="outlined" defaultValue={init.description || ""} fullWidth /> - <TextField autoComplete="off" className={classes.textField} id="git" label="git" variant="outlined" defaultValue={init.git || ""} fullWidth onChange={(event) => setGitRepo(event.target.value)} /> - - <Autocomplete - className={classes.textField} - autoHighlight - id="version" - options={tagOrCommitId} - onFocus={(event) => {getTagOrCommitId(gitRepo);}} - getOptionLabel={(option) => {return option}} - disabled={(!gitRepo) || (gitRepo.trim() === "")} - renderInput={(params) => <TextField {...params} label="Git reference" variant="outlined"/>} - /> - - <Autocomplete - className={classes.textField} - autoHighlight - id="host" - options={hosts} - getOptionLabel={option => {console.log(option); return option?.csEntryHost?.fqdn}} - renderInput={(params) => <TextField {...params} label="host" variant="outlined" />} - onChange={(event, value, reason) => setHost(value)} - onInputChange={(event, value, reason) => {event && onHostKeyUp(event.nativeEvent)}} - /> - </DialogContent> - <DialogActions> - <Button onClick={handleClose} color="primary">Cancel</Button> - <Button color="primary" variant="contained" type="submit">{buttonText}</Button> - </DialogActions> - </form> - </Dialog> - ); -} \ No newline at end of file