-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f6d455
commit eb4269d
Showing
3 changed files
with
212 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
/* | ||
* Copyright (c) [2023] SUSE LLC | ||
* | ||
* All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of version 2 of the GNU General Public License as published | ||
* by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, contact SUSE LLC. | ||
* | ||
* To contact SUSE LLC about this file by physical or electronic mail, you may | ||
* find current contact information at www.suse.com. | ||
*/ | ||
|
||
import React, { useEffect, useState } from "react"; | ||
import { DropdownToggle, Form, FormGroup, TextInput, Skeleton } from "@patternfly/react-core"; | ||
import { TableComposable, Thead, Tr, Th, Tbody, Td, ActionsColumn } from '@patternfly/react-table'; | ||
|
||
import { Icon } from '~/components/layout'; | ||
import { Section, Popup } from "~/components/core"; | ||
|
||
import { useInstallerClient } from "~/context/installer"; | ||
import { useCancellablePromise } from "~/utils"; | ||
|
||
const RowActions = ({ actions, id, ...props }) => { | ||
const actionsToggle = (props) => ( | ||
<DropdownToggle | ||
id={id} | ||
aria-label="Actions" | ||
toggleIndicator={null} | ||
isDisabled={props.isDisabled} | ||
onToggle={props.onToggle} | ||
> | ||
<Icon name="more_vert" size="24" /> | ||
</DropdownToggle> | ||
); | ||
|
||
return ( | ||
<ActionsColumn | ||
items={actions} | ||
actionsToggle={actionsToggle} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
const NodesPresenter = ({ nodes, isLoading }) => { | ||
const NodeRow = ({ node }) => { | ||
const actions = (node) => { | ||
return [ | ||
{ | ||
title: "Edit", | ||
onClick: null | ||
} | ||
]; | ||
}; | ||
|
||
return ( | ||
<Tr> | ||
<Td>{node.target}</Td> | ||
<Td>{node.address + ":" + node.port}</Td> | ||
<Td>{node.interface}</Td> | ||
<Td>{node.ibft ? "Yes" : "No"}</Td> | ||
<Td>{node.connected ? "Connected" : "Disconnected"}</Td> | ||
<Td isActionCell> | ||
<RowActions actions={actions(node)} id={`actions-for-node${node.id}`} /> | ||
</Td> | ||
</Tr> | ||
); | ||
}; | ||
|
||
const Content = () => { | ||
if (isLoading) { | ||
return ( | ||
<Tr> | ||
<Td colSpan={6}> | ||
<Skeleton /> | ||
</Td> | ||
</Tr> | ||
); | ||
} | ||
|
||
return nodes.map(n => <NodeRow node={n} key={`node${n.id}`} />); | ||
}; | ||
|
||
return ( | ||
<TableComposable gridBreakPoint="grid-sm" variant="compact" className="users"> | ||
<Thead> | ||
<Tr> | ||
<Th>Name</Th> | ||
<Th>Portal</Th> | ||
<Th>Interface</Th> | ||
<Th>iBFT</Th> | ||
<Th>Status</Th> | ||
<Th /> | ||
</Tr> | ||
</Thead> | ||
<Tbody> | ||
<Content /> | ||
</Tbody> | ||
</TableComposable> | ||
); | ||
}; | ||
|
||
// const InitiatorForm = ({ initiator, onSubmit, onCancel }) => { | ||
// const [data, setData] = useState({ ...initiator }); | ||
|
||
// const onNameChange = (name) => { | ||
// setData({ ...data, name }); | ||
// }; | ||
|
||
// const onSubmitWrapper = (event) => { | ||
// event.preventDefault(); | ||
// onSubmit(data); | ||
// }; | ||
|
||
// const id = "editIscsiInitiator"; | ||
// const isSubmitDisabled = data.name === ""; | ||
|
||
// return ( | ||
// <Popup isOpen height="medium" title="Edit iSCSI Initiator"> | ||
// <Form id={id} onSubmit={onSubmitWrapper}> | ||
// <FormGroup fieldId="initiatorName" label="Name"> | ||
// <TextInput | ||
// id="initiatorName" | ||
// name="name" | ||
// aria-label="Initiator name" | ||
// value={data.name || ""} | ||
// label="Name" | ||
// isRequired | ||
// onChange={onNameChange} | ||
// /> | ||
// </FormGroup> | ||
// </Form> | ||
// <Popup.Actions> | ||
// <Popup.Confirm | ||
// form={id} | ||
// type="submit" | ||
// isDisabled={isSubmitDisabled} | ||
// /> | ||
// <Popup.Cancel onClick={onCancel} /> | ||
// </Popup.Actions> | ||
// </Popup> | ||
// ); | ||
// }; | ||
|
||
export default function TargetsSection() { | ||
const { storage: client } = useInstallerClient(); | ||
const { cancellablePromise } = useCancellablePromise(); | ||
const [nodes, setNodes] = useState([]); | ||
const [isLoading, setIsLoading] = useState(false); | ||
// const [isFormOpen, setIsFormOpen] = useState(false); | ||
|
||
useEffect(() => { | ||
const loadNodes = async () => { | ||
setIsLoading(true); | ||
const nodes = await cancellablePromise(client.iscsi.getNodes()); | ||
setNodes(nodes); | ||
setIsLoading(false); | ||
}; | ||
|
||
loadNodes().catch(console.error); | ||
|
||
// return client.iscsi.onInitiatorChange(loadInitiator); | ||
}, [cancellablePromise, client.iscsi]); | ||
|
||
// const openForm = () => { | ||
// setIsFormOpen(true); | ||
// }; | ||
|
||
// const closeForm = () => { | ||
// setIsFormOpen(false); | ||
// }; | ||
|
||
// const acceptForm = async (data) => { | ||
// setIsLoading(true); | ||
// closeForm(); | ||
// await client.iscsi.setInitiatorName(data.name); | ||
// }; | ||
|
||
return ( | ||
<Section title="Targets" iconName="lan"> | ||
<NodesPresenter | ||
nodes={nodes} | ||
isLoading={isLoading} | ||
// handlers={ { edit: openForm } } | ||
/> | ||
{/* { isFormOpen && | ||
<InitiatorForm | ||
initiator={initiator} | ||
onSubmit={acceptForm} | ||
onCancel={closeForm} | ||
/> } */} | ||
</Section> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters