Skip to content

Commit

Permalink
added skeleton loaders to home screen (#951)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsladerman committed May 10, 2024
1 parent 75df2dd commit e71186e
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from 'components/cd/clusters/Clusters'
import { useFetchPaginatedData } from 'components/cd/utils/useFetchPaginatedData'
import { GqlError } from 'components/utils/Alert'
import LoadingIndicator from 'components/utils/LoadingIndicator'
import { useClustersQuery, useUpgradeStatisticsQuery } from 'generated/graphql'

import { POLL_INTERVAL } from 'components/cd/ContinuousDeployment'
Expand Down Expand Up @@ -46,10 +45,6 @@ export function ClusterOverviewCard() {
return <GqlError error={tableError} />
}

if (!tableData?.clusters?.edges) {
return <LoadingIndicator />
}

return (
<HomeCard overflow="none">
<div
Expand All @@ -71,7 +66,7 @@ export function ClusterOverviewCard() {
}}
>
<ClusterOverViewTable
data={tableData.clusters.edges}
data={tableData?.clusters?.edges}
refetch={refetch}
virtualizeRows
hasNextPage={pageInfo?.hasNextPage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import {
} from 'components/utils/RadialBarChart'
import { UpgradeStatisticsQuery } from 'generated/graphql'
import styled from 'styled-components'
import LoadingIndicator from 'components/utils/LoadingIndicator'

import { useMemo } from 'react'

import { ChartSkeleton } from 'components/utils/SkeletonLoaders'

import { CustomLegend } from './CustomLegend'

const CHART_SIZE = 275
Expand All @@ -29,7 +30,7 @@ export function ClusterOverviewChart({
const { chartData, legendData } = useChartData(data || {}, chartColors)

if (!data?.upgradeStatistics) {
return <LoadingIndicator />
return <ChartSkeleton />
}

const CenterLabel = createCenteredMetric(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from 'components/cd/clusters/ClustersColumns'
import { TableCaretLink } from 'components/cluster/TableElements'
import { CLUSTERS_REACT_VIRTUAL_OPTIONS } from 'components/cd/clusters/Clusters'
import { TableSkeleton } from 'components/utils/SkeletonLoaders'

export function ClusterOverViewTable({
refetch,
Expand All @@ -28,6 +29,10 @@ export function ClusterOverViewTable({
meta: { refetch },
}

if (!data) {
return <TableSkeleton centered />
}

return (
<Table
loose
Expand Down
8 changes: 2 additions & 6 deletions assets/src/components/home/deployments/DeploymentsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
SERVICES_REACT_VIRTUAL_OPTIONS,
} from 'components/cd/services/Services'
import { GqlError } from 'components/utils/Alert'
import LoadingIndicator from 'components/utils/LoadingIndicator'
import pluralize from 'pluralize'

import { Title2H1 } from '../../utils/typography/Text'
Expand Down Expand Up @@ -40,11 +39,8 @@ export function DeploymentsCard() {
if (error) {
return <GqlError error={error} />
}
if (!data?.serviceDeployments?.edges) {
return <LoadingIndicator />
}

const numDeployments = data.serviceDeployments.edges.length
const numDeployments = data?.serviceDeployments?.edges?.length

return (
<div>
Expand All @@ -53,7 +49,7 @@ export function DeploymentsCard() {
errors
</Title2H1>
<DeploymentsTable
data={data.serviceDeployments.edges}
data={data?.serviceDeployments?.edges}
emptyStateProps={{ message: 'All services healthy!' }}
refetch={refetch}
virtualizeRows
Expand Down
5 changes: 5 additions & 0 deletions assets/src/components/home/deployments/DeploymentsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ColServiceDeployment,
ColStatus,
} from 'components/cd/services/ServicesColumns'
import { TableSkeleton } from 'components/utils/SkeletonLoaders'

export function DeploymentsTable({
refetch,
Expand All @@ -29,6 +30,10 @@ export function DeploymentsTable({
meta: { refetch },
}

if (!data) {
return <TableSkeleton centered />
}

return (
<Table
loose
Expand Down
8 changes: 2 additions & 6 deletions assets/src/components/home/pullrequests/PrCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useFetchPaginatedData } from 'components/cd/utils/useFetchPaginatedData
import { usePullRequestsQuery } from 'generated/graphql'
import { PR_QUERY_PAGE_SIZE } from 'components/pr/queue/PrQueue'
import { GqlError } from 'components/utils/Alert'
import LoadingIndicator from 'components/utils/LoadingIndicator'

import { Title2H1 } from '../../utils/typography/Text'

Expand Down Expand Up @@ -32,19 +31,16 @@ export function PrCard() {
if (error) {
return <GqlError error={error} />
}
if (!data?.pullRequests?.edges) {
return <LoadingIndicator />
}

const numPrs = data.pullRequests.edges.length
const numPrs = data?.pullRequests?.edges?.length || '-'
const headerText =
numPrs === 1 ? `1 PR needs action` : `${numPrs} PRs need action`

return (
<div>
<Title2H1>{headerText}</Title2H1>
<PrTable
data={data.pullRequests.edges}
data={data?.pullRequests?.edges}
emptyStateProps={{ message: 'All services healthy!' }}
refetch={refetch}
virtualizeRows
Expand Down
5 changes: 5 additions & 0 deletions assets/src/components/home/pullrequests/PrTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Table } from '@pluralsh/design-system'
import { ComponentProps } from 'react'
import { prColumns } from 'components/pr/queue/PrQueueColumns'
import { PRS_REACT_VIRTUAL_OPTIONS } from 'components/pr/queue/PrQueue'
import { TableSkeleton } from 'components/utils/SkeletonLoaders'

export function PrTable({
refetch,
Expand All @@ -15,6 +16,10 @@ export function PrTable({
meta: { refetch },
}

if (!data) {
return <TableSkeleton />
}

return (
<Table
loose
Expand Down
168 changes: 168 additions & 0 deletions assets/src/components/utils/SkeletonLoaders.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import styled, { keyframes, useTheme } from 'styled-components'

const shimmerKeyframes = keyframes`
0% {
stop-color: #2D3037;
}
50% {
stop-color: #393C44;
}
100% {
stop-color: #2D3037;
}
`
const LinearGradient = styled.linearGradient`
stop {
animation: ${shimmerKeyframes} 1.5s linear infinite;
}
`

export function TableSkeleton({
width = 870,
height = 312,
numRows = 8,
numColumns = 2,
centered = false,
}) {
const theme = useTheme()

return (
<div
css={{
overflow: 'hidden',
...(centered
? {
display: 'flex',
alignSelf: 'center',
justifyContent: 'center',
width: '100%',
}
: {}),
}}
>
<svg
width={width + theme.spacing.large * numColumns}
height={height}
viewBox={`0 0 ${width + theme.spacing.large * numColumns} ${height}`}
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
{Array.from({ length: numRows * numColumns }, (_, i) => (
<rect
key={i}
x={(i % numColumns) * (width / numColumns + theme.spacing.large)}
y={Math.floor(i / numColumns) * 60}
width={width / numColumns}
height="12"
rx="4"
fill={`url(#paint${i}_linear)`}
/>
))}
<defs>
{Array.from({ length: numRows * numColumns }, (_, i) => (
<LinearGradient
key={i}
id={`paint${i}_linear`}
x1={(i % numColumns) * (width / numColumns)}
y1={Math.floor(i / numColumns) * 60 + 6}
x2={((i % numColumns) + 1) * (width / numColumns)}
y2={Math.floor(i / numColumns) * 60 + 6}
gradientUnits="userSpaceOnUse"
>
<stop
offset="0%"
stopColor="#2D3037"
/>
<stop
offset="100%"
stopColor="#393C44"
/>
</LinearGradient>
))}
</defs>
</svg>
</div>
)
}

export function ChartSkeleton({ _centered }: { _centered?: boolean }) {
return (
<svg
width="276"
height="314"
viewBox="0 0 276 314"
xmlns="http://www.w3.org/2000/svg"
>
<rect
x="30"
y="302"
width="217"
height="12"
rx="4"
fill="url(#paint0)"
/>
<path
d="M0 138C0 61.7847 61.7848 0 138 0C214.215 0 276 61.7847 276 138C276 214.215 214.215 276 138 276C61.7847 276 0 214.215 0 138ZM253.202 138C253.202 74.3755 201.625 22.7976 138 22.7976C74.3755 22.7976 22.7976 74.3755 22.7976 138C22.7976 201.625 74.3755 253.202 138 253.202C201.625 253.202 253.202 201.625 253.202 138Z"
fill="url(#paint1)"
/>
<rect
x="106"
y="132"
width="65"
height="12"
rx="4"
fill="url(#paint2)"
/>
<defs>
<LinearGradient
id="paint0"
x1="30"
y1="308"
x2="247"
y2="308"
>
<stop
offset="0%"
stopColor="#2D3037"
/>
<stop
offset="100%"
stopColor="#393C44"
/>
</LinearGradient>
<LinearGradient
id="paint1"
x1="276"
y1="138"
x2="0"
y2="138"
>
<stop
offset="0%"
stopColor="#2D3037"
/>
<stop
offset="100%"
stopColor="#393C44"
/>
</LinearGradient>
<LinearGradient
id="paint2"
x1="106"
y1="138"
x2="171"
y2="138"
>
<stop
offset="0%"
stopColor="#2D3037"
/>
<stop
offset="100%"
stopColor="#393C44"
/>
</LinearGradient>
</defs>
</svg>
)
}

0 comments on commit e71186e

Please sign in to comment.