Skip to content

Improve error handling and add loading state in List component #1487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions ui/src/pages/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Dropdown,
OverlayTrigger,
Row,
Spinner,
Table,
Tooltip as OverlayTooltip,
} from 'react-bootstrap'
Expand All @@ -16,7 +17,7 @@ import {useLocation, useNavigate} from 'react-router-dom'
import Navbar from '../components/Navbar'
import {Labels, labelsString, MetricName, parseLabels} from '../labels'
import {createConnectTransport} from '@bufbuild/connect-web'
import {createPromiseClient} from '@connectrpc/connect'
import {createPromiseClient, Code} from '@connectrpc/connect'
import {ObjectiveService} from '../proto/objectives/v1alpha1/objectives_connect'
import {
Alert as ObjectiveAlert,
Expand Down Expand Up @@ -459,7 +460,7 @@ const List = () => {
// TODO: Pass in the search to the useObjectivesList hook
const {
response: objectiveResponse,
// error: objectiveError,
error: objectiveError,
status: objectiveStatus,
} = useObjectivesList(client, labelsString(filterLabels), '')

Expand Down Expand Up @@ -670,6 +671,54 @@ const List = () => {
)}`
}

if (objectiveStatus === 'loading') {
return (
<>
<Navbar />
<Container className="content list">
<Row className="mt-3 justify-content-center">
<Col xs="auto" className="text-center">
<Spinner animation="border" role="status">
<span className="visually-hidden">Loading objectives...</span>
</Spinner>
<p className="mt-3">Loading objectives...</p>
</Col>
</Row>
</Container>
</>
)
}

if (objectiveError !== null && objectiveError !== undefined) {
return (
<>
<Navbar />
<Container className="content list">
<Row className="mt-3">
<Col>
{objectiveError.code === Code.Unavailable && (
<Alert variant="danger">
<h5>Backend connection failed</h5>
<p className="mb-0">
Cannot reach the backend service. Ensure the <b>filesystem</b> or{' '}
<b>Kubernetes</b> backend is running.
</p>
</Alert>
)}
{objectiveError.code !== Code.NotFound &&
objectiveError.code !== Code.Unavailable && (
<Alert variant="danger">
<h5>Error loading objectives</h5>
<p className="mb-0">{objectiveError.message}</p>
</Alert>
)}
</Col>
</Row>
</Container>
</>
)
}

return (
<>
<Navbar />
Expand Down
Loading