-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1047 from sgratch/plan-resources-align-to-dec-point
🐞 Align Resources tab's table columns by decimal point
- Loading branch information
Showing
8 changed files
with
165 additions
and
30 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
37 changes: 37 additions & 0 deletions
37
...forklift-console-plugin/src/modules/Plans/views/details/tabs/Resources/AlignedDecimal.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,37 @@ | ||
import React from 'react'; | ||
import { useForkliftTranslation } from 'src/utils'; | ||
|
||
export type AlignedDecimalProps = { | ||
/** | ||
* The number to align. | ||
*/ | ||
value: number; | ||
/** | ||
* (optional) units to be displayed next to the number. E.g 'MB', 'Cores'. | ||
*/ | ||
unit?: string; | ||
/** | ||
* (optional) The number fractional part precision, I.e, number of fractional digits to leave. | ||
*/ | ||
fractionalPrecision?: number; | ||
}; | ||
|
||
export const AlignedDecimal: React.FC<AlignedDecimalProps> = ({ | ||
value, | ||
unit = '', | ||
fractionalPrecision = 2, | ||
}) => { | ||
const { t } = useForkliftTranslation(); | ||
|
||
const [integerPart, fractionalPart] = value.toFixed(fractionalPrecision).split('.'); | ||
const formattedFractionalPart = fractionalPrecision === 0 ? ' ' : '.' + fractionalPart; | ||
|
||
return ( | ||
<div> | ||
<div className="forklift-page-plan-resources-td-integer">{integerPart}</div> | ||
<div className="forklift-page-plan-resources-td-fractional"> | ||
{formattedFractionalPart} {t(unit)} | ||
</div> | ||
</div> | ||
); | ||
}; |
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
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
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
1 change: 1 addition & 0 deletions
1
packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/Resources/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