Skip to content

Commit 5475959

Browse files
soujayjohnsimons
andauthored
Copy feature in message headers in message view (#2281)
* add option to copy the header values to clipboard Co-authored-by: John Simons <[email protected]>
1 parent 88bbb2f commit 5475959

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/Frontend/src/components/CopyToClipboard.vue

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
import { Tippy, TippyComponent } from "vue-tippy";
33
import { useTemplateRef } from "vue";
44
5-
const props = defineProps<{
6-
value: string;
7-
}>();
5+
const props = withDefaults(
6+
defineProps<{
7+
value: string;
8+
isIconOnly?: boolean;
9+
}>(),
10+
{ isIconOnly: false }
11+
);
812
913
const tippyRef = useTemplateRef<TippyComponent | null>("tippyRef");
1014
let timeoutId: number;
@@ -19,6 +23,7 @@ async function copyToClipboard() {
1923

2024
<template>
2125
<Tippy content="Copied" ref="tippyRef" trigger="manual">
22-
<button type="button" class="btn btn-secondary btn-sm" @click="copyToClipboard"><i class="fa fa-copy"></i> Copy to clipboard</button>
26+
<button v-if="!props.isIconOnly" type="button" class="btn btn-secondary btn-sm" @click="copyToClipboard"><i class="fa fa-copy"></i> Copy to clipboard</button>
27+
<button v-else type="button" class="btn btn-secondary btn-sm" @click="copyToClipboard" v-tippy="'Copy to clipboard'"><i class="fa fa-copy"></i></button>
2328
</Tippy>
2429
</template>
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
<script setup lang="ts">
22
import { ExtendedFailedMessage } from "@/resources/FailedMessage";
3-
3+
import CopyToClipboard from "@/components/CopyToClipboard.vue";
4+
import { ref } from "vue";
45
const props = defineProps<{
56
message: ExtendedFailedMessage;
67
}>();
8+
9+
const hoverStates = ref<Record<number, boolean>>({});
10+
11+
const toggleHover = (index: number, state: boolean) => {
12+
hoverStates.value[index] = state;
13+
};
714
</script>
815

916
<template>
@@ -12,12 +19,21 @@ const props = defineProps<{
1219
<tr class="interactiveList" v-for="(header, index) in props.message.headers" :key="index">
1320
<td nowrap="nowrap">{{ header.key }}</td>
1421
<td>
15-
<pre>{{ header.value }}</pre>
22+
<div class="headercopy" @mouseover="toggleHover(index, true)" @mouseleave="toggleHover(index, false)">
23+
<pre>{{ header.value }}</pre>
24+
<CopyToClipboard v-if="hoverStates[index]" :value="header.value || ''" :isIconOnly="true" />
25+
</div>
1626
</td>
1727
</tr>
1828
</tbody>
1929
</table>
2030
<div v-if="props.message.headersNotFound" class="alert alert-info">Could not find message headers. This could be because the message URL is invalid or the corresponding message was processed and is no longer tracked by ServiceControl.</div>
2131
</template>
2232

23-
<style scoped></style>
33+
<style scoped>
34+
.headercopy {
35+
display: flex;
36+
align-items: top;
37+
gap: 0.4rem;
38+
}
39+
</style>

0 commit comments

Comments
 (0)