Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apps/roam/src/components/DiscourseContextOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ const getOverlayInfo = async (
ignoreCache?: boolean,
): Promise<DiscourseData> => {
try {
const relations = getDiscourseRelations();
const nodes = getDiscourseNodes(relations);
const trace = {
source: "DiscourseContextOverlay:getOverlayInfo",
content: tag,
};
const relations = getDiscourseRelations(undefined, trace);
const nodes = getDiscourseNodes(relations, undefined, trace);

const [results, refs] = await Promise.all([
getDiscourseContextResults({
Expand Down
52 changes: 47 additions & 5 deletions apps/roam/src/components/DiscourseNodeMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
import { OnloadArgs } from "roamjs-components/types";
import { formatHexColor } from "./settings/DiscourseNodeCanvasSettings";
import posthog from "posthog-js";
import { setPersonalSetting } from "~/components/settings/utils/accessors";
import {
setPersonalSetting,
type SettingsSnapshot,
} from "~/components/settings/utils/accessors";
import { PERSONAL_KEYS } from "~/components/settings/utils/settingKeys";
import type { PersonalSettings } from "~/components/settings/utils/zodSchema";
import type { PerformanceTraceContext } from "~/utils/performanceLogger";

type Props = {
textarea?: HTMLTextAreaElement;
Expand All @@ -38,6 +42,24 @@
trigger?: JSX.Element;
isShift?: boolean;
menuMaxHeight?: number;
trace?: PerformanceTraceContext;
settingsSnapshot?: SettingsSnapshot;
getSettingsSnapshot?: (trace?: PerformanceTraceContext) => SettingsSnapshot;
};

const compactTraceContent = (content?: string): string | undefined => {
const compacted = content?.replace(/\s+/g, " ").trim();
return compacted ? compacted.slice(0, 120) : undefined;
};

const getNodeMenuTraceContent = ({
trace,
textarea,
blockUid,
}: Pick<Props, "trace" | "textarea" | "blockUid">): string | undefined => {
if (trace?.content) return compactTraceContent(trace.content);
if (blockUid) return `blockUid:${blockUid}`;
return compactTraceContent(textarea?.value);
};

const NodeMenu = ({
Expand All @@ -48,17 +70,34 @@
trigger,
isShift,
menuMaxHeight,
trace,
settingsSnapshot,
getSettingsSnapshot,
}: { onClose: () => void } & Props) => {
const isInitialTextSelected =
!!textarea && textarea.selectionStart !== textarea.selectionEnd;

const [showNodeTypes, setShowNodeTypes] = useState(
isInitialTextSelected || (isShift ?? false),
);
const userDiscourseNodes = useMemo(
() => getDiscourseNodes().filter((n) => n.backedBy === "user"),
[],
);
const userDiscourseNodes = useMemo(() => {
const traceContext = {
source: trace?.source ?? "component:DiscourseNodeMenu:userDiscourseNodes",
content: getNodeMenuTraceContent({ trace, textarea, blockUid }),
};
return getDiscourseNodes(
undefined,
settingsSnapshot ?? getSettingsSnapshot?.(traceContext),
traceContext,
).filter((n) => n.backedBy === "user");
}, [

Check warning on line 93 in apps/roam/src/components/DiscourseNodeMenu.tsx

View workflow job for this annotation

GitHub Actions / eslint (apps/roam)

[eslint (apps/roam)] apps/roam/src/components/DiscourseNodeMenu.tsx#L93

React Hook useMemo has a missing dependency: 'trace'. Either include it or remove the dependency array react-hooks/exhaustive-deps
Raw output
   93:6   warning  React Hook useMemo has a missing dependency: 'trace'. Either include it or remove the dependency array                                         react-hooks/exhaustive-deps
blockUid,
getSettingsSnapshot,
settingsSnapshot,
textarea,
trace?.content,
trace?.source,
]);
const discourseNodes = userDiscourseNodes.filter(
(n) => showNodeTypes || n.tag,
);
Expand Down Expand Up @@ -359,10 +398,12 @@
textarea,
extensionAPI,
onClose,
settingsSnapshot,
}: {
textarea: HTMLTextAreaElement;
extensionAPI: OnloadArgs["extensionAPI"];
onClose: () => void;
settingsSnapshot?: SettingsSnapshot;
}) => {
const trigger = (
<Button
Expand Down Expand Up @@ -403,6 +444,7 @@
onClose={onClose}
isShift
menuMaxHeight={menuMaxHeight}
settingsSnapshot={settingsSnapshot}
/>
);
};
Expand Down
5 changes: 4 additions & 1 deletion apps/roam/src/components/SuggestionsBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ const getOverlayInfo = async (
try {
if (cache[tag]) return cache[tag];

const nodes = getDiscourseNodes(relations);
const nodes = getDiscourseNodes(relations, undefined, {
source: "SuggestionsBody:getOverlayInfo",
content: tag,
});

const [results, refs] = await Promise.all([
getDiscourseContextResults({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import setBlockProps from "~/utils/setBlockProps";
import { DiscourseNodeSchema } from "./utils/zodSchema";
import { getGlobalSettings, setGlobalSetting } from "./utils/accessors";
import { GLOBAL_KEYS } from "./utils/settingKeys";
import { invalidateDiscourseNodeTypeCaches } from "~/utils/discourseNodeTypeCache";

type DiscourseNodeConfigPanelProps = React.ComponentProps<
CustomField["options"]["component"]
Expand Down Expand Up @@ -60,6 +61,7 @@ const DiscourseNodeConfigPanel: React.FC<DiscourseNodeConfigPanelProps> = ({
await window.roamAlphaAPI.deletePage({
page: { uid },
});
invalidateDiscourseNodeTypeCaches();
setNodes((prevNodes) => prevNodes.filter((nn) => nn.type !== uid));
refreshConfigTree();
setDeleteConfirmation(null);
Expand Down Expand Up @@ -117,6 +119,7 @@ const DiscourseNodeConfigPanel: React.FC<DiscourseNodeConfigPanelProps> = ({
format,
}),
);
invalidateDiscourseNodeTypeCaches();
setNodes([
...nodes,
{
Expand Down
Loading
Loading