Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit ·
2bb9807
1
Parent(s): 32ee7c2
backend stabilisation
Browse files- api/v1/kb.py +4 -1
- api/v1/messages.py +10 -0
- core/sync.py +31 -0
- frontend/apps/customer/src/components/NewTicketView.tsx +5 -0
- frontend/apps/customer/src/components/ThreadView.tsx +5 -5
- frontend/apps/internal/src/components/TicketDetails.tsx +9 -7
- frontend/packages/shared/src/components/RichEditor.tsx +88 -36
- frontend/packages/shared/src/hooks/useMentions.ts +6 -1
- services/ticket_service.py +8 -0
api/v1/kb.py
CHANGED
|
@@ -19,7 +19,7 @@ from models.kb_article_version import KBArticleVersion
|
|
| 19 |
from models.project import Project
|
| 20 |
from core.llm import get_llm, get_text_embeddings
|
| 21 |
from models.attachment import Attachment
|
| 22 |
-
from core.sync import sync_markdown_images
|
| 23 |
from core.cache import (
|
| 24 |
generate_cache_key, get_cached_search, set_cached_search,
|
| 25 |
SemanticCacheManager, invalidate_cache, delete_by_pattern,
|
|
@@ -693,6 +693,9 @@ async def update_kb_article(
|
|
| 693 |
|
| 694 |
# Sync images if content is updated
|
| 695 |
if "content" in update_data:
|
|
|
|
|
|
|
|
|
|
| 696 |
# Corrected signature: (db, entity_id, workspace_id, content, entity_type, uploader_id)
|
| 697 |
await sync_markdown_images(db, article.id, article.workspace_id, update_data["content"], entity_type="article", uploader_id=current_user.id)
|
| 698 |
|
|
|
|
| 19 |
from models.project import Project
|
| 20 |
from core.llm import get_llm, get_text_embeddings
|
| 21 |
from models.attachment import Attachment
|
| 22 |
+
from core.sync import sync_markdown_images, link_internal_attachments
|
| 23 |
from core.cache import (
|
| 24 |
generate_cache_key, get_cached_search, set_cached_search,
|
| 25 |
SemanticCacheManager, invalidate_cache, delete_by_pattern,
|
|
|
|
| 693 |
|
| 694 |
# Sync images if content is updated
|
| 695 |
if "content" in update_data:
|
| 696 |
+
# Link internal attachments first
|
| 697 |
+
await link_internal_attachments(db, article.id, update_data["content"], entity_type="article")
|
| 698 |
+
# Then sync external images
|
| 699 |
# Corrected signature: (db, entity_id, workspace_id, content, entity_type, uploader_id)
|
| 700 |
await sync_markdown_images(db, article.id, article.workspace_id, update_data["content"], entity_type="article", uploader_id=current_user.id)
|
| 701 |
|
api/v1/messages.py
CHANGED
|
@@ -17,6 +17,7 @@ from models.user import User, UserRole
|
|
| 17 |
from models.ticket import Ticket
|
| 18 |
from models.message import Message
|
| 19 |
from schemas.message import MessageCreate, MessageResponse
|
|
|
|
| 20 |
|
| 21 |
router = APIRouter()
|
| 22 |
|
|
@@ -117,6 +118,10 @@ async def send_message(
|
|
| 117 |
mentions=mentions
|
| 118 |
)
|
| 119 |
db.add(new_message)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
await db.commit()
|
| 121 |
await db.refresh(new_message)
|
| 122 |
|
|
@@ -244,6 +249,11 @@ async def edit_message(
|
|
| 244 |
message.mentions = mentions
|
| 245 |
|
| 246 |
db.add(message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
await db.commit()
|
| 248 |
await db.refresh(message)
|
| 249 |
|
|
|
|
| 17 |
from models.ticket import Ticket
|
| 18 |
from models.message import Message
|
| 19 |
from schemas.message import MessageCreate, MessageResponse
|
| 20 |
+
from core.sync import link_internal_attachments
|
| 21 |
|
| 22 |
router = APIRouter()
|
| 23 |
|
|
|
|
| 118 |
mentions=mentions
|
| 119 |
)
|
| 120 |
db.add(new_message)
|
| 121 |
+
|
| 122 |
+
# Auto-link images pasted into the message
|
| 123 |
+
await link_internal_attachments(db, ticket_id, payload.content)
|
| 124 |
+
|
| 125 |
await db.commit()
|
| 126 |
await db.refresh(new_message)
|
| 127 |
|
|
|
|
| 249 |
message.mentions = mentions
|
| 250 |
|
| 251 |
db.add(message)
|
| 252 |
+
|
| 253 |
+
# Auto-link images if content was updated
|
| 254 |
+
if old_content != payload.content:
|
| 255 |
+
await link_internal_attachments(db, ticket_id, payload.content)
|
| 256 |
+
|
| 257 |
await db.commit()
|
| 258 |
await db.refresh(message)
|
| 259 |
|
core/sync.py
CHANGED
|
@@ -20,6 +20,37 @@ IMAGE_PATTERN = re.compile(
|
|
| 20 |
re.IGNORECASE
|
| 21 |
)
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
async def sync_markdown_images(db: AsyncSession, entity_id: UUID, workspace_id: UUID, content: str, entity_type: str = "ticket", uploader_id: UUID = None):
|
| 24 |
"""
|
| 25 |
Parses content for external images (Markdown or raw URLs), downloads them,
|
|
|
|
| 20 |
re.IGNORECASE
|
| 21 |
)
|
| 22 |
|
| 23 |
+
INTERNAL_ATTACHMENT_PATTERN = re.compile(r'/attachments/([0-9a-fA-F-]{36})/')
|
| 24 |
+
|
| 25 |
+
async def link_internal_attachments(db: AsyncSession, entity_id: UUID, content: str, entity_type: str = "ticket"):
|
| 26 |
+
"""
|
| 27 |
+
Scans content for our own attachment IDs and links them to the entity if they are currently unlinked.
|
| 28 |
+
This ensures that images pasted into the RichEditor appear in the 'Files' tab.
|
| 29 |
+
"""
|
| 30 |
+
if not content:
|
| 31 |
+
return
|
| 32 |
+
|
| 33 |
+
matches = INTERNAL_ATTACHMENT_PATTERN.findall(content)
|
| 34 |
+
if not matches:
|
| 35 |
+
return
|
| 36 |
+
|
| 37 |
+
attachment_ids = [UUID(m) for m in matches]
|
| 38 |
+
|
| 39 |
+
from sqlalchemy import update
|
| 40 |
+
stmt = (
|
| 41 |
+
update(Attachment)
|
| 42 |
+
.where(Attachment.id.in_(attachment_ids))
|
| 43 |
+
.where(Attachment.ticket_id.is_(None))
|
| 44 |
+
.where(Attachment.article_id.is_(None))
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
if entity_type == "ticket":
|
| 48 |
+
stmt = stmt.values(ticket_id=entity_id)
|
| 49 |
+
else:
|
| 50 |
+
stmt = stmt.values(article_id=entity_id)
|
| 51 |
+
|
| 52 |
+
await db.execute(stmt)
|
| 53 |
+
|
| 54 |
async def sync_markdown_images(db: AsyncSession, entity_id: UUID, workspace_id: UUID, content: str, entity_type: str = "ticket", uploader_id: UUID = None):
|
| 55 |
"""
|
| 56 |
Parses content for external images (Markdown or raw URLs), downloads them,
|
frontend/apps/customer/src/components/NewTicketView.tsx
CHANGED
|
@@ -270,6 +270,11 @@ export const NewTicketView: React.FC<NewTicketViewProps> = ({ onBack, onCreate }
|
|
| 270 |
<RichEditor
|
| 271 |
value={form.description}
|
| 272 |
onChange={val => setForm(f => ({ ...f, description: val }))}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
placeholder="Provide context, logs, or steps to reproduce. You can paste screenshots directly here..."
|
| 274 |
/>
|
| 275 |
|
|
|
|
| 270 |
<RichEditor
|
| 271 |
value={form.description}
|
| 272 |
onChange={val => setForm(f => ({ ...f, description: val }))}
|
| 273 |
+
onAttachmentUpload={(att) => {
|
| 274 |
+
const backendBase = api.defaults.baseURL?.endsWith('/') ? api.defaults.baseURL : api.defaults.baseURL + '/';
|
| 275 |
+
const downloadUrl = `${backendBase}tickets/attachments/${att.id}/download/`;
|
| 276 |
+
setAttachments(prev => [...prev, { ...att, downloadUrl }]);
|
| 277 |
+
}}
|
| 278 |
placeholder="Provide context, logs, or steps to reproduce. You can paste screenshots directly here..."
|
| 279 |
/>
|
| 280 |
|
frontend/apps/customer/src/components/ThreadView.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
| 7 |
getStorageKey,
|
| 8 |
useMentions,
|
| 9 |
MentionOverlay,
|
|
|
|
| 10 |
useTheme,
|
| 11 |
useNotification
|
| 12 |
} from '@nexus/shared';
|
|
@@ -697,12 +698,11 @@ export const ThreadView: React.FC<ThreadViewProps> = ({ ticket: initialTicket, o
|
|
| 697 |
|
| 698 |
{isEditingDesc ? (
|
| 699 |
<div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
|
| 700 |
-
<
|
| 701 |
-
className={styles.feedbackTextarea}
|
| 702 |
value={descDraft}
|
| 703 |
-
onChange={
|
| 704 |
-
|
| 705 |
-
|
| 706 |
/>
|
| 707 |
<div style={{ display: 'flex', gap: 12, justifyContent: 'flex-end' }}>
|
| 708 |
<button onClick={() => setIsEditingDesc(false)} className={styles.btnSecondary} style={{ padding: '8px 20px' }}>CANCEL</button>
|
|
|
|
| 7 |
getStorageKey,
|
| 8 |
useMentions,
|
| 9 |
MentionOverlay,
|
| 10 |
+
RichEditor,
|
| 11 |
useTheme,
|
| 12 |
useNotification
|
| 13 |
} from '@nexus/shared';
|
|
|
|
| 698 |
|
| 699 |
{isEditingDesc ? (
|
| 700 |
<div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
|
| 701 |
+
<RichEditor
|
|
|
|
| 702 |
value={descDraft}
|
| 703 |
+
onChange={setDescDraft}
|
| 704 |
+
ticketId={ticket.id}
|
| 705 |
+
placeholder="Provide context, logs, or steps to reproduce..."
|
| 706 |
/>
|
| 707 |
<div style={{ display: 'flex', gap: 12, justifyContent: 'flex-end' }}>
|
| 708 |
<button onClick={() => setIsEditingDesc(false)} className={styles.btnSecondary} style={{ padding: '8px 20px' }}>CANCEL</button>
|
frontend/apps/internal/src/components/TicketDetails.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
| 7 |
getFileIcon,
|
| 8 |
useMentions,
|
| 9 |
MentionOverlay,
|
|
|
|
| 10 |
useNotification,
|
| 11 |
getStorageKey
|
| 12 |
} from '@nexus/shared';
|
|
@@ -1334,10 +1335,11 @@ export const TicketDetails: React.FC<TicketDetailsProps> = ({ initialTicket, onB
|
|
| 1334 |
exit={{ opacity: 0, scale: 0.98 }}
|
| 1335 |
className={styles.descriptionEditor}
|
| 1336 |
>
|
| 1337 |
-
<
|
| 1338 |
-
className={styles.descriptionTextarea}
|
| 1339 |
value={descriptionDraft}
|
| 1340 |
-
onChange={
|
|
|
|
|
|
|
| 1341 |
/>
|
| 1342 |
<div className={styles.editorActions}>
|
| 1343 |
<button onClick={() => setIsEditingDescription(false)} className={styles.btnSecondary}>Cancel</button>
|
|
@@ -1372,11 +1374,11 @@ export const TicketDetails: React.FC<TicketDetailsProps> = ({ initialTicket, onB
|
|
| 1372 |
<label style={{ fontSize: 9, color: 'var(--primary)', fontWeight: 900, marginBottom: 8, display: 'block' }}>ROOT CAUSE ANALYSIS</label>
|
| 1373 |
{isEditingRCA ? (
|
| 1374 |
<div className={styles.descriptionEditor}>
|
| 1375 |
-
<
|
| 1376 |
-
className={styles.descriptionTextarea}
|
| 1377 |
-
style={{ minHeight: 100, fontSize: 13, marginBottom: 12 }}
|
| 1378 |
value={rcaDraft}
|
| 1379 |
-
onChange={
|
|
|
|
|
|
|
| 1380 |
/>
|
| 1381 |
<div className={styles.editorActions}>
|
| 1382 |
<button onClick={() => { setIsEditingRCA(false); setRcaDraft(ticket.rca_notes || ticket.ai_metadata?.initial_analysis?.rca || ""); }} className={styles.btnSecondary}>Cancel</button>
|
|
|
|
| 7 |
getFileIcon,
|
| 8 |
useMentions,
|
| 9 |
MentionOverlay,
|
| 10 |
+
RichEditor,
|
| 11 |
useNotification,
|
| 12 |
getStorageKey
|
| 13 |
} from '@nexus/shared';
|
|
|
|
| 1335 |
exit={{ opacity: 0, scale: 0.98 }}
|
| 1336 |
className={styles.descriptionEditor}
|
| 1337 |
>
|
| 1338 |
+
<RichEditor
|
|
|
|
| 1339 |
value={descriptionDraft}
|
| 1340 |
+
onChange={setDescriptionDraft}
|
| 1341 |
+
ticketId={ticket.id}
|
| 1342 |
+
placeholder="Refine the technical description..."
|
| 1343 |
/>
|
| 1344 |
<div className={styles.editorActions}>
|
| 1345 |
<button onClick={() => setIsEditingDescription(false)} className={styles.btnSecondary}>Cancel</button>
|
|
|
|
| 1374 |
<label style={{ fontSize: 9, color: 'var(--primary)', fontWeight: 900, marginBottom: 8, display: 'block' }}>ROOT CAUSE ANALYSIS</label>
|
| 1375 |
{isEditingRCA ? (
|
| 1376 |
<div className={styles.descriptionEditor}>
|
| 1377 |
+
<RichEditor
|
|
|
|
|
|
|
| 1378 |
value={rcaDraft}
|
| 1379 |
+
onChange={setRcaDraft}
|
| 1380 |
+
ticketId={ticket.id}
|
| 1381 |
+
placeholder="Enter technical root cause..."
|
| 1382 |
/>
|
| 1383 |
<div className={styles.editorActions}>
|
| 1384 |
<button onClick={() => { setIsEditingRCA(false); setRcaDraft(ticket.rca_notes || ticket.ai_metadata?.initial_analysis?.rca || ""); }} className={styles.btnSecondary}>Cancel</button>
|
frontend/packages/shared/src/components/RichEditor.tsx
CHANGED
|
@@ -15,9 +15,11 @@ interface RichEditorProps {
|
|
| 15 |
value: string;
|
| 16 |
onChange: (markdown: string) => void;
|
| 17 |
placeholder?: string;
|
|
|
|
|
|
|
| 18 |
}
|
| 19 |
|
| 20 |
-
export const RichEditor: React.FC<RichEditorProps> = ({ value, onChange, placeholder }) => {
|
| 21 |
const editorRef = useRef<HTMLDivElement>(null);
|
| 22 |
const [selectedImage, setSelectedImage] = useState<HTMLImageElement | null>(null);
|
| 23 |
|
|
@@ -33,6 +35,8 @@ export const RichEditor: React.FC<RichEditorProps> = ({ value, onChange, placeho
|
|
| 33 |
// Convert HTML from contentEditable to Markdown
|
| 34 |
const htmlToMarkdown = (html: string) => {
|
| 35 |
let md = html
|
|
|
|
|
|
|
| 36 |
.replace(/<b>(.*?)<\/b>/g, '**$1**')
|
| 37 |
.replace(/<strong>(.*?)<\/strong>/g, '**$1**')
|
| 38 |
.replace(/<i>(.*?)<\/i>/g, '*$1*')
|
|
@@ -57,6 +61,7 @@ export const RichEditor: React.FC<RichEditorProps> = ({ value, onChange, placeho
|
|
| 57 |
const markdownToHtml = (md: string) => {
|
| 58 |
if (!md) return '';
|
| 59 |
return md
|
|
|
|
| 60 |
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
| 61 |
.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
| 62 |
.replace(/`(.*?)`/g, '<code>$1</code>')
|
|
@@ -88,8 +93,19 @@ export const RichEditor: React.FC<RichEditorProps> = ({ value, onChange, placeho
|
|
| 88 |
const selection = window.getSelection();
|
| 89 |
if (selection && selection.rangeCount > 0) {
|
| 90 |
const range = selection.getRangeAt(0);
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
}
|
| 94 |
}
|
| 95 |
};
|
|
@@ -110,19 +126,30 @@ export const RichEditor: React.FC<RichEditorProps> = ({ value, onChange, placeho
|
|
| 110 |
if (!match) return;
|
| 111 |
|
| 112 |
const startPos = match.index!;
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
selection.removeAllRanges();
|
| 125 |
-
selection.addRange(
|
| 126 |
|
| 127 |
closeMentions();
|
| 128 |
handleInput();
|
|
@@ -130,27 +157,36 @@ export const RichEditor: React.FC<RichEditorProps> = ({ value, onChange, placeho
|
|
| 130 |
|
| 131 |
const handlePaste = async (e: React.ClipboardEvent) => {
|
| 132 |
const items = e.clipboardData.items;
|
| 133 |
-
let
|
| 134 |
for (let i = 0; i < items.length; i++) {
|
| 135 |
-
if (items[i].type.indexOf("image") !== -1
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
}
|
| 155 |
}
|
| 156 |
}
|
|
@@ -300,11 +336,14 @@ export const RichEditor: React.FC<RichEditorProps> = ({ value, onChange, placeho
|
|
| 300 |
{!value && placeholder && (
|
| 301 |
<div style={{
|
| 302 |
position: 'absolute',
|
| 303 |
-
top:
|
| 304 |
left: 24,
|
| 305 |
pointerEvents: 'none',
|
| 306 |
color: 'var(--text-muted)',
|
| 307 |
-
opacity: 0.5
|
|
|
|
|
|
|
|
|
|
| 308 |
}}>
|
| 309 |
{placeholder}
|
| 310 |
</div>
|
|
@@ -341,6 +380,19 @@ export const RichEditor: React.FC<RichEditorProps> = ({ value, onChange, placeho
|
|
| 341 |
color: var(--text-muted);
|
| 342 |
opacity: 0.5;
|
| 343 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
`}</style>
|
| 345 |
</div>
|
| 346 |
);
|
|
|
|
| 15 |
value: string;
|
| 16 |
onChange: (markdown: string) => void;
|
| 17 |
placeholder?: string;
|
| 18 |
+
ticketId?: string;
|
| 19 |
+
onAttachmentUpload?: (attachment: any) => void;
|
| 20 |
}
|
| 21 |
|
| 22 |
+
export const RichEditor: React.FC<RichEditorProps> = ({ value, onChange, placeholder, ticketId, onAttachmentUpload }) => {
|
| 23 |
const editorRef = useRef<HTMLDivElement>(null);
|
| 24 |
const [selectedImage, setSelectedImage] = useState<HTMLImageElement | null>(null);
|
| 25 |
|
|
|
|
| 35 |
// Convert HTML from contentEditable to Markdown
|
| 36 |
const htmlToMarkdown = (html: string) => {
|
| 37 |
let md = html
|
| 38 |
+
// First, preserve styled mentions before stripping tags
|
| 39 |
+
.replace(/<span.*?class="mention-badge".*?data-id="(.*?)".*?data-name="(.*?)">.*?<\/span>/g, '@[$2]($1)')
|
| 40 |
.replace(/<b>(.*?)<\/b>/g, '**$1**')
|
| 41 |
.replace(/<strong>(.*?)<\/strong>/g, '**$1**')
|
| 42 |
.replace(/<i>(.*?)<\/i>/g, '*$1*')
|
|
|
|
| 61 |
const markdownToHtml = (md: string) => {
|
| 62 |
if (!md) return '';
|
| 63 |
return md
|
| 64 |
+
.replace(/@\[(.*?)\]\((.*?)\)/g, '<span class="mention-badge" data-id="$2" data-name="$1">@$1</span>')
|
| 65 |
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
| 66 |
.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
| 67 |
.replace(/`(.*?)`/g, '<code>$1</code>')
|
|
|
|
| 93 |
const selection = window.getSelection();
|
| 94 |
if (selection && selection.rangeCount > 0) {
|
| 95 |
const range = selection.getRangeAt(0);
|
| 96 |
+
let textBefore = "";
|
| 97 |
+
let offset = 0;
|
| 98 |
+
|
| 99 |
+
if (range.startContainer.nodeType === Node.TEXT_NODE) {
|
| 100 |
+
textBefore = range.startContainer.textContent?.slice(0, range.startOffset) || "";
|
| 101 |
+
offset = range.startOffset;
|
| 102 |
+
} else {
|
| 103 |
+
// At start of block or empty
|
| 104 |
+
textBefore = editorRef.current.innerText.slice(0, selection.focusOffset);
|
| 105 |
+
offset = selection.focusOffset;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
handleInputChange(textBefore, offset);
|
| 109 |
}
|
| 110 |
}
|
| 111 |
};
|
|
|
|
| 126 |
if (!match) return;
|
| 127 |
|
| 128 |
const startPos = match.index!;
|
| 129 |
+
|
| 130 |
+
// Create the styled mention badge
|
| 131 |
+
const badgeHtml = `<span class="mention-badge" data-id="${user.id}" data-name="${user.full_name}">@${user.full_name}</span> `;
|
| 132 |
+
|
| 133 |
+
// Select the @query text to replace it
|
| 134 |
+
range.setStart(node, startPos);
|
| 135 |
+
range.setEnd(node, range.startOffset);
|
| 136 |
+
range.deleteContents();
|
| 137 |
+
|
| 138 |
+
// Insert the badge
|
| 139 |
+
const div = document.createElement('div');
|
| 140 |
+
div.innerHTML = badgeHtml;
|
| 141 |
+
const frag = document.createDocumentFragment();
|
| 142 |
+
let lastNode;
|
| 143 |
+
while (lastNode = div.firstChild) {
|
| 144 |
+
frag.appendChild(lastNode);
|
| 145 |
+
}
|
| 146 |
+
range.insertNode(frag);
|
| 147 |
+
|
| 148 |
+
// Move cursor after the mention
|
| 149 |
+
range.setStartAfter(lastNode!);
|
| 150 |
+
range.collapse(true);
|
| 151 |
selection.removeAllRanges();
|
| 152 |
+
selection.addRange(range);
|
| 153 |
|
| 154 |
closeMentions();
|
| 155 |
handleInput();
|
|
|
|
| 157 |
|
| 158 |
const handlePaste = async (e: React.ClipboardEvent) => {
|
| 159 |
const items = e.clipboardData.items;
|
| 160 |
+
let imageItem = null;
|
| 161 |
for (let i = 0; i < items.length; i++) {
|
| 162 |
+
if (items[i].type.indexOf("image") !== -1) {
|
| 163 |
+
imageItem = items[i];
|
| 164 |
+
break;
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
if (imageItem) {
|
| 169 |
+
e.preventDefault();
|
| 170 |
+
const file = imageItem.getAsFile();
|
| 171 |
+
if (file) {
|
| 172 |
+
const formData = new FormData();
|
| 173 |
+
formData.append("file", file);
|
| 174 |
+
try {
|
| 175 |
+
const endpoint = ticketId ? `tickets/${ticketId}/attachments/` : `tickets/upload/`;
|
| 176 |
+
const resp = await api.post(endpoint, formData);
|
| 177 |
+
|
| 178 |
+
if (onAttachmentUpload) {
|
| 179 |
+
onAttachmentUpload(resp.data);
|
| 180 |
}
|
| 181 |
+
const token = localStorage.getItem(getStorageKey('token'));
|
| 182 |
+
const backendBase = api.defaults.baseURL?.endsWith('/') ? api.defaults.baseURL : api.defaults.baseURL + '/';
|
| 183 |
+
const downloadUrl = `${backendBase}tickets/attachments/${resp.data.id}/download/${token ? `?token=${token}` : ''}`;
|
| 184 |
+
|
| 185 |
+
// Insert image at cursor
|
| 186 |
+
const img = `<img src="${downloadUrl}" width="300" style="max-width: 100%; border-radius: 12px; cursor: pointer; margin: 10px 0;" />`;
|
| 187 |
+
execCommand('insertHTML', img);
|
| 188 |
+
} catch (err) {
|
| 189 |
+
console.error("Upload failed", err);
|
| 190 |
}
|
| 191 |
}
|
| 192 |
}
|
|
|
|
| 336 |
{!value && placeholder && (
|
| 337 |
<div style={{
|
| 338 |
position: 'absolute',
|
| 339 |
+
top: 88,
|
| 340 |
left: 24,
|
| 341 |
pointerEvents: 'none',
|
| 342 |
color: 'var(--text-muted)',
|
| 343 |
+
opacity: 0.5,
|
| 344 |
+
fontSize: 16,
|
| 345 |
+
lineHeight: 1.8,
|
| 346 |
+
fontFamily: 'var(--font-sans)'
|
| 347 |
}}>
|
| 348 |
{placeholder}
|
| 349 |
</div>
|
|
|
|
| 380 |
color: var(--text-muted);
|
| 381 |
opacity: 0.5;
|
| 382 |
}
|
| 383 |
+
.mention-badge {
|
| 384 |
+
background: var(--primary-glow);
|
| 385 |
+
color: var(--primary);
|
| 386 |
+
padding: 2px 8px;
|
| 387 |
+
border-radius: 6px;
|
| 388 |
+
font-weight: 800;
|
| 389 |
+
display: inline-block;
|
| 390 |
+
border: 1px solid var(--primary);
|
| 391 |
+
box-shadow: var(--shadow-sm);
|
| 392 |
+
user-select: none;
|
| 393 |
+
cursor: default;
|
| 394 |
+
margin: 0 2px;
|
| 395 |
+
}
|
| 396 |
`}</style>
|
| 397 |
</div>
|
| 398 |
);
|
frontend/packages/shared/src/hooks/useMentions.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import { useState, useCallback, useMemo } from 'react';
|
| 2 |
import { api } from '../utils/api';
|
| 3 |
|
| 4 |
export interface UserProfile {
|
|
@@ -29,6 +29,11 @@ export const useMentions = ({ mentionableUsers: initialUsers }: UseMentionsProps
|
|
| 29 |
}
|
| 30 |
}, []);
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
const filteredUsers = useMemo(() => {
|
| 33 |
if (!mentionQuery) return users.slice(0, 3);
|
| 34 |
return users.filter(u =>
|
|
|
|
| 1 |
+
import { useState, useCallback, useMemo, useEffect } from 'react';
|
| 2 |
import { api } from '../utils/api';
|
| 3 |
|
| 4 |
export interface UserProfile {
|
|
|
|
| 29 |
}
|
| 30 |
}, []);
|
| 31 |
|
| 32 |
+
// Proactively fetch users on mount to ensure immediate responsiveness
|
| 33 |
+
useEffect(() => {
|
| 34 |
+
if (users.length === 0) fetchUsers();
|
| 35 |
+
}, [fetchUsers]);
|
| 36 |
+
|
| 37 |
const filteredUsers = useMemo(() => {
|
| 38 |
if (!mentionQuery) return users.slice(0, 3);
|
| 39 |
return users.filter(u =>
|
services/ticket_service.py
CHANGED
|
@@ -37,6 +37,7 @@ from schemas.ticket import (
|
|
| 37 |
)
|
| 38 |
from tasks.system import enqueue_task
|
| 39 |
|
|
|
|
| 40 |
logger = get_logger(__name__)
|
| 41 |
settings = get_settings()
|
| 42 |
|
|
@@ -322,6 +323,9 @@ class TicketService:
|
|
| 322 |
if payload.attachment_ids:
|
| 323 |
await db.execute(update(Attachment).where(Attachment.id.in_(payload.attachment_ids)).values(ticket_id=new_ticket.id))
|
| 324 |
|
|
|
|
|
|
|
|
|
|
| 325 |
db.add(AuditLog(workspace_id=current_user.workspace_id, entity_type="ticket", entity_id=new_ticket.id, action="create", user_id=current_user.id, new_value=payload.model_dump(mode='json')))
|
| 326 |
await db.commit()
|
| 327 |
|
|
@@ -401,6 +405,10 @@ class TicketService:
|
|
| 401 |
setattr(ticket, key, value)
|
| 402 |
else:
|
| 403 |
setattr(ticket, key, value)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
|
| 405 |
if "assigned_to" in update_data and update_data["assigned_to"]:
|
| 406 |
from models.user import User
|
|
|
|
| 37 |
)
|
| 38 |
from tasks.system import enqueue_task
|
| 39 |
|
| 40 |
+
from core.sync import link_internal_attachments
|
| 41 |
logger = get_logger(__name__)
|
| 42 |
settings = get_settings()
|
| 43 |
|
|
|
|
| 323 |
if payload.attachment_ids:
|
| 324 |
await db.execute(update(Attachment).where(Attachment.id.in_(payload.attachment_ids)).values(ticket_id=new_ticket.id))
|
| 325 |
|
| 326 |
+
# Auto-link images pasted into the description
|
| 327 |
+
await link_internal_attachments(db, new_ticket.id, payload.description)
|
| 328 |
+
|
| 329 |
db.add(AuditLog(workspace_id=current_user.workspace_id, entity_type="ticket", entity_id=new_ticket.id, action="create", user_id=current_user.id, new_value=payload.model_dump(mode='json')))
|
| 330 |
await db.commit()
|
| 331 |
|
|
|
|
| 405 |
setattr(ticket, key, value)
|
| 406 |
else:
|
| 407 |
setattr(ticket, key, value)
|
| 408 |
+
|
| 409 |
+
# Auto-link images if description was updated
|
| 410 |
+
if "description" in update_data:
|
| 411 |
+
await link_internal_attachments(db, ticket.id, update_data["description"])
|
| 412 |
|
| 413 |
if "assigned_to" in update_data and update_data["assigned_to"]:
|
| 414 |
from models.user import User
|