Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Refactor all displayed units to use common utils (featuring bigger suffixes) #10257

Merged
merged 7 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Format all bytes using helpers, even the ones that are already MiBs
  • Loading branch information
DingoEatingFuzz committed Mar 31, 2021
commit f82fe6b87545acc2c295ac4a30e895b5e86b63e7
6 changes: 3 additions & 3 deletions ui/app/components/allocation-stat.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Component from '@ember/component';
import { computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import { formatScheduledBytes } from 'nomad-ui/utils/units';
import { formatScheduledBytes, formatBytes } from 'nomad-ui/utils/units';
import { tagName } from '@ember-decorators/component';
import classic from 'ember-classic-decorator';

Expand Down Expand Up @@ -35,13 +35,13 @@ export default class AllocationStat extends Component {
@computed('metric', 'stat.used')
get formattedStat() {
if (!this.stat) return undefined;
if (this.metric === 'memory') return formatScheduledBytes(this.stat.used);
if (this.metric === 'memory') return formatBytes(this.stat.used);
return this.stat.used;
}

@computed('metric', 'statsTracker.{reservedMemory,reservedCPU}')
get formattedReserved() {
if (this.metric === 'memory') return `${this.statsTracker.reservedMemory} MiB`;
if (this.metric === 'memory') return formatBytes(this.statsTracker.reservedMemory, 'MiB');
if (this.metric === 'cpu') return `${this.statsTracker.reservedCPU} MHz`;
return undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion ui/app/components/primary-metric/allocation.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{{#if (eq this.metric "cpu")}}
<strong>{{this.data.lastObject.used}} MHz</strong> / {{this.reservedAmount}} MHz Total
{{else if (eq this.metric "memory")}}
<strong>{{format-scheduled-bytes this.data.lastObject.used}}</strong> / {{this.reservedAmount}} MiB Total
<strong>{{format-scheduled-bytes this.data.lastObject.used}}</strong> / {{format-scheduled-bytes this.reservedAmount start="MiB"}} Total
{{else}}
<strong>{{this.data.lastObject.used}}</strong> / {{this.reservedAmount}} Total
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion ui/app/components/primary-metric/node.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{{#if (eq this.metric "cpu")}}
<strong>{{this.data.lastObject.used}} MHz</strong> / {{this.reservedAmount}} MHz Total
{{else if (eq this.metric "memory")}}
<strong>{{format-scheduled-bytes this.data.lastObject.used}}</strong> / {{this.reservedAmount}} MiB Total
<strong>{{format-scheduled-bytes this.data.lastObject.used}}</strong> / {{format-scheduled-bytes this.reservedAmount start="MiB"}} Total
{{else}}
<strong>{{this.data.lastObject.used}}</strong> / {{this.reservedAmount}} Total
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion ui/app/components/primary-metric/task.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{{#if (eq this.metric "cpu")}}
<strong>{{this.data.lastObject.used}} MHz</strong> / {{this.reservedAmount}} MHz Total
{{else if (eq this.metric "memory")}}
<strong>{{format-scheduled-bytes this.data.lastObject.used}}</strong> / {{this.reservedAmount}} MiB Total
<strong>{{format-scheduled-bytes this.data.lastObject.used}}</strong> / {{format-scheduled-bytes this.reservedAmount start="MiB"}} Total
{{else}}
<strong>{{this.data.lastObject.used}}</strong> / {{this.reservedAmount}} Total
{{/if}}
Expand Down
6 changes: 3 additions & 3 deletions ui/app/helpers/format-bytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ 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.
*/
function formatBytesHelper([bytes]) {
return formatBytes(bytes);
function formatBytesHelper([bytes], { start }) {
return formatBytes(bytes, start);
}

export default Helper.helper(formatBytesHelper);
6 changes: 3 additions & 3 deletions ui/app/helpers/format-scheduled-bytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { formatScheduledBytes } from 'nomad-ui/utils/units';
/**
* Scheduled Bytes Formatter
*
* Usage: {{format-scheduled-bytes bytes}}
* Usage: {{format-scheduled-bytes bytes start="KiB"}}
*
* Outputs the bytes reduced to the resolution the scheduler
* and job spec operate at.
*/
function formatScheduledBytesHelper([bytes]) {
return formatScheduledBytes(bytes);
function formatScheduledBytesHelper([bytes], { start }) {
return formatScheduledBytes(bytes, start);
}

export default Helper.helper(formatScheduledBytesHelper);
4 changes: 2 additions & 2 deletions ui/tests/acceptance/behaviors/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from 'qunit';
import { currentURL, visit } from '@ember/test-helpers';

import { filesForPath } from 'nomad-ui/mirage/config';
import { formatBytes } from 'nomad-ui/helpers/format-bytes';
import { formatBytes } from 'nomad-ui/utils/units';
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';

import Response from 'ember-cli-mirage/response';
Expand Down Expand Up @@ -130,7 +130,7 @@ export default function browseFilesystem({
const fileRecord = sortedFiles[2];
assert.equal(file.name, fileRecord.name);
assert.ok(file.isFile);
assert.equal(file.size, formatBytes([fileRecord.size]));
assert.equal(file.size, formatBytes(fileRecord.size));
assert.equal(file.lastModified, moment(fileRecord.modTime).fromNow());
});

Expand Down
7 changes: 5 additions & 2 deletions ui/tests/acceptance/client-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
import { formatBytes } from 'nomad-ui/helpers/format-bytes';
import { formatBytes } from 'nomad-ui/utils/units';
import moment from 'moment';
import ClientDetail from 'nomad-ui/tests/pages/clients/detail';
import Clients from 'nomad-ui/tests/pages/clients/list';
Expand Down Expand Up @@ -175,7 +175,10 @@ module('Acceptance | client detail', function(hooks) {
);
assert.equal(
allocationRow.memTooltip,
`${formatBytes([allocStats.resourceUsage.MemoryStats.RSS])} / ${memoryUsed} MiB`,
`${formatBytes(allocStats.resourceUsage.MemoryStats.RSS)} / ${formatBytes(
memoryUsed,
'MiB'
)}`,
'Detailed memory information is in a tooltip'
);
});
Expand Down
7 changes: 5 additions & 2 deletions ui/tests/acceptance/plugin-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
import moment from 'moment';
import { formatBytes } from 'nomad-ui/helpers/format-bytes';
import { formatBytes } from 'nomad-ui/utils/units';
import PluginDetail from 'nomad-ui/tests/pages/storage/plugins/detail';
import Layout from 'nomad-ui/tests/pages/layout';

Expand Down Expand Up @@ -137,7 +137,10 @@ module('Acceptance | plugin detail', function(hooks) {
);
assert.equal(
allocationRow.memTooltip,
`${formatBytes([allocStats.resourceUsage.MemoryStats.RSS])} / ${memoryUsed} MiB`,
`${formatBytes(allocStats.resourceUsage.MemoryStats.RSS)} / ${formatBytes(
memoryUsed,
'MiB'
)}`,
'Detailed memory information is in a tooltip'
);
});
Expand Down
7 changes: 5 additions & 2 deletions ui/tests/acceptance/task-group-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
import { formatBytes } from 'nomad-ui/helpers/format-bytes';
import { formatBytes } from 'nomad-ui/utils/units';
import TaskGroup from 'nomad-ui/tests/pages/jobs/job/task-group';
import Layout from 'nomad-ui/tests/pages/layout';
import pageSizeSelect from './behaviors/page-size-select';
Expand Down Expand Up @@ -223,7 +223,10 @@ module('Acceptance | task group detail', function(hooks) {

assert.equal(
allocationRow.memTooltip,
`${formatBytes([allocStats.resourceUsage.MemoryStats.RSS])} / ${memoryUsed} MiB`,
`${formatBytes(allocStats.resourceUsage.MemoryStats.RSS)} / ${formatBytes(
memoryUsed,
'MiB'
)}`,
'Detailed memory information is in a tooltip'
);
});
Expand Down
15 changes: 6 additions & 9 deletions ui/tests/acceptance/topology-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
import Topology from 'nomad-ui/tests/pages/topology';
import { reduceToLargestUnit } from 'nomad-ui/helpers/format-bytes';
import { reduceBytes, formatBytes, formatScheduledBytes } from 'nomad-ui/utils/units';
import queryString from 'query-string';

const sumResources = (list, dimension) =>
Expand Down Expand Up @@ -60,12 +60,9 @@ module('Acceptance | topology', function(hooks) {
assert.equal(Topology.clusterInfoPanel.memoryProgressValue, reservedMem / totalMem);
assert.equal(Topology.clusterInfoPanel.cpuProgressValue, reservedCPU / totalCPU);

const [rNum, rUnit] = reduceToLargestUnit(reservedMem * 1024 * 1024);
const [tNum, tUnit] = reduceToLargestUnit(totalMem * 1024 * 1024);

assert.equal(
Topology.clusterInfoPanel.memoryAbsoluteValue,
`${Math.floor(rNum)} ${rUnit} / ${Math.floor(tNum)} ${tUnit} reserved`
`${formatBytes(reservedMem, 'MiB')} / ${formatBytes(totalMem, 'MiB')} reserved`
);

assert.equal(
Expand Down Expand Up @@ -199,12 +196,12 @@ module('Acceptance | topology', function(hooks) {
assert.equal(Topology.nodeInfoPanel.memoryProgressValue, reservedMem / totalMem);
assert.equal(Topology.nodeInfoPanel.cpuProgressValue, reservedCPU / totalCPU);

const [rNum, rUnit] = reduceToLargestUnit(reservedMem * 1024 * 1024);
const [tNum, tUnit] = reduceToLargestUnit(totalMem * 1024 * 1024);

assert.equal(
Topology.nodeInfoPanel.memoryAbsoluteValue,
`${Math.floor(rNum)} ${rUnit} / ${Math.floor(tNum)} ${tUnit} reserved`
`${formatScheduledBytes(reservedMem * 1024 * 1024)} / ${formatScheduledBytes(
totalMem,
'MiB'
)} reserved`
);

assert.equal(
Expand Down
7 changes: 5 additions & 2 deletions ui/tests/acceptance/volume-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
import moment from 'moment';
import { formatBytes } from 'nomad-ui/helpers/format-bytes';
import { formatBytes } from 'nomad-ui/utils/units';
import VolumeDetail from 'nomad-ui/tests/pages/storage/volumes/detail';
import Layout from 'nomad-ui/tests/pages/layout';

Expand Down Expand Up @@ -152,7 +152,10 @@ module('Acceptance | volume detail', function(hooks) {
);
assert.equal(
allocationRow.memTooltip,
`${formatBytes([allocStats.resourceUsage.MemoryStats.RSS])} / ${memoryUsed} MiB`,
`${formatBytes(allocStats.resourceUsage.MemoryStats.RSS)} / ${formatBytes(
memoryUsed,
'MiB'
)}`,
'Detailed memory information is in a tooltip'
);
});
Expand Down
4 changes: 2 additions & 2 deletions ui/tests/integration/components/image-file-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import hbs from 'htmlbars-inline-precompile';
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
import sinon from 'sinon';
import RSVP from 'rsvp';
import { formatBytes } from 'nomad-ui/helpers/format-bytes';
import { formatBytes } from 'nomad-ui/utils/units';

module('Integration | Component | image file', function(hooks) {
setupRenderingTest(hooks);
Expand Down Expand Up @@ -81,7 +81,7 @@ module('Integration | Component | image file', function(hooks) {
'Width and height are formatted correctly'
);
assert.ok(
statsEl.textContent.trim().endsWith(formatBytes([commonProperties.size]) + ')'),
statsEl.textContent.trim().endsWith(formatBytes(commonProperties.size) + ')'),
'Human-formatted size is included'
);
});
Expand Down
36 changes: 0 additions & 36 deletions ui/tests/unit/helpers/format-bytes-test.js

This file was deleted.