-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 #10257 from hashicorp/f-ui/bigger-units
UI: Refactor all displayed units to use common utils (featuring bigger suffixes)
- Loading branch information
Showing
35 changed files
with
448 additions
and
181 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,16 @@ | ||
import Helper from '@ember/component/helper'; | ||
|
||
const UNITS = ['Bytes', 'KiB', 'MiB', 'GiB']; | ||
import { formatBytes } from 'nomad-ui/utils/units'; | ||
|
||
/** | ||
* Bytes Formatter | ||
* | ||
* Usage: {{format-bytes bytes}} | ||
* Usage: {{format-bytes bytes start="KiB"}} | ||
* | ||
* Outputs the bytes reduced to the largest supported unit size for which | ||
* bytes is larger than one. | ||
*/ | ||
export function reduceToLargestUnit(bytes) { | ||
bytes || (bytes = 0); | ||
let unitIndex = 0; | ||
while (bytes >= 1024 && unitIndex < UNITS.length - 1) { | ||
bytes /= 1024; | ||
unitIndex++; | ||
} | ||
|
||
return [bytes, UNITS[unitIndex]]; | ||
} | ||
|
||
export function formatBytes([bytes]) { | ||
const [number, unit] = reduceToLargestUnit(bytes); | ||
return `${Math.floor(number)} ${unit}`; | ||
function formatBytesHelper([bytes], { start }) { | ||
return formatBytes(bytes, start); | ||
} | ||
|
||
export default Helper.helper(formatBytes); | ||
export default Helper.helper(formatBytesHelper); |
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,16 @@ | ||
import Helper from '@ember/component/helper'; | ||
import { formatHertz } from 'nomad-ui/utils/units'; | ||
|
||
/** | ||
* Hertz Formatter | ||
* | ||
* Usage: {{format-hertz hertz}} | ||
* | ||
* Outputs the frequency reduced to the largest supported unit size for which | ||
* the resulting number is larger than one. | ||
*/ | ||
function formatHertzHelper([hertz], { start }) { | ||
return formatHertz(hertz, start || 'MHz'); | ||
} | ||
|
||
export default Helper.helper(formatHertzHelper); |
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,16 @@ | ||
import Helper from '@ember/component/helper'; | ||
import { formatScheduledBytes } from 'nomad-ui/utils/units'; | ||
|
||
/** | ||
* Scheduled Bytes Formatter | ||
* | ||
* Usage: {{format-scheduled-bytes bytes start="KiB"}} | ||
* | ||
* Outputs the bytes reduced to the resolution the scheduler | ||
* and job spec operate at. | ||
*/ | ||
function formatScheduledBytesHelper([bytes], { start }) { | ||
return formatScheduledBytes(bytes, start); | ||
} | ||
|
||
export default Helper.helper(formatScheduledBytesHelper); |
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,16 @@ | ||
import Helper from '@ember/component/helper'; | ||
import { formatScheduledHertz } from 'nomad-ui/utils/units'; | ||
|
||
/** | ||
* Scheduled Hertz Formatter | ||
* | ||
* Usage: {{format-scheduled-hertz hertz}} | ||
* | ||
* Outputs the frequency reduced to the resolution the scheduler | ||
* and job spec operate at. | ||
*/ | ||
function formatScheduledHertzHelper([hertz], { start }) { | ||
return formatScheduledHertz(hertz, start || 'MHz'); | ||
} | ||
|
||
export default Helper.helper(formatScheduledHertzHelper); |
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
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
Oops, something went wrong.