-
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.
add progress cell renderer (finos#683)
- Loading branch information
Showing
6 changed files
with
142 additions
and
7 deletions.
There are no files selected for viewing
6 changes: 1 addition & 5 deletions
6
vuu-ui/packages/vuu-table-extras/src/cell-renderers/background-cell/BackgroundCell.tsx
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
39 changes: 39 additions & 0 deletions
39
vuu-ui/packages/vuu-table-extras/src/cell-renderers/progress-cell/ProgressCell.css
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 @@ | ||
.vuuProgressCell { | ||
align-items: center; | ||
display: flex; | ||
} | ||
|
||
.vuuProgressCell-track { | ||
display: inline-block; | ||
flex: auto 1 1; | ||
height: 4px; | ||
overflow: hidden; | ||
position: relative; | ||
} | ||
|
||
.vuuProgressCell-bg { | ||
background-color: var(--salt-measured-background); | ||
display: inline-block; | ||
height: 2px; | ||
left: 0; | ||
position: absolute; | ||
top: 1px; | ||
width: 100%; | ||
} | ||
|
||
|
||
.vuuProgressCell-bar { | ||
background-color: var(--salt-measured-fill); | ||
display: inline-block; | ||
height: 100%; | ||
left: 0; | ||
position: absolute; | ||
top:0; | ||
transform: translateX(var(--progress-bar-pct, -100%)); | ||
width: 100%; | ||
} | ||
|
||
.vuuProgressCell-text { | ||
flex: 35px 0 0; | ||
text-align: right; | ||
} |
66 changes: 66 additions & 0 deletions
66
vuu-ui/packages/vuu-table-extras/src/cell-renderers/progress-cell/ProgressCell.tsx
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,66 @@ | ||
import { TableCellProps } from "@finos/vuu-datagrid-types"; | ||
import { | ||
isColumnTypeRenderer, | ||
isTypeDescriptor, | ||
registerComponent, | ||
} from "@finos/vuu-utils"; | ||
import cx from "classnames"; | ||
import { CSSProperties } from "react"; | ||
|
||
import "./ProgressCell.css"; | ||
|
||
const classBase = "vuuProgressCell"; | ||
|
||
const ProgressCell = ({ column, columnMap, row }: TableCellProps) => { | ||
//TODO what about click handling | ||
|
||
const { type } = column; | ||
const value = row[column.key]; | ||
let showProgress = false; | ||
let percentage = 0; | ||
|
||
if (isTypeDescriptor(type) && isColumnTypeRenderer(type.renderer)) { | ||
const { associatedField } = type.renderer; | ||
const associatedValue = row[columnMap[associatedField]]; | ||
if (typeof value === "number" && typeof associatedValue === "number") { | ||
percentage = Math.min(Math.round((value / associatedValue) * 100), 100); | ||
showProgress = isFinite(percentage); | ||
} else { | ||
// Temp workaround for bug on server that sends aggregated values as strings | ||
const floatValue = parseFloat(value as string); | ||
if (Number.isFinite(floatValue)) { | ||
const floatOtherValue = parseFloat(associatedValue as string); | ||
if (Number.isFinite(floatOtherValue)) { | ||
percentage = Math.min( | ||
Math.round((floatValue / floatOtherValue) * 100), | ||
100 | ||
); | ||
showProgress = isFinite(percentage); | ||
} | ||
} | ||
} | ||
} | ||
|
||
const className = cx(classBase, {}); | ||
|
||
return ( | ||
<div className={className} tabIndex={-1}> | ||
{showProgress ? ( | ||
<span className={`${classBase}-track`}> | ||
<span className={`${classBase}-bg`} /> | ||
<span | ||
className={`${classBase}-bar`} | ||
style={ | ||
{ "--progress-bar-pct": `-${100 - percentage}%` } as CSSProperties | ||
} | ||
/> | ||
</span> | ||
) : null} | ||
<span className={`${classBase}-text`}>{`${percentage} %`}</span> | ||
</div> | ||
); | ||
}; | ||
|
||
registerComponent("vuu.progress", ProgressCell, "cell-renderer", { | ||
serverDataType: ["long", "int", "double"], | ||
}); |
1 change: 1 addition & 0 deletions
1
vuu-ui/packages/vuu-table-extras/src/cell-renderers/progress-cell/index.ts
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 @@ | ||
export * from "./ProgressCell"; |
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