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
27 changes: 26 additions & 1 deletion apps/roam/src/components/Export.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import { AddReferencedNodeType } from "./canvas/DiscourseRelationShape/Discourse
import posthog from "posthog-js";
import { getMyGroups, type MyGroup } from "@repo/database/lib/groups";
import {
getAllPublishedIdsByGroup,
publishNodeUidsWithTypeToGroups,
type NodeUidWithType,
} from "~/utils/publishNodesToGroups";
Expand Down Expand Up @@ -821,6 +822,23 @@ const ExportDialog: ExportDialogComponent = ({
const client = await getLoggedInClient();
if (!client) throw new Error("Could not connect to sync.");
const groups = await getMyGroups(client);
const context = await getSupabaseContext();
if (context && groups.length && publishableNodes.length) {
const publishedIdsByGroup = await getAllPublishedIdsByGroup(
client,
context.spaceId,
groups.map((g) => g.id),
);
Comment on lines +827 to +831

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Limit or paginate the published-resource lookup

For a space/group combination with more than 1,000 ResourceAccess entries, this call receives only the first page because packages/database/supabase/config.toml sets max_rows = 1000, while getAllPublishedIdsByGroup neither paginates nor filters by the nodes being checked. An already-published node omitted from that page is therefore shown as unchecked. Query only the relevant node UIDs for this precheck or paginate until all matching rows have been read.

Useful? React with 👍 / 👎.

setSelectedGroupIds(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Refresh prechecked groups when the dialog reopens

When the persistent Export component in ResultsView.tsx is closed and later reopened after its query results change, groupsLoaded is still true, so the effect returns before recalculating this selection. The group IDs automatically selected here therefore remain associated with the previous nodes; publishing the new results can unintentionally share them with those stale groups. Reset the loading/selection state on close or recompute the prechecked groups whenever publishableNodes changes.

Useful? React with 👍 / 👎.

groups
.map((g) => g.id)
.filter((id) =>
publishableNodes.every(({ uid }) =>
publishedIdsByGroup[id].has(uid),
),
),
);
}
setMyGroups(groups);
} catch (e) {
setGroupsError((e as Error).message || "Failed to load groups.");
Expand All @@ -829,7 +847,14 @@ const ExportDialog: ExportDialogComponent = ({
setGroupsLoaded(true);
}
})();
}, [syncEnabled, isOpen, selectedTabId, groupsLoaded, groupsLoading]);
}, [
syncEnabled,
isOpen,
selectedTabId,
groupsLoaded,
groupsLoading,
publishableNodes,
]);

const handlePublish = async () => {
setPublishError("");
Expand Down
2 changes: 1 addition & 1 deletion apps/roam/src/utils/publishNodesToGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type NodeUidWithType = {
type: string;
};

const getAllPublishedIdsByGroup = async (
export const getAllPublishedIdsByGroup = async (
client: DGSupabaseClient,
spaceId: number,
groupIds: string[],
Expand Down