Skip to content

Commit

Permalink
Merge pull request #699 from balsa-asanovic/improve-form-errors
Browse files Browse the repository at this point in the history
Form now scrolls up if warning is shown
  • Loading branch information
imobachgs authored Aug 12, 2023
2 parents a242827 + 2243352 commit ff4b61c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
7 changes: 7 additions & 0 deletions web/package/cockpit-agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Sat Aug 12 11:35:12 UTC 2023 - Balsa Asanovic <[email protected]>

- Added scroll up functionality to the discover iSCSI form when
the warning shows up after the submit action
(gh#openSUSE/agama#468).

-------------------------------------------------------------------
Wed Aug 2 18:59:16 UTC 2023 - Balsa Asanovic <[email protected]>

Expand Down
24 changes: 20 additions & 4 deletions web/src/components/storage/iscsi/DiscoverForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* find current contact information at www.suse.com.
*/

import React, { useEffect, useState } from "react";
import React, { useEffect, useRef, useState } from "react";
import {
Alert,
Form, FormGroup,
Expand All @@ -46,11 +46,21 @@ export default function DiscoverForm({ onSubmit: onSubmitProp, onCancel }) {
const [isLoading, setIsLoading] = useState(false);
const [isFailed, setIsFailed] = useState(false);
const [isValidAuth, setIsValidAuth] = useState(true);
const alertRef = useRef(null);

useEffect(() => {
setData(savedData);
}, [setData, savedData]);

useEffect(() => {
// Scroll the alert into view
if (isFailed)
alertRef.current.scrollIntoView({
behavior: "smooth",
block: "start"
});
});

const updateData = (key, value) => setData({ ...data, [key]: value });
const onAddressChange = v => updateData("address", v);
const onPortChange = v => updateData("port", v);
Expand Down Expand Up @@ -89,9 +99,15 @@ export default function DiscoverForm({ onSubmit: onSubmitProp, onCancel }) {
<Popup isOpen title="Discover iSCSI Targets">
<Form id={id} onSubmit={onSubmit}>
{ isFailed &&
<Alert variant="warning" isInline title="Something went wrong">
<p>Make sure you provide the correct values</p>
</Alert> }
<div ref={alertRef}>
<Alert
variant="warning"
isInline
title="Something went wrong"
>
<p>Make sure you provide the correct values</p>
</Alert>
</div> }
<FormGroup
fieldId="address"
label="IP address"
Expand Down

0 comments on commit ff4b61c

Please sign in to comment.