Skip to content

Commit

Permalink
status
Browse files Browse the repository at this point in the history
  • Loading branch information
himdel committed Jun 18, 2024
1 parent 7f709f6 commit 8c7c680
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/components/hub-about-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const HubAboutModal = ({ isOpen, onClose, user, userName }: IProps) => {
<Label>{t`UI Version`}</Label>
<Value>
<ExternalLink
href={`https://github.com/ansible/ansible-hub-ui/commit/${ui_sha}`}
href={`https://github.com/himdel/pulp-ui/commit/${ui_sha}`}
>
{ui_sha}
</ExternalLink>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui-version.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ const HTMLComment = ({ text, ...props }: IProps) => (
export const UIVersion = () => (
<HTMLComment
className='hub-ui-version'
text={`ansible-hub-ui ${UI_COMMIT_HASH}`}
text={`pulp-ui ${UI_COMMIT_HASH}`}
/>
);
47 changes: 41 additions & 6 deletions src/containers/pulp-status.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { t } from '@lingui/macro';
import { Card, CardBody, CardTitle } from '@patternfly/react-core';
import { Card, CardBody, CardTitle, Progress } from '@patternfly/react-core';
import React, { Component } from 'react';
import { PulpStatusAPI } from 'src/api';
import {
Expand All @@ -10,10 +10,16 @@ import {
Main,
closeAlert,
} from 'src/components';
import { type RouteProps, jsxErrorMessage, withRouter } from 'src/utilities';
import {
type RouteProps,
getHumanSize,
jsxErrorMessage,
withRouter,
} from 'src/utilities';

interface IState {
alerts: AlertType[];
status?;
}

class PulpStatus extends Component<RouteProps, IState> {
Expand All @@ -22,6 +28,7 @@ class PulpStatus extends Component<RouteProps, IState> {

this.state = {
alerts: [],
status: null,
};
}

Expand All @@ -30,7 +37,12 @@ class PulpStatus extends Component<RouteProps, IState> {
}

render() {
const { alerts } = this.state;
const { alerts, status } = this.state;

const value = status
? (100 / status.storage.total) * status.storage.used
: 0;
const free = status ? getHumanSize(status.storage.free) : 0;

return (
<>
Expand All @@ -51,7 +63,31 @@ class PulpStatus extends Component<RouteProps, IState> {
<h2>{t`TODO`}</h2>
</CardTitle>
<CardBody>
<LoadingSpinner />
{!status ? (
<LoadingSpinner />
) : (
<>
<Progress
value={value}
title={t`Storage`}
variant={
value > 88
? 'danger'
: value > 66
? 'warning'
: value > 33
? null
: 'success'
}
/>
<br />
{t`Free`} {free}
<br />
TODO versions, workers.. .. and enable/disable menu based on
.versions
<pre>{JSON.stringify(status, null, 2)}</pre>
</>
)}
</CardBody>
</section>
</Card>
Expand All @@ -63,8 +99,7 @@ class PulpStatus extends Component<RouteProps, IState> {
private query() {
PulpStatusAPI.get()
.then(({ data }) => {
// TODO
console.log(data);
this.setState({ status: data });
})
.catch((e) => {
const { status, statusText } = e.response;
Expand Down
1 change: 0 additions & 1 deletion src/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function standaloneMenu() {
return [
menuItem(t`Status`, {
url: formatPath(Paths.status),
condition: isLoggedIn,
}),
menuItem(t`Search`, {
url: formatPath(Paths.search),
Expand Down
7 changes: 4 additions & 3 deletions src/utilities/get-human-size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ export function getHumanSize(x) {
let l = 0,
n = parseInt(x, 10) || 0;

while (n >= 1024 && ++l) {
n = n / 1024;
while (n >= 1024) {
l++;
n /= 1024;
}

if (l === 0) {
Expand All @@ -17,5 +18,5 @@ export function getHumanSize(x) {
});
}

return n.toFixed(n < 10 && l > 0 ? 1 : 0) + ' ' + units[l];
return n.toFixed(n < 10 ? 1 : 0) + ' ' + units[l];
}

0 comments on commit 8c7c680

Please sign in to comment.