Skip to content

Commit 0dd6e01

Browse files
authored
RI-7065: Replace EUI Progress with custom Progress Bar Loader (#4663)
* create progress bar loader component * replace EuiProgress with ProgressBarLoader * apply the background color logic; this will be extracted and reused at a later point
1 parent e3f0b73 commit 0dd6e01

File tree

21 files changed

+141
-92
lines changed

21 files changed

+141
-92
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
export { default as Loader } from './loader/Loader'
1+
import Loader from './loader/Loader'
2+
import ProgressBarLoader from './progress-bar/ProgressBarLoader'
3+
4+
export { Loader, ProgressBarLoader }

redisinsight/ui/src/components/base/display/loader/Loader.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ const convertSizeToPx = (tShirtSize: string, space: Space) => {
2222
}
2323
}
2424

25-
export default function Loader({ size, ...rest }: RedisLoaderProps) {
25+
const Loader = ({ size, ...rest }: RedisLoaderProps) => {
2626
const theme = useTheme()
2727
const { space } = theme.core
2828
const sizeInPx = size ? convertSizeToPx(size, space) : space.space100
2929
return <RedisLoader size={sizeInPx} {...rest} />
3030
}
31+
32+
export default Loader
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react'
2+
import {
3+
LoaderBar,
4+
ProgressBarLoaderProps,
5+
LoaderContainer,
6+
} from './progress-bar-loader.styles'
7+
8+
const ProgressBarLoader = ({
9+
className,
10+
style,
11+
color,
12+
...rest
13+
}: ProgressBarLoaderProps) => (
14+
<LoaderContainer className={className} style={style} {...rest}>
15+
<LoaderBar $color={color} />
16+
</LoaderContainer>
17+
)
18+
19+
export default ProgressBarLoader
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { Theme, theme } from '@redis-ui/styles'
2+
import { ReactNode } from 'react'
3+
import styled, { css, keyframes } from 'styled-components'
4+
5+
export type EuiColorNames =
6+
| 'inherit'
7+
| 'default'
8+
| 'primary'
9+
| 'danger'
10+
| 'warning'
11+
| 'success'
12+
13+
interface LoaderBarProps {
14+
color?: string
15+
}
16+
17+
export type ColorType = EuiColorNames | (string & {})
18+
type ThemeColors = typeof theme.semantic.color
19+
20+
export const getBarBackgroundColor = (
21+
themeColors: ThemeColors,
22+
color?: ColorType,
23+
) => {
24+
if (!color) {
25+
return themeColors.background.primary300
26+
}
27+
28+
const barBackgroundColors: Record<ColorType, string> = {
29+
inherit: 'inherit',
30+
default: themeColors.background.primary300,
31+
primary: themeColors.background.primary300,
32+
danger: themeColors.background.danger600,
33+
warning: themeColors.background.attention600,
34+
success: themeColors.background.success600,
35+
}
36+
37+
return barBackgroundColors[color] ?? color
38+
}
39+
40+
export interface MapProps extends LoaderBarProps {
41+
$color?: ColorType
42+
theme: Theme
43+
}
44+
45+
export const getColorBackgroundStyles = ({ $color, theme }: MapProps) => {
46+
const colors = theme.semantic.color
47+
48+
const getColorValue = (color?: ColorType) =>
49+
getBarBackgroundColor(colors, color)
50+
51+
return css`
52+
background-color: ${getColorValue($color)};
53+
`
54+
}
55+
56+
const loading = keyframes`
57+
0% {
58+
transform: scaleX(1) translateX(-100%);
59+
}
60+
100% {
61+
transform: scaleX(1) translateX(100%);
62+
}
63+
`
64+
65+
interface LoaderContainerProps {
66+
children?: ReactNode
67+
style?: React.CSSProperties
68+
className?: string
69+
}
70+
71+
export const LoaderContainer = styled.div<LoaderContainerProps>`
72+
position: relative;
73+
height: 3px;
74+
overflow: hidden;
75+
border-radius: 2px;
76+
`
77+
78+
export const LoaderBar = styled.div<MapProps>`
79+
${({ $color, theme }) => getColorBackgroundStyles({ $color, theme })};
80+
81+
position: absolute;
82+
height: 100%;
83+
width: 100%;
84+
border-radius: 2px;
85+
86+
animation: ${loading} 1s ease-in-out infinite;
87+
`
88+
89+
export type ProgressBarLoaderProps = LoaderContainerProps & LoaderBarProps

redisinsight/ui/src/components/base/layout/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ResizableContainer from './resize/container/ResizableContainer'
44
import ResizablePanel from './resize/panel/ResizablePanel'
55
import ResizablePanelHandle from './resize/handle/ResizablePanelHandle'
66

7+
78
export * from './card'
89
export {
910
HorizontalRule,

redisinsight/ui/src/components/multi-search/MultiSearch.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EuiFieldText, EuiIcon, EuiProgress, keys } from '@elastic/eui'
1+
import { EuiFieldText, EuiIcon, keys } from '@elastic/eui'
22
import cx from 'classnames'
33
import React, { ChangeEvent, useEffect, useRef, useState } from 'react'
44

@@ -15,6 +15,7 @@ import {
1515
ActionIconButton,
1616
IconButton,
1717
} from 'uiSrc/components/base/forms/buttons'
18+
import { ProgressBarLoader } from 'uiSrc/components/base/display'
1819
import styles from './styles.module.scss'
1920

2021
interface MultiSearchSuggestion {
@@ -204,11 +205,9 @@ const MultiSearch = (props: Props) => {
204205
data-testid="suggestions"
205206
>
206207
{suggestions?.loading && (
207-
<EuiProgress
208-
color="primary"
209-
size="xs"
210-
position="absolute"
208+
<ProgressBarLoader
211209
data-testid="progress-suggestions"
210+
color="primary"
212211
/>
213212
)}
214213
<ul role="listbox">

redisinsight/ui/src/components/virtual-grid/VirtualGrid.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import React, { useCallback, useEffect, useRef, useState } from 'react'
22
import cx from 'classnames'
33
import AutoSizer, { Size } from 'react-virtualized-auto-sizer'
44
import { isObject, xor } from 'lodash'
5-
import { EuiProgress, EuiIcon } from '@elastic/eui'
5+
import { EuiIcon } from '@elastic/eui'
66
import InfiniteLoader from 'react-window-infinite-loader'
77
import { VariableSizeGrid as Grid, GridChildComponentProps } from 'react-window'
88

99
import { Maybe, Nullable } from 'uiSrc/utils'
1010
import { SortOrder } from 'uiSrc/constants'
1111
import { SCAN_COUNT_DEFAULT } from 'uiSrc/constants/api'
1212
import { Text } from 'uiSrc/components/base/text'
13+
import { ProgressBarLoader } from 'uiSrc/components/base/display'
1314
import { IProps } from './interfaces'
1415
import { getColumnWidth, useInnerElementType } from './utils'
1516

@@ -308,10 +309,8 @@ const VirtualGrid = (props: IProps) => {
308309
data-testid="virtual-grid-container"
309310
>
310311
{loading && !hideProgress && (
311-
<EuiProgress
312+
<ProgressBarLoader
312313
color="primary"
313-
size="xs"
314-
position="absolute"
315314
className={styles.progress}
316315
data-testid="progress-entry-list"
317316
/>

redisinsight/ui/src/components/virtual-grid/styles.module.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ $paddingCell: 12px;
7878
overflow-y: hidden !important;
7979
}
8080

81-
.progress {
82-
z-index: 2;
83-
}
84-
8581
.container {
8682
position: relative;
8783
height: 100%;

redisinsight/ui/src/components/virtual-table/VirtualTable.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EuiIcon, EuiProgress } from '@elastic/eui'
1+
import { EuiIcon } from '@elastic/eui'
22
import cx from 'classnames'
33
import { findIndex, isNumber, sumBy, xor } from 'lodash'
44
import React, { useCallback, useEffect, useRef, useState } from 'react'
@@ -21,7 +21,7 @@ import { isEqualBuffers, Maybe, Nullable } from 'uiSrc/utils'
2121

2222
import { Text } from 'uiSrc/components/base/text'
2323
import { RIResizeObserver } from 'uiSrc/components/base/utils'
24-
24+
import { ProgressBarLoader } from 'uiSrc/components/base/display'
2525
import {
2626
ColumnWidthSizes,
2727
IColumnSearchState,
@@ -599,12 +599,9 @@ const VirtualTable = (props: IProps) => {
599599
data-testid="virtual-table-container"
600600
>
601601
{loading && !hideProgress && (
602-
<EuiProgress
602+
<ProgressBarLoader
603603
color="primary"
604-
size="xs"
605-
position="absolute"
606-
className={styles.progress}
607-
data-testid="progress-key-list"
604+
data-testid="progress-key-table"
608605
/>
609606
)}
610607
<InfiniteLoader

redisinsight/ui/src/components/virtual-table/styles.module.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ $footerHeight: 38px;
1313
overflow-y: hidden !important;
1414
}
1515

16-
.progress {
17-
z-index: 2;
18-
}
19-
2016
.container {
2117
position: relative;
2218
height: 100%;

0 commit comments

Comments
 (0)