Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions src/Frontend/src/components/messages/BodyView.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<script setup lang="ts">
import { computed, watch } from "vue";
import { computed, ref, watch } from "vue";
import CodeEditor from "@/components/CodeEditor.vue";
import HexView from "@/components/messages/HexView.vue";
import parseContentType from "@/composables/contentTypeParser";
import { useMessageStore } from "@/stores/MessageStore";
import LoadingSpinner from "@/components/LoadingSpinner.vue";
import { storeToRefs } from "pinia";

type ViewMode = "formatted" | "hex";

const store = useMessageStore();
const { body: bodyState, state } = storeToRefs(store);
const viewMode = ref<ViewMode>("formatted");

watch(
() => state.value.data.body_url,
Expand All @@ -18,6 +22,16 @@ watch(
);
const contentType = computed(() => parseContentType(bodyState.value.data.content_type));
const body = computed(() => bodyState.value.data.value);
const rawBytes = computed(() => bodyState.value.data.rawBytes);
const parseFailed = computed(() => bodyState.value.data.parse_failed);

watch(
parseFailed,
(failed) => {
if (failed) viewMode.value = "hex";
},
{ immediate: true }
);
Comment on lines 14 to +34
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

viewMode is only forced to "hex" when parseFailed becomes truthy, but it’s never reset when navigating to a different message or when a subsequent body parses successfully. This means the UI can stay in Hex view across messages even when parse_failed is false. Reset viewMode to "formatted" on body_url change (or when parseFailed becomes falsy) and then re-apply the auto-switch when parse fails.

Copilot uses AI. Check for mistakes.
</script>

<template>
Expand All @@ -29,13 +43,25 @@ const body = computed(() => bodyState.value.data.value);
Body was too large and not stored. Edit <a href="https://docs.particular.net/servicecontrol/audit-instances/configuration#performance-tuning-servicecontrol-auditmaxbodysizetostore">ServiceControl/MaxBodySizeToStore</a> to be larger in the
ServiceControl configuration.
</div>
<CodeEditor v-else-if="body !== undefined && contentType.isSupported" :model-value="body" :language="contentType.language" :read-only="true" :show-gutter="true"></CodeEditor>
<div v-else-if="body && !contentType.isSupported" class="alert alert-warning">Message body cannot be displayed because content type "{{ bodyState.data.content_type }}" is not supported.</div>
<template v-else-if="rawBytes">
<div v-if="parseFailed" class="alert alert-warning">Message body could not be parsed as {{ bodyState.data.content_type }}. Showing hex view.</div>
<div class="btn-group btn-group-sm" role="group" aria-label="View mode">
<button type="button" :class="['btn', viewMode === 'formatted' ? 'btn-primary' : 'btn-outline-secondary']" @click="viewMode = 'formatted'">Formatted</button>
<button type="button" :class="['btn', viewMode === 'hex' ? 'btn-primary' : 'btn-outline-secondary']" @click="viewMode = 'hex'">Hex</button>
</div>
<CodeEditor v-if="viewMode === 'formatted' && body !== undefined && contentType.isSupported" :model-value="body" :language="contentType.language" :read-only="true" :show-gutter="true" />
<div v-else-if="viewMode === 'formatted' && !contentType.isSupported" class="alert alert-warning">Message body cannot be displayed because content type "{{ bodyState.data.content_type }}" is not supported.</div>
<HexView v-else-if="viewMode === 'hex'" :data="rawBytes" />
</template>
</div>
</template>

<style scoped>
.gap {
margin-top: 5px;
}

.btn-group {
margin-bottom: 5px;
}
</style>
Loading
Loading