Skip to content

Commit 271f990

Browse files
Fix: Remove leading # from search result tags in advanced search (#1115)
* fix: remove leading # from search result tags in advanced search - Strip # prefix from node badges to show correct 3-letter abbreviations - Applies to both nodeConfig and nodeTypeLabel fallback cases - Fixes tags showing as #CL and #QU instead of CLM and QUE Co-authored-by: Michael Gartner <mdroidian@users.noreply.github.com> * refactor: introduce formatBadgeText utility for consistent badge formatting - Added formatBadgeText function to standardize the removal of leading # and limit badge text to 3 uppercase letters. - Updated getNodeBadgeText and ResultRow components to utilize the new utility for improved consistency in badge display. --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Michael Gartner <mdroidian@users.noreply.github.com>
1 parent 3e60913 commit 271f990

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

apps/roam/src/components/AdvancedNodeSearchDialog/AdvancedSearchDialog.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import React, {
2-
useCallback,
3-
useEffect,
4-
useMemo,
5-
useRef,
6-
useState,
7-
} from "react";
1+
import React, { useCallback, useEffect, useRef, useState } from "react";
82
import {
93
Button,
104
Dialog,
@@ -37,6 +31,7 @@ import {
3731
type SearchResult,
3832
type SortConfig,
3933
buildSearchIndex,
34+
formatBadgeText,
4035
formatMetadataDate,
4136
searchIndexedNodes,
4237
sortSearchResults,
@@ -49,8 +44,9 @@ import { AdvancedSearchFooter } from "./AdvancedSearchFooter";
4944

5045
type Props = Record<string, unknown>;
5146

52-
const getNodeBadgeText = (node: DiscourseNode): string =>
53-
(node.tag?.trim() || node.text).slice(0, 3).toUpperCase();
47+
const getNodeBadgeText = (node: DiscourseNode): string => {
48+
return formatBadgeText(node.tag?.trim() || node.text);
49+
};
5450

5551
const getTagStyle = (node: DiscourseNode | undefined): React.CSSProperties => {
5652
const color = node?.canvasSettings?.color;
@@ -102,7 +98,9 @@ const ResultRow = ({
10298
}}
10399
>
104100
<Tag minimal style={getTagStyle(nodeConfig)}>
105-
{nodeConfig ? getNodeBadgeText(nodeConfig) : result.nodeTypeLabel}
101+
{nodeConfig
102+
? getNodeBadgeText(nodeConfig)
103+
: formatBadgeText(result.nodeTypeLabel)}
106104
</Tag>
107105
<span className="min-w-0 break-words text-sm leading-snug text-gray-900">
108106
{renderHighlightedText(stripTypePrefix(result.title), keywords)}

apps/roam/src/components/AdvancedNodeSearchDialog/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ export const formatMetadataDate = (value: string): string => {
6868
});
6969
};
7070

71+
export const formatBadgeText = (text: string): string =>
72+
text.replace(/^#/, "").slice(0, 3).toUpperCase();
73+
7174
export const stripTypePrefix = (title: string): string => {
7275
const match = title.match(/^\[\[.*?\]\]\s*-\s*(.*)/s);
7376
return match ? match[1] : title;

0 commit comments

Comments
 (0)