Skip to content

Commit

Permalink
ui: Create a helper to show the last 8 characters of token Accessor ID (
Browse files Browse the repository at this point in the history
#7327)

* Create substr helper
* Create a test for the new substr helper
* Display the last 8 characters of token Accessor ID in the Token lists page
  • Loading branch information
kaxcode authored and John Cowen committed May 12, 2020
1 parent 95031f9 commit 191496e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ui-v2/app/helpers/substr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { helper } from '@ember/component/helper';

export default helper(function substr([str = '', start = 0, length], hash) {
return str.substr(start, length);
});
2 changes: 1 addition & 1 deletion ui-v2/app/templates/dc/acls/tokens/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</BlockSlot>
<BlockSlot @name="row">
<td data-test-token="{{item.AccessorID}}" class={{if (eq item.AccessorID token.AccessorID) 'me' }}>
<a href={{href-to 'dc.acls.tokens.edit' item.AccessorID}}>{{truncate item.AccessorID 8 false}}</a>
<a href={{href-to 'dc.acls.tokens.edit' item.AccessorID}}>{{substr item.AccessorID -8}}</a>
</td>
<td>
{{if item.Local 'local' 'global' }}
Expand Down
17 changes: 17 additions & 0 deletions ui-v2/tests/integration/helpers/substr-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('helper:substr', function(hooks) {
setupRenderingTest(hooks);

// Replace this with your real tests.
test('it returns last 2 characters of string', async function(assert) {
this.set('inputValue', 'd9a54409-648b-4327-974f-62a45c8c65f1');

await render(hbs`{{substr inputValue -4}}`);

assert.dom('*').hasText('65f1');
});
});

0 comments on commit 191496e

Please sign in to comment.