-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI to interact with Relay server (#3484)
* PBENCH-1141 Create UI to interact with the relay server pull API
- Loading branch information
Showing
9 changed files
with
209 additions
and
2 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,42 @@ | ||
import * as TYPES from "./types"; | ||
|
||
import { DANGER, SUCCESS } from "assets/constants/toastConstants"; | ||
|
||
import API from "../utils/axiosInstance"; | ||
import { getDatasets } from "./overviewActions"; | ||
import { showToast } from "./toastActions"; | ||
import { uriTemplate } from "../utils/helper"; | ||
|
||
export const uploadFile = (fileURI) => async (dispatch, getState) => { | ||
try { | ||
dispatch({ type: TYPES.LOADING }); | ||
const endpoints = getState().apiEndpoint.endpoints; | ||
|
||
const uri = uriTemplate(endpoints, "relay", { uri: fileURI }); | ||
const response = await API.post(uri, null, null); | ||
if (response.status >= 200 && response.status < 300) { | ||
dispatch(showToast(SUCCESS, response.data.message)); | ||
dispatch(setRelayModalState(false)); | ||
dispatch(handleInputChange("")); | ||
if (response.status === 201) { | ||
// need to remove once response returns the uploaded dataset | ||
dispatch(getDatasets()); | ||
} | ||
} | ||
} catch (error) { | ||
dispatch( | ||
showToast(DANGER, error?.response?.data?.message ?? `Error: ${error}`) | ||
); | ||
dispatch({ type: TYPES.NETWORK_ERROR }); | ||
} | ||
dispatch({ type: TYPES.COMPLETED }); | ||
}; | ||
export const setRelayModalState = (isOpen) => ({ | ||
type: TYPES.TOGGLE_RELAY_MODAL, | ||
payload: isOpen, | ||
}); | ||
|
||
export const handleInputChange = (value) => ({ | ||
type: TYPES.SET_RELAY_DATA, | ||
payload: value, | ||
}); |
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
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
114 changes: 114 additions & 0 deletions
114
dashboard/src/modules/components/RelayUIComponent/index.jsx
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,114 @@ | ||
import "./index.less"; | ||
|
||
import { | ||
ActionGroup, | ||
Button, | ||
Card, | ||
CardBody, | ||
Form, | ||
FormGroup, | ||
Modal, | ||
ModalVariant, | ||
Popover, | ||
TextInput, | ||
Title, | ||
} from "@patternfly/react-core"; | ||
import { | ||
handleInputChange, | ||
setRelayModalState, | ||
uploadFile, | ||
} from "actions/relayActions"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
|
||
import { OutlinedQuestionCircleIcon } from "@patternfly/react-icons"; | ||
import React from "react"; | ||
|
||
const AboutComponent = () => ( | ||
<div className="about-container"> | ||
<p> | ||
The Pbench Agent can push datasets to a Pbench Server directly, when the | ||
server is accessible from the system where the Pbench Agent is being used. | ||
</p> | ||
<p> | ||
When a firewall prevents this direct access, the Pbench Agent can store a | ||
dataset tarball and a manifest file on a file relay server which can be | ||
reached by both the Pbench Agent and the Pbench Server. | ||
</p> | ||
<p> | ||
Enter the relay server URI reported by the Pbench Agent and press Submit | ||
to begin the upload. | ||
</p> | ||
</div> | ||
); | ||
const PopoverComponent = () => ( | ||
<Popover | ||
aria-label="Basic popover" | ||
headerContent={<div>About</div>} | ||
bodyContent={<AboutComponent />} | ||
maxWidth="4vw" | ||
> | ||
<Button variant="plain" aria-label="About"> | ||
<OutlinedQuestionCircleIcon /> | ||
</Button> | ||
</Popover> | ||
); | ||
|
||
const RelayComponent = () => { | ||
const { isRelayModalOpen, relayInput } = useSelector( | ||
(state) => state.overview | ||
); | ||
const dispatch = useDispatch(); | ||
|
||
const handleClose = () => { | ||
dispatch(handleInputChange("")); | ||
dispatch(setRelayModalState(false)); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
className="relay-ui-container" | ||
aria-label="Relay" | ||
variant={ModalVariant.small} | ||
isOpen={isRelayModalOpen} | ||
onClose={handleClose} | ||
> | ||
<div className="modal-heading"> | ||
<Title headingLevel="h3">Relay</Title> | ||
<PopoverComponent /> | ||
</div> | ||
<div className="card-wrapper"> | ||
<Card> | ||
<CardBody> | ||
<Form> | ||
<FormGroup | ||
label="Enter the Relay URI" | ||
isRequired | ||
fieldId="relay-uri" | ||
> | ||
<TextInput | ||
isRequired | ||
type="text" | ||
id="relay-uri" | ||
name="relay-uri" | ||
value={relayInput} | ||
onChange={(value) => dispatch(handleInputChange(value))} | ||
/> | ||
</FormGroup> | ||
<ActionGroup> | ||
<Button | ||
variant="primary" | ||
isDisabled={!relayInput} | ||
onClick={() => dispatch(uploadFile())} | ||
> | ||
Submit | ||
</Button> | ||
</ActionGroup> | ||
</Form> | ||
</CardBody> | ||
</Card> | ||
</div> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default RelayComponent; |
23 changes: 23 additions & 0 deletions
23
dashboard/src/modules/components/RelayUIComponent/index.less
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,23 @@ | ||
.relay-ui-container { | ||
padding: 2vw; | ||
.divider { | ||
margin-top: 5vh; | ||
} | ||
.modal-heading { | ||
display: flex; | ||
} | ||
.card-wrapper { | ||
height: 45vh; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
.pf-c-card { | ||
width: 45vw; | ||
} | ||
} | ||
} | ||
.about-container { | ||
p { | ||
margin-bottom: 0.5vw; | ||
} | ||
} |
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