Skip to content

Commit

Permalink
Update NavFooter to fetch stats from server
Browse files Browse the repository at this point in the history
  • Loading branch information
ligangty committed Nov 14, 2023
1 parent 4fe04dd commit 194378b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/main/webui/src/app/RestClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ const http = {
};

const jsonRest ={
get: (url, payload) => httpCall(url, "GET", {"Content-type": "application/json"}, payload),
post: (url, payload) => httpCall(url, "POST", {"Content-type": "application/json"}, payload),
put: (url, payload) => httpCall(url, "PUT", {"Content-type": "application/json"}, payload)
get: (url, payload) => httpCall(url, "GET", {"Content-type": "application/json"}, JSON.stringify(payload)),
post: (url, payload) => httpCall(url, "POST", {"Content-type": "application/json"}, JSON.stringify(payload)),
put: (url, payload) => httpCall(url, "PUT", {"Content-type": "application/json"}, JSON.stringify(payload))
};

export {http, jsonRest};
35 changes: 27 additions & 8 deletions src/main/webui/src/app/components/nav/NavFooter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,35 @@
* limitations under the License.
*/

import React from 'react';
import React, {useEffect, useState} from 'react';
import {jsonRest} from '../../RestClient';
import {Utils} from '../CompUtils';

export default function NavFooter() {
// TODO: stats will be render based on the backend addons response, this is a mock;
const stats = {
version: "1.6.0",
commitId: "f472176",
builder: "ligangty",
timestamp: "2018-10-24 05:54 +0000"
};
const [state, setState] = useState({stats: {}});

(function(){
const versionUrl = `/api/stats/version-info`;
useEffect(()=>{
const fetchVersion = async () => {
const response = await jsonRest.get(versionUrl);
if (response.ok){
const raw = await response.json();
setState({
stats: raw
});
}else{
response.text().then(data => {
Utils.logMessage(`Failed to version info. Error reason: ${response.status}->${response.statusText}`);
});
}
};

fetchVersion();
}, []);
}());

const stats = state.stats;
const gridClass = "col-md-auto border-right border-secondary";
return (
<nav className="navbar fixed-bottom navbar-expand-lg navbar-light bg-light" role="navigation">
Expand Down
9 changes: 9 additions & 0 deletions src/main/webui/src/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ app.get('/api/stats/package-type/keys', (req, res)=>{
res.status(200).json(["generic-http", "maven", "npm"]);
});

app.get('/api/stats/version-info', (req, res) => {
res.status(200).json({
version: "3.3.2",
commitId: "f472176",
builder: "test-builder",
timestamp: "2023-10-24 05:54 +0000"
});
});

app.get('/api/admin/stores/_all/remote', (req, res) => {
const remoteList = require('./mock/list/FakeRemoteList.json');
res.status(200).json(remoteList);
Expand Down

0 comments on commit 194378b

Please sign in to comment.