mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
fix(work-orders): harden mention highlight boundary and submit catch [SH-217]
This commit is contained in:
parent
3b59bce973
commit
95bd443359
3 changed files with 21 additions and 4 deletions
|
|
@ -75,9 +75,14 @@ export function WorkOrderActivityPanel({
|
||||||
if (!trimmed) {
|
if (!trimmed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void Promise.resolve(onSubmitComment(trimmed)).then(() => {
|
void (async () => {
|
||||||
setCommentText("");
|
try {
|
||||||
});
|
await onSubmitComment(trimmed);
|
||||||
|
setCommentText("");
|
||||||
|
} catch {
|
||||||
|
// Mutation toast handles failure; keep the draft for retry.
|
||||||
|
}
|
||||||
|
})();
|
||||||
}}
|
}}
|
||||||
className="mt-4 flex flex-col gap-2"
|
className="mt-4 flex flex-col gap-2"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,8 @@ function appendPlainMentionMatches(
|
||||||
|
|
||||||
const sortedNames = [...mentionNames].sort((a, b) => b.length - a.length);
|
const sortedNames = [...mentionNames].sort((a, b) => b.length - a.length);
|
||||||
const namePattern = sortedNames.map((name) => escapeRegExp(name)).join("|");
|
const namePattern = sortedNames.map((name) => escapeRegExp(name)).join("|");
|
||||||
const mentionRegex = new RegExp(`@(${namePattern})`, "g");
|
// Require a non-word boundary after the name so "@Ann" does not match inside "@Annual".
|
||||||
|
const mentionRegex = new RegExp(`@(${namePattern})(?![\\w])`, "g");
|
||||||
|
|
||||||
let cursor = 0;
|
let cursor = 0;
|
||||||
for (const match of plainText.matchAll(mentionRegex)) {
|
for (const match of plainText.matchAll(mentionRegex)) {
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,17 @@ describe("comment-mentions", () => {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("does not highlight shorter mention names as prefixes of longer @words", () => {
|
||||||
|
const text = "Check @Annual maintenance with @Ann";
|
||||||
|
|
||||||
|
expect(buildCommentBodySegments(text, ["user-ann"], [{ id: "user-ann", name: "Ann" }])).toEqual(
|
||||||
|
[
|
||||||
|
{ type: "text", value: "Check @Annual maintenance with " },
|
||||||
|
{ type: "mention", userId: "Ann", label: "Ann" },
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("finds active mention query at cursor", () => {
|
it("finds active mention query at cursor", () => {
|
||||||
const text = "Hello @ja";
|
const text = "Hello @ja";
|
||||||
const query = findActiveMentionQuery(text, text.length);
|
const query = findActiveMentionQuery(text, text.length);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue