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
ae1e429
commit f99ae86
Showing
5 changed files
with
168 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
103 changes: 103 additions & 0 deletions
103
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,103 @@ | ||
/* | ||
-*- 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; | ||
} | ||
|
||
// The workflow could be completely restored from the cache, in which case | ||
// the total number of steps would be 0. If the workflow is finished, we | ||
// want to show the full progress bar as finished even in this case. | ||
if (status === "finished") { | ||
lengthFinishedArc = circumference; | ||
lengthRunningArc = 0; | ||
lengthFailedArc = 0; | ||
} | ||
|
||
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["progress-bar-workflow-status-" + status] | ||
}`} | ||
strokeDasharray={`${lengthRunningArc} ${circumference}`} | ||
strokeDashoffset={`-${lengthFinishedArc}`} | ||
strokeWidth={`${strokeWidth}`} | ||
/> | ||
<circle | ||
cx={`${size / 2}`} | ||
cy={`${size / 2}`} | ||
r={`${radius}`} | ||
className={`${styles["progress-bar-finished"]} ${ | ||
styles["progress-bar-workflow-status-" + status] | ||
}`} | ||
strokeDasharray={`${lengthFinishedArc} ${circumference}`} | ||
strokeDashoffset="0" | ||
strokeWidth={`${strokeWidth}`} | ||
/> | ||
<circle | ||
cx={`${size / 2}`} | ||
cy={`${size / 2}`} | ||
r={`${radius}`} | ||
className={`${styles["progress-bar-failed"]} ${ | ||
styles["progress-bar-workflow-status-" + status] | ||
}`} | ||
strokeDasharray={`${lengthFailedArc} ${circumference}`} | ||
strokeDashoffset={`-${lengthFinishedArc}`} | ||
strokeWidth={`${strokeWidth}`} | ||
/> | ||
</svg> | ||
</div> | ||
); | ||
} | ||
|
||
WorkflowProgressCircleBar.propTypes = { | ||
workflow: PropTypes.object.isRequired, | ||
size: PropTypes.number, | ||
}; |
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
@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-workflow-status-queued, | ||
.progress-bar-workflow-status-pending, | ||
.progress-bar-workflow-status-created { | ||
stroke: $light-gray; | ||
} | ||
|
||
.progress-bar-workflow-status-deleted { | ||
stroke: $gray; | ||
} | ||
|
||
.progress-bar-workflow-status-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