Skip to content

Commit 52fa904

Browse files
jpggvilacadwesolow
authored andcommitted
Move circular-progress to dataset-import folder
1 parent e2d7f02 commit 52fa904

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright (C) 2022-2025 Intel Corporation
2+
// LIMITED EDGE SOFTWARE DISTRIBUTION LICENSE
3+
4+
import { useMemo } from 'react';
5+
6+
import { ColorValue } from '@react-types/shared/src/dna';
7+
8+
interface CircularProgressProps {
9+
percentage: number;
10+
size?: number;
11+
labelFontSize?: number;
12+
strokeWidth?: number;
13+
labelFontColor?: ColorValue;
14+
backStrokeColor?: ColorValue;
15+
color?: ColorValue;
16+
hasError?: boolean;
17+
checkMarkOnComplete?: boolean;
18+
checkMarkSize?: number;
19+
checkMarkColor?: ColorValue | string;
20+
}
21+
22+
export const CircularProgress = ({
23+
percentage,
24+
size = 50,
25+
strokeWidth = 4,
26+
labelFontSize = 10,
27+
labelFontColor = 'gray-600',
28+
backStrokeColor = 'gray-100',
29+
color = 'blue-400',
30+
hasError = false,
31+
checkMarkSize = 50,
32+
checkMarkOnComplete = true,
33+
checkMarkColor = '--energy-blue-shade',
34+
}: CircularProgressProps): JSX.Element => {
35+
const progress = Math.max(0, Math.min(100, percentage)) | 0;
36+
37+
const viewBox = useMemo<string>((): string => `0 0 ${size} ${size}`, [size]);
38+
const radius = useMemo<number>((): number => (size - strokeWidth) / 2, [size, strokeWidth]);
39+
const circumference = useMemo<number>((): number => radius * Math.PI * 2, [radius]);
40+
const dash = useMemo<number>((): number => (progress * circumference) / 100, [progress, circumference]);
41+
const getCheckMarkColor = useMemo<string>(
42+
(): string =>
43+
checkMarkColor.startsWith('--') ? `var(${checkMarkColor})` : `var(--spectrum-global-color-${color})`,
44+
[checkMarkColor, color]
45+
);
46+
47+
return (
48+
<svg width={size} height={size} viewBox={viewBox} aria-label='progress-circular-loader'>
49+
<circle
50+
fill='none'
51+
stroke={`var(--spectrum-global-color-${backStrokeColor})`}
52+
cx={size / 2}
53+
cy={size / 2}
54+
r={radius}
55+
strokeWidth={`${strokeWidth}px`}
56+
/>
57+
<circle
58+
fill='none'
59+
stroke={
60+
checkMarkOnComplete
61+
? progress < 100
62+
? `var(--spectrum-global-color-${color})`
63+
: getCheckMarkColor
64+
: `var(--spectrum-global-color-${color})`
65+
}
66+
cx={size / 2}
67+
cy={size / 2}
68+
r={radius}
69+
strokeWidth={`${strokeWidth}px`}
70+
transform={`rotate(-90 ${size / 2} ${size / 2})`}
71+
strokeDasharray={`${[dash, circumference - dash]}`}
72+
strokeLinecap='square'
73+
style={{ transition: 'all 0.5s' }}
74+
/>
75+
<text
76+
fill={
77+
checkMarkOnComplete
78+
? progress < 100
79+
? `var(--spectrum-global-color-${labelFontColor})`
80+
: getCheckMarkColor
81+
: `var(--spectrum-global-color-${labelFontColor})`
82+
}
83+
fontSize={
84+
checkMarkOnComplete
85+
? progress < 100
86+
? `${labelFontSize}px`
87+
: `${checkMarkSize}px`
88+
: `${labelFontSize}px`
89+
}
90+
dy={
91+
checkMarkOnComplete
92+
? progress < 100
93+
? `${labelFontSize / 2}px`
94+
: `${checkMarkSize / 2.5}px`
95+
: `${labelFontSize / 2}px`
96+
}
97+
textAnchor='middle'
98+
x='50%'
99+
y='50%'
100+
>
101+
{hasError ? 'N/A' : checkMarkOnComplete ? (progress < 100 ? `${progress}%` : '✓') : `${progress}%`}
102+
</text>
103+
</svg>
104+
);
105+
};

web_ui/src/shared/components/dataset-import-progress/dataset-import-progress.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { DatasetImportItem } from '../../../core/datasets/dataset.interface';
1414
import { useDatasetImportQueries } from '../../../core/datasets/hooks/use-dataset-import-queries.hook';
1515
import { getJobInfo, isPreparingJob } from '../../../core/datasets/utils';
1616
import { useWorkspaceIdentifier } from '../../../providers/workspaces-provider/use-workspace-identifier.hook';
17-
import { CircularProgress } from '../circular-progress/circular-progress.component';
17+
import { CircularProgress } from './circular-progress/circular-progress.component';
1818

1919
import classes from './dataset-import-progress.module.scss';
2020

0 commit comments

Comments
 (0)