feat: add starting state to sidebar indicator (#587)

This commit is contained in:
Cafe137
2022-11-22 10:33:38 +01:00
committed by GitHub
parent c3a940c8d7
commit 848e61a7a0
4 changed files with 21 additions and 12 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ export default function Card({ buttonProps, icon, title, subtitle, status }: Pro
} else if (status === 'error') { } else if (status === 'error') {
statusIcon = <AlertCircle size="13" color="#f44336" /> statusIcon = <AlertCircle size="13" color="#f44336" />
} else if (status === 'loading') { } else if (status === 'loading') {
statusIcon = <RefreshLine size="13" color="#096cca" /> statusIcon = <RefreshLine size="13" color="orange" />
} }
return ( return (
+3
View File
@@ -25,6 +25,9 @@ export default function StatusIcon({ checkState, size, className, isLoading }: P
case CheckState.ERROR: case CheckState.ERROR:
backgroundColor = '#ff3a52' backgroundColor = '#ff3a52'
break break
case CheckState.STARTING:
backgroundColor = 'orange'
break
default: default:
// Default is error // Default is error
backgroundColor = '#ff3a52' backgroundColor = '#ff3a52'
+2 -2
View File
@@ -9,10 +9,10 @@ import { CheckState, Context as BeeContext } from '../../providers/Bee'
import { ROUTES } from '../../routes' import { ROUTES } from '../../routes'
export default function NodeInfoCard(): ReactElement { export default function NodeInfoCard(): ReactElement {
const { debugApiHealth, debugApiReadiness, status } = useContext(BeeContext) const { status } = useContext(BeeContext)
const navigate = useNavigate() const navigate = useNavigate()
if (debugApiHealth && !debugApiReadiness) { if (status.all === CheckState.STARTING) {
return ( return (
<Card <Card
buttonProps={{ iconType: Settings, children: 'Open node setup', onClick: () => navigate(ROUTES.STATUS) }} buttonProps={{ iconType: Settings, children: 'Open node setup', onClick: () => navigate(ROUTES.STATUS) }}
+15 -9
View File
@@ -25,6 +25,7 @@ export enum CheckState {
OK = 'OK', OK = 'OK',
WARNING = 'Warning', WARNING = 'Warning',
ERROR = 'Error', ERROR = 'Error',
STARTING = 'Starting',
} }
interface StatusItem { interface StatusItem {
@@ -119,7 +120,7 @@ interface Props {
function getStatus( function getStatus(
debugApiHealth: Health | null, debugApiHealth: Health | null,
nodeAddresses: NodeAddresses | null, debugApiReadiness: boolean,
nodeInfo: NodeInfo | null, nodeInfo: NodeInfo | null,
apiHealth: boolean, apiHealth: boolean,
topology: Topology | null, topology: Topology | null,
@@ -171,18 +172,23 @@ function getStatus(
else status.chequebook.checkState = CheckState.OK else status.chequebook.checkState = CheckState.OK
} }
// Determine overall status status.all = determineOverallStatus(debugApiHealth, debugApiReadiness, status)
if (Object.values(status).some(({ isEnabled, checkState }) => isEnabled && checkState === CheckState.ERROR)) {
status.all = CheckState.ERROR return status
}
function determineOverallStatus(debugApiHealth: Health | null, debugApiReadiness: boolean, status: Status): CheckState {
if (debugApiHealth?.status === 'ok' && !debugApiReadiness) {
return CheckState.STARTING
} else if (Object.values(status).some(({ isEnabled, checkState }) => isEnabled && checkState === CheckState.ERROR)) {
return CheckState.ERROR
} else if ( } else if (
Object.values(status).some(({ isEnabled, checkState }) => isEnabled && checkState === CheckState.WARNING) Object.values(status).some(({ isEnabled, checkState }) => isEnabled && checkState === CheckState.WARNING)
) { ) {
status.all = CheckState.WARNING return CheckState.WARNING
} else { } else {
status.all = CheckState.OK return CheckState.OK
} }
return status
} }
// This does not need to be exposed and works much better as variable than state variable which may trigger some unnecessary re-renders // This does not need to be exposed and works much better as variable than state variable which may trigger some unnecessary re-renders
@@ -390,7 +396,7 @@ export function Provider({ children }: Props): ReactElement {
const status = getStatus( const status = getStatus(
debugApiHealth, debugApiHealth,
nodeAddresses, debugApiReadiness,
nodeInfo, nodeInfo,
apiHealth, apiHealth,
topology, topology,