Skip to content

Commit 1010bce

Browse files
authored
feat: show-card-loading-state-and-prevent-opening-until-data-arrives (#6165)
1 parent b4f962e commit 1010bce

4 files changed

Lines changed: 25 additions & 19 deletions

File tree

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React from 'react'
1+
import React, { FC } from 'react'
22

3-
export default function AppLoader() {
3+
const AppLoader: FC = () => {
44
return (
55
<div
66
style={{
@@ -14,3 +14,5 @@ export default function AppLoader() {
1414
</div>
1515
)
1616
}
17+
18+
export default AppLoader

frontend/web/components/base/accordion/AccordionCard.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ interface AccordionCardProps {
88
title?: string
99
className?: string
1010
defaultOpen?: boolean
11+
isLoading?: boolean
1112
}
1213

1314
const AccordionCard: FC<AccordionCardProps> = ({
1415
children,
1516
defaultOpen = false,
17+
isLoading = false,
1618
title = 'Summary',
1719
}) => {
1820
const [open, setOpen] = useState(defaultOpen)
@@ -26,16 +28,21 @@ const AccordionCard: FC<AccordionCardProps> = ({
2628
display: 'flex',
2729
justifyContent: 'space-between',
2830
}}
29-
onClick={() => setOpen(!open)}
31+
onClick={isLoading ? undefined : () => setOpen(!open)}
3032
className='d-flex flex-row justify-content-between font-weight-medium'
3133
>
32-
{title}
33-
<IconButton size='small'>
34-
<IonIcon
35-
className='fs-small me-2 text-muted'
36-
icon={open ? chevronUp : chevronDown}
37-
/>
38-
</IconButton>
34+
<div className='d-flex flex-row align-items-center gap-1'>
35+
{title}
36+
{isLoading && <Loader width='15px' height='15px' />}
37+
</div>
38+
{!isLoading && (
39+
<IconButton size='small'>
40+
<IonIcon
41+
className='fs-small me-2 text-muted'
42+
icon={open ? chevronUp : chevronDown}
43+
/>
44+
</IconButton>
45+
)}
3946
</div>
4047
<Collapse in={open}>
4148
<div className='mt-2 mb-2'>{children}</div>

frontend/web/components/metrics/EnvironmentMetricsList.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const EnvironmentMetricsList: FC<EnvironmentMetricsListProps> = ({
1515
forceRefetch,
1616
projectId,
1717
}) => {
18-
const { data, refetch } = useGetEnvironmentMetricsQuery({
18+
const { data, isLoading, refetch } = useGetEnvironmentMetricsQuery({
1919
id: environmentApiKey,
2020
})
2121

@@ -30,13 +30,9 @@ const EnvironmentMetricsList: FC<EnvironmentMetricsListProps> = ({
3030
}
3131
}, [forceRefetch, refetch])
3232

33-
if (!data || data.metrics.length === 0) {
34-
return null
35-
}
36-
3733
return (
3834
<div className='mb-3'>
39-
<AccordionCard title='Summary'>
35+
<AccordionCard title='Summary' isLoading={isLoading}>
4036
<div className='flex gap-2 mt-4'>
4137
<div
4238
className='metrics-grid'

frontend/web/project/project-components.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,21 @@ window.Loader = class extends PureComponent {
4747
static displayName = 'Loader'
4848

4949
render() {
50+
const { fill = '#6633ff', height = '40px', width = '40px' } = this.props
5051
return (
5152
<svg
5253
className='loader'
5354
version='1.1'
5455
id='loader-1'
5556
x='0px'
5657
y='0px'
57-
width='40px'
58-
height='40px'
58+
width={width}
59+
height={height}
5960
viewBox='0 0 50 50'
6061
style={{ enableBackground: '0 0 50 50' }}
6162
>
6263
<path
63-
fill='#6633ff'
64+
fill={fill}
6465
d='M25.251,6.461c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615V6.461z'
6566
>
6667
<animateTransform

0 commit comments

Comments
 (0)