Skip to content

Commit d504d42

Browse files
committed
Replaces tab navigation with TabsLayout component
Replaces the custom tab navigation in the message view with a reusable TabsLayout component. This change improves code maintainability and reduces duplication by centralizing the tab layout logic. The tabs are now dynamically generated based on the message context, such as whether it's an error or if MassTransit is connected.
1 parent a561975 commit d504d42

File tree

2 files changed

+60
-18
lines changed

2 files changed

+60
-18
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<script setup lang="ts">
2+
import { ref, type Component, type DefineComponent } from "vue";
3+
4+
interface Tab {
5+
text: string;
6+
component: Component | DefineComponent;
7+
}
8+
9+
const props = defineProps<{ tabs: Tab[] }>();
10+
const activePanel = ref(0);
11+
const activeComponent = ref(props.tabs[0].component);
12+
13+
function togglePanel(panelIndex: number) {
14+
activePanel.value = panelIndex;
15+
activeComponent.value = props.tabs[panelIndex].component;
16+
}
17+
</script>
18+
19+
<template>
20+
<div class="nav tabs msg-tabs">
21+
<h5 :class="{ active: activePanel === index }" class="nav-item" @click.prevent="togglePanel(index)" v-for="(tab, index) in props.tabs" :key="tab.text">
22+
<a href="#">{{ tab.text }}</a>
23+
</h5>
24+
</div>
25+
<keep-alive>
26+
<component v-bind:is="activeComponent"></component>
27+
</keep-alive>
28+
</template>
29+
30+
<style scoped></style>

src/Frontend/src/components/messages/MessageView2.vue

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { computed, onMounted, ref, watch } from "vue";
2+
import { computed, watch } from "vue";
33
import { RouterLink, useRoute } from "vue-router";
44
import NoData from "../NoData.vue";
55
import TimeSince from "../TimeSince.vue";
@@ -16,10 +16,10 @@ import RetryMessageButton from "@/components/messages/RetryMessageButton.vue";
1616
import EditAndRetryButton from "@/components/messages/EditAndRetryButton.vue";
1717
import ExportMessageButton from "@/components/messages/ExportMessageButton.vue";
1818
import LoadingSpinner from "@/components/LoadingSpinner.vue";
19+
import TabsLayout from "@/components/TabsLayout.vue";
1920
import { storeToRefs } from "pinia";
2021
import MetadataLabel from "@/components/messages/MetadataLabel.vue";
2122
22-
const panel = ref<number>(1);
2323
const route = useRoute();
2424
const id = computed(() => route.params.id as string);
2525
const messageId = computed(() => route.params.messageId as string);
@@ -29,10 +29,6 @@ const isMassTransitConnected = useIsMassTransitConnected();
2929
const store = useMessageViewStore();
3030
const { state } = storeToRefs(store);
3131
32-
function togglePanel(panelNum: number) {
33-
panel.value = panelNum;
34-
}
35-
3632
watch(
3733
[id, messageId],
3834
async ([newId, newMessageId], [oldId, oldMessageId]) => {
@@ -49,8 +45,33 @@ watch(
4945
{ immediate: true }
5046
);
5147
52-
onMounted(() => {
53-
togglePanel(isError.value ? 1 : 2);
48+
const tabs = computed(() => {
49+
const currentTabs = [
50+
{
51+
text: "Message body",
52+
component: BodyView,
53+
},
54+
{
55+
text: "Headers",
56+
component: HeadersView,
57+
},
58+
];
59+
60+
if (isError.value) {
61+
currentTabs.unshift({
62+
text: "Stacktrace",
63+
component: StackTraceView,
64+
});
65+
}
66+
67+
if (!isMassTransitConnected.value) {
68+
currentTabs.push({
69+
text: "Flow Diagram",
70+
component: FlowDiagram,
71+
});
72+
}
73+
74+
return currentTabs;
5475
});
5576
</script>
5677

@@ -117,16 +138,7 @@ onMounted(() => {
117138
</div>
118139
<div class="row">
119140
<div class="col-sm-12 no-side-padding">
120-
<div class="nav tabs msg-tabs">
121-
<h5 v-if="isError" :class="{ active: panel === 1 }" class="nav-item" @click.prevent="togglePanel(1)"><a href="#">Stacktrace</a></h5>
122-
<h5 :class="{ active: panel === 2 }" class="nav-item" @click.prevent="togglePanel(2)"><a href="#">Message body</a></h5>
123-
<h5 :class="{ active: panel === 3 }" class="nav-item" @click.prevent="togglePanel(3)"><a href="#">Headers</a></h5>
124-
<h5 v-if="!isMassTransitConnected" :class="{ active: panel === 4 }" class="nav-item" @click.prevent="togglePanel(4)"><a href="#">Flow Diagram</a></h5>
125-
</div>
126-
<StackTraceView v-if="isError && panel === 1" />
127-
<BodyView v-if="panel === 2" />
128-
<HeadersView v-if="panel === 3" />
129-
<FlowDiagram v-if="panel === 4" />
141+
<TabsLayout :tabs="tabs" />
130142
</div>
131143
</div>
132144
</template>

0 commit comments

Comments
 (0)