Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Open contact results on the details tab on mobile, tidy excerpts

François Zaninottoe33ab095e1e6
diff --git a/src/components/atomic-crm/search/getSearchResultUrl.test.ts b/src/components/atomic-crm/search/getSearchResultUrl.test.ts
index 426f0d27..e11700f6 100644
--- a/src/components/atomic-crm/search/getSearchResultUrl.test.ts
+++ b/src/components/atomic-crm/search/getSearchResultUrl.test.ts
@@ -50,6 +50,19 @@ describe("getSearchResultUrl", () => {
expect(getSearchResultUrl(result, true)).toBeNull();
});
+ it("opens a contact on its details tab on mobile", () => {
+ const result = buildResult({
+ resource: "contacts",
+ record_id: 3,
+ contact_id: 3,
+ deal_id: null,
+ });
+
+ expect(getSearchResultUrl(result, true)).toBe(
+ "/contacts/3/show?tab=details",
+ );
+ });
+
it("links a task to the contact it belongs to", () => {
const result = buildResult({
resource: "tasks",
diff --git a/src/components/atomic-crm/search/getSearchResultUrl.ts b/src/components/atomic-crm/search/getSearchResultUrl.ts
index 061f7253..0cbe23b8 100644
--- a/src/components/atomic-crm/search/getSearchResultUrl.ts
+++ b/src/components/atomic-crm/search/getSearchResultUrl.ts
@@ -20,7 +20,11 @@ export const getSearchResultUrl = (
case "companies":
return `/companies/${result.record_id}/show`;
case "contacts":
- return `/contacts/${result.record_id}/show`;
+ // On mobile, open the details tab: looking up a contact is usually
+ // about reaching their email or phone, not their notes.
+ return isMobile
+ ? `/contacts/${result.record_id}/show?tab=details`
+ : `/contacts/${result.record_id}/show`;
case "deals":
return isMobile ? null : `/deals/${result.record_id}/show`;
case "tasks":
diff --git a/src/components/atomic-crm/search/searchHighlight.test.ts b/src/components/atomic-crm/search/searchHighlight.test.ts
index b27c2434..a527d739 100644
--- a/src/components/atomic-crm/search/searchHighlight.test.ts
+++ b/src/components/atomic-crm/search/searchHighlight.test.ts
@@ -63,6 +63,16 @@ describe("getSnippet", () => {
expect(snippet).toContain("delivery of sourdough loaves");
});
+ it("does not end an excerpt on the separator between two fields", () => {
+ // the 60-character window after "Web" ends inside the long last field,
+ // so the cut falls back to the space right after the " · "
+ const content = `Web-enabled · Voluptate in nihil dolor sit amet. · ${"x".repeat(80)}`;
+
+ const snippet = getSnippet("Rachel", content, getSearchTerms("web"));
+
+ expect(snippet).toBe("Web-enabled · Voluptate in nihil dolor sit amet.…");
+ });
+
it("looks only for the terms missing from the title", () => {
const snippet = getSnippet(
"Boulangerie Martin",
diff --git a/src/components/atomic-crm/search/searchHighlight.ts b/src/components/atomic-crm/search/searchHighlight.ts
index 781dde17..24183783 100644
--- a/src/components/atomic-crm/search/searchHighlight.ts
+++ b/src/components/atomic-crm/search/searchHighlight.ts
@@ -111,6 +111,10 @@ export const getSnippet = (
: Math.min(content.indexOf(" ", from) + 1 || from, match.start);
const lastSpace = content.lastIndexOf(" ", to);
const end = to === content.length || lastSpace <= match.end ? to : lastSpace;
- const excerpt = content.slice(start, end).replace(/\s+/g, " ").trim();
+ // trim whitespace, and the " · " between fields when the cut lands on one
+ const excerpt = content
+ .slice(start, end)
+ .replace(/\s+/g, " ")
+ .replace(/^[\s·]+|[\s·]+$/g, "");
return `${start > 0 ? "…" : ""}${excerpt}${end < content.length ? "…" : ""}`;
};