forked from reanahub/reana-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(progress): add circular progress bar in workflow list page (rean…
- Loading branch information
1 parent
6e2337f
commit b0043ff
Showing
5 changed files
with
157 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
reana-ui/src/pages/workflowList/components/WorkflowProgressCircleBar.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
-*- coding: utf-8 -*- | ||
This file is part of REANA. | ||
Copyright (C) 2024 CERN. | ||
REANA is free software; you can redistribute it and/or modify it | ||
under the terms of the MIT License; see LICENSE file for more details. | ||
*/ | ||
|
||
import PropTypes from "prop-types"; | ||
import styles from "./WorkflowProgressCircleBar.module.scss"; | ||
|
||
export default function WorkflowProgressCircleBar({ workflow }) { | ||
const { completed, failed, running, total, status } = workflow; | ||
|
||
const size = 80; | ||
const strokeWidth = 10; | ||
const radius = size / 2 - strokeWidth; | ||
const circumference = 2 * Math.PI * radius; | ||
|
||
let lengthFinishedArc = (completed / total) * circumference; | ||
let lengthRunningArc = (running / total) * circumference; | ||
let lengthFailedArc = (failed / total) * circumference; | ||
// Explicitly set the size of the progress bar for workflows that | ||
// are not running to avoid dealing with undefined number of steps | ||
const TERMINAL_STATUSES = ["finished", "failed", "stopped"]; | ||
const PREPARING_STATUSES = ["created", "queued", "pending"]; | ||
if (TERMINAL_STATUSES.includes(status)) { | ||
lengthRunningArc = 0; | ||
} | ||
if (PREPARING_STATUSES.includes(status)) { | ||
lengthFinishedArc = 0; | ||
lengthRunningArc = 0; | ||
lengthFailedArc = 0; | ||
} | ||
|
||
let additionalClass = ""; | ||
if (PREPARING_STATUSES.includes(status)) { | ||
additionalClass = "progress-bar-preparing"; | ||
} else if (["deleted", "stopped"].includes(status)) { | ||
additionalClass = `progress-bar-${status}`; | ||
} | ||
return ( | ||
<div className={styles["progress-bar-container"]}> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox={`0 0 ${size} ${size}`} | ||
width={`${size}`} | ||
height={`${size}`} | ||
> | ||
<circle | ||
cx={`${size / 2}`} | ||
cy={`${size / 2}`} | ||
r={`${radius}`} | ||
className={styles["progress-bar-background"]} | ||
strokeWidth={`${strokeWidth}`} | ||
/> | ||
<circle | ||
cx={`${size / 2}`} | ||
cy={`${size / 2}`} | ||
r={`${radius}`} | ||
className={`${styles["progress-bar-running"]} ${styles[additionalClass]}`} | ||
strokeDasharray={`${lengthRunningArc} ${circumference}`} | ||
strokeDashoffset={`-${lengthFinishedArc}`} | ||
strokeWidth={`${strokeWidth}`} | ||
/> | ||
<circle | ||
cx={`${size / 2}`} | ||
cy={`${size / 2}`} | ||
r={`${radius}`} | ||
className={`${styles["progress-bar-finished"]} ${styles[additionalClass]}`} | ||
strokeDasharray={`${lengthFinishedArc} ${circumference}`} | ||
strokeDashoffset="0" | ||
strokeWidth={`${strokeWidth}`} | ||
/> | ||
<circle | ||
cx={`${size / 2}`} | ||
cy={`${size / 2}`} | ||
r={`${radius}`} | ||
className={`${styles["progress-bar-failed"]} ${styles[additionalClass]}`} | ||
strokeDasharray={`${lengthFailedArc} ${circumference}`} | ||
strokeDashoffset={`-${lengthFinishedArc}`} | ||
strokeWidth={`${strokeWidth}`} | ||
/> | ||
</svg> | ||
</div> | ||
); | ||
} | ||
|
||
WorkflowProgressCircleBar.propTypes = { | ||
workflow: PropTypes.object.isRequired, | ||
size: PropTypes.number, | ||
}; |
39 changes: 39 additions & 0 deletions
39
reana-ui/src/pages/workflowList/components/WorkflowProgressCircleBar.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
@import "@palette"; | ||
|
||
.progress-bar-container { | ||
svg { | ||
width: 100%; | ||
height: 100%; | ||
transform: rotate(-90deg); | ||
} | ||
|
||
circle { | ||
fill: none; | ||
transition: stroke-dasharray 0.35s ease; | ||
} | ||
|
||
.progress-bar-running { | ||
stroke: $sui-blue; | ||
} | ||
|
||
.progress-bar-finished { | ||
stroke: $sui-green; | ||
} | ||
|
||
.progress-bar-failed { | ||
stroke: $sui-red; | ||
} | ||
|
||
.progress-bar-background, | ||
.progress-bar-preparing { | ||
stroke: $light-gray; | ||
} | ||
|
||
.progress-bar-deleted { | ||
stroke: $gray; | ||
} | ||
|
||
.progress-bar-stopped { | ||
stroke: $sui-yellow !important; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters