-
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.
UI: Add copy button for client/allocation UUIDs (#5926)
The button shows a success icon and tooltip on click, and resets after two seconds.
- Loading branch information
Showing
16 changed files
with
237 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// This lets us use copy-button to wrap ember-cli-clipboard’s component | ||
export { default } from 'ember-cli-clipboard/components/copy-button'; |
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 Component from '@ember/component'; | ||
import { task, timeout } from 'ember-concurrency'; | ||
|
||
export default Component.extend({ | ||
classNames: ['copy-button'], | ||
|
||
clipboardText: null, | ||
state: null, | ||
|
||
indicateSuccess: task(function*() { | ||
this.set('state', 'success'); | ||
|
||
yield timeout(2000); | ||
this.set('state', null); | ||
}).restartable(), | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.copy-button { | ||
padding-left: 0.5rem; | ||
margin-bottom: 2px; | ||
|
||
.button { | ||
color: inherit; | ||
|
||
&.is-static { | ||
background-color: inherit; | ||
} | ||
|
||
svg { | ||
fill: currentColor; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{{#if (eq state 'success')}} | ||
<div class='button is-borderless is-small is-static'> | ||
<span class="tooltip text-center always-active" role="tooltip" aria-label="Copied!"> | ||
{{x-icon 'copy-success'}} | ||
</span> | ||
</div> | ||
{{else if (eq state 'error')}} | ||
<div class='button is-borderless is-small is-static'> | ||
<span class="tooltip text-center" role="tooltip" aria-label="Error copying"> | ||
{{x-icon 'alert-triangle'}} | ||
</span> | ||
</div> | ||
{{else}} | ||
{{#addon-copy-button | ||
class='button is-borderless is-small' | ||
clipboardText=clipboardText | ||
success=(perform indicateSuccess) | ||
error=(action (mut state) 'error') | ||
}} | ||
{{x-icon 'copy-action'}} | ||
{{/addon-copy-button}} | ||
{{/if}} |
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,6 @@ | ||
{{#freestyle-usage "copy-button" title="Copy Button"}} | ||
<span class="tag is-hollow is-small no-text-transform"> | ||
e8c898a0-794b-9063-7a7f-bf0c4a405f83 | ||
{{copy-button clipboardText="e8c898a0-794b-9063-7a7f-bf0c4a405f83"}} | ||
</span> | ||
{{/freestyle-usage}} |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { click, render } from '@ember/test-helpers'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
import sinon from 'sinon'; | ||
|
||
import { triggerCopyError, triggerCopySuccess } from 'ember-cli-clipboard/test-support'; | ||
|
||
module('Integration | Component | copy-button', function(hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test('it shows the copy icon by default', async function(assert) { | ||
await render(hbs`{{copy-button class='copy-button'}}`); | ||
|
||
assert.dom('.copy-button .icon-is-copy-action').exists(); | ||
}); | ||
|
||
test('it shows the success icon on success and resets afterward', async function(assert) { | ||
const clock = sinon.useFakeTimers(); | ||
|
||
await render(hbs`{{copy-button class='copy-button'}}`); | ||
|
||
await click('.copy-button button'); | ||
await triggerCopySuccess('.copy-button button'); | ||
|
||
assert.dom('.copy-button .icon-is-copy-success').exists(); | ||
|
||
clock.runAll(); | ||
|
||
assert.dom('.copy-button .icon-is-copy-success').doesNotExist(); | ||
assert.dom('.copy-button .icon-is-copy-action').exists(); | ||
|
||
clock.restore(); | ||
}); | ||
|
||
test('it shows the error icon on error', async function(assert) { | ||
await render(hbs`{{copy-button class='copy-button'}}`); | ||
|
||
await click('.copy-button button'); | ||
await triggerCopyError('.copy-button button'); | ||
|
||
assert.dom('.copy-button .icon-is-alert-triangle').exists(); | ||
}); | ||
}); |
Oops, something went wrong.