Skip to content

Commit 2bb37a5

Browse files
kalvinnchauam
andauthored
feat: add search operators to ranked message queries (#628)
Signed-off-by: am <6e30cd56c30e030cd31bb0939b94a7c257c9a09d5ba2d92cf2735da45629f248@buzz.block.builderlab.xyz> Co-authored-by: am <6e30cd56c30e030cd31bb0939b94a7c257c9a09d5ba2d92cf2735da45629f248@buzz.block.builderlab.xyz>
1 parent c54696b commit 2bb37a5

18 files changed

Lines changed: 2629 additions & 100 deletions

‎src/app/shell/SearchChoices.css‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,32 @@
5454
min-width: 0;
5555
}
5656

57+
.search-palette-author-prefix {
58+
flex: 0 1 auto;
59+
min-width: 0;
60+
max-width: 45%;
61+
}
62+
63+
.search-palette-author-chip {
64+
display: block;
65+
width: 100%;
66+
overflow: hidden;
67+
text-overflow: ellipsis;
68+
white-space: nowrap;
69+
border: 0;
70+
border-radius: var(--radius-chip);
71+
padding: var(--space-half) var(--space-2);
72+
background: var(--affordance-subtle);
73+
color: var(--text-link);
74+
font: inherit;
75+
font-size: var(--text-body-sm);
76+
cursor: pointer;
77+
}
78+
79+
.search-palette-author-chip:hover {
80+
background: var(--affordance-subtle-hover);
81+
}
82+
5783
.search-palette-scope {
5884
display: inline-flex;
5985
align-items: center;

‎src/app/shell/SearchChoices.tsx‎

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type ReactNode,
99
} from "react";
1010
import type { ChatCircleIcon } from "../../shared/design-system/icons/index";
11+
import { Avatar } from "../../shared/design-system/ui/Avatar";
1112
import { NavigationItem } from "../../shared/design-system/ui/NavigationItem";
1213
import { NavigationSection } from "../../shared/design-system/ui/NavigationSection";
1314
import { SearchField } from "../../shared/design-system/ui/SearchField";
@@ -23,6 +24,9 @@ export type SearchDestination = {
2324
matches?: readonly number[];
2425
icon: typeof ChatCircleIcon;
2526
image?: string | undefined;
27+
avatar?:
28+
| { src?: string | undefined; shape: "circle" | "squircle" }
29+
| undefined;
2630
run: () => void;
2731
};
2832

@@ -144,12 +148,20 @@ export type SearchInputProps = {
144148
label?: string;
145149
placeholder?: string | undefined;
146150
scope?: { label: string; onRemove: () => void } | undefined;
151+
authorChip?:
152+
| { label: string; title: string; onRemove: () => void }
153+
| undefined;
154+
displayQuery?: string | undefined;
155+
onDisplayQueryChange?: ((value: string) => void) | undefined;
147156
};
148157

149158
export function SearchChoices({
150159
groups,
151160
query,
152161
onQueryChange,
162+
authorChip,
163+
displayQuery,
164+
onDisplayQueryChange,
153165
input,
154166
label = "Search Buzz",
155167
placeholder = "Search pages, conversations and messages…",
@@ -220,6 +232,21 @@ export function SearchChoices({
220232
</button>
221233
)}
222234
<SearchField
235+
prefix={
236+
authorChip ? (
237+
<span className="search-palette-author-prefix">
238+
<button
239+
type="button"
240+
className="search-palette-author-chip"
241+
aria-label={`Remove author ${authorChip.label}`}
242+
title={authorChip.title}
243+
onClick={authorChip.onRemove}
244+
>
245+
<span aria-hidden="true">×</span> from:@{authorChip.label}
246+
</button>
247+
</span>
248+
) : undefined
249+
}
223250
inputRef={input}
224251
role="combobox"
225252
aria-controls={id}
@@ -228,8 +255,8 @@ export function SearchChoices({
228255
aria-activedescendant={selected ? optionId(selected) : undefined}
229256
label={label}
230257
placeholder={placeholder}
231-
value={query}
232-
onValueChange={onQueryChange}
258+
value={displayQuery ?? query}
259+
onValueChange={onDisplayQueryChange ?? onQueryChange}
233260
spellCheck={false}
234261
autoCorrect="off"
235262
autoCapitalize="off"
@@ -308,7 +335,16 @@ export function SearchChoices({
308335
>
309336
<NavigationSection label={label}>
310337
{destinations.map(
311-
({ key, label, detail, matches, icon, image, run }) => (
338+
({
339+
key,
340+
label,
341+
detail,
342+
matches,
343+
icon,
344+
image,
345+
avatar,
346+
run,
347+
}) => (
312348
<NavigationItem
313349
key={key}
314350
id={optionId(key)}
@@ -325,7 +361,17 @@ export function SearchChoices({
325361
}
326362
icon={
327363
<span className="grid size-6 shrink-0 place-items-center">
328-
<PageIcon icon={icon} image={image} size={17} />
364+
{avatar ? (
365+
<Avatar
366+
alt=""
367+
fallback={label}
368+
src={avatar.src}
369+
size="small"
370+
shape={avatar.shape}
371+
/>
372+
) : (
373+
<PageIcon icon={icon} image={image} size={17} />
374+
)}
329375
</span>
330376
}
331377
label={

0 commit comments

Comments
 (0)