{
store.useAuth &&
- handleValueChange(e, "key_password")}/>
+
}
@@ -44,7 +45,8 @@ const CertificateSection = ({store, handleValueChange}) =>
handleValueChange(e, "key_certificate_pem")}>
+
}
@@ -54,14 +56,15 @@ const CertificateSection = ({store, handleValueChange}) =>
handleValueChange(e, "server_certificate_pem")}>
+
;
CertificateSection.propTypes = {
store: PropTypes.object.isRequired,
- handleValueChange: PropTypes.func
+ register: PropTypes.func
};
export default function RemoteEdit() {
@@ -74,6 +77,12 @@ export default function RemoteEdit() {
const [useX509, setUseX509] = useState(false);
const location = useLocation();
const {packageType, name} = useParams();
+ const {
+ register,
+ reset,
+ handleSubmit,
+ formState: {errors}
+ } = useForm();
const path = location.pathname;
const mode = path.match(/.*\/new$/u)? 'new':'edit';
@@ -81,11 +90,12 @@ export default function RemoteEdit() {
// Give a default packageType
let store = {"packageType": "maven", "type": "remote"};
[pkgType, storeName] = [packageType, name];
+ const storeAPIEndpoint = `${STORE_API_BASE_URL}/${pkgType}/remote/${storeName}`;
useEffect(()=>{
if(mode === 'edit'){
const fetchStore = async () =>{
// get Store data
- const response = await jsonRest.get(`${STORE_API_BASE_URL}/${pkgType}/remote/${storeName}`);
+ const response = await jsonRest.get(storeAPIEndpoint);
if (response.ok){
const raw = await response.json();
const storeView = Utils.cloneObj(raw);
@@ -109,6 +119,7 @@ export default function RemoteEdit() {
storeView: cloned,
store: raw
});
+ reset(raw);
setUseProxy(storeView.useProxy);
setUseAuth(storeView.useAuth);
setUseX509(storeView.useX509);
@@ -122,23 +133,12 @@ export default function RemoteEdit() {
fetchStore();
}
- }, [pkgType, storeName, mode]);
+ }, [storeAPIEndpoint, mode, reset]);
if (mode === 'edit'){
store = state.store;
}
- const handleCheckChange = (event, field) => {
- if (event.target.checked) {
- store[field] = true;
- } else {
- store[field] = false;
- }
- };
- const handleValueChange = (event, field) => {
- store[field] = event.target.value;
- };
-
const handleUseProxy = event=>{
setUseProxy(event.target.checked);
};
@@ -150,9 +150,9 @@ export default function RemoteEdit() {
};
return (
-
+
);
}
diff --git a/src/main/webui/src/app/components/styles/indy.css b/src/main/webui/src/app/components/styles/indy.css
index 8b8d102..cd4b900 100644
--- a/src/main/webui/src/app/components/styles/indy.css
+++ b/src/main/webui/src/app/components/styles/indy.css
@@ -454,3 +454,7 @@ label, .label{
font-family: Arial, Helvetica, sans-serif;
box-sizing: border-box;
}
+
+.alert {
+ color: red;
+}
\ No newline at end of file
diff --git a/src/main/webui/src/app/utils/AppUtils.js b/src/main/webui/src/app/utils/AppUtils.js
index 5a34954..e4c0f5f 100644
--- a/src/main/webui/src/app/utils/AppUtils.js
+++ b/src/main/webui/src/app/utils/AppUtils.js
@@ -144,5 +144,15 @@ export const Utils = {
const allParams = [message];
params.forEach(p => allParams.push(p));
Reflect.apply(console.log, undefined, allParams);
+ },
+ rewriteTargetObject: (origin, target) => {
+ for (const prop in origin) {
+ if (origin[prop] !== undefined){
+ const val = origin[prop];
+ if(typeof val !== 'string' || val.trim() !== ''){
+ target[prop] = val;
+ }
+ }
+ }
}
};
diff --git a/src/main/webui/src/app/utils/AppUtils.test.js b/src/main/webui/src/app/utils/AppUtils.test.js
index a51c7b2..845a0d9 100644
--- a/src/main/webui/src/app/utils/AppUtils.test.js
+++ b/src/main/webui/src/app/utils/AppUtils.test.js
@@ -179,4 +179,51 @@ describe('AppUtils tests', () => {
expect(Utils.cloneObj({a: {b: "2"}, c: ["3", "4"]})).toEqual({c: ["3", "4"], a: {b: "2"}});
});
+ it("Check rewriteTargetObject", ()=>{
+ let origin = {
+ "name": "central",
+ "type": "remote",
+ "packageType": "maven",
+ "key": "maven:remote:central",
+ "url": "https://repo1.maven.org/maven2/"
+ };
+ let target = {};
+ Utils.rewriteTargetObject(origin, target);
+ expect(target).toEqual(origin);
+
+ target = {
+ "name": "central",
+ "type": "remote",
+ "packageType": "maven",
+ "key": "maven:remote:central",
+ "url": "https://notexist.com/fake/"
+ };
+ Utils.rewriteTargetObject(origin, target);
+ expect(target).toEqual(origin);
+
+ origin ={
+ "name": "central",
+ "type": "remote",
+ "packageType": "maven",
+ "key": "maven:remote:central",
+ "url": " ",
+ };
+ target = {
+ "name": "central",
+ "type": "remote",
+ "packageType": "maven",
+ "key": "maven:remote:central",
+ "url": "https://repo2.maven.org/maven2/",
+ "user": "testUser"
+ };
+ Utils.rewriteTargetObject(origin, target);
+ expect(target.name).toEqual(origin.name);
+ expect(target.type).toEqual(origin.type);
+ expect(target.packageType).toEqual(origin.packageType);
+ expect(target.url).not.toEqual(origin.url);
+ expect(target.url).toBe("https://repo2.maven.org/maven2/");
+ expect(target.user).not.toEqual(origin.user);
+ expect(target.user).toBe("testUser");
+ });
+
});