-
Notifications
You must be signed in to change notification settings - Fork 6
ENG-1855 Add Roam shared-node import discovery #1214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sid597
wants to merge
5
commits into
main
Choose a base branch
from
eng-1855-add-roam-shared-node-import-discovery-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+726
−0
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
da4d214
[ENG-1855] Add Roam shared-node import discovery
sid597 b805ddf
[ENG-1855] Keep discovery dialog open
sid597 6d2b17a
[ENG-1855] Fix discovery dialog dismissing on keyboard launch
sid597 aba903d
[ENG-1855] Use getAllPages for ResourceAccess pagination
sid597 9f7f93e
Avoid racing Supabase context initialization
sid597 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,263 @@ | ||
| import { | ||
| Button, | ||
| Callout, | ||
| Classes, | ||
| Dialog, | ||
| HTMLTable, | ||
| InputGroup, | ||
| Intent, | ||
| NonIdealState, | ||
| Spinner, | ||
| Tag, | ||
| Tooltip, | ||
| } from "@blueprintjs/core"; | ||
| import React, { useCallback, useEffect, useMemo, useState } from "react"; | ||
| import createOverlayRender from "roamjs-components/util/createOverlayRender"; | ||
| import { | ||
| discoverSharedNodes, | ||
| type DiscoveredSharedNode, | ||
| } from "~/utils/discoverSharedNodes"; | ||
| import { getLoggedInClient, getSupabaseContext } from "~/utils/supabaseContext"; | ||
|
|
||
| const formatModifiedAt = (modifiedAt: string): string => | ||
| new Date(modifiedAt).toLocaleString(); | ||
|
|
||
| const SharedNodeRow = ({ node }: { node: DiscoveredSharedNode }) => ( | ||
| <tr> | ||
| <td> | ||
| <Tag minimal>{node.sourceApp}</Tag> | ||
| </td> | ||
| <td> | ||
| <div | ||
| style={{ maxWidth: "13rem", overflowWrap: "anywhere", fontWeight: 500 }} | ||
| > | ||
| {node.sourceSpaceName} | ||
| </div> | ||
| <div | ||
| className={[Classes.MONOSPACE_TEXT, Classes.TEXT_MUTED].join(" ")} | ||
| style={{ | ||
| maxWidth: "13rem", | ||
| overflow: "hidden", | ||
| textOverflow: "ellipsis", | ||
| whiteSpace: "nowrap", | ||
| fontSize: "0.75rem", | ||
| }} | ||
| title={node.sourceSpaceId} | ||
| > | ||
| {node.sourceSpaceId} | ||
| </div> | ||
| </td> | ||
| <td> | ||
| <div | ||
| style={{ maxWidth: "18rem", overflowWrap: "anywhere", fontWeight: 500 }} | ||
| > | ||
| {node.title} | ||
| </div> | ||
| </td> | ||
| <td> | ||
| {node.sourceNodeId ? ( | ||
| <div | ||
| className={Classes.MONOSPACE_TEXT} | ||
| style={{ | ||
| maxWidth: "11rem", | ||
| overflow: "hidden", | ||
| textOverflow: "ellipsis", | ||
| whiteSpace: "nowrap", | ||
| fontSize: "0.75rem", | ||
| }} | ||
| title={node.sourceNodeRid} | ||
| > | ||
| {node.sourceNodeId} | ||
| </div> | ||
| ) : ( | ||
| <span className={Classes.TEXT_MUTED}>Not provided</span> | ||
| )} | ||
| </td> | ||
| <td style={{ whiteSpace: "nowrap" }} title={node.modifiedAt}> | ||
| {formatModifiedAt(node.modifiedAt)} | ||
| </td> | ||
| <td> | ||
| {node.alreadyImported ? ( | ||
| <Tag intent={Intent.SUCCESS} minimal> | ||
| Imported | ||
| </Tag> | ||
| ) : ( | ||
| <Tag minimal>Available</Tag> | ||
| )} | ||
| </td> | ||
| </tr> | ||
| ); | ||
|
|
||
| const DiscoverSharedNodesDialog = ({ onClose }: { onClose: () => void }) => { | ||
| const [nodes, setNodes] = useState<DiscoveredSharedNode[]>([]); | ||
| const [loading, setLoading] = useState(true); | ||
| const [error, setError] = useState(""); | ||
| const [search, setSearch] = useState(""); | ||
|
|
||
| const loadNodes = useCallback(async (): Promise<void> => { | ||
| setLoading(true); | ||
| setError(""); | ||
| try { | ||
| const [client, context] = await Promise.all([ | ||
| getLoggedInClient(), | ||
| getSupabaseContext(), | ||
| ]); | ||
| if (!client || !context) | ||
| throw new Error("Could not connect to shared persistence."); | ||
| setNodes( | ||
| await discoverSharedNodes({ | ||
| client, | ||
| currentSpaceId: context.spaceId, | ||
| }), | ||
| ); | ||
| } catch (loadError) { | ||
| console.error("Failed to discover shared nodes:", loadError); | ||
| setError( | ||
| loadError instanceof Error | ||
| ? loadError.message | ||
| : "Could not load shared nodes.", | ||
| ); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| void loadNodes(); | ||
| }, [loadNodes]); | ||
|
|
||
| const visibleNodes = useMemo(() => { | ||
| const normalizedSearch = search.trim().toLocaleLowerCase(); | ||
| if (!normalizedSearch) return nodes; | ||
| return nodes.filter((node) => | ||
| [ | ||
| node.sourceApp, | ||
| node.sourceSpaceName, | ||
| node.sourceSpaceId, | ||
| node.title, | ||
| node.sourceNodeId, | ||
| ].some((value) => value?.toLocaleLowerCase().includes(normalizedSearch)), | ||
| ); | ||
| }, [nodes, search]); | ||
|
|
||
| return ( | ||
| <Dialog | ||
| canEscapeKeyClose | ||
| canOutsideClickClose | ||
| style={{ width: "min(68rem, calc(100vw - 2rem))" }} | ||
| isOpen | ||
| onClose={onClose} | ||
| title="Discover shared nodes" | ||
| > | ||
| <div | ||
| className={Classes.DIALOG_BODY} | ||
| style={{ | ||
| display: "flex", | ||
| minHeight: "18rem", | ||
| flexDirection: "column", | ||
| gap: "0.75rem", | ||
| }} | ||
| > | ||
| <div style={{ display: "flex", alignItems: "center", gap: "0.5rem" }}> | ||
| <InputGroup | ||
| style={{ minWidth: 0, flex: 1 }} | ||
| leftIcon="search" | ||
| onChange={(event: React.ChangeEvent<HTMLInputElement>) => | ||
| setSearch(event.target.value) | ||
| } | ||
| placeholder="Search shared nodes" | ||
| value={search} | ||
| /> | ||
| <Tooltip content="Reload shared nodes"> | ||
| <Button | ||
| aria-label="Reload shared nodes" | ||
| disabled={loading} | ||
| icon="refresh" | ||
| minimal | ||
| onClick={() => void loadNodes()} | ||
| /> | ||
| </Tooltip> | ||
| </div> | ||
|
|
||
| {loading ? ( | ||
| <div | ||
| style={{ | ||
| display: "flex", | ||
| minHeight: "13rem", | ||
| alignItems: "center", | ||
| justifyContent: "center", | ||
| }} | ||
| > | ||
| <Spinner /> | ||
| </div> | ||
| ) : error ? ( | ||
| <Callout intent={Intent.DANGER} title="Could not load shared nodes"> | ||
| <div style={{ marginBottom: "0.75rem" }}>{error}</div> | ||
| <Button icon="refresh" onClick={() => void loadNodes()}> | ||
| Try again | ||
| </Button> | ||
| </Callout> | ||
| ) : visibleNodes.length === 0 ? ( | ||
| <div | ||
| style={{ | ||
| display: "flex", | ||
| minHeight: "13rem", | ||
| alignItems: "center", | ||
| justifyContent: "center", | ||
| }} | ||
| > | ||
| <NonIdealState | ||
| icon="search" | ||
| title={search ? "No matching shared nodes" : "No shared nodes"} | ||
| /> | ||
| </div> | ||
| ) : ( | ||
| <div style={{ minHeight: 0, overflow: "auto" }}> | ||
| <HTMLTable striped style={{ width: "100%" }}> | ||
| <thead> | ||
| <tr> | ||
| <th>Source app</th> | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This stays intentionally read-only: these columns match ENG-1855's pre-import metadata, while materialization remains in ENG-1859. |
||
| <th>Source space</th> | ||
| <th>Title</th> | ||
| <th>Source ID</th> | ||
| <th>Modified</th> | ||
| <th>Status</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {visibleNodes.map((node) => ( | ||
| <SharedNodeRow key={node.sourceNodeRid} node={node} /> | ||
| ))} | ||
| </tbody> | ||
| </HTMLTable> | ||
| </div> | ||
| )} | ||
| </div> | ||
| <div className={Classes.DIALOG_FOOTER}> | ||
| <div | ||
| style={{ | ||
| display: "flex", | ||
| alignItems: "center", | ||
| justifyContent: "space-between", | ||
| }} | ||
| > | ||
| <span className={Classes.TEXT_MUTED} style={{ fontSize: "0.75rem" }}> | ||
| {loading || error | ||
| ? "" | ||
| : `${visibleNodes.length} of ${nodes.length} nodes`} | ||
| </span> | ||
| <Button onClick={onClose}>Close</Button> | ||
| </div> | ||
| </div> | ||
| </Dialog> | ||
| ); | ||
| }; | ||
|
|
||
| type Props = Record<string, never>; | ||
|
|
||
| export const renderDiscoverSharedNodesDialog = createOverlayRender<Props>( | ||
| "discourse-discover-shared-nodes", | ||
| DiscoverSharedNodesDialog, | ||
| ); | ||
|
|
||
| export default DiscoverSharedNodesDialog; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.