Skip to content

Commit afe9ade

Browse files
committed
address PR comments
1 parent a1184ff commit afe9ade

4 files changed

Lines changed: 74 additions & 30 deletions

File tree

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

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ const AdvancedNodeSearchDialog = ({
408408
autoFocus={false}
409409
canEscapeKeyClose
410410
canOutsideClickClose
411-
className="flex max-w-4xl flex-col overflow-hidden bg-white p-0"
411+
className="flex w-full max-w-4xl flex-col overflow-hidden bg-white p-0"
412412
enforceFocus={false}
413413
isOpen={isOpen}
414414
onClose={onClose}
@@ -424,9 +424,16 @@ const AdvancedNodeSearchDialog = ({
424424
onMouseUp={(event) => event.stopPropagation()}
425425
className="flex min-h-0 flex-1 flex-col overflow-hidden"
426426
>
427-
<div className="flex flex-none items-center gap-2 border-b border-gray-200 px-3 py-2">
428-
<div className="flex min-w-0 flex-1 items-center rounded border border-gray-300 bg-white px-2 py-1">
429-
<Icon icon="search" size={16} className="mr-2 text-gray-500" />
427+
<div className="flex w-full flex-none items-start gap-2 border-b border-gray-200 px-3 py-2">
428+
<div
429+
className="flex min-h-9 w-full min-w-0 flex-1 items-center rounded border border-gray-300 bg-white px-2 py-1"
430+
style={{ flex: "1 1 0", minWidth: 0 }}
431+
>
432+
<Icon
433+
className="mr-2 shrink-0 self-center text-gray-500"
434+
icon="search"
435+
size={16}
436+
/>
430437
<NodeTypeChipsSearchInput
431438
inputRef={inputRef}
432439
nodeTypes={discourseNodes}
@@ -453,24 +460,27 @@ const AdvancedNodeSearchDialog = ({
453460
selectedTypeIds={selectedNodeTypeIds}
454461
/>
455462
</div>
456-
<DiscourseNodeTypeFilter
457-
nodeTypes={discourseNodes}
458-
onPopoverOpenChange={setIsTypeFilterPopoverOpen}
459-
onSelectedTypeIdsChange={setSelectedNodeTypeIds}
460-
selectedTypeIds={selectedNodeTypeIds}
461-
/>
462-
<DiscourseNodeSortControl
463-
disabled={isIndexLoading || indexError}
464-
onSortChange={handleSortChange}
465-
sort={sort}
466-
/>
467-
<Button
468-
className="shrink-0"
469-
icon="cross"
470-
minimal
471-
onClick={onClose}
472-
title="Close search"
473-
/>
463+
<div className="flex h-9 shrink-0 items-center gap-1">
464+
<DiscourseNodeTypeFilter
465+
layoutAnchorKey={selectedNodeTypeIds.length}
466+
nodeTypes={discourseNodes}
467+
onPopoverOpenChange={setIsTypeFilterPopoverOpen}
468+
onSelectedTypeIdsChange={setSelectedNodeTypeIds}
469+
selectedTypeIds={selectedNodeTypeIds}
470+
/>
471+
<DiscourseNodeSortControl
472+
disabled={isIndexLoading || indexError}
473+
onSortChange={handleSortChange}
474+
sort={sort}
475+
/>
476+
<Button
477+
className="shrink-0"
478+
icon="cross"
479+
minimal
480+
onClick={onClose}
481+
title="Close search"
482+
/>
483+
</div>
474484
</div>
475485
<div className="flex min-h-0 w-full flex-1 overflow-hidden">
476486
{showSplitView ? (

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export type DiscourseNodeTypeFilterProps = {
2828
selectedTypeIds: string[];
2929
onSelectedTypeIdsChange: (ids: string[]) => void;
3030
onPopoverOpenChange?: (isOpen: boolean) => void;
31+
/** Bumps when surrounding layout changes (e.g. chip wrap) so the popover repositions. */
32+
layoutAnchorKey?: number;
3133
};
3234

3335
const getNodeIndicatorColor = (node: DiscourseNode): string =>
@@ -186,6 +188,7 @@ const FilterPopoverPanel = ({
186188
};
187189

188190
export const DiscourseNodeTypeFilter = ({
191+
layoutAnchorKey = 0,
189192
nodeTypes,
190193
onPopoverOpenChange,
191194
onSelectedTypeIdsChange,
@@ -249,6 +252,11 @@ export const DiscourseNodeTypeFilter = ({
249252

250253
const isTriggerActive = isOpen || isFilterActive;
251254

255+
useEffect(() => {
256+
if (!isOpen) return;
257+
window.dispatchEvent(new Event("resize"));
258+
}, [isOpen, layoutAnchorKey]);
259+
252260
const filterButton = (
253261
<span className="relative inline-flex shrink-0 items-center">
254262
<Button
@@ -314,7 +322,7 @@ export const DiscourseNodeTypeFilter = ({
314322
onInteraction={handlePopoverInteraction}
315323
popoverClassName="p-0 overflow-hidden"
316324
popoverRef={popoverRef}
317-
position={Position.BOTTOM_RIGHT}
325+
position={Position.BOTTOM}
318326
target={filterButton}
319327
usePortal
320328
/>

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Classes, Tag } from "@blueprintjs/core";
22
import React, { useEffect, useRef, useState } from "react";
3-
import { getNodeTagStyles } from "~/utils/getDiscourseNodeColors";
3+
import { getNodeTagColorStyles } from "~/utils/getDiscourseNodeColors";
44
import { type DiscourseNode } from "~/utils/getDiscourseNodes";
55

66
type NodeTypeChipsSearchInputProps = {
@@ -239,7 +239,10 @@ export const NodeTypeChipsSearchInput = ({
239239
};
240240

241241
return (
242-
<div className="flex min-w-0 flex-1 flex-wrap items-center gap-1 py-0.5">
242+
<div
243+
className="flex w-full min-w-0 flex-1 flex-wrap items-center gap-1 py-0.5"
244+
style={{ flex: "1 1 0", minWidth: 0, width: "100%" }}
245+
>
243246
{selectedNodeTypes.map((nodeType, index) => {
244247
const isFocused = focusedChipIndex === index;
245248
return (
@@ -271,9 +274,14 @@ export const NodeTypeChipsSearchInput = ({
271274
);
272275
focusInput();
273276
}}
274-
style={getNodeTagStyles(
275-
nodeType.canvasSettings?.color ?? "#000000",
276-
)}
277+
style={{
278+
...getNodeTagColorStyles(
279+
nodeType.canvasSettings?.color ?? "#000000",
280+
),
281+
alignItems: "center",
282+
display: "inline-flex",
283+
flexDirection: "row",
284+
}}
277285
>
278286
<span
279287
className="truncate"
@@ -285,7 +293,10 @@ export const NodeTypeChipsSearchInput = ({
285293
</span>
286294
);
287295
})}
288-
<span className="relative flex-1" style={{ minWidth: INPUT_MIN_WIDTH }}>
296+
<span
297+
className="relative min-w-0 flex-1"
298+
style={{ minWidth: INPUT_MIN_WIDTH }}
299+
>
289300
{completionSuffix && (
290301
<span className="pointer-events-none absolute inset-0 flex items-center overflow-hidden whitespace-nowrap text-sm">
291302
<span className="invisible">{searchTerm}</span>

apps/roam/src/utils/getDiscourseNodeColors.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export const getDiscourseNodeColors = ({
4242
return { backgroundColor, textColor };
4343
};
4444

45-
export const getNodeTagStyles = (color: string): CSSProperties | undefined => {
45+
const getNodeTagColorProperties = (
46+
color: string,
47+
): Pick<CSSProperties, "backgroundColor" | "color" | "border"> | undefined => {
4648
const formattedColor = formatHexColor(color);
4749
if (!formattedColor) return undefined;
4850
const { background, text, border } = getPleasingColors(
@@ -52,6 +54,19 @@ export const getNodeTagStyles = (color: string): CSSProperties | undefined => {
5254
backgroundColor: background,
5355
color: text,
5456
border: `1px solid ${border}`,
57+
};
58+
};
59+
60+
/** Color tokens for Blueprint `Tag` (layout handled by the component). */
61+
export const getNodeTagColorStyles = (
62+
color: string,
63+
): CSSProperties | undefined => getNodeTagColorProperties(color);
64+
65+
export const getNodeTagStyles = (color: string): CSSProperties | undefined => {
66+
const colorStyles = getNodeTagColorProperties(color);
67+
if (!colorStyles) return undefined;
68+
return {
69+
...colorStyles,
5570
fontWeight: "500",
5671
padding: "2px 6px",
5772
borderRadius: "12px",

0 commit comments

Comments
 (0)