diff --git a/portals/admin/src/main/webapp/source/src/app/components/APISettings/ApisTableContent.jsx b/portals/admin/src/main/webapp/source/src/app/components/APISettings/ApisTableContent.jsx index 73eba8d9653..002cfcc6d89 100644 --- a/portals/admin/src/main/webapp/source/src/app/components/APISettings/ApisTableContent.jsx +++ b/portals/admin/src/main/webapp/source/src/app/components/APISettings/ApisTableContent.jsx @@ -4,8 +4,11 @@ import TableCell from '@material-ui/core/TableCell'; import TableRow from '@material-ui/core/TableRow'; import ResourceNotFound from 'AppComponents/Base/Errors/ResourceNotFound'; import PropTypes from 'prop-types'; +import API from 'AppData/api'; import { makeStyles, withStyles } from '@material-ui/core/styles'; -import Tooltip from '@material-ui/core/Tooltip'; +import Alert from 'AppComponents/Shared/Alert'; +import Button from '@material-ui/core/Button'; +import TextField from '@material-ui/core/TextField'; import EditIcon from '@material-ui/icons/Edit'; import { IconButton } from '@material-ui/core'; @@ -27,6 +30,11 @@ const useStyles = makeStyles((theme) => ({ color: '#1b9ec7 !important', }, }, + button: { + marginLeft: theme.spacing(0.5), + marginRight: theme.spacing(0.5), + marginTop: theme.spacing(1), + }, appTablePaper: { '& table tr td': { paddingLeft: theme.spacing(1), @@ -69,27 +77,100 @@ const StyledTableRow = withStyles((theme) => ({ }, }))(TableRow); -const ApisTableContent = ({ apis }) => { +const ApisTableContent = ({ apis, updateApiList }) => { const [notFound, setNotFound] = useState(false); + const restApi = new API(); + const [provider, setProvider] = useState(""); + const [editableRows, setEditableRows] = useState(new Set()); + const classes = useStyles(); if (notFound) { return ; } + const handleEditClick = (apiId) => { + setEditableRows((prevRows) => { + const newRows = new Set(prevRows); + newRows.add(apiId); + return newRows; + }); + }; + + const handleCancelClick = (apiId) => { + setEditableRows((prevRows) => { + const newRows = new Set(prevRows); + newRows.delete(apiId); + return newRows; + }); + }; + + const handleSubmitClick = (apiId, apiProvider) => { + return restApi.updateApiProvider(apiId, apiProvider) + .then(() => { + return ( + Alert.success( + , + ) + ); + }) + .catch((error) => { + let validationError = 'Something went wrong when validating the user'; + const { response } = error; + // This api returns 404 when the $provider is not found. + // error codes: 901502, 901500 for user not found and scope not found + if (response?.body?.code === 901502 || response?.body?.code === 901500) { + validationError = `${provider} is not a valid User`; + } + if (response?.body?.code === 500) { + const notValidUser = 'Error while updating the provider name to ' + provider; + throw notValidUser; + } else { + const updateError = validationError; + throw updateError; + } + }) + .finally(() => { + updateApiList(); + handleCancelClick(apiId); + }); + }; + return ( {apis && apis.map((api) => ( - + {api.name} {api.version} - {api.provider} - console.log("123")}> - - + {!editableRows.has(api.id) && ( + <> + {api.provider} + handleEditClick(api.id)}> + + + + )} + {editableRows.has(api.id) && ( + <> + { setProvider(e.target.value) }} + /> + + + + )} ))} diff --git a/portals/admin/src/main/webapp/source/src/app/components/APISettings/ListApis.jsx b/portals/admin/src/main/webapp/source/src/app/components/APISettings/ListApis.jsx index 9e65862e0df..d5a0a76a022 100644 --- a/portals/admin/src/main/webapp/source/src/app/components/APISettings/ListApis.jsx +++ b/portals/admin/src/main/webapp/source/src/app/components/APISettings/ListApis.jsx @@ -236,7 +236,7 @@ export default function ListApis() { editComponentProps={{ apiList, }} - apiCall={apiCall} + updateApiList={apiCall} />