diff --git a/apps/studio/components/interfaces/Explorer/utils.ts b/apps/studio/components/interfaces/Explorer/utils.ts index cba4ad53729..6ae75fc3de9 100644 --- a/apps/studio/components/interfaces/Explorer/utils.ts +++ b/apps/studio/components/interfaces/Explorer/utils.ts @@ -40,8 +40,9 @@ export const createLogCellSkeleton = ({ } const DEFAULT_MARKDOWN_CONTENT = ` - # New section - Add notes about your queries and results +# New section + +Add notes about your queries and results `.trim() export const createMarkdownCellSkeleton = ({ diff --git a/apps/studio/components/layouts/ExplorerLayout/ExplorerNavHome.tsx b/apps/studio/components/layouts/ExplorerLayout/ExplorerNavHome.tsx index dc8c0bd2892..2cab289d42b 100644 --- a/apps/studio/components/layouts/ExplorerLayout/ExplorerNavHome.tsx +++ b/apps/studio/components/layouts/ExplorerLayout/ExplorerNavHome.tsx @@ -12,6 +12,7 @@ import { } from './ExplorerLayout.constants' import { formatRelativeTimeShort, getRecentlyUpdatedItems } from './ExplorerNavHome.utils' import { useCreateChat } from '@/components/interfaces/Explorer/hooks' +import { useContentCountQuery } from '@/data/content/content-count-query' import { useNotebooksInfiniteQuery } from '@/data/content/notebooks/notebooks-infinite-query' import { useAiAssistantChatList } from '@/state/ai-assistant-state' @@ -27,6 +28,10 @@ export const ExplorerNavHome = ({ const notebooks = notebooksData?.pages.flatMap((page) => page.content) ?? [] const chats = useAiAssistantChatList() + const { data: notebookCountData } = useContentCountQuery({ projectRef: ref, type: 'notebook' }) + // [Joshen] Notebooks are all shared by default, none private + const notebookCount = notebookCountData?.shared ?? 0 + const recentItems = getRecentlyUpdatedItems({ notebooks, chats }) return ( @@ -52,7 +57,9 @@ export const ExplorerNavHome = ({ > {label} - {/* Length will be here */} + + {type === 'notebook' ? notebookCount : chats.length} + ) diff --git a/apps/studio/components/layouts/ExplorerLayout/ExplorerNavNotebooks.tsx b/apps/studio/components/layouts/ExplorerLayout/ExplorerNavNotebooks.tsx index 39646c4e2d0..65a379cfaac 100644 --- a/apps/studio/components/layouts/ExplorerLayout/ExplorerNavNotebooks.tsx +++ b/apps/studio/components/layouts/ExplorerLayout/ExplorerNavNotebooks.tsx @@ -7,23 +7,69 @@ import { cn } from 'ui' import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader' import { ExplorerNavResourceWrapper, rowClassName } from './ExplorerLayout.constants' -import { useNotebooksInfiniteQuery } from '@/data/content/notebooks/notebooks-infinite-query' +import { + InfiniteListDefault, + LoaderForIconMenuItems, + type RowComponentBaseProps, +} from '@/components/ui/InfiniteList' +import { + NotebookRow, + useNotebooksInfiniteQuery, +} from '@/data/content/notebooks/notebooks-infinite-query' + +const NOTEBOOK_ROW_HEIGHT = 28 + +type NotebookListItemProps = RowComponentBaseProps & { + projectRef: string | undefined + activeNotebookId: string | undefined +} + +const NotebookListItem = ({ + item: notebook, + style, + projectRef, + activeNotebookId, +}: NotebookListItemProps) => { + const isActive = activeNotebookId === notebook.id + + return ( + + + {notebook.name} + + ) +} export const ExplorerNavNotebooks = ({ onBack }: { onBack: () => void }) => { const router = useRouter() const { ref, id } = useParams() const [search, setSearch] = useState('') - const { data: notebooksData, isPending } = useNotebooksInfiniteQuery({ + const { + data: notebooksData, + isPending, + hasNextPage, + isFetchingNextPage, + fetchNextPage, + } = useNotebooksInfiniteQuery({ projectRef: ref, limit: 100, name: search, }) + const notebooks = useMemo(() => { const items = notebooksData?.pages.flatMap((page) => page.content) ?? [] return items }, [notebooksData?.pages]) + const activeNotebookId = router.pathname.includes('/explorer/notebook/') ? id : undefined + + const itemProps = useMemo(() => ({ projectRef: ref, activeNotebookId }), [ref, activeNotebookId]) + return ( void }) => { setSearch={setSearch} onBack={onBack} > -
+
{isPending ? ( ) : notebooks.length === 0 ? ( @@ -39,20 +85,19 @@ export const ExplorerNavNotebooks = ({ onBack }: { onBack: () => void }) => { {search ? 'No notebooks found' : 'No notebooks created yet'}

) : ( - notebooks.map((notebook) => { - const isActive = router.pathname.includes('/explorer/notebook/') && id === notebook.id - - return ( - - - {notebook.name} - - ) - }) + notebooks[index]?.id ?? `notebook-${index}`} + getItemSize={() => NOTEBOOK_ROW_HEIGHT} + gap={1} + hasNextPage={hasNextPage} + isLoadingNextPage={isFetchingNextPage} + onLoadNextPage={fetchNextPage} + /> )}