@@ -8,11 +8,14 @@ import router from '@/router'
88import { getRouteName , useDashboard } from ' @/composables/dashboard'
99
1010const props = defineProps <{
11- service: KafkaService ,
11+ service? : KafkaService ,
1212 topicName? : string
1313}>()
1414
15- const labels = [{name: ' name' , value: props .service ! .name }]
15+ const labels = []
16+ if (props .service ) {
17+ labels .push ({name: ' name' , value: props .service .name })
18+ }
1619if (props .topicName ){
1720 labels .push ({name: ' topic' , value: props .topicName })
1821}
@@ -156,18 +159,36 @@ function showMessage(event: ServiceEvent){
156159 }
157160}
158161
159- function getTopic(name : string ): KafkaTopic {
160- for (const topic of props .service ! .topics ) {
161- if (topic .name === name ) {
162- return topic
162+ function getTopic(event : ServiceEvent ): KafkaTopic | undefined {
163+ const topicName = event .traits [" topic" ]!
164+
165+ let service = props .service
166+ if (! service ) {
167+ const { services } = dashboard .value .getServices (' kafka' , false );
168+ for (const s of services .value ) {
169+ console .log (s )
170+ if (s .name === event .traits [' name' ]) {
171+ service = s as KafkaService
172+ }
163173 }
164174 }
165- throw new Error (` topic ${name } not found ` )
175+
176+ if (props .service ) {
177+ for (const topic of props .service .topics ) {
178+ if (topic .name === topicName ) {
179+ return topic
180+ }
181+ }
182+ }
183+
184+ return undefined
166185}
167186function getMessageConfig(event : ServiceEvent ): KafkaMessage | undefined {
168- const topicName = event .traits [" topic" ]!
169187 const data = eventData (event )
170- const topic = getTopic (topicName )
188+ const topic = getTopic (event )
189+ if (! topic ) {
190+ return undefined
191+ }
171192
172193 const keys = Object .keys (topic .messages )
173194 if (keys .length === 1 ) {
0 commit comments