diff --git a/src/main/webui/src/app/components/content/RemoteEdit.jsx b/src/main/webui/src/app/components/content/RemoteEdit.jsx index e959ef2..a915ac3 100644 --- a/src/main/webui/src/app/components/content/RemoteEdit.jsx +++ b/src/main/webui/src/app/components/content/RemoteEdit.jsx @@ -15,10 +15,11 @@ */ import React, {useState, useEffect} from 'react'; -import {useLocation, useNavigate, useParams} from 'react-router-dom'; +import {useLocation, useParams} from 'react-router-dom'; import {PropTypes} from 'prop-types'; import {StoreEditControlPanel as EditControlPanel} from './common/StoreControlPanels.jsx'; import {DisableTimeoutHint, DurationHint, PrefetchHint, Hint} from './common/Hints.jsx'; +import {PackageTypeSelect} from './common/PackageTypeSelect.jsx'; // import ViewJsonDebugger from './Debugger.jsx'; import {Utils} from '../../utils/AppUtils.js'; import {TimeUtils} from '../../utils/TimeUtils.js'; @@ -29,11 +30,10 @@ const init = (pkgType, storeName, setState) => { useEffect(()=>{ const fetchStore = async () =>{ // get Store data - let isError = false; const response = await jsonRest.get(getUrl); if (response.ok){ - let raw = await response.json(); - let storeView = Utils.cloneObj(raw); + const raw = await response.json(); + const storeView = Utils.cloneObj(raw); storeView.disabled = raw.disabled === undefined ? false : raw.disabled; storeView.useX509 = raw.server_certificate_pem || raw.key_certificate_pem; storeView.useProxy = raw.proxy_host && true; @@ -43,7 +43,7 @@ const init = (pkgType, storeName, setState) => { // get Store disablement data const timeoutUrl = `/api/admin/schedule/store/${storeView.packageType}/${storeView.type}/${storeView.name}/disable-timeout`; const timeoutResponse = await jsonRest.get(timeoutUrl); - let cloned = Utils.cloneObj(storeView); + const cloned = Utils.cloneObj(storeView); if (timeoutResponse.ok){ const timeout = await timeoutResponse.json(); cloned.disableExpiration = timeout.expiration; @@ -57,6 +57,7 @@ const init = (pkgType, storeName, setState) => { store: raw }); }else{ + // TODO: find another way to do error handling response.text().then(error=>setState({ message: error })); @@ -67,35 +68,42 @@ const init = (pkgType, storeName, setState) => { }, []); }; -const saveStore = store => { - const getUrl = `/api/admin/stores/${store.packageType}/remote/${store.name}`; - const postStore = async () =>{ - // get Store data - let isError = false; - const response = await jsonRest.post(getUrl, store); - if (!response.ok){ - response.text().then(error=>Utils.logMessage(error)); - } - const navigate = useNavigate(); - if(!isError && (response.status >= 200 || response.status < 300)){ - navigate(`/remote/${store.packageType}/view/${store.name}`); - } - }; - postStore(); -}; - -const handlers = { - handleSave: () => { - // TODO need to implement save logic - }, - - handleCancel: () => { - // TODO need to implement cancel logic - }, +const CertificateSection = ({store, handleValueChange}) =>
+ { + store.useAuth && +
+ + handleValueChange(e, "key_password")}/> +
+ } +
+ { + store.useAuth && +
+
+ (PEM Format) +
+ { + // 64 columns is the original PEM line-length spec + } + +
+ } +
+
+ (PEM Format) +
+ { + // 64 columns is the original PEM line-length spec + } + +
+
+
; - handleRemove: () => { - // TODO need to implement remove logic - }, +CertificateSection.propTypes = { + store: PropTypes.object.isRequired, + handleValueChange: PropTypes.func }; export default function RemoteEdit() { @@ -105,9 +113,10 @@ export default function RemoteEdit() { }); const location = useLocation(); const path = location.pathname; - let mode = path.endsWith('remote/new')? 'new':'edit'; + const mode = path.match(/.*\/new$/u)? 'new':'edit'; let [pkgType, storeName] = ["",""]; - let store = {}; + // Give a default packageType + let store = {"packageType": "maven", "type": "remote"}; if(mode === 'edit'){ const {packageType, name} = useParams(); [pkgType, storeName] = [packageType, name]; @@ -115,13 +124,6 @@ export default function RemoteEdit() { store = state.store; } - mode = state.mode; - // Utils.logMessage(mode); - let storeView = state.storeView; - // let store = state.store; - // TODO: this package types should be fetched from backend - let pkgTypes = ["maven", "generic-http", "npm"]; - const handleCheckChange = (event, field) => { if (event.target.checked) { store[field] = true; @@ -146,51 +148,11 @@ export default function RemoteEdit() { // TODO: need to implement }; - const CertificateSection = function(){ - return ( -
- { - storeView.useAuth && -
- - handleValueChange(e, "key_password")}/> -
- } -
- { - storeView.useAuth && -
-
- (PEM Format) -
- { - // 64 columns is the original PEM line-length spec - } - -
- } -
-
- (PEM Format) -
- { - // 64 columns is the original PEM line-length spec - } - -
-
-
- ); - }; - return (
- +
@@ -200,32 +162,30 @@ export default function RemoteEdit() {
{ - mode==='new'? - - - : - {storeView.packageType} + mode==='new'||mode==='edit'? + + handleValueChange(e, "packageType")} /> + : + {store.packageType} }
{ mode==='new'? - : - {storeView.name} + handleValueChange(e, "name")} />: + {store.name} }
- handleCheckChange(e, "disabled")} />{' '} + handleCheckChange(e, "disabled")} />{' '} { - storeView.disabled && store.disableExpiration && - Set to automatically re-enable at {TimeUtils.timestampToDateFormat(storeView.disableExpiration)} + store.disabled && store.disableExpiration && + Set to automatically re-enable at {TimeUtils.timestampToDateFormat(store.disableExpiration)} }
@@ -271,17 +231,17 @@ export default function RemoteEdit() {
- handleValueChange(e,"prefetch_priority")} size="5"/> + handleValueChange(e,"prefetch_priority")} size="5"/>
- handleCheckChange(e,"prefetch_rescan")} />{' '} + handleCheckChange(e,"prefetch_rescan")} />{' '}
- handleRadioChange(e, "prefetch_listing_type")} value="html"/> html{' '} - handleRadioChange(e, "prefetch_listing_type")} value="koji"/> koji + handleRadioChange(e, "prefetch_listing_type")} value="html"/> html{' '} + handleRadioChange(e, "prefetch_listing_type")} value="koji"/> koji
@@ -289,17 +249,17 @@ export default function RemoteEdit() {
Description
- +
Capabilities
- handleCheckChange(e, "allow_releases")}/>{' '} + handleCheckChange(e, "allow_releases")}/>{' '}
- handleCheckChange(e, "allow_snapshots")}/>{' '} + handleCheckChange(e, "allow_snapshots")}/>{' '}
@@ -308,7 +268,7 @@ export default function RemoteEdit() {
- handleValueChange(e, "timeout_seconds")}/> + handleValueChange(e, "timeout_seconds")}/>
@@ -319,11 +279,11 @@ export default function RemoteEdit() { // HTTP Proxy }
- handleUseProxy(e)} />{' '} + handleUseProxy(e)} />{' '}
{ - storeView.useProxy&& + store.useProxy&&
@@ -339,40 +299,40 @@ export default function RemoteEdit() { // X.509 / auth }
- handleUseAuth(e)} />{' '} + handleUseAuth(e)} />{' '}
{ - storeView.useAuth && + store.useAuth &&
- handleValueChange(e, "user")} size="25"/> + handleValueChange(e, "user")} size="25"/>
- handleValueChange(e, "password")} size="25"/> + handleValueChange(e, "password")} size="25"/>
{ - storeView.use_proxy && + store.use_proxy &&
- handleValueChange(e, "proxy_user")} size="20"/> + handleValueChange(e, "proxy_user")} size="20"/>
- handleValueChange(e, "proxy_password")} size="20"/> + handleValueChange(e, "proxy_password")} size="20"/>
}
}
- handleUseX509(e)} />{' '} + handleUseX509(e)} />{' '}
{ - storeView.useX509 && + store.useX509 && }
diff --git a/src/main/webui/src/app/components/content/common/StoreControlPanels.jsx b/src/main/webui/src/app/components/content/common/StoreControlPanels.jsx index cc369c0..dd052c6 100644 --- a/src/main/webui/src/app/components/content/common/StoreControlPanels.jsx +++ b/src/main/webui/src/app/components/content/common/StoreControlPanels.jsx @@ -18,19 +18,70 @@ import React from 'react'; import {useNavigate} from 'react-router-dom'; import {PropTypes} from 'prop-types'; import {Utils} from '../../../utils/AppUtils'; -import {http} from '../../../utils/RestClient'; +import {jsonRest,http} from '../../../utils/RestClient'; -const StoreEditControlPanel = ({handleSave, handleCancel, handleRemove}) =>
+const StoreEditControlPanel = ({mode, store}) =>{ + const navigate = useNavigate(); + const handleSave = () => { + const saveUrl = `/api/admin/stores/${store.packageType}/${store.type}/${store.name}`; + const saveStore = async () => { + let response = {}; + if(mode==="new"){ + response = await jsonRest.post(saveUrl, store); + }else if(mode ==="edit"){ + response = await jsonRest.put(saveUrl, store); + } + if (!response.ok){ + // TODO: find another way to do error handling + response.text().then(error=>Utils.logMessage(error)); + } + if(response.status >= 200 || response.status < 300){ + navigate(`/${store.type}/${store.packageType}/view/${store.name}`); + } + }; + saveStore(); + }; + + const handleCancel = () => { + if(mode === 'edit'){ + navigate(`/${store.type}/${store.packageType}/view/${store.name}`); + } + if(mode==='new'){ + navigate(`/${store.type}/${store.packageType}`); + } + }; + + const handleRemove = () => { + // Only edit page should handle delete logic + if(mode==="edit"){ + const deleteUrl = `/api/admin/stores/${store.packageType}/${store.type}/${store.name}`; + const deleteStore = async () => { + const response = await http.delete(deleteUrl); + if (!response.ok){ + // TODO: find another way to do error handling + response.text().then(error=>Utils.logMessage(error)); + } + if(response.status >= 200 || response.status < 300){ + navigate(`/${store.type}/${store.packageType}`); + } + }; + deleteStore(); + } + }; + + return
{' '} {' '} - + { + mode==="edit" && + }
; +}; StoreEditControlPanel.propTypes={ - handleSave: PropTypes.func, - handleCancel: PropTypes.func, - handleRemove: PropTypes.func + mode: PropTypes.string, + store: PropTypes.object }; const StoreViewControlPanel = function({enabled, storeObj, handleDisable, handleEnable}){