diff --git a/src/main/webui/src/app/components/content/hosted/HostedEdit.jsx b/src/main/webui/src/app/components/content/hosted/HostedEdit.jsx index 989e740..e0d5c27 100644 --- a/src/main/webui/src/app/components/content/hosted/HostedEdit.jsx +++ b/src/main/webui/src/app/components/content/hosted/HostedEdit.jsx @@ -14,8 +14,196 @@ * limitations under the License. */ -import React from 'react'; +import React, {useState, useEffect} from 'react'; +import {useLocation, useParams} from 'react-router-dom'; +import {useForm} from 'react-hook-form'; +import {PropTypes} from 'prop-types'; +import {StoreEditControlPanel as EditControlPanel} from '../common/StoreControlPanels.jsx'; +import {DisableTimeoutHint, DurationHint} 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'; +import {IndyRest} from '#utils/RestClient.js'; +import {Filters} from '#utils/Filters.js'; + +const {storeRes, disableRes} = IndyRest; + export default function HostedEdit() { - return
This is not implemented yet!
; + const [state, setState] = useState({ + store: {}, + storeView: {} + }); + const location = useLocation(); + const {packageType, name} = useParams(); + const { + register, + reset, + trigger, + handleSubmit, + formState: {errors} + } = useForm(); + + const path = location.pathname; + const mode = path.match(/.*\/new$/u)? 'new':'edit'; + // Give a default packageType + let store = {"packageType": "maven", "type": "hosted"}; + useEffect(()=>{ + if(mode === 'edit'){ + const fetchStore = async () =>{ + // get Store data + const res = await storeRes.get(packageType, "hosted", name); + if (res.success){ + const raw = res.result; + const storeView = Utils.cloneObj(raw); + storeView.disabled = raw.disabled === undefined ? false : raw.disabled; + // get Store disablement data + const timeoutRes = await disableRes.getStoreTimeout(packageType, "hosted", name); + const cloned = Utils.cloneObj(storeView); + if (timeoutRes.success){ + const timeout = timeoutRes.result; + cloned.disableExpiration = timeout.expiration; + }else{ + Utils.logMessage(`disable timeout getting failed! Error reason: ${timeoutRes.error.message}`); + } + // Change state and re-rendering + setState({ + storeView: cloned, + store: raw + }); + reset(raw); + }else{ + // TODO: find another way to do error handling + Utils.logMessage(`Failed to get store data. Error reason: ${res.error.status}->${res.error.message}`); + } + }; + + fetchStore(); + } + }, [packageType, name, mode, reset]); + + if (mode === 'edit'){ + store = state.store; + } + + const changelog = register("changelog"); + return ( +
e.preventDefault()}> +
+ +
+ +
+
Basics
+
+
+ + { + mode==='new'? + : + {store.packageType} + } +
+
+ + { + mode==='new'? + + {' '} + {errors.name?.type === "required" && Name is required} + {errors.name?.type === "maxLength" && Name's length should be less than 50} + : + {store.name} + } +
+ +
+ {' '} + + { + store.disabled && store.disableExpiration && + Set to automatically re-enable at {TimeUtils.timestampToDateFormat(store.disableExpiration)} + } +
+
+ {' '} + + If set to readonly, all uploading and deleting operations to this repo are prohibited +
+
+ {' '} + + Make the content index authoritative to this repository +
+ +
+
+ + {' '} + {errors.disable_timeout && Not a valid number}
+ +
+
+ +
+ + + (calculated by default) +
+
+ + +
Description
+
+ +
+ +
Capabilities
+
+
+ {Filters.checkmark(store.allow_releases || store.allow_snapshots)} + +
+
+ + + {' '} + +
+
+ + + {' '} + +
+ { + store.allow_snapshots && +
+
+ + + +
+
+ } +
+ +
+ { + // + ); } + +HostedEdit.propTypes={ + store: PropTypes.object, + location: PropTypes.object, + match: PropTypes.object +}; diff --git a/src/main/webui/src/app/components/content/remote/RemoteEdit.jsx b/src/main/webui/src/app/components/content/remote/RemoteEdit.jsx index 98184f0..04391a7 100644 --- a/src/main/webui/src/app/components/content/remote/RemoteEdit.jsx +++ b/src/main/webui/src/app/components/content/remote/RemoteEdit.jsx @@ -161,10 +161,8 @@ export default function RemoteEdit() { { mode==='new'? - - - : - {store.packageType} + : + {store.packageType} }