Skip to content

Commit

Permalink
UI Conditionally Copy Tooltips (#12890)
Browse files Browse the repository at this point in the history
* adds conditional tooltip copying to InfoTableRow component

* adds changelog entry
  • Loading branch information
Jordan Reimer committed Oct 21, 2021
1 parent 4ef0d3e commit 39b80b8
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changelog/12890.txt
@@ -0,0 +1,3 @@
```release-note:improvement
ui: Click to copy database static role last rotation value in tooltip
```
Expand Up @@ -76,6 +76,7 @@
@label="Last Vault rotation"
@value={{date-format @model.lastVaultRotation 'MMMM d yyyy, h:mm:ss a'}}
@tooltipText={{@model.lastVaultRotation}}
@isTooltipCopyable={{true}}
/>
<InfoTableRow @label="Password" @value={{@model.password}}>
<MaskedInput
Expand Down
2 changes: 2 additions & 0 deletions ui/lib/core/addon/components/info-table-row.js
Expand Up @@ -25,6 +25,7 @@ import layout from '../templates/components/info-table-row';
* @param [backend] {String} - Passed through to InfoTableItemArray. To specify secrets backend to point link to Ex: transformation
* @param [viewAll] {String} - Passed through to InfoTableItemArray. Specify the word at the end of the link View all.
* @param [tooltipText] {String} - Text if a tooltip should display over the value.
* @param [isTooltipCopyable] {Boolean} - Allows tooltip click to copy
* @param [defaultShown] {String} - Text that renders as value if alwaysRender=true. Eg. "Vault default"
*/

Expand All @@ -39,6 +40,7 @@ export default Component.extend({
helperText: null,
value: null,
tooltipText: '',
isTooltipCopyable: false,
defaultShown: '',

valueIsBoolean: computed('value', function() {
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/core/addon/components/tool-tip.js
Expand Up @@ -3,6 +3,6 @@ import layout from '../templates/components/tool-tip';

export default HoverDropdown.extend({
layout,
delay: 0,
delay: 200, // delay allows tooltip to remain open on content hover
horizontalPosition: 'auto-right',
});
15 changes: 12 additions & 3 deletions ui/lib/core/addon/templates/components/info-table-row.hbs
Expand Up @@ -58,9 +58,18 @@
<code class="is-word-break has-text-black" data-test-row-value="{{label}}">{{value}}</code>
</T.trigger>
<T.content @class="tool-tip">
<div class="box">
{{tooltipText}}
</div>
<CopyButton
@clipboardText={{tooltipText}}
@success={{action (set-flash-message 'Data copied!')}}
@tagName="div"
@disabled={{not this.isTooltipCopyable}}
class={{if this.isTooltipCopyable "has-pointer"}}
data-test-tooltip-copy
>
<div class="box">
{{tooltipText}}
</div>
</CopyButton>
</T.content>
</ToolTip>
{{else}}
Expand Down
10 changes: 7 additions & 3 deletions ui/lib/core/addon/templates/components/tool-tip.hbs
@@ -1,4 +1,5 @@
{{#basic-dropdown-hover renderInPlace=renderInPlace
{{#basic-dropdown-hover
renderInPlace=renderInPlace
verticalPosition=verticalPosition
horizontalPosition=horizontalPosition
matchTriggerWidth=matchTriggerWidth
Expand All @@ -8,14 +9,17 @@
onOpen=onOpen
onClose=onClose
onFocus=onFocus
calculateInPlacePosition=calculateInPlacePosition as |dd|}}
calculateInPlacePosition=calculateInPlacePosition
as |dd|
}}
{{yield (assign
dd
(hash
trigger=(component dd.trigger
onMouseDown=(action "prevent")
onMouseEnter=(action "open")
onMouseLeave=(action "close"))
onMouseLeave=(action "close")
)
content=(component dd.content
onMouseEnter=(action "open")
onMouseLeave=(action "close")
Expand Down
23 changes: 23 additions & 0 deletions ui/tests/integration/components/info-table-row-test.js
Expand Up @@ -71,6 +71,29 @@ module('Integration | Component | InfoTableRow', function(hooks) {
assert.equal(tooltip, 'Tooltip text!', 'renders tooltip text');
});

test('it should copy tooltip', async function(assert) {
assert.expect(4);

this.set('isCopyable', false);

await render(hbs`
<InfoTableRow
@label={{label}}
@value={{value}}
@tooltipText="Foo bar"
@isTooltipCopyable={{isCopyable}}
/>
`);

await triggerEvent('[data-test-value-div="test label"] .ember-basic-dropdown-trigger', 'mouseenter');
await settled();
assert.dom('[data-test-tooltip-copy]').hasAttribute('disabled', '', 'Tooltip copy button is disabled');
assert.dom('[data-test-tooltip-copy]').doesNotHaveClass('has-pointer', 'Pointer class not applied when disabled');
this.set('isCopyable', true);
assert.dom('[data-test-tooltip-copy]').doesNotHaveAttribute('disabled', 'Tooltip copy button is enabled');
assert.dom('[data-test-tooltip-copy]').hasClass('has-pointer', 'Pointer class applied to copy button');
});

test('it renders a string with no link if isLink is true and the item type is not an array.', async function(assert) {
// This could be changed in the component so that it adds a link for any item type, but right now it should only add a link if item type is an array.
await render(hbs`<InfoTableRow
Expand Down

0 comments on commit 39b80b8

Please sign in to comment.