Skip to content

Commit f9f93a3

Browse files
authored
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 aebc425 commit f9f93a3

File tree

4 files changed

+87
-45
lines changed

4 files changed

+87
-45
lines changed

apps/roam/src/components/GitHubSync.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
import CustomPanel from "roamjs-components/components/ConfigPanels/CustomPanel";
5050
import getShallowTreeByParentUid from "roamjs-components/queries/getShallowTreeByParentUid";
5151
import isFlagEnabled from "~/utils/isFlagEnabled";
52+
import getPageTitleByBlockUid from "roamjs-components/queries/getPageTitleByBlockUid";
5253

5354
const CommentUidCache = new Set<string>();
5455
const CommentContainerUidCache = new Set<string>();
@@ -130,7 +131,7 @@ export const insertNewCommentsFromGitHub = async ({
130131
}: {
131132
pageUid: string;
132133
extensionAPI: OnloadArgs["extensionAPI"];
133-
matchingNode?: DiscourseNode;
134+
matchingNode: DiscourseNode;
134135
}) => {
135136
const getCommentsOnPage = (pageUid: string) => {
136137
const query = `[:find
@@ -314,6 +315,7 @@ export const renderGitHubSyncPage = async ({
314315
<CommentsContainerComponent
315316
commentsContainerUid={commentsContainerUid}
316317
extensionAPI={extensionAPI}
318+
matchingNode={matchingNode}
317319
/>,
318320
containerDiv,
319321
);
@@ -466,9 +468,11 @@ const CommentsComponent = ({ blockUid }: { blockUid: string }) => {
466468
const CommentsContainerComponent = ({
467469
commentsContainerUid,
468470
extensionAPI,
471+
matchingNode,
469472
}: {
470473
commentsContainerUid: string;
471474
extensionAPI: OnloadArgs["extensionAPI"];
475+
matchingNode: DiscourseNode;
472476
}) => {
473477
const [loadingComments, setLoadingComments] = useState(false);
474478
return (
@@ -523,7 +527,11 @@ const CommentsContainerComponent = ({
523527
onClick={async () => {
524528
setLoadingComments(true);
525529
const pageUid = getPageUidByBlockUid(commentsContainerUid);
526-
await insertNewCommentsFromGitHub({ pageUid, extensionAPI });
530+
await insertNewCommentsFromGitHub({
531+
pageUid,
532+
extensionAPI,
533+
matchingNode,
534+
});
527535
setLoadingComments(false);
528536
}}
529537
/>
@@ -907,6 +915,12 @@ const initializeGitHubSync = async (onloadArgs: OnloadArgs) => {
907915
const { blockUid } = getUids(b);
908916
if (CommentContainerUidCache.has(blockUid)) {
909917
if (b.hasAttribute("github-sync-comment-container")) return;
918+
919+
// TODO: move this to renderGitHubSyncPage so we can pass in the matching node
920+
const title = getPageTitleByBlockUid(blockUid);
921+
const matchingNode = isGitHubSyncPage(title);
922+
if (!matchingNode) return;
923+
910924
b.setAttribute("github-sync-comment-container", "true");
911925
const containerDiv = document.createElement("div");
912926
containerDiv.className = "inline-block ml-2";
@@ -916,6 +930,7 @@ const initializeGitHubSync = async (onloadArgs: OnloadArgs) => {
916930
<CommentsContainerComponent
917931
commentsContainerUid={blockUid}
918932
extensionAPI={onloadArgs.extensionAPI}
933+
matchingNode={matchingNode}
919934
/>,
920935
containerDiv,
921936
);

apps/roam/src/components/settings/GeneralSettings.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ const DiscourseGraphHome = ({ onloadArgs }: { onloadArgs: OnloadArgs }) => {
4040
uid={settings.githubSync.uid}
4141
value={settings.githubSync.value}
4242
options={{
43-
onChange: (checked) => toggleGitHubSync(checked, onloadArgs),
43+
onChange: async (checked) => {
44+
await toggleGitHubSync(checked, onloadArgs);
45+
setTimeout(() => {
46+
// Wait for the GitHub Sync flag block to be updated
47+
refreshConfigTree();
48+
}, 250);
49+
},
4450
}}
4551
/>
4652
</div>

apps/roam/src/components/settings/NodeConfig.tsx

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from "react";
1+
import React, { useState, useEffect, useMemo } from "react";
22
import { DiscourseNode } from "~/utils/getDiscourseNodes";
33
import FlagPanel from "roamjs-components/components/ConfigPanels/FlagPanel";
44
import SelectPanel from "roamjs-components/components/ConfigPanels/SelectPanel";
@@ -14,20 +14,24 @@ import {
1414
Checkbox,
1515
Icon,
1616
Tooltip,
17+
Button,
1718
} from "@blueprintjs/core";
1819
import DiscourseNodeSpecification from "./DiscourseNodeSpecification";
1920
import DiscourseNodeAttributes from "./DiscourseNodeAttributes";
2021
import DiscourseNodeCanvasSettings from "./DiscourseNodeCanvasSettings";
2122
import DiscourseNodeIndex from "./DiscourseNodeIndex";
2223
import { OnloadArgs } from "roamjs-components/types";
2324
import CommentsQuery from "~/components/GitHubSyncCommentsQuery";
25+
import { getFormattedConfigTree } from "~/utils/discourseConfigRef";
2426

2527
const NodeConfig = ({
2628
node,
2729
onloadArgs,
30+
setMainTab,
2831
}: {
2932
node: DiscourseNode;
3033
onloadArgs: OnloadArgs;
34+
setMainTab: (tabId: TabId) => void;
3135
}) => {
3236
const getUid = (key: string) =>
3337
getSubTree({
@@ -69,6 +73,8 @@ const NodeConfig = ({
6973
node.githubSync?.enabled || false,
7074
);
7175

76+
const globalSettings = useMemo(() => getFormattedConfigTree(), []);
77+
const globalGithubSyncEnabled = globalSettings.githubSync.value;
7278
return (
7379
<>
7480
<Tabs
@@ -207,49 +213,58 @@ const NodeConfig = ({
207213
<li>Configure where comments appear in the page</li>
208214
</ul>
209215
</div>
210-
<Checkbox
211-
style={{ width: 240, lineHeight: "normal" }}
212-
checked={isGithubSyncEnabled}
213-
onChange={(e) => {
214-
const target = e.target as HTMLInputElement;
215-
setIsGithubSyncEnabled(target.checked);
216-
if (target.checked) {
217-
setInputSetting({
218-
blockUid: githubSyncUid,
219-
key: "Enabled",
220-
value: "true",
221-
});
222-
} else {
223-
setInputSetting({
224-
blockUid: githubSyncUid,
225-
key: "Enabled",
226-
value: "false",
227-
});
228-
}
229-
}}
230-
>
231-
GitHub Sync Enabled
232-
<Tooltip
233-
content={`When enabled, ${node.text} pages can be synced with GitHub Issues.`}
234-
>
235-
<Icon
236-
icon={"info-sign"}
237-
iconSize={12}
238-
className={"ml-2 align-middle opacity-80"}
216+
217+
{!globalGithubSyncEnabled && (
218+
<div className="flex flex-col gap-2">
219+
<p>GitHub Sync is not enabled globally.</p>
220+
<Button
221+
intent="primary"
222+
className="max-w-xs"
223+
text="Navigate to global settings"
224+
onClick={() => setMainTab("discourse-graph-home")}
239225
/>
240-
</Tooltip>
241-
</Checkbox>
226+
</div>
227+
)}
242228

243-
{isGithubSyncEnabled && (
229+
{globalGithubSyncEnabled && (
244230
<>
245-
<Label>
246-
Comments Configuration
247-
<Description description="Define where GitHub Issue comments should appear on this node type. This query will run when comments are imported." />
248-
</Label>
249-
<CommentsQuery
250-
parentUid={githubCommentsFormatUid}
251-
onloadArgs={onloadArgs}
252-
/>
231+
<Checkbox
232+
style={{ width: 240, lineHeight: "normal" }}
233+
checked={isGithubSyncEnabled}
234+
onChange={(e) => {
235+
const target = e.target as HTMLInputElement;
236+
setIsGithubSyncEnabled(target.checked);
237+
setInputSetting({
238+
blockUid: githubSyncUid,
239+
key: "Enabled",
240+
value: target.checked ? "true" : "false",
241+
});
242+
}}
243+
>
244+
GitHub Sync Enabled
245+
<Tooltip
246+
content={`When enabled, ${node.text} pages can be synced with GitHub Issues.`}
247+
>
248+
<Icon
249+
icon={"info-sign"}
250+
iconSize={12}
251+
className={"ml-2 align-middle opacity-80"}
252+
/>
253+
</Tooltip>
254+
</Checkbox>
255+
256+
{isGithubSyncEnabled && (
257+
<>
258+
<Label>
259+
Comments Configuration
260+
<Description description="Define where GitHub Issue comments should appear on this node type. This query will run when comments are imported." />
261+
</Label>
262+
<CommentsQuery
263+
parentUid={githubCommentsFormatUid}
264+
onloadArgs={onloadArgs}
265+
/>
266+
</>
267+
)}
253268
</>
254269
)}
255270
</div>

apps/roam/src/components/settings/Settings.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,13 @@ export const SettingsDialog = ({
155155
id={n.type}
156156
title={n.text}
157157
className="overflow-y-auto"
158-
panel={<NodeConfig node={n} onloadArgs={onloadArgs} />}
158+
panel={
159+
<NodeConfig
160+
node={n}
161+
onloadArgs={onloadArgs}
162+
setMainTab={setSelectedTabId}
163+
/>
164+
}
159165
/>
160166
))}
161167
<Tabs.Expander />

0 commit comments

Comments
 (0)