Skip to content

Commit 113cf5f

Browse files
trangdoan982mdroidian
authored andcommitted
parent 6080afb
author Trang Doan <[email protected]> 1744314525 -0400 committer Michael Gartner <[email protected]> 1747354088 -0600 ENG-96 Create new relationship between nodes (#115) * instantiate new relationship worked * fix * address PR comments * fix bi-directional update issues * show only compatible node type options * small fix * breakdown the components. use datacore * working * address PR comments * improve search by only allowing compatible node results * . * rm dataview --------- Co-authored-by: Michael Gartner <[email protected]> Move llm-api endpoints to vercel serverless (#102) * testing gemini * move endgoint to website * open ai endpoint * added anthropic endpoint * pass env vars * add cors handdling and options * . * using centralised cors middleware * only adding bypass cookie * use right key * remove the bypass token requirement * sanitize, fix routes * remove server action config * DRY * remove unused * address review * adress review Roam: Add feedback toggle (#118) * add settings to hide or show button, also works when disabled or enabled midway * review * . --------- Co-authored-by: Michael Gartner <[email protected]> [ENG-197] Fix creating link with invalid chars (#121) * fix creating link with invalid chars * placeholder update --------- Co-authored-by: Michael Gartner <[email protected]> Roam: Add feedback button to settings menu - ENG-147 (#122) * add button to bottom right, don't hide sdk css, tested * remove intent not working git * remove ts-ignore and use a better type def * remove styling Update NodeConfig to use new UIDs for DiscourseNodeIndex and DiscourseNodeSpecification components (#126) Roam: Add PostHog user identification for enhanced analytics tracking using user's roam UID as the unique identifier - ENG-177 (#123) * add posthog identify * remove username and email to keep it anonymus * double userUid and best practice for js Roam: Discourse Context Overlay - remove queue and arbitrary delay (#127) * Refactor getOverlayInfo to use async/await and improve error handling. Update cache key from title to tag and remove overlayQueue logic for cleaner implementation. * Remove experimental getOverlayInfo function * Remove unused refreshUi logic [ENG-44] Display relations (#116) * instantiate new relationship worked * add display relations * remove dv * sm fix [ENG-198] Filtered out related file in search (#125) * filtered out related file * fix some naming [ENG-97] Use TailwindCSS in obsidian app (#128) * Update Obsidian app to integrate Tailwind CSS with PostCSS and Autoprefixer support - Added Tailwind CSS, PostCSS, and Autoprefixer to package dependencies - Configured styles.css to include Tailwind directives - Enhanced compile script to process styles using PostCSS with Tailwind and Autoprefixer * delete irrelevant package [ENG-192] Change all existing styles to using tw (#129) * Update Obsidian app to integrate Tailwind CSS with PostCSS and Autoprefixer support - Added Tailwind CSS, PostCSS, and Autoprefixer to package dependencies - Configured styles.css to include Tailwind directives - Enhanced compile script to process styles using PostCSS with Tailwind and Autoprefixer * delete irrelevant package * changing all styles to tailwindcss * Update Obsidian app to integrate Tailwind CSS with PostCSS and Autoprefixer support - Added Tailwind CSS, PostCSS, and Autoprefixer to package dependencies - Configured styles.css to include Tailwind directives - Enhanced compile script to process styles using PostCSS with Tailwind and Autoprefixer * delete irrelevant package * changing all styles to tailwindcss --------- Co-authored-by: Michael Gartner <[email protected]> Roam: Bug-fix: Don't let user create discourse nodes with empty text using node context menu - ENG-171 (#130) * functional covering all three cases tested locally * apply coderabbit review suggestion * better approach one that I understand and can reason about * accidental removal of onClose Update Roam app version to 0.13.0 in package.json and package-lock.json (#134) [ENG-204] Move from localStorage to extensionAPI.settings (#133) * cur progress * address PR comments * kinda works. need to test more * small fix * address PR comments . Create publish-obsidian.yml Update publish-obsidian.yml Update publish-obsidian.yml Update publish-obsidian.yml Enhance DiscourseContextOverlay: Update button styles to include loading state and improve score/ref display during loading. Use placeholders for score and refs when loading. (#136) . Update publish-obsidian.yml Update publish-obsidian.yml Update publish-obsidian.yml Update publish-obsidian.yml Refactor ExportDialog: Remove discourseGraphEnabled state and simplify FormGroup visibility logic. Set includeDiscourseContext to false by default. (#139) Enhance LabelDialog: Add confirmText to return object for improved button text handling based on action type. (#141) Additional styles / cursor rules (#142) * Update STYLE_GUIDE.md and main.mdc: Add guideline for utilizing utility functions for reusable logic and common operations. * Update STYLE_GUIDE.md and main.mdc: Add guideline to prefer arrow functions over regular function declarations. * Update main.mdc: Add guideline to prefer Tailwind classes when refactoring inline styles. * Update STYLE_GUIDE.md and main.mdc: Add guideline to prefer early returns over nested conditionals for improved readability. Roam: When a user deletes a node also delete all the corresponding relations to the node - ENG-26 (#149) * ask user for confirmation, delete corresponding relations * address review * address review * address comments [ENG-301] Create node in right-click menu (#152) * create node in right-click menu * small fix * address PR comments * address PR comments add readme and remove sample commands remove sample editor command rm space minor fixes Roam: Bug fix - Insert Discourse Node after creation (#154) * remove focus after menu select to allow updateBlock to work * add clarifying comment [ENG-308] Add command to open DG settings (#158) * add command to open DG settings * edit comment ENG-322 - Switch from MIT to Apache 2.0 license (#156) * Switch from MIT to Apache 2.0 license * copyright discourse graphs * rm liscense from apps/roam --------- Co-authored-by: Michael Gartner <[email protected]> initial port [ENG-207] Move Github sync setting to individual nodes (#124) * current progress * improve in UI: if sync is turned off then also turn off the comments configuration * address PR comments * revert graphOverviewUid bug * revert graphOverviewUid bug - getDiscourseNodes * avoid racing conditions for github sync * nested settings * temp fix to race condition * remove unecessary DOM and match existing styles --------- Co-authored-by: Michael Gartner <[email protected]> Eng 286 show when GitHub sync is disabled globally (#143) * Refactor GitHub Sync settings in NodeConfig and GeneralSettings components - Updated the onChange handler for GitHub Sync to use async/await and added a timeout for refreshing the config tree. - Introduced a global settings check in NodeConfig to conditionally render the GitHub Sync checkbox and comments configuration. - Passed setMainTab prop to NodeConfig for better navigation control. This improves the user experience by ensuring that settings are updated correctly and provides clear feedback when global settings are disabled. * matchingNode fix . Refactor Export components to use getSetting for consistent settings retrieval - Updated ExportDialog and ExportGithub components to replace localStorageGet with getSetting for fetching GitHub OAuth and repository settings. - Modified extensionSettings utility functions to use arrow functions and provide a default value for getSetting. - Improved code readability and maintainability by standardizing the method of accessing settings. Eng 286 show when GitHub sync is disabled globally (#143) * Refactor GitHub Sync settings in NodeConfig and GeneralSettings components - Updated the onChange handler for GitHub Sync to use async/await and added a timeout for refreshing the config tree. - Introduced a global settings check in NodeConfig to conditionally render the GitHub Sync checkbox and comments configuration. - Passed setMainTab prop to NodeConfig for better navigation control. This improves the user experience by ensuring that settings are updated correctly and provides clear feedback when global settings are disabled. * matchingNode fix .
1 parent ae40fe6 commit 113cf5f

File tree

9 files changed

+219
-154
lines changed

9 files changed

+219
-154
lines changed

apps/roam/src/components/Export.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const ExportDialog: ExportDialogComponent = ({
119119
initialExportDestination,
120120
}) => {
121121
const [selectedRepo, setSelectedRepo] = useState<string>(
122-
getSetting<string>("selected-repo", ""),
122+
getSetting("selected-repo"),
123123
);
124124
const exportId = useMemo(() => nanoid(), []);
125125
useEffect(() => {
@@ -171,7 +171,7 @@ const ExportDialog: ExportDialogComponent = ({
171171
}, [initialPanel]);
172172
const [includeDiscourseContext, setIncludeDiscourseContext] = useState(false);
173173
const [gitHubAccessToken, setGitHubAccessToken] = useState<string | null>(
174-
getSetting<string | null>("oauth-github", null),
174+
getSetting<string>("oauth-github"),
175175
);
176176

177177
const [canSendToGitHub, setCanSendToGitHub] = useState(false);
@@ -185,8 +185,8 @@ const ExportDialog: ExportDialogComponent = ({
185185
content: string;
186186
setError: (error: string) => void;
187187
}): Promise<{ status: number }> => {
188-
const gitHubAccessToken = localStorageGet("github-oauth");
189-
const selectedRepo = localStorageGet("github-repo");
188+
const gitHubAccessToken = getSetting("github-oauth");
189+
const selectedRepo = getSetting("github-repo");
190190

191191
const encoder = new TextEncoder();
192192
const uint8Array = encoder.encode(content);
@@ -233,8 +233,8 @@ const ExportDialog: ExportDialogComponent = ({
233233
setError: (error: string) => void;
234234
pageUid: string;
235235
}): Promise<{ status: number }> => {
236-
const gitHubAccessToken = localStorageGet("github-oauth");
237-
const selectedRepo = localStorageGet("github-repo");
236+
const gitHubAccessToken = getSetting("github-oauth");
237+
const selectedRepo = getSetting("github-repo");
238238
try {
239239
// https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#create-an-issue
240240
const response = await apiPost({
@@ -253,7 +253,7 @@ const ExportDialog: ExportDialogComponent = ({
253253
});
254254
if (response.status === 401) {
255255
setError("Authentication failed. Please log in again.");
256-
localStorageSet("github-oauth", "");
256+
setSetting("github-oauth", "");
257257
return { status: 401 };
258258
}
259259

@@ -699,7 +699,7 @@ const ExportDialog: ExportDialogComponent = ({
699699
if (activeExportDestination === "github") {
700700
const { title, content } = files[0];
701701
const githubDestination =
702-
localStorageGet("github-destination");
702+
getSetting("github-destination");
703703
try {
704704
let status;
705705
if (githubDestination === "File") {

apps/roam/src/components/ExportGithub.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import apiGet from "roamjs-components/util/apiGet";
1212
import apiPost from "roamjs-components/util/apiPost";
1313
import { getNodeEnv } from "roamjs-components/util/env";
1414
import getExtensionApi from "roamjs-components/util/extensionApiContext";
15-
import { setSetting } from "~/utils/extensionSettings";
15+
import { getSetting, setSetting } from "~/utils/extensionSettings";
1616

1717
export type UserReposResponse = {
1818
data: [
@@ -45,7 +45,7 @@ export const fetchInstallationStatus = async () => {
4545
domain: "https://api.github.com",
4646
path: "user/installations",
4747
headers: {
48-
Authorization: `token ${localStorageGet("github-oauth")}`,
48+
Authorization: `token ${getSetting("github-oauth")}`,
4949
},
5050
});
5151
const installations = res.installations;
@@ -75,14 +75,12 @@ export const ExportGithub = ({
7575
const [repos, setRepos] = useState<UserRepos>(initialRepos);
7676
const [state, setState] = useState("");
7777
const [gitHubAccessToken, _setGitHubAccessToken] = useState<string>(
78-
localStorageGet("github-oauth"),
78+
getSetting("github-oauth"),
7979
);
8080
const [githubDestination, _setGithubDestination] =
81-
useState<GitHubDestination>(
82-
(localStorageGet("github-destination") as GitHubDestination) || "File",
83-
);
84-
const [selectedRepo, _setSelectedRepo] = useState(
85-
localStorageGet("github-repo"),
81+
useState<GitHubDestination>(getSetting("github-destination") || "File");
82+
const [selectedRepo, _setSelectedRepo] = useState<string>(
83+
getSetting("github-repo"),
8684
);
8785
const showGitHubLogin = isGitHubAppInstalled && !gitHubAccessToken;
8886
const repoAndDestinationSelectEnabled =

apps/roam/src/components/GitHubSync.tsx

Lines changed: 42 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@ import React, {
55
useRef,
66
useState,
77
} from "react";
8-
import getDiscourseNodes from "~/utils/getDiscourseNodes";
8+
import getDiscourseNodes, { DiscourseNode } from "~/utils/getDiscourseNodes";
99
import matchDiscourseNode from "~/utils/matchDiscourseNode";
10-
import { OnloadArgs, PullBlock, RoamBasicNode } from "roamjs-components/types";
10+
import { OnloadArgs, RoamBasicNode } from "roamjs-components/types";
1111
import { Button, Card, Classes, Dialog, Tag } from "@blueprintjs/core";
1212
import getBasicTreeByParentUid from "roamjs-components/queries/getBasicTreeByParentUid";
1313
import getPageTitleByPageUid from "roamjs-components/queries/getPageTitleByPageUid";
1414
import getPageUidByPageTitle from "roamjs-components/queries/getPageUidByPageTitle";
1515
import createBlock from "roamjs-components/writes/createBlock";
1616
import runQuery from "~/utils/runQuery";
1717
import { render as renderToast } from "roamjs-components/components/Toast";
18-
import { createConfigObserver } from "roamjs-components/components/ConfigPage";
19-
import SelectPanel from "roamjs-components/components/ConfigPanels/SelectPanel";
2018
import { render as exportRender } from "~/components/Export";
2119
import getBlockProps from "~/utils/getBlockProps";
2220
import localStorageGet from "roamjs-components/util/localStorageGet";
@@ -40,17 +38,10 @@ import {
4038
fetchInstallationStatus,
4139
} from "~/components/ExportGithub";
4240
import localStorageSet from "roamjs-components/util/localStorageSet";
43-
import { getNodeEnv } from "roamjs-components/util/env";
4441
import nanoid from "nanoid";
45-
import {
46-
CustomField,
47-
Field,
48-
} from "roamjs-components/components/ConfigPanels/types";
49-
import CustomPanel from "roamjs-components/components/ConfigPanels/CustomPanel";
5042
import getShallowTreeByParentUid from "roamjs-components/queries/getShallowTreeByParentUid";
51-
import CommentsQuery from "./GitHubSyncCommentsQuery";
52-
import getSubTree from "roamjs-components/util/getSubTree";
5343
import isFlagEnabled from "~/utils/isFlagEnabled";
44+
import getPageTitleByBlockUid from "roamjs-components/queries/getPageTitleByBlockUid";
5445

5546
const CommentUidCache = new Set<string>();
5647
const CommentContainerUidCache = new Set<string>();
@@ -105,27 +96,21 @@ const getPageGitHubPropsDetails = (pageUid: string) => {
10596
const getRoamCommentsContainerUid = async ({
10697
pageUid,
10798
extensionAPI,
99+
matchingNode,
108100
}: {
109101
pageUid: string;
110102
extensionAPI: OnloadArgs["extensionAPI"];
103+
matchingNode?: DiscourseNode;
111104
}) => {
112105
const pageTitle = getPageTitleByPageUid(pageUid);
113-
const configUid = getPageUidByPageTitle(CONFIG_PAGE);
114-
const configTree = getBasicTreeByParentUid(configUid);
115-
const queryNode = getSubTree({
116-
tree: configTree,
117-
key: "Comments Block",
118-
});
119-
if (!queryNode) {
120-
renderToast({
121-
id: "github-issue-comments",
122-
content: `Comments Block query not set. Set it in ${CONFIG_PAGE}`,
123-
});
106+
107+
if (!matchingNode?.githubSync?.commentsQueryUid || !matchingNode) {
124108
return;
125109
}
110+
126111
const results = await runQuery({
127112
extensionAPI,
128-
parentUid: queryNode.uid,
113+
parentUid: matchingNode.githubSync?.commentsQueryUid,
129114
inputs: { NODETEXT: pageTitle, NODEUID: pageUid },
130115
});
131116

@@ -134,9 +119,11 @@ const getRoamCommentsContainerUid = async ({
134119
export const insertNewCommentsFromGitHub = async ({
135120
pageUid,
136121
extensionAPI,
122+
matchingNode,
137123
}: {
138124
pageUid: string;
139125
extensionAPI: OnloadArgs["extensionAPI"];
126+
matchingNode: DiscourseNode;
140127
}) => {
141128
const getCommentsOnPage = (pageUid: string) => {
142129
const query = `[:find
@@ -171,6 +158,7 @@ export const insertNewCommentsFromGitHub = async ({
171158
const commentsContainerUid = await getRoamCommentsContainerUid({
172159
pageUid,
173160
extensionAPI,
161+
matchingNode,
174162
});
175163

176164
const gitHubAccessToken = localStorageGet("github-oauth");
@@ -250,47 +238,41 @@ export const insertNewCommentsFromGitHub = async ({
250238
});
251239
}
252240
};
241+
253242
export const isGitHubSyncPage = (pageTitle: string) => {
254-
if (!enabled) return;
255-
const gitHubNodeResult = window.roamAlphaAPI.data.fast.q(`[:find
256-
(pull ?node [:block/string])
257-
:where
258-
[?roamjsgithub-sync :node/title "roam/js/github-sync"]
259-
[?node :block/page ?roamjsgithub-sync]
260-
[?p :block/children ?node]
261-
(or [?p :block/string ?p-String]
262-
[?p :node/title ?p-String])
263-
[(clojure.string/includes? ?p-String "Node Select")]
264-
]`) as [PullBlock][];
265-
const nodeText = gitHubNodeResult[0]?.[0]?.[":block/string"] || "";
266-
if (!nodeText) return;
243+
if (!enabled) return null;
267244

268245
const discourseNodes = getDiscourseNodes();
269-
const selectedNode = discourseNodes.find((node) => node.text === nodeText);
270-
const isPageTypeOfNode = matchDiscourseNode({
271-
format: selectedNode?.format || "",
272-
specification: selectedNode?.specification || [],
273-
text: selectedNode?.text || "",
274-
title: pageTitle,
275-
});
276-
return isPageTypeOfNode;
246+
return discourseNodes.find(
247+
(node) =>
248+
node.githubSync?.enabled &&
249+
matchDiscourseNode({
250+
format: node.format || "",
251+
specification: node.specification || [],
252+
text: node.text || "",
253+
title: pageTitle,
254+
}),
255+
);
277256
};
278257

279258
export const renderGitHubSyncPage = async ({
280259
title,
281260
h1,
282261
onloadArgs,
262+
matchingNode,
283263
}: {
284264
title: string;
285265
h1: HTMLHeadingElement;
286266
onloadArgs: OnloadArgs;
267+
matchingNode: DiscourseNode;
287268
}) => {
288269
const extensionAPI = onloadArgs.extensionAPI;
289270
const pageUid = getPageUidByPageTitle(title);
290271

291272
const commentsContainerUid = await getRoamCommentsContainerUid({
292273
pageUid,
293274
extensionAPI,
275+
matchingNode,
294276
});
295277
const commentHeaderEl = document.querySelector(
296278
`.rm-block__input[id$="${commentsContainerUid}"]`,
@@ -325,6 +307,7 @@ export const renderGitHubSyncPage = async ({
325307
<CommentsContainerComponent
326308
commentsContainerUid={commentsContainerUid}
327309
extensionAPI={extensionAPI}
310+
matchingNode={matchingNode}
328311
/>,
329312
containerDiv,
330313
);
@@ -477,9 +460,11 @@ const CommentsComponent = ({ blockUid }: { blockUid: string }) => {
477460
const CommentsContainerComponent = ({
478461
commentsContainerUid,
479462
extensionAPI,
463+
matchingNode,
480464
}: {
481465
commentsContainerUid: string;
482466
extensionAPI: OnloadArgs["extensionAPI"];
467+
matchingNode: DiscourseNode;
483468
}) => {
484469
const [loadingComments, setLoadingComments] = useState(false);
485470
return (
@@ -534,7 +519,11 @@ const CommentsContainerComponent = ({
534519
onClick={async () => {
535520
setLoadingComments(true);
536521
const pageUid = getPageUidByBlockUid(commentsContainerUid);
537-
await insertNewCommentsFromGitHub({ pageUid, extensionAPI });
522+
await insertNewCommentsFromGitHub({
523+
pageUid,
524+
extensionAPI,
525+
matchingNode,
526+
});
538527
setLoadingComments(false);
539528
}}
540529
/>
@@ -913,78 +902,17 @@ const initializeGitHubSync = async (onloadArgs: OnloadArgs) => {
913902
const unloads = new Set<() => void>();
914903
const toggle = async (flag: boolean) => {
915904
if (flag && !enabled) {
916-
const { observer: configObserver } = await createConfigObserver({
917-
title: "roam/js/github-sync",
918-
config: {
919-
tabs: [
920-
{
921-
id: "home",
922-
fields: [
923-
// @ts-ignore
924-
{
925-
title: "Docs",
926-
description: `More information about the GitHub Sync Feature.`,
927-
Panel: CustomPanel,
928-
options: {
929-
component: () => {
930-
return (
931-
<div>
932-
<p>
933-
For more information about the GitHub Sync feature,
934-
visit the GitHub page:
935-
</p>
936-
<a
937-
href="https://github.com/RoamJS/query-builder/blob/main/docs/github-sync.md"
938-
target="_blank"
939-
>
940-
GitHub Sync Documentation
941-
</a>
942-
</div>
943-
);
944-
},
945-
},
946-
} as Field<CustomField>,
947-
{
948-
// @ts-ignore
949-
Panel: SelectPanel,
950-
title: "Node Select",
951-
description:
952-
"Select the node type to sync with GitHub Issues",
953-
options: {
954-
items: [
955-
"None",
956-
...getDiscourseNodes()
957-
.map((node) => node.text)
958-
.filter((text) => text !== "Block"),
959-
],
960-
},
961-
defaultValue: "None",
962-
},
963-
// @ts-ignore
964-
{
965-
Panel: CustomPanel,
966-
title: "Comments Block",
967-
description:
968-
"Where comments are synced to. This will fire when the node is loaded. You have access to ':in NODETEXT' and ':in NODEUID' as variables for the current node.",
969-
options: {
970-
component: ({ uid }) =>
971-
React.createElement(CommentsQuery, {
972-
parentUid: uid,
973-
onloadArgs,
974-
}),
975-
},
976-
} as Field<CustomField>,
977-
],
978-
},
979-
],
980-
},
981-
});
982-
983905
const commentObserver = createBlockObserver({
984906
onBlockLoad: (b) => {
985907
const { blockUid } = getUids(b);
986908
if (CommentContainerUidCache.has(blockUid)) {
987909
if (b.hasAttribute("github-sync-comment-container")) return;
910+
911+
// TODO: move this to renderGitHubSyncPage so we can pass in the matching node
912+
const title = getPageTitleByBlockUid(blockUid);
913+
const matchingNode = isGitHubSyncPage(title);
914+
if (!matchingNode) return;
915+
988916
b.setAttribute("github-sync-comment-container", "true");
989917
const containerDiv = document.createElement("div");
990918
containerDiv.className = "inline-block ml-2";
@@ -994,6 +922,7 @@ const initializeGitHubSync = async (onloadArgs: OnloadArgs) => {
994922
<CommentsContainerComponent
995923
commentsContainerUid={blockUid}
996924
extensionAPI={onloadArgs.extensionAPI}
925+
matchingNode={matchingNode}
997926
/>,
998927
containerDiv,
999928
);
@@ -1013,7 +942,6 @@ const initializeGitHubSync = async (onloadArgs: OnloadArgs) => {
1013942
},
1014943
});
1015944

1016-
unloads.add(() => configObserver?.disconnect());
1017945
unloads.add(() => commentObserver.forEach((o) => o.disconnect()));
1018946
unloads.add(() => CommentUidCache.clear());
1019947
unloads.add(() => CommentContainerUidCache.clear());
@@ -1026,7 +954,6 @@ const initializeGitHubSync = async (onloadArgs: OnloadArgs) => {
1026954
await toggle(isFlagEnabled(SETTING));
1027955
return toggle;
1028956
};
1029-
1030957
export const toggleGitHubSync = async (
1031958
flag: boolean,
1032959
onloadArgs: OnloadArgs,

0 commit comments

Comments
 (0)