-
Notifications
You must be signed in to change notification settings - Fork 6
[ENG-1890] Add Publish tab to Roam query-results share dialog #1133
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
6
commits into
main
Choose a base branch
from
eng-1890-add-publish-tab-to-roam-query-results-share-dialog
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.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
75ec5a3
[ENG-1890] Add Publish tab to Roam query-results share dialog
sid597 f02bace
[ENG-1890] Address publish tab review feedback
sid597 6f8349c
[ENG-1890] Import group helpers directly in Obsidian
sid597 817d312
[ENG-1890] Resolve referenced nodes in Roam publish
sid597 c80b7bd
[ENG-1851] Add Roam single-node publish action (#1132)
sid597 2565ab2
[ENG-1890] Show existing Roam publish access
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
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
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,114 @@ | ||
| import type { DGSupabaseClient } from "@repo/database/lib/client"; | ||
|
|
||
| export type PublishNode = { | ||
| uid: string; | ||
| type: string; | ||
| }; | ||
|
|
||
| type PublishNodesResult = { | ||
| publishedNodeUids: string[]; | ||
| skippedUnsyncedUids: string[]; | ||
| okGroupIds: string[]; | ||
| failedGroupIds: string[]; | ||
| }; | ||
|
|
||
| // 23505 = unique_violation: the grant already exists, which counts as success. | ||
| const isIgnorableUpsertError = (error: { code?: string } | null): boolean => | ||
| !error || error.code === "23505"; | ||
|
|
||
| const onlyStrings = (values: (string | null)[]): string[] => | ||
| values.filter((value): value is string => typeof value === "string"); | ||
|
|
||
| // Grants a group access to already-synced discourse nodes by mirroring the | ||
| // Obsidian publish-to-group access model (SpaceAccess + ResourceAccess), | ||
| // without its file/frontmatter/relation/asset coupling. | ||
| // | ||
| // ResourceAccess has no foreign key on source_local_id, so granting access to a | ||
| // node that has not synced yet would create an orphaned row. We therefore only | ||
| // publish nodes confirmed present as instance concepts in this space, and | ||
| // report the rest as not-yet-synced (they self-heal on the next sync). | ||
| export const publishNodesToGroups = async ({ | ||
| client, | ||
| spaceId, | ||
| groupIds, | ||
| nodes, | ||
| }: { | ||
| client: DGSupabaseClient; | ||
| spaceId: number; | ||
| groupIds: string[]; | ||
| nodes: PublishNode[]; | ||
| }): Promise<PublishNodesResult> => { | ||
| const result: PublishNodesResult = { | ||
| publishedNodeUids: [], | ||
| skippedUnsyncedUids: [], | ||
| okGroupIds: [], | ||
| failedGroupIds: [], | ||
| }; | ||
| if (nodes.length === 0 || groupIds.length === 0) return result; | ||
|
|
||
| const uids = [...new Set(nodes.map((node) => node.uid))]; | ||
|
|
||
| const syncedRes = await client | ||
| .from("my_concepts") | ||
| .select("source_local_id") | ||
| .eq("space_id", spaceId) | ||
| .eq("is_schema", false) | ||
| .in("source_local_id", uids); | ||
| if (syncedRes.error) throw syncedRes.error; | ||
| const syncedUids = new Set( | ||
| onlyStrings((syncedRes.data ?? []).map((row) => row.source_local_id)), | ||
| ); | ||
|
|
||
| result.skippedUnsyncedUids = uids.filter((uid) => !syncedUids.has(uid)); | ||
| const syncedNodeUids = uids.filter((uid) => syncedUids.has(uid)); | ||
| if (syncedNodeUids.length === 0) return result; | ||
|
|
||
| // Required dependency: the node-type schema concept, when it is synced too. | ||
| const types = [ | ||
| ...new Set( | ||
| nodes.filter((node) => syncedUids.has(node.uid)).map((node) => node.type), | ||
| ), | ||
| ]; | ||
| const schemaRes = await client | ||
| .from("my_concepts") | ||
| .select("source_local_id") | ||
| .eq("space_id", spaceId) | ||
| .eq("is_schema", true) | ||
| .in("source_local_id", types); | ||
| const syncedSchemaIds = onlyStrings( | ||
| (schemaRes.data ?? []).map((row) => row.source_local_id), | ||
| ); | ||
|
sid597 marked this conversation as resolved.
sid597 marked this conversation as resolved.
|
||
|
|
||
| const resourceIds = [...syncedNodeUids, ...syncedSchemaIds]; | ||
|
|
||
| for (const groupId of groupIds) { | ||
| const spaceAccessRes = await client | ||
| .from("SpaceAccess") | ||
| .upsert( | ||
| { account_uid: groupId, space_id: spaceId, permissions: "partial" }, | ||
| { ignoreDuplicates: true }, | ||
| ); | ||
| if (!isIgnorableUpsertError(spaceAccessRes.error)) { | ||
| result.failedGroupIds.push(groupId); | ||
| continue; | ||
| } | ||
|
sid597 marked this conversation as resolved.
|
||
|
|
||
| const grantRes = await client.from("ResourceAccess").upsert( | ||
| resourceIds.map((sourceLocalId) => ({ | ||
| account_uid: groupId, | ||
| source_local_id: sourceLocalId, | ||
| space_id: spaceId, | ||
| })), | ||
| { ignoreDuplicates: true }, | ||
| ); | ||
| if (!isIgnorableUpsertError(grantRes.error)) { | ||
| result.failedGroupIds.push(groupId); | ||
| continue; | ||
| } | ||
|
|
||
| result.okGroupIds.push(groupId); | ||
| } | ||
|
|
||
| result.publishedNodeUids = result.okGroupIds.length > 0 ? syncedNodeUids : []; | ||
|
sid597 marked this conversation as resolved.
|
||
| return result; | ||
| }; | ||
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.