Skip to content

Commit

Permalink
🔖 0.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaoz-Topsy committed Aug 14, 2024
1 parent 5bac851 commit cac504a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 53 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "status-nmscd",
"version": "0.2.3",
"version": "0.2.4",
"description": "",
"scripts": {
"start": "vite",
Expand Down
10 changes: 5 additions & 5 deletions src/components/monitorDetailModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ApiService } from "../services/api/ApiService";
import { MonitorStatusIcon } from "./monitorStatusRow";

export interface ISelectedMonitorTickProps {
maxStatus: number;
percentage: number;
monitorId: number;
hour: number;
}
Expand Down Expand Up @@ -51,15 +51,15 @@ export const MonitorDetailModal: Component<ISelectedMonitorTickProps> = (
setNetworkState(NetworkState.Success);
};

const getMaxStatus = (record: MonitorStatusTickViewModel) => {
const getPercentage = (record: MonitorStatusTickViewModel) => {
const successPerc = record.numSuccessStatuses / record.numStatuses;
return successPerc == 1 ? 2 : 9;
return successPerc * 100;
};

return (
<>
<ModalHeader>
<MonitorStatusIcon maxStatus={props.maxStatus} />
<MonitorStatusIcon percentage={props.percentage} />
{monitorHourFormat(hoursToEpoch(props.hour))}
</ModalHeader>
<ModalBody>
Expand Down Expand Up @@ -98,7 +98,7 @@ export const MonitorDetailModal: Component<ISelectedMonitorTickProps> = (
<For each={monitorTickRecords()}>
{(record) => (
<p>
<MonitorStatusIcon maxStatus={getMaxStatus(record)} />
<MonitorStatusIcon percentage={getPercentage(record)} />
{monitorTickFormat(
minutesToEpoch(record.minutesSinceEpochInterval)
)}
Expand Down
50 changes: 17 additions & 33 deletions src/components/monitorList.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,25 @@
import {
Component,
createSignal,
For,
Match,
onMount,
Show,
Switch,
} from "solid-js";
import { ApiService } from "../services/api/ApiService";
import { NetworkState } from "../constants/enum/NetworkState";
import {
MonitorStatusHourViewModel,
MonitorStatusViewModel,
} from "../contracts/MonitorStatusViewModel";
import { MonitorStatusIcon, MonitorStatusRow } from "./monitorStatusRow";
import {
Button,
createDisclosure,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
Text,
} from "@hope-ui/solid";
import { anyObject } from "../helper/typescriptHacks";
import { Component, createSignal, For, Match, onMount, Switch } from "solid-js";
import { NetworkState } from "../constants/enum/NetworkState";
import {
formatDate,
hoursToEpoch,
monitorHourFormat,
monitorTickFormat,
} from "../helper/dateHelper";
MonitorStatusHourViewModel,
MonitorStatusViewModel,
} from "../contracts/MonitorStatusViewModel";
import { anyObject } from "../helper/typescriptHacks";
import { ApiService } from "../services/api/ApiService";
import {
ISelectedMonitorTickProps,
MonitorDetailModal,
} from "./monitorDetailModal";
import { MonitorStatusIcon, MonitorStatusRow } from "./monitorStatusRow";

export const MonitorList: Component = () => {
const { isOpen, onOpen, onClose } = createDisclosure();
Expand Down Expand Up @@ -75,13 +58,16 @@ export const MonitorList: Component = () => {
(monitorRecordPerHour: MonitorStatusHourViewModel) => {
setSelectedMonitorTickRecord({
monitorId,
maxStatus: monitorRecordPerHour.maxStatus,
percentage:
(monitorRecordPerHour.numSuccessStatuses /
monitorRecordPerHour.numStatuses) *
100,
hour: monitorRecordPerHour.hourSinceEpochInterval,
});
onOpen();
};

const getAvailability = (monitor: MonitorStatusViewModel): string => {
const getPercentage = (monitor: MonitorStatusViewModel) => {
const totalStatuses = monitor.hours.reduce(
(partial, cur) => partial + cur.numStatuses,
0
Expand All @@ -91,9 +77,7 @@ export const MonitorList: Component = () => {
0
);

const successPerc = totalSuccessStatuses / totalStatuses;

return `${Math.round(successPerc * 100)}%`;
return (totalSuccessStatuses / totalStatuses) * 100;
};

return (
Expand Down Expand Up @@ -126,9 +110,9 @@ export const MonitorList: Component = () => {
{(monitor) => (
<div class="col-12 monitor">
<h3 data-id={monitor.monitorId}>
<MonitorStatusIcon maxStatus={monitor.status} />
<MonitorStatusIcon percentage={getPercentage(monitor)} />
&nbsp;{monitor.name}
<small>Availablity: {getAvailability(monitor)}</small>
<small>Availablity: {Math.round(getPercentage(monitor))}%</small>
</h3>
<MonitorStatusRow
record={monitor}
Expand All @@ -145,7 +129,7 @@ export const MonitorList: Component = () => {
<ModalCloseButton />
<MonitorDetailModal
monitorId={selectedMonitorTickRecord().monitorId}
maxStatus={selectedMonitorTickRecord().maxStatus}
percentage={selectedMonitorTickRecord().percentage}
hour={selectedMonitorTickRecord().hour}
/>
<ModalFooter>
Expand Down
24 changes: 11 additions & 13 deletions src/components/monitorStatusRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,13 @@ export const MonitorStatusRow: Component<IMonitorStatusRow> = (
arrItems[arrIndex] = perHour;
} else {
arrItems[arrIndex] = {
maxStatus: 0,
numStatuses: 0,
numSuccessStatuses: 0,
hourSinceEpochInterval: hourSinceEpochInterval,
};
}
}
const reversed = arrItems.reverse();

// If latest value is unknown, use the previous hour's value
if (reversed[reversed.length - 1].maxStatus === 0) {
reversed[reversed.length - 1].maxStatus =
reversed[reversed.length - 2].maxStatus;
}

return reversed;
};

Expand All @@ -84,6 +76,11 @@ export const MonitorStatusRow: Component<IMonitorStatusRow> = (
};
};

const getPercentage = (hour: MonitorStatusHourViewModel) => {
const successPerc = hour.numSuccessStatuses / hour.numStatuses;
return successPerc * 100;
};

return (
<div class="status-row" data-num-bars={numBars()}>
<For each={getHourArr(numBars())}>
Expand All @@ -94,13 +91,13 @@ export const MonitorStatusRow: Component<IMonitorStatusRow> = (
mt="0.5em"
label={
<>
<MonitorStatusIcon maxStatus={hour.maxStatus} />
<MonitorStatusIcon percentage={getPercentage(hour)} />
{monitorHourFormat(hoursToEpoch(hour.hourSinceEpochInterval))}
</>
}
>
<div
class={classNames("bar", "bar-" + hour.maxStatus)}
class={classNames("bar", "bar-" + 0)}
style={getOverrideStyleBasedOnMinuteStatuses(hour)}
onClick={() => props.setModalContent(hour)}
></div>
Expand All @@ -112,12 +109,13 @@ export const MonitorStatusRow: Component<IMonitorStatusRow> = (
};

interface IMonitorStatusIcon {
maxStatus: number;
percentage: number;
}
export const MonitorStatusIcon: Component<IMonitorStatusIcon> = (
props: IMonitorStatusIcon
) => {
if (props.maxStatus === 0) return <QuestionMarkIcon />;
if (props.maxStatus === 2) return <CheckMarkIcon />;
if (props.percentage === 100) return <CheckMarkIcon />;
if (props.percentage < 100 && props.percentage > 33)
return <QuestionMarkIcon />;
return <ErrorCrossIcon />;
};
1 change: 0 additions & 1 deletion src/contracts/MonitorStatusViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export interface MonitorStatusViewModel {
}

export interface MonitorStatusHourViewModel {
maxStatus: number;
numStatuses: number;
numSuccessStatuses: number;
hourSinceEpochInterval: number;
Expand Down

0 comments on commit cac504a

Please sign in to comment.