Skip to content

Commit

Permalink
[ui] Copyable server and client attribute values (#16548)
Browse files Browse the repository at this point in the history
* Copyable server and client attribute values

* Changelog
  • Loading branch information
philrenaud authored Mar 22, 2023
1 parent cb9ce8b commit 2a22d71
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .changelog/16548.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
ui: Added copy-to-clipboard buttons to server and client pages
```
3 changes: 2 additions & 1 deletion ui/app/components/copy-button.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Component from '@ember/component';
import { task, timeout } from 'ember-concurrency';
import { classNames } from '@ember-decorators/component';
import { classNames, classNameBindings } from '@ember-decorators/component';
import classic from 'ember-classic-decorator';

@classic
@classNames('copy-button')
@classNameBindings('inset')
export default class CopyButton extends Component {
clipboardText = null;
state = null;
Expand Down
5 changes: 5 additions & 0 deletions ui/app/components/metadata-kv.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
{{~@key}}
</td>
<td title="{{@value}}">
<CopyButton
@inset={{true}}
@compact={{true}}
@clipboardText={{@value}}
/>
<span data-test-value>{{@value}}</span>
{{#if @editable}}
<button class="button is-light is-compact edit-existing-metadata-button" type="button"
Expand Down
4 changes: 4 additions & 0 deletions ui/app/styles/components/copy-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
padding-left: 0.5rem;
margin-bottom: 2px;

&.inset {
display: inline-block;
}

.button {
color: inherit;

Expand Down
4 changes: 4 additions & 0 deletions ui/app/styles/core/buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ $button-box-shadow-standard: 0 2px 0 0 rgba($grey, 0.2);
box-shadow: none;
}

&.is-inset {
background-color: transparent;
}

&.is-disabled {
opacity: 0.7;
box-shadow: none;
Expand Down
1 change: 1 addition & 0 deletions ui/app/templates/clients/client/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@
data-test-attributes
@attributePairs={{this.model.attributes.structured}}
@class="attributes-table"
@copyable={{true}}
/>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions ui/app/templates/components/attributes-section.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</td>
</tr>
<AttributesSection @prefix={{if this.prefix (concat this.prefix "." key) key}} @attributes={{value}}
@key={{key}} @value={{value}} @editable={{@editable}} @onKVSave={{@onKVSave}} />
@key={{key}} @value={{value}} @editable={{@editable}} @onKVSave={{@onKVSave}} @copyable={{@copyable}} />
{{else}}
<MetadataKv @prefix={{this.prefix}}
@key={{key}} @value={{value}} @editable={{@editable}} @onKVSave={{@onKVSave}} />
@key={{key}} @value={{value}} @editable={{@editable}} @onKVSave={{@onKVSave}} @copyable={{@copyable}} />
{{/if}}
{{/each-in}}
1 change: 1 addition & 0 deletions ui/app/templates/components/attributes-table.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@editable={{@editable}}
@onKVEdit={{@onKVEdit}}
@onKVSave={{@onKVSave}}
@copyable={{@copyable}}
/>
</tbody>
</table>
22 changes: 15 additions & 7 deletions ui/app/templates/components/copy-button.hbs
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
{{#if (eq this.state 'success')}}
<div class='button is-small is-static {{if @compact "is-compact"}} {{unless @border "is-borderless"}}'>
<span class="tooltip text-center always-active" role="tooltip" aria-label="Copied!">
{{x-icon 'copy-success'}}
</span>
{{#if @inset}}
<span aria-label="Copied!">{{x-icon 'copy-success'}}</span>
{{else}}
<span class="tooltip text-center always-active" role="tooltip" aria-label="Copied!">
{{x-icon 'copy-success'}}
</span>
{{/if}}
{{yield}}
</div>
{{else if (eq this.state 'error')}}
<div class='button is-small is-static {{if @compact "is-compact"}} {{unless @border "is-borderless"}}'>
<span class="tooltip text-center" role="tooltip" aria-label="Error copying">
{{x-icon 'alert-triangle'}}
</span>
{{#if @inset}}
<span aria-label="Error copying">{{x-icon 'alert-triangle'}}</span>
{{else}}
<span class="tooltip text-center" role="tooltip" aria-label="Error copying">
{{x-icon 'alert-triangle'}}
</span>
{{/if}}
{{yield}}
</div>
{{else}}
<AddonCopyButton
@class="button is-small {{if @compact "is-compact"}} {{unless @border "is-borderless"}}"
@class="button is-small {{if @compact "is-compact"}} {{unless @border "is-borderless"}} {{if @inset "is-inset"}}"
@clipboardText={{this.clipboardText}}
@success={{perform this.indicateSuccess}}
@error={{action (mut this.state) "error"}}
Expand Down
9 changes: 8 additions & 1 deletion ui/app/templates/servers/server/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@
<t.body as |row|>
<tr data-test-server-tag>
<td>{{row.model.name}}</td>
<td>{{row.model.value}}</td>
<td>
<CopyButton
@inset={{true}}
@compact={{true}}
@clipboardText={{row.model.value}}
/>
{{row.model.value}}
</td>
</tr>
</t.body>
</ListTable>
Expand Down

0 comments on commit 2a22d71

Please sign in to comment.