-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display GenAI analysis in the case page in the Web UI (#5301)
* Display GenAI analysis in the case page in the Web UI * adds GenaiAnalysisDisplay.vue component * makes eslint happy * Sanitize the formatted text to avoid XSS
- Loading branch information
Showing
6 changed files
with
115 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/dispatch/static/dispatch/src/components/GenaiAnalysisDisplay.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<template> | ||
<div> | ||
<h2>GenAI Analysis</h2> | ||
<div v-if="analysis && Object.keys(analysis).length > 0"> | ||
<div v-for="(value, key) in analysis" :key="key" class="analysis-item"> | ||
<h3> | ||
<b>{{ key }}</b> | ||
</h3> | ||
<div v-if="isObject(value)"> | ||
<!-- Render each sub-value with formatText to handle links and code formatting --> | ||
<span | ||
v-for="(subValue, subKey) in value" | ||
:key="subKey" | ||
v-html="formatText(subValue)" | ||
></span> | ||
</div> | ||
<span v-else v-html="formatText(value)"></span> | ||
</div> | ||
</div> | ||
<div v-else> | ||
<p>A GenAI analysis does not exist for this case.</p> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { defineProps } from "vue" | ||
import DOMPurify from "dompurify" | ||
// Define the `analysis` prop | ||
defineProps({ | ||
analysis: { | ||
type: Object, | ||
required: false, | ||
default: null, | ||
}, | ||
}) | ||
// Helper function to check if a value is an object | ||
function isObject(value) { | ||
return typeof value === "object" && value !== null | ||
} | ||
// Function to format text, converting <URL|text> format to clickable links and wrapping `code` with <code> tags | ||
function formatText(text) { | ||
if (typeof text !== "string") return text | ||
// Convert <URL|text> format to clickable links | ||
let formattedText = text.replace(/<([^|]+)\|([^>]+)>/g, '<a href="$1" target="_blank">$2</a>') | ||
// Convert `code` format to <code>code</code> for inline code styling | ||
formattedText = formattedText.replace(/`([^`]+)`/g, "<code>$1</code>") | ||
// Sanitize the formatted text to avoid XSS | ||
return DOMPurify.sanitize(formattedText) | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
h2 { | ||
margin-bottom: 1rem; | ||
font-size: 1.5em; | ||
} | ||
.analysis-item h3 { | ||
margin-top: 1em; | ||
} | ||
a { | ||
color: #1a73e8; | ||
text-decoration: underline; | ||
} | ||
code { | ||
font-family: monospace; | ||
background-color: #f5f5f5; | ||
padding: 0.2em 0.4em; | ||
border-radius: 4px; | ||
} | ||
</style> |