Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form now scrolls up if warning is shown #699

Merged
merged 3 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading