mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-05 23:42:21 +00:00
remove page counts and fix workspace icon display
This commit is contained in:
parent
f5e5e36de4
commit
08154b321d
2 changed files with 7 additions and 38 deletions
|
|
@ -1,6 +1,6 @@
|
|||
from dataclasses import dataclass
|
||||
|
||||
from sqlalchemy import and_, func
|
||||
from sqlalchemy import and_
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.future import select
|
||||
|
||||
|
|
@ -76,17 +76,14 @@ class NotionToolMetadataService:
|
|||
return {
|
||||
"accounts": [],
|
||||
"parent_pages": {},
|
||||
"total_pages_per_account": {},
|
||||
"error": "No Notion accounts connected",
|
||||
}
|
||||
|
||||
parent_pages = await self._get_parent_pages_by_account(search_space_id, accounts)
|
||||
page_counts = await self._get_page_counts_by_account(search_space_id, accounts)
|
||||
|
||||
return {
|
||||
"accounts": [acc.to_dict() for acc in accounts],
|
||||
"parent_pages": parent_pages,
|
||||
"total_pages_per_account": page_counts,
|
||||
}
|
||||
|
||||
async def get_update_context(
|
||||
|
|
@ -183,23 +180,3 @@ class NotionToolMetadataService:
|
|||
]
|
||||
|
||||
return parent_pages
|
||||
|
||||
async def _get_page_counts_by_account(
|
||||
self, search_space_id: int, accounts: list[NotionAccount]
|
||||
) -> dict:
|
||||
counts = {}
|
||||
|
||||
for account in accounts:
|
||||
result = await self._db_session.execute(
|
||||
select(func.count(Document.id)).filter(
|
||||
and_(
|
||||
Document.search_space_id == search_space_id,
|
||||
Document.connector_id == account.id,
|
||||
Document.document_type == DocumentType.NOTION_CONNECTOR,
|
||||
)
|
||||
)
|
||||
)
|
||||
count = result.scalar()
|
||||
counts[account.id] = count
|
||||
|
||||
return counts
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ interface InterruptResult {
|
|||
document_id: number;
|
||||
}>
|
||||
>;
|
||||
total_pages_per_account?: Record<number, number>;
|
||||
error?: string;
|
||||
};
|
||||
}
|
||||
|
|
@ -105,7 +104,6 @@ function ApprovalCard({
|
|||
|
||||
const accounts = interruptData.context?.accounts ?? [];
|
||||
const parentPages = interruptData.context?.parent_pages ?? {};
|
||||
const totalPagesPerAccount = interruptData.context?.total_pages_per_account ?? {};
|
||||
|
||||
const defaultAccountId = useMemo(() => {
|
||||
if (args.connector_id) return String(args.connector_id);
|
||||
|
|
@ -115,7 +113,7 @@ function ApprovalCard({
|
|||
|
||||
const [selectedAccountId, setSelectedAccountId] = useState<string>(defaultAccountId);
|
||||
const [selectedParentPageId, setSelectedParentPageId] = useState<string>(
|
||||
args.parent_page_id ? String(args.parent_page_id) : ""
|
||||
args.parent_page_id ? String(args.parent_page_id) : "__none__"
|
||||
);
|
||||
|
||||
const availableParentPages = useMemo(() => {
|
||||
|
|
@ -183,7 +181,7 @@ function ApprovalCard({
|
|||
value={selectedAccountId}
|
||||
onValueChange={(value) => {
|
||||
setSelectedAccountId(value);
|
||||
setSelectedParentPageId("");
|
||||
setSelectedParentPageId("__none__");
|
||||
}}
|
||||
>
|
||||
<SelectTrigger className="w-full">
|
||||
|
|
@ -192,13 +190,7 @@ function ApprovalCard({
|
|||
<SelectContent>
|
||||
{accounts.map((account) => (
|
||||
<SelectItem key={account.id} value={String(account.id)}>
|
||||
<div className="flex items-center gap-2">
|
||||
<span>{account.workspace_icon}</span>
|
||||
<span>{account.workspace_name}</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
({totalPagesPerAccount[account.id] ?? 0} pages)
|
||||
</span>
|
||||
</div>
|
||||
{account.workspace_name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
|
|
@ -216,7 +208,7 @@ function ApprovalCard({
|
|||
<SelectValue placeholder="None (create at root level)" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="">None (create at root level)</SelectItem>
|
||||
<SelectItem value="__none__">None (create at root level)</SelectItem>
|
||||
{availableParentPages.map((page) => (
|
||||
<SelectItem key={page.page_id} value={page.page_id}>
|
||||
📄 {page.title}
|
||||
|
|
@ -325,7 +317,7 @@ function ApprovalCard({
|
|||
args: {
|
||||
...editedArgs,
|
||||
connector_id: selectedAccountId ? Number(selectedAccountId) : null,
|
||||
parent_page_id: selectedParentPageId || null,
|
||||
parent_page_id: selectedParentPageId === "__none__" ? null : selectedParentPageId,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
@ -359,7 +351,7 @@ function ApprovalCard({
|
|||
args: {
|
||||
...args,
|
||||
connector_id: selectedAccountId ? Number(selectedAccountId) : null,
|
||||
parent_page_id: selectedParentPageId || null,
|
||||
parent_page_id: selectedParentPageId === "__none__" ? null : selectedParentPageId,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue