Skip to content

Commit

Permalink
only set available don't reset entire state
Browse files Browse the repository at this point in the history
Signed-off-by: Harsh Modi <[email protected]>
  • Loading branch information
hjmodi committed Feb 1, 2024
1 parent f13d8e6 commit 9f2ac6e
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions src/main/webui/src/app/components/content/group/GroupEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,8 @@ EditConstituents.propTypes = {
};

export default function GroupEdit() {
const [state, setState] = useState({
available: [],
store: {},
storeView: {}
});
const [store, setStore] = useState({"packageType": "maven", "type": "group", "constituents": []});
const [available, setAvailable] = useState([]);
const location = useLocation();
const {packageType, name} = useParams();
const {
Expand All @@ -184,9 +181,6 @@ export default function GroupEdit() {

const path = location.pathname;
const mode = path.match(/.*\/new$/u) ? 'new' : 'edit';
// Give a default packageType
let store = {"packageType": "maven", "type": "group", "constituents": []};
let available = [];
useEffect(() => {
if (mode === 'edit') {
const fetchStore = async () => {
Expand Down Expand Up @@ -216,11 +210,8 @@ export default function GroupEdit() {
Utils.logMessage(`disable timeout getting failed! Error reason: ${timeoutRes.error.message}`);
}
// Change state and re-rendering
setState({
storeView: cloned,
store: raw,
available: Array.from(allAvailable),
});
setStore(raw);
setAvailable(Array.from(allAvailable));
reset(raw);
} else {
// TODO: find another way to do error handling
Expand All @@ -239,22 +230,14 @@ export default function GroupEdit() {
if (availableRes.success) {
let availableResult = availableRes.result.items;
availableResult.forEach(item => allAvailable.add(item.packageType + ':' + item.type + ':' + item.name));
setState({
available: Array.from(allAvailable),
});
setAvailable(Array.from(allAvailable));
} else {
Utils.logMessage(`Getting available constituents failed! Error reason: ${statsRes.error.message}`);
}
})();
}
}, [packageType, name, mode, reset]);

if (mode === 'edit') {
store = state.store;
}

available = state.available;

const changelog = register("changelog");
return (
<form onSubmit={e => e.preventDefault()}>
Expand Down

0 comments on commit 9f2ac6e

Please sign in to comment.