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
59 changes: 22 additions & 37 deletions apps/roam/src/components/settings/DiscourseNodeCanvasSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
Tooltip,
Icon,
ControlGroup,
Checkbox,
} from "@blueprintjs/core";
import React, { useState, useMemo } from "react";
import getBasicTreeByParentUid from "roamjs-components/queries/getBasicTreeByParentUid";
import getSettingValueFromTree from "roamjs-components/util/getSettingValueFromTree";
import setInputSetting from "roamjs-components/util/setInputSetting";
import { DiscourseNodeFlagPanel } from "./components/BlockPropSettingPanels";

export const formatHexColor = (color: string) => {
if (!color) return "";
Expand All @@ -25,7 +25,7 @@ export const formatHexColor = (color: string) => {
return "";
};

const DiscourseNodeCanvasSettings = ({ uid }: { uid: string }) => {
const DiscourseNodeCanvasSettings = ({ nodeType, uid }: { nodeType: string; uid: string }) => {
const tree = useMemo(() => getBasicTreeByParentUid(uid), [uid]);
const [color, setColor] = useState<string>(() => {
const color = getSettingValueFromTree({ tree, key: "color" });
Expand All @@ -43,6 +43,7 @@ const DiscourseNodeCanvasSettings = ({ uid }: { uid: string }) => {
const [keyImageOption, setKeyImageOption] = useState(() =>
getSettingValueFromTree({ tree, key: "key-image-option" }),
);

return (
<div>
<div className="mb-4">
Expand Down Expand Up @@ -91,49 +92,33 @@ const DiscourseNodeCanvasSettings = ({ uid }: { uid: string }) => {
}}
/>
</Label>
<Checkbox
style={{ width: 240, lineHeight: "normal" }}
checked={isKeyImage}
onChange={(e) => {
const target = e.target as HTMLInputElement;
setIsKeyImage(target.checked);
if (target.checked) {
if (!keyImageOption) setKeyImageOption("first-image");
setInputSetting({
blockUid: uid,
key: "key-image",
value: "true",
});
} else {
setInputSetting({
blockUid: uid,
key: "key-image",
value: "false",
});
}
<DiscourseNodeFlagPanel
nodeType={nodeType}
title="Key Image"
description="Add an image to the discourse node"
settingKeys={["canvasSettings", "key-image"]}
defaultValue={isKeyImage}
onChange={(checked) => {
setIsKeyImage(checked);
if (checked && !keyImageOption) setKeyImageOption("first-image");
setInputSetting({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the void operator.eslint@typescript-eslint/no-floating-promises

blockUid: uid,
key: "key-image",
value: checked ? "true" : "false",
});
}}
>
Key image
<Tooltip content={"Add an image to the discourse node"}>
<Icon
icon={"info-sign"}
iconSize={12}
className={"ml-2 align-middle opacity-80"}
/>
</Tooltip>
</Checkbox>
{/* </Tooltip> */}
/>
<RadioGroup
disabled={!isKeyImage}
selectedValue={!!keyImageOption ? keyImageOption : "first-image"}
selectedValue={keyImageOption || "first-image"}
label="Key image location"
onChange={(e) => {
const target = e.target as HTMLInputElement;
setKeyImageOption(target.value);
const value = (e.target as HTMLInputElement).value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the purpose of this change?

setKeyImageOption(value);
setInputSetting({
blockUid: uid,
key: "key-image-option",
value: target.value,
value,
});
}}
>
Expand Down
50 changes: 18 additions & 32 deletions apps/roam/src/components/settings/DiscourseNodeSuggestiveRules.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import React, {
useState,
useMemo,
useEffect,
useRef,
useCallback,
} from "react";
import React, { useState, useMemo, useEffect, useRef } from "react";
import { Button, Intent } from "@blueprintjs/core";
import BlocksPanel from "roamjs-components/components/ConfigPanels/BlocksPanel";
import FlagPanel from "roamjs-components/components/ConfigPanels/FlagPanel";
import TextPanel from "roamjs-components/components/ConfigPanels/TextPanel";
import getSubTree from "roamjs-components/util/getSubTree";
import { DiscourseNode } from "~/utils/getDiscourseNodes";
import extractRef from "roamjs-components/util/extractRef";
import { getAllDiscourseNodesSince } from "~/utils/getAllDiscourseNodesSince";
import { upsertNodesToSupabaseAsContentWithEmbeddings } from "~/utils/syncDgNodesToSupabase";
import { discourseNodeBlockToLocalConcept } from "~/utils/conceptConversion";
import { getLoggedInClient, getSupabaseContext } from "~/utils/supabaseContext";
import {
DiscourseNodeFlagPanel,
DiscourseNodeTextPanel,
} from "./components/BlockPropSettingPanels";

const BlockRenderer = ({ uid }: { uid: string }) => {
const containerRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -43,13 +38,9 @@ const DiscourseNodeSuggestiveRules = ({
parentUid: string;
}) => {
const nodeUid = node.type;
const nodeType = node.type;

const [embeddingRef, setEmbeddingRef] = useState(node.embeddingRef);

useEffect(() => {
setEmbeddingRef(node.embeddingRef || "");
}, [node.embeddingRef]);

const [embeddingRef, setEmbeddingRef] = useState(node.embeddingRef || "");
const blockUidToRender = useMemo(
() => extractRef(embeddingRef),
[embeddingRef],
Expand All @@ -64,14 +55,6 @@ const DiscourseNodeSuggestiveRules = ({
[nodeUid],
);

const handleEmbeddingRefChange = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
const newValue = e.target.value;
setEmbeddingRef(newValue);
node.embeddingRef = newValue;
},
[node],
);
const [isUpdating, setIsUpdating] = useState(false);

const handleUpdateEmbeddings = async (): Promise<void> => {
Expand All @@ -96,6 +79,7 @@ const DiscourseNodeSuggestiveRules = ({
setIsUpdating(false);
}
};

return (
<div className="flex flex-col gap-4 p-4">
<BlocksPanel
Expand All @@ -107,17 +91,17 @@ const DiscourseNodeSuggestiveRules = ({
defaultValue={node.template}
/>

<TextPanel
<DiscourseNodeTextPanel
nodeType={nodeType}
title="Embedding Block Ref"
description="Copy block ref from template which you want to be embedded and ranked."
settingKeys={["suggestiveRules", "embeddingRef"]}
defaultValue={node.embeddingRef || ""}
placeholder="((block-uid))"
onChange={setEmbeddingRef}
order={1}
uid={node.embeddingRefUid || ""}
parentUid={parentUid}
defaultValue={embeddingRef || ""}
options={{
placeholder: "((block-uid))",
onChange: handleEmbeddingRefChange,
}}
/>

{blockUidToRender && (
Expand All @@ -127,13 +111,15 @@ const DiscourseNodeSuggestiveRules = ({
</div>
)}

<FlagPanel
<DiscourseNodeFlagPanel
nodeType={nodeType}
title="First Child"
description="If the block is the first child of the embedding block ref, it will be embedded and ranked."
settingKeys={["suggestiveRules", "isFirstChild"]}
defaultValue={node.isFirstChild?.value || false}
order={2}
uid={node.isFirstChild?.uid || ""}
parentUid={parentUid}
value={node.isFirstChild?.value || false}
/>

<Button
Expand Down
Loading