From 4f12019dfb45bc4354f370601c714e595854a70c Mon Sep 17 00:00:00 2001 From: Harsh Modi Date: Wed, 10 Jan 2024 18:34:20 -0500 Subject: [PATCH] implement group UI Signed-off-by: Harsh Modi --- .../components/content/group/GroupEdit.jsx | 199 +++++++++++++++++- .../components/content/group/GroupList.jsx | 107 +++++++++- 2 files changed, 301 insertions(+), 5 deletions(-) diff --git a/src/main/webui/src/app/components/content/group/GroupEdit.jsx b/src/main/webui/src/app/components/content/group/GroupEdit.jsx index b03752c..449fbdf 100644 --- a/src/main/webui/src/app/components/content/group/GroupEdit.jsx +++ b/src/main/webui/src/app/components/content/group/GroupEdit.jsx @@ -14,8 +14,203 @@ * 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, Hint} from "../common/Hints.jsx"; +import {PackageTypeSelect} from "../common/PackageTypeSelect.jsx"; +// import ViewJsonDebugger from './Debugger.jsx'; +import {Utils} from "#utils/AppUtils.js"; +import {IndyRest} from "#utils/RestClient.js"; + +const {storeRes, disableRes} = IndyRest; export default function GroupEdit() { - 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: "group"}; + useEffect(() => { + if (mode === "edit") { + const fetchStore = async () => { + // get Store data + const res = await storeRes.get(packageType, "group", 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, + "group", + 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 && + + + + } +
+
+ {" "} + + + + +
+ +
+
+ + {" "} + {errors.disable_timeout && + Not a valid number + } +
+ +
+
+
+ +
Description
+
+ +
+ +
Constituents
+
+
    + (hover for controls) + {store.constituents.map((constituent, i) =>
  1. {constituent}
  2. )} + +
+
    + (click to add to constituents) + {store.available.map((available, i) =>
  1. {available}
  2. )} +
+
+
+ { + // + ); } + +GroupEdit.propTypes = { + store: PropTypes.object, + location: PropTypes.object, + match: PropTypes.object, +}; diff --git a/src/main/webui/src/app/components/content/group/GroupList.jsx b/src/main/webui/src/app/components/content/group/GroupList.jsx index f7b207d..a8910ef 100644 --- a/src/main/webui/src/app/components/content/group/GroupList.jsx +++ b/src/main/webui/src/app/components/content/group/GroupList.jsx @@ -14,8 +14,109 @@ * limitations under the License. */ -import React from 'react'; +import React, {useEffect, useState} from "react"; +import {useParams} from "react-router-dom"; +import {ListJsonDebugger} from "../common/Debugger.jsx"; +import ListControl from "../common/ListControl.jsx"; +import {groupOptionLegend as options} from "../../ComponentConstants.js"; +import {StoreListingWidget} from "../common/StoreListingWidget.jsx"; +import {LoadingSpiner} from "../common/LoadingSpiner.jsx"; +import {Utils} from "#utils/AppUtils.js"; +import {IndyRest} from "#utils/RestClient.js"; -export default function GruopList() { - return
This is not implemented yet!
; +const {storeRes, disableRes} = IndyRest; + +const handlers = { + handleDebug: (event, setState) => { + setState({ + enableDebug: event.target.checked, + }); + }, + handleSearch: (event, rawList, setState) => { + setState({ + rawList, + listing: Utils.searchByKeyForNewStores(event.target.value, rawList), + }); + }, + handleSortBy: (event, rawList, setState) => { + setState({ + rawList, + listing: Utils.sortByPropForStores(event.target.value, rawList), + }); + }, +}; + +export default function GroupList() { + const {packageType} = useParams(); + const [state, setState] = useState({ + rawList: [], + listing: [], + disabledMap: {}, + enableDebug: false, + message: "", + }); + const [loading, setLoading] = useState(true); + + useEffect(() => { + setLoading(true); + const fetchdData = async () => { + const res = await storeRes.getStores(packageType, "group"); + if (res.success) { + const timeoutRes = await disableRes.getAllStoreTimeout(); + let disabledMap = {}; + if (timeoutRes.success) { + const timeoutData = timeoutRes.result; + disabledMap = Utils.setDisableMap(timeoutData); + } else { + Utils.logMessage(`disable timeout get failed in group listing! Error reason: ${timeoutRes.error.message}`,); + } + let data = res.result; + if (typeof data === "string") { + data = JSON.parse(data); + } + setState({ + rawList: data.items, + listing: data.items, + disabledMap, + }); + } else { + setState({ + message: res.error.message, + }); + } + setLoading(false); + }; + fetchdData(); + }, [packageType]); + + if (loading) { + return ; + } + + return ( + + handlers.handleSearch(event, state.rawList, setState) + } + handleDebug={event => handlers.handleDebug(event, setState)} + handleSortBy={event => handlers.handleSortBy(event, state.rawList, setState) + } + /> + {state.listing ? + + : +
No content fetched!
+ } + +
+ ); }