Skip to content
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

chore(dashboard): add loading state #1155

Merged
merged 2 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
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
17 changes: 15 additions & 2 deletions src/layouts/ReviewRequest/Dashboard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { markReviewRequestAsViewedHandler } from "../../mocks/handlers"
import { ReviewRequestDashboard } from "./Dashboard"

const dashboardMeta = {
title: "Components/ReviewRequest/Dashboard",
title: "Pages/ReviewRequest",
component: ReviewRequestDashboard,
parameters: {
msw: {
Expand Down Expand Up @@ -51,6 +51,19 @@ const dashboardMeta = {

const Template = ReviewRequestDashboard

export const Playground: Story = Template.bind({})
export const Default: Story = Template.bind({})

export const Loading: Story = Template.bind({})
Loading.parameters = {
msw: {
handlers: {
reviewRequest: buildReviewRequestData(
{
reviewRequest: MOCK_REVIEW_REQUEST,
},
"infinite"
),
},
},
}
export default dashboardMeta
56 changes: 37 additions & 19 deletions src/layouts/ReviewRequest/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
PopoverArrow,
IconButton,
useDisclosure,
Skeleton,
} from "@chakra-ui/react"
import { Button } from "@opengovsg/design-system-react"
import { Footer } from "components/Footer"
Expand Down Expand Up @@ -58,7 +59,6 @@ export const ReviewRequestDashboard = (): JSX.Element => {
const { onOpen, isOpen, onClose } = useDisclosure()
// TODO!: redirect to /sites if cannot parse reviewId as string
const prNumber = parseInt(reviewId, 10)
// TODO!: Refactor so that loading is not a concern here
const { data, isLoading: isGetReviewRequestLoading } = useGetReviewRequest(
siteName,
prNumber
Expand All @@ -69,7 +69,6 @@ export const ReviewRequestDashboard = (): JSX.Element => {
const {
mutateAsync: updateReviewRequestViewed,
} = useUpdateReviewRequestViewed()
// TODO!: redirect to /sites if cannot parse reviewId as string
const {
mutateAsync: mergeReviewRequest,
isLoading: isMergingReviewRequest,
Expand All @@ -92,8 +91,8 @@ export const ReviewRequestDashboard = (): JSX.Element => {
}, [reviewStatus, setRedirectToPage, siteName])

useEffect(() => {
updateReviewRequestViewed({ siteName, prNumber: parseInt(reviewId, 10) })
}, [reviewId, siteName, updateReviewRequestViewed])
updateReviewRequestViewed({ siteName, prNumber })
}, [prNumber, siteName, updateReviewRequestViewed])

return (
<>
Expand All @@ -116,7 +115,13 @@ export const ReviewRequestDashboard = (): JSX.Element => {
>
<Flex w="100%">
<HStack spacing="0.25rem">
<Text textStyle="h5">{data?.title || ""}</Text>
<Skeleton
isLoaded={!isGetReviewRequestLoading}
minW="10rem"
minH="1rem"
>
<Text textStyle="h5">{data?.title}</Text>
</Skeleton>
{/* Closes after 1.5s and does not refocus on the button to avoid the outline */}
<Popover returnFocusOnClose={false} isOpen={hasCopied}>
<PopoverTrigger>
Expand All @@ -125,6 +130,7 @@ export const ReviewRequestDashboard = (): JSX.Element => {
variant="clear"
aria-label="link to pull request"
onClick={onCopy}
isLoading={isGetReviewRequestLoading}
/>
</PopoverTrigger>
<PopoverContent
Expand All @@ -150,28 +156,40 @@ export const ReviewRequestDashboard = (): JSX.Element => {
<ApprovalButton isApproved={isApproved} />
)}
</Flex>
<SecondaryDetails
requestor={data?.requestor || ""}
reviewers={data?.reviewers || []}
reviewRequestedTime={
data?.reviewRequestedTime
? new Date(data?.reviewRequestedTime)
: new Date()
}
admins={
collaborators
?.filter((user) => user.role === "ADMIN")
.map(({ email }) => email) || []
<Skeleton
isLoaded={
!!(
data?.requestor &&
data?.reviewers &&
data?.reviewRequestedTime
)
}
/>
>
<SecondaryDetails
requestor={data?.requestor || ""}
reviewers={data?.reviewers || []}
reviewRequestedTime={
data?.reviewRequestedTime
? new Date(data?.reviewRequestedTime)
: new Date()
}
admins={
collaborators
?.filter((user) => user.role === "ADMIN")
.map(({ email }) => email) || []
}
/>
</Skeleton>
</VStack>
<Flex h="100%" w="7.25rem" pt="2rem" justifyContent="end">
{/* TODO: swap this to a slide out component and not a drawer */}
<CommentsDrawer siteName={siteName} requestId={prNumber} />
</Flex>
</HStack>
<Box pl="9.25rem" pr="2rem">
<RequestOverview items={data?.changedItems || []} allowEditing />
<Skeleton isLoaded={!isGetReviewRequestLoading}>
<RequestOverview items={data?.changedItems || []} allowEditing />
</Skeleton>
</Box>
{isApproved && (
<Footer>
Expand Down