-
-
Notifications
You must be signed in to change notification settings - Fork 715
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Integrate request-response API
Signed-off-by: Moeez Ahmed <x311099@gmail.com>
- Loading branch information
Showing
5 changed files
with
74 additions
and
20 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
52 changes: 38 additions & 14 deletions
52
addOns/webuipoc/src/main/pocs/reactWebUI/src/Components/Request-Response/Req-Resp-Bar.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 |
---|---|---|
@@ -1,38 +1,62 @@ | ||
import React from 'react'; | ||
import React, { useContext } from 'react'; | ||
import { useState,useEffect} from "react"; | ||
import { sendMessage } from "../../Utilities/req-resp"; | ||
import { nodeIDContext } from '../../Contexts/SitesTreeNodeIDContext'; | ||
|
||
|
||
function reqResp() { | ||
|
||
const [initialreqRep, setinitialreqRep] = useState(null) | ||
const {nodeID} = useContext(nodeIDContext) | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
try { | ||
const response = await sendMessage(nodeID); | ||
setinitialreqRep(response); | ||
} catch (error) { | ||
console.error("Error fetching data:", error); | ||
} | ||
}; | ||
if (nodeID != 0) {fetchData();} | ||
|
||
}, [nodeID]); | ||
|
||
|
||
|
||
|
||
function ResponseBar() { | ||
return ( | ||
<div className="w-full bg-gray-600 text-white mt-2"> | ||
|
||
<div className="flex flex-row mr-2"> | ||
|
||
|
||
<div className='h-[594px] w-1/2 ml-2 bg-gray-700 rounded-lg'> | ||
<div className='h-[594px] w-1/2 ml-2 bg-gray-700 rounded-lg overflow-scroll'> | ||
<div className="flex flex-row text-center justify-center "> | ||
<div className="w-1/3 p-4 font-serif text-center">Request</div> | ||
</div> | ||
</div> | ||
<div className="flex justify-center text-center"> | ||
<div className="p-4"> | ||
<p className='font-mono'>############</p> | ||
</div> | ||
<div className="p-4 overflow-x-auto"> {initialreqRep?.requestHeader} </div> | ||
</div> | ||
</div> | ||
|
||
<p className=" justify-center text-center overflow-x-auto">{initialreqRep?.requestBody}</p> | ||
</div> | ||
|
||
|
||
<div className='h-[594px] w-1/2 ml-2 bg-gray-700 rounded-lg'> | ||
<div className='h-[594px] w-1/2 ml-2 bg-gray-700 rounded-lg overflow-scroll'> | ||
<div className="flex flex-row text-center justify-center"> | ||
<div className="w-1/3 p-4 font-serif text-center">Response</div> | ||
</div> | ||
<div className="flex justify-center text-center"> | ||
<div className="p-4"> | ||
<p className='font-mono'>#############</p> | ||
</div> | ||
<div className="p-4 overflow-x-auto"> {initialreqRep?.responseHeader} </div> | ||
</div> | ||
|
||
<p className=" p-4 justify-center text-center overflow-x-auto">{initialreqRep?.responseBody}</p> | ||
|
||
</div> | ||
|
||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default ResponseBar; | ||
export default reqResp; |
14 changes: 14 additions & 0 deletions
14
addOns/webuipoc/src/main/pocs/reactWebUI/src/Contexts/SitesTreeNodeIDContext.js
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,14 @@ | ||
import React, { useState, createContext } from 'react'; | ||
|
||
|
||
export const nodeIDContext = createContext(); | ||
|
||
export const NodeIDProvider = ({ children }) => { | ||
const [nodeID, setNodeID] = useState(0); | ||
return ( | ||
<nodeIDContext.Provider value={{ nodeID, setNodeID }}> | ||
{children} | ||
</nodeIDContext.Provider> | ||
); | ||
}; | ||
|
13 changes: 13 additions & 0 deletions
13
addOns/webuipoc/src/main/pocs/reactWebUI/src/Utilities/req-resp.js
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,13 @@ | ||
import axios from 'axios'; | ||
|
||
const sendMessage = async (id) => { | ||
try { | ||
const response = await axios.get(`/JSON/core/view/message?id=${id}`); | ||
return response.data.message; | ||
} catch (error) { | ||
console.error('Error fetching data:', error); | ||
throw error; | ||
} | ||
}; | ||
|
||
export { sendMessage }; |