Skip to content

Commit

Permalink
ui: create tooltip component (#11363)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgfa29 authored Oct 21, 2021
1 parent f757f61 commit d599c63
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 6 deletions.
14 changes: 14 additions & 0 deletions ui/app/components/tooltip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Component from '@glimmer/component';

export default class Tooltip extends Component {
get text() {
const inputText = this.args.text;
if (!inputText || inputText.length < 30) {
return inputText;
}

const prefix = inputText.substr(0, 15).trim();
const suffix = inputText.substr(inputText.length - 10, inputText.length).trim();
return `${prefix}...${suffix}`;
}
}
8 changes: 4 additions & 4 deletions ui/app/templates/components/allocation-row.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@
</td>
{{#if (eq this.context "volume")}}
<td data-test-client>
<span class="tooltip multiline" aria-label="{{this.allocation.node.name}}">
<Tooltip @text={{this.allocation.node.name}}>
<LinkTo @route="clients.client" @model={{this.allocation.node}}>
{{this.allocation.node.shortId}}
</LinkTo>
</span>
</Tooltip>
</td>
{{/if}}
{{#if (or (eq this.context "taskGroup") (eq this.context "job"))}}
<td data-test-job-version>{{this.allocation.jobVersion}}</td>
<td data-test-client>
<span class="tooltip multiline" aria-label="{{this.allocation.node.name}}">
<Tooltip @text={{this.allocation.node.name}}>
<LinkTo @route="clients.client" @model={{this.allocation.node}}>
{{this.allocation.node.shortId}}
</LinkTo>
</span>
</Tooltip>
</td>
{{else if (or (eq this.context "node") (eq this.context "volume"))}}
<td>
Expand Down
4 changes: 2 additions & 2 deletions ui/app/templates/components/plugin-allocation-row.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
</td>

<td data-test-client>
<span class="tooltip multiline" aria-label="{{this.allocation.node.name}}">
<Tooltip @text={{this.allocation.node.name}}>
<LinkTo @route="clients.client" @model={{this.allocation.node}}>
{{this.allocation.node.shortId}}
</LinkTo>
</span>
</Tooltip>
</td>
<td>
{{#if (or this.allocation.job.isPending this.allocation.job.isReloading)}}
Expand Down
3 changes: 3 additions & 0 deletions ui/app/templates/components/tooltip.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span class="tooltip" aria-label="{{this.text}}">
{{yield}}
</span>
5 changes: 5 additions & 0 deletions ui/tests/acceptance/plugin-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ module('Acceptance | plugin detail', function(hooks) {
server.db.nodes.find(allocation.nodeId).id.split('-')[0],
'Node ID'
);
assert.equal(
allocationRow.clientTooltip.substr(0, 15),
server.db.nodes.find(allocation.nodeId).name.substr(0, 15),
'Node Name'
);
assert.equal(allocationRow.job, server.db.jobs.find(allocation.jobId).name, 'Job name');
assert.ok(allocationRow.taskGroup, 'Task group name');
assert.ok(allocationRow.jobVersion, 'Job Version');
Expand Down
5 changes: 5 additions & 0 deletions ui/tests/acceptance/volume-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ module('Acceptance | volume detail', function(hooks) {
server.db.nodes.find(allocation.nodeId).id.split('-')[0],
'Node ID'
);
assert.equal(
allocationRow.clientTooltip.substr(0, 15),
server.db.nodes.find(allocation.nodeId).name.substr(0, 15),
'Node Name'
);
assert.equal(
allocationRow.cpu,
Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks) / cpuUsed,
Expand Down
1 change: 1 addition & 0 deletions ui/tests/pages/components/allocations.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function(selector = '[data-test-allocation]', propKey = 'allocati
job: text('[data-test-job]'),
taskGroup: text('[data-test-task-group]'),
client: text('[data-test-client]'),
clientTooltip: attribute('aria-label', '[data-test-client] .tooltip'),
jobVersion: text('[data-test-job-version]'),
volume: text('[data-test-volume]'),
cpu: text('[data-test-cpu]'),
Expand Down
13 changes: 13 additions & 0 deletions ui/tests/unit/components/tooltip-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import setupGlimmerComponentFactory from 'nomad-ui/tests/helpers/glimmer-factory';

module('Unit | Component | tooltip', function(hooks) {
setupTest(hooks);
setupGlimmerComponentFactory(hooks, 'tooltip');

test('long texts are ellipsised in the middle', function(assert) {
const tooltip = this.createComponent({ text: 'reeeeeeeeeeeeeeeeeally long text' });
assert.equal(tooltip.text, 'reeeeeeeeeeeeee...long text');
});
});

0 comments on commit d599c63

Please sign in to comment.