Skip to content

Commit ee62721

Browse files
committed
refactor(ui): remove copyToClipborad function usage
1 parent 85b1d43 commit ee62721

File tree

7 files changed

+52
-71
lines changed

7 files changed

+52
-71
lines changed

web/src/components/CopyClipboardButton.vue

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
<template>
2-
<div>
2+
<span>
3+
<!-- eslint-disable-next-line vuejs-accessibility/form-control-has-label -->
34
<textarea
45
style="position: absolute; left: -9999px; top: -9999px;"
56
ref="copy_to_clipboard_textarea"
67
></textarea>
8+
79
<v-btn
810
icon
9-
color="white"
1011
@click="copy()"
12+
:large="large"
1113
>
1214
<v-icon>mdi-content-copy</v-icon>
1315
</v-btn>
14-
</div>
16+
</span>
1517
</template>
1618

1719
<script>
@@ -22,8 +24,10 @@ export default {
2224
text: String,
2325
successMessage: {
2426
type: String,
25-
default: 'Text copied to clipboard!'
27+
default: 'Text copied to clipboard!',
2628
},
29+
large: Boolean,
30+
color: String,
2731
},
2832
methods: {
2933
copy() {
@@ -40,15 +44,15 @@ export default {
4044
4145
EventBus.$emit('i-snackbar', {
4246
color: 'success',
43-
text: this.successMessage
47+
text: this.successMessage,
4448
});
4549
} catch (e) {
4650
EventBus.$emit('i-snackbar', {
4751
color: 'error',
48-
text: `Can't copy to clipboard: ${e.message}`
52+
text: `Can't copy to clipboard: ${e.message}`,
4953
});
5054
}
51-
}
52-
}
55+
},
56+
},
5357
};
5458
</script>

web/src/components/UserForm.vue

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,13 @@
169169
>
170170
{{ item.totp.recovery_code }}
171171
</code>
172-
<v-btn
172+
173+
<CopyClipboardButton
173174
style="position: absolute; right: -4px; top: -12px;"
174-
icon
175+
:text="item.totp.recovery_code"
175176
large
176177
color="white"
177-
@click="copyToClipboard(item.totp.recovery_code)"
178-
>
179-
<v-icon>mdi-content-copy</v-icon>
180-
</v-btn>
178+
/>
181179
</div>
182180
</div>
183181
</div>
@@ -188,13 +186,12 @@
188186
<script>
189187
import ItemFormBase from '@/components/ItemFormBase';
190188
import axios from 'axios';
191-
import EventBus from '@/event-bus';
192189
import EditDialog from '@/components/EditDialog.vue';
193190
import ChangePasswordForm from '@/components/ChangePasswordForm.vue';
194-
import copyToClipboard from '@/lib/copyToClipboard';
191+
import CopyClipboardButton from '@/components/CopyClipboardButton.vue';
195192
196193
export default {
197-
components: { ChangePasswordForm, EditDialog },
194+
components: { CopyClipboardButton, ChangePasswordForm, EditDialog },
198195
props: {
199196
isAdmin: Boolean,
200197
authMethods: Object,
@@ -250,7 +247,6 @@ export default {
250247
},
251248
252249
methods: {
253-
copyToClipboard,
254250
255251
afterLoadData() {
256252
if (this.item.totp == null) {

web/src/views/Runners.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@ import RunnerForm from '@/components/RunnerForm.vue';
362362
import axios from 'axios';
363363
import DashboardMenu from '@/components/DashboardMenu.vue';
364364
import delay from '@/lib/delay';
365-
import copyToClipboard from '@/lib/copyToClipboard';
366365
import CopyClipboardButton from '@/components/CopyClipboardButton.vue';
367366
368367
export default {
@@ -449,8 +448,6 @@ semaphore runner start --no-config`;
449448
450449
methods: {
451450
452-
copyToClipboard,
453-
454451
async clearCache(runner) {
455452
const projectId = this.projectId || this.getProjectIdOfItem(runner.id);
456453

web/src/views/Tokens.vue

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@
4343
<v-icon>mdi-eye</v-icon>
4444
</v-btn>
4545

46-
<v-btn
47-
icon
46+
<CopyClipboardButton
4847
v-if="item.token_id"
49-
@click="copyToClipboard(item.token_id)"
50-
>
51-
<v-icon>mdi-content-copy</v-icon>
52-
</v-btn>
48+
:text="item.token_id"
49+
success-message="The token has been copied to the clipboard."
50+
/>
5351

5452
</template>
5553

@@ -86,11 +84,13 @@
8684
import EventBus from '@/event-bus';
8785
import ItemListPageBase from '@/components/ItemListPageBase';
8886
import axios from 'axios';
87+
import CopyClipboardButton from '@/components/CopyClipboardButton.vue';
8988
9089
export default {
9190
mixins: [ItemListPageBase],
9291
9392
components: {
93+
CopyClipboardButton,
9494
},
9595
9696
props: {
@@ -173,21 +173,6 @@ export default {
173173
getEventName() {
174174
return 'i-token';
175175
},
176-
177-
async copyToClipboard(text) {
178-
try {
179-
await window.navigator.clipboard.writeText(text);
180-
EventBus.$emit('i-snackbar', {
181-
color: 'success',
182-
text: 'The token has been copied to the clipboard.',
183-
});
184-
} catch (e) {
185-
EventBus.$emit('i-snackbar', {
186-
color: 'error',
187-
text: `Can't copy the token: ${e.message}`,
188-
});
189-
}
190-
},
191176
},
192177
};
193178
</script>

web/src/views/project/IntegrationExtractor.vue

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
22
<div v-if="integration != null">
3-
<IntegrationExtractorCrumb :integration="integration"/>
3+
<IntegrationExtractorCrumb :integration="integration" />
44

55
<div class="px-4 pt-3 pb-2">
66
<v-switch
7-
class="mt-0"
7+
class="mt-0"
88
v-model="integration.searchable"
99
:label="$t('globalAlias')"
1010
@change="updateIntegration()"
@@ -22,11 +22,12 @@
2222

2323
<div v-else v-for="alias of (aliases || [])" :key="alias.id">
2424
<code class="mr-2">{{ alias.url }}</code>
25-
<v-btn icon
26-
@click="copyToClipboard(
27-
alias.url, 'The alias URL has been copied to the clipboard.')">
28-
<v-icon>mdi-content-copy</v-icon>
29-
</v-btn>
25+
26+
<CopyClipboardButton
27+
:text="alias.url"
28+
success-message="The alias URL has been copied to the clipboard."
29+
/>
30+
3031
<v-btn icon @click="deleteAlias(alias.id)">
3132
<v-icon>mdi-delete</v-icon>
3233
</v-btn>
@@ -45,21 +46,23 @@
4546

4647
<IntegrationMatcher class="mb-6" v-if="integration.searchable" />
4748

48-
<IntegrationExtractValue/>
49+
<IntegrationExtractValue />
4950

5051
</div>
5152
</template>
5253
<script>
5354
import IntegrationsBase from '@/views/project/IntegrationsBase';
54-
import copyToClipboard from '@/lib/copyToClipboard';
5555
import axios from 'axios';
56+
import CopyClipboardButton from '@/components/CopyClipboardButton.vue';
5657
import IntegrationExtractValue from './IntegrationExtractValue.vue';
5758
import IntegrationMatcher from './IntegrationMatcher.vue';
5859
import IntegrationExtractorCrumb from './IntegrationExtractorCrumb.vue';
5960
6061
export default {
6162
mixins: [IntegrationsBase],
62-
components: { IntegrationMatcher, IntegrationExtractValue, IntegrationExtractorCrumb },
63+
components: {
64+
CopyClipboardButton, IntegrationMatcher, IntegrationExtractValue, IntegrationExtractorCrumb,
65+
},
6366
props: {
6467
projectId: Number,
6568
},
@@ -79,7 +82,6 @@ export default {
7982
},
8083
8184
methods: {
82-
copyToClipboard,
8385
allowActions() {
8486
return true;
8587
},

web/src/views/project/Integrations.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,16 @@
5252

5353
<div v-else v-for="alias of (aliases || [])" :key="alias.id">
5454
<code class="mr-2">{{ alias.url }}</code>
55-
<v-btn icon
56-
@click="copyToClipboard(alias.url, $t('aliasUrlCopied'))">
57-
<v-icon>mdi-content-copy</v-icon>
58-
</v-btn>
55+
56+
<CopyClipboardButton
57+
:text="alias.url"
58+
:success-message="$t('aliasUrlCopied')"
59+
/>
60+
5961
<v-btn icon @click="deleteAlias(alias.id)">
6062
<v-icon>mdi-delete</v-icon>
6163
</v-btn>
6264
</div>
63-
6465
<v-btn color="primary" @click="addAlias()" :disabled="aliases == null">
6566
{{ aliases == null ? $t('LoadAlias') : $t('AddAlias') }}
6667
</v-btn>
@@ -85,7 +86,7 @@
8586
<router-link
8687
:to="`/project/${projectId}/templates/${item.template_id}`"
8788
>
88-
{{ (templates.find((t) => t.id === item.template_id) || {name: '—'}).name }}
89+
{{ (templates.find((t) => t.id === item.template_id) || { name: '—' }).name }}
8990
</router-link>
9091
</template>
9192
<template v-slot:item.actions="{ item }">
@@ -109,11 +110,11 @@ import { USER_PERMISSIONS } from '@/lib/constants';
109110
import ItemListPageBase from '@/components/ItemListPageBase';
110111
import IntegrationForm from '@/components/IntegrationForm.vue';
111112
import IntegrationsBase from '@/views/project/IntegrationsBase';
112-
import copyToClipboard from '@/lib/copyToClipboard';
113+
import CopyClipboardButton from '@/components/CopyClipboardButton.vue';
113114
114115
export default {
115116
mixins: [ItemListPageBase, IntegrationsBase],
116-
components: { IntegrationForm },
117+
components: { IntegrationForm, CopyClipboardButton },
117118
data() {
118119
return {
119120
templates: null,
@@ -129,7 +130,6 @@ export default {
129130
},
130131
131132
methods: {
132-
copyToClipboard,
133133
allowActions() {
134134
return this.can(USER_PERMISSIONS.updateProject);
135135
},

web/src/views/project/template/TemplateTerraformState.vue

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,10 @@
203203

204204
<div v-else v-for="alias of (aliases || [])" :key="alias.id">
205205
<code class="mr-2">{{ alias.url }}</code>
206-
<v-btn
207-
icon
208-
@click="copyToClipboard(alias.url, $t('aliasUrlCopied'))"
209-
>
210-
<v-icon>mdi-content-copy</v-icon>
211-
</v-btn>
206+
<CopyClipboardButton
207+
:text="alias.url"
208+
:success-message="$t('aliasUrlCopied')"
209+
/>
212210
<v-btn icon @click="editAlias(alias.id)">
213211
<v-icon>mdi-pencil</v-icon>
214212
</v-btn>
@@ -289,7 +287,6 @@
289287
<script>
290288
291289
import axios from 'axios';
292-
import EventBus from '@/event-bus';
293290
import TerraformInventoryForm from '@/components/TerraformInventoryForm.vue';
294291
import EditDialog from '@/components/EditDialog.vue';
295292
import { APP_INVENTORY_TITLE } from '@/lib/constants';
@@ -300,7 +297,7 @@ import TerraformAliasForm from '@/components/TerraformAliasForm.vue';
300297
import TaskStatus from '@/components/TaskStatus.vue';
301298
import TaskLink from '@/components/TaskLink.vue';
302299
import TerraformStateView from '@/components/TerraformStateView.vue';
303-
import copyToClipboard from '@/lib/copyToClipboard';
300+
import CopyClipboardButton from '@/components/CopyClipboardButton.vue';
304301
305302
export default {
306303
mixins: [AppsMixin],
@@ -311,6 +308,7 @@ export default {
311308
},
312309
313310
components: {
311+
CopyClipboardButton,
314312
TerraformStateView,
315313
TaskLink,
316314
TaskStatus,
@@ -381,7 +379,6 @@ export default {
381379
},
382380
383381
methods: {
384-
copyToClipboard,
385382
386383
deleteState(id) {
387384
console.log(id);

0 commit comments

Comments
 (0)