Skip to content

Commit

Permalink
feat: add starting state to sidebar indicator (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cafe137 authored Nov 22, 2022
1 parent c3a940c commit 848e61a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/components/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function Card({ buttonProps, icon, title, subtitle, status }: Pro
} else if (status === 'error') {
statusIcon = <AlertCircle size="13" color="#f44336" />
} else if (status === 'loading') {
statusIcon = <RefreshLine size="13" color="#096cca" />
statusIcon = <RefreshLine size="13" color="orange" />
}

return (
Expand Down
3 changes: 3 additions & 0 deletions src/components/StatusIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export default function StatusIcon({ checkState, size, className, isLoading }: P
case CheckState.ERROR:
backgroundColor = '#ff3a52'
break
case CheckState.STARTING:
backgroundColor = 'orange'
break
default:
// Default is error
backgroundColor = '#ff3a52'
Expand Down
4 changes: 2 additions & 2 deletions src/pages/info/NodeInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { CheckState, Context as BeeContext } from '../../providers/Bee'
import { ROUTES } from '../../routes'

export default function NodeInfoCard(): ReactElement {
const { debugApiHealth, debugApiReadiness, status } = useContext(BeeContext)
const { status } = useContext(BeeContext)
const navigate = useNavigate()

if (debugApiHealth && !debugApiReadiness) {
if (status.all === CheckState.STARTING) {
return (
<Card
buttonProps={{ iconType: Settings, children: 'Open node setup', onClick: () => navigate(ROUTES.STATUS) }}
Expand Down
24 changes: 15 additions & 9 deletions src/providers/Bee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export enum CheckState {
OK = 'OK',
WARNING = 'Warning',
ERROR = 'Error',
STARTING = 'Starting',
}

interface StatusItem {
Expand Down Expand Up @@ -119,7 +120,7 @@ interface Props {

function getStatus(
debugApiHealth: Health | null,
nodeAddresses: NodeAddresses | null,
debugApiReadiness: boolean,
nodeInfo: NodeInfo | null,
apiHealth: boolean,
topology: Topology | null,
Expand Down Expand Up @@ -171,18 +172,23 @@ function getStatus(
else status.chequebook.checkState = CheckState.OK
}

// Determine overall status
if (Object.values(status).some(({ isEnabled, checkState }) => isEnabled && checkState === CheckState.ERROR)) {
status.all = CheckState.ERROR
status.all = determineOverallStatus(debugApiHealth, debugApiReadiness, status)

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 (
Object.values(status).some(({ isEnabled, checkState }) => isEnabled && checkState === CheckState.WARNING)
) {
status.all = CheckState.WARNING
return CheckState.WARNING
} 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
Expand Down Expand Up @@ -390,7 +396,7 @@ export function Provider({ children }: Props): ReactElement {

const status = getStatus(
debugApiHealth,
nodeAddresses,
debugApiReadiness,
nodeInfo,
apiHealth,
topology,
Expand Down

0 comments on commit 848e61a

Please sign in to comment.