diff --git a/examples/nextjs-import-airbyte-github-export-seafowl/components/EmbeddedQuery/TabButton.tsx b/examples/nextjs-import-airbyte-github-export-seafowl/components/EmbeddedQuery/TabButton.tsx index 7f4c9e9..ae6368f 100644 --- a/examples/nextjs-import-airbyte-github-export-seafowl/components/EmbeddedQuery/TabButton.tsx +++ b/examples/nextjs-import-airbyte-github-export-seafowl/components/EmbeddedQuery/TabButton.tsx @@ -1,10 +1,11 @@ -import type { ButtonHTMLAttributes } from "react"; +import type { ButtonHTMLAttributes, CSSProperties } from "react"; import TabButtonStyle from "./TabButton.module.css"; interface TabButtonProps extends ButtonHTMLAttributes { active: boolean; onClick: () => void; + size?: CSSProperties["fontSize"]; } export const TabButton = ({ @@ -12,6 +13,7 @@ export const TabButton = ({ onClick, disabled: alwaysDisabled, children, + size, ...rest }: React.PropsWithChildren) => { const className = [ @@ -29,7 +31,11 @@ export const TabButton = ({ className={className} {...rest} > - {children} + {typeof size !== "undefined" ? ( + {children} + ) : ( + children + )} ); }; diff --git a/examples/nextjs-import-airbyte-github-export-seafowl/components/RepositoryAnalytics/ImportedRepoMetadata.tsx b/examples/nextjs-import-airbyte-github-export-seafowl/components/RepositoryAnalytics/ImportedRepoMetadata.tsx index bc05767..81c708d 100644 --- a/examples/nextjs-import-airbyte-github-export-seafowl/components/RepositoryAnalytics/ImportedRepoMetadata.tsx +++ b/examples/nextjs-import-airbyte-github-export-seafowl/components/RepositoryAnalytics/ImportedRepoMetadata.tsx @@ -46,11 +46,6 @@ export const ImportedRepoMetadata = ({ /> - ); }; diff --git a/examples/nextjs-import-airbyte-github-export-seafowl/pages/[github_namespace]/[github_repository].tsx b/examples/nextjs-import-airbyte-github-export-seafowl/pages/[github_namespace]/[github_repository].tsx index 06cec7d..6d8bfa4 100644 --- a/examples/nextjs-import-airbyte-github-export-seafowl/pages/[github_namespace]/[github_repository].tsx +++ b/examples/nextjs-import-airbyte-github-export-seafowl/pages/[github_namespace]/[github_repository].tsx @@ -7,7 +7,50 @@ import { useRouter } from "next/router"; import type { ImportedRepository } from "../../types"; import { ImportedRepoMetadata } from "../../components/RepositoryAnalytics/ImportedRepoMetadata"; -import { useMemo } from "react"; +import { useCallback, useMemo } from "react"; + +import { + EmbeddedQueryPreviews, + EmbeddedTablePreviews, + EmbeddedQueryPreviewHeadingAndDescription, + EmbeddedTablePreviewHeadingAndDescription, +} from "../../components/EmbeddedQuery/EmbeddedPreviews"; + +import { useQueriesToExport } from "../../lib/config/queries-to-export"; +import { useTablesToExport } from "../../lib/config/github-tables"; +import { getQueryParamAsString } from "../../lib/util"; +import { TabButton } from "../../components/EmbeddedQuery/TabButton"; + +type ActiveTab = "charts" | "tables" | "queries"; + +const useActiveTab = (defaultTab: ActiveTab) => { + const router = useRouter(); + + const activeTab = + getQueryParamAsString(router.query, "activeTab") ?? defaultTab; + + const switchTab = useCallback( + (nextTab: ActiveTab) => { + if (nextTab === activeTab) { + return; + } + + return router.push({ + pathname: router.pathname, + query: { + ...router.query, + activeTab: nextTab, + }, + }); + }, + [router.query] + ); + + return { + activeTab, + switchTab, + }; +}; const useImportedRepoFromURL = () => { const { query } = useRouter(); @@ -43,12 +86,79 @@ const useImportedRepoFromURL = () => { const RepositoryAnalyticsPage = () => { const importedRepository = useImportedRepoFromURL(); + const tablesToExport = useTablesToExport(importedRepository); + const queriesToExport = useQueriesToExport(importedRepository); + + const { activeTab, switchTab } = useActiveTab("charts"); + return ( }> - + + + + + + + + + ({ loading: false, completed: true })} + tablesToExport={tablesToExport} + splitgraphRepository={importedRepository.splitgraphRepository} + splitgraphNamespace={importedRepository.splitgraphNamespace} + /> + + + + + ({ loading: false, completed: true })} + queriesToExport={queriesToExport} + splitgraphRepository={importedRepository.splitgraphRepository} + splitgraphNamespace={importedRepository.splitgraphNamespace} + /> + ); }; +const TabPane = ({ active, children }: { active: boolean; children: any }) => { + return
{children}
; +}; + +const PageTabs = ({ + activeTab, + switchTab, +}: ReturnType) => { + return ( +
+ switchTab("charts")} + style={{ marginRight: "1rem" }} + size="1.5rem" + > + Charts + + switchTab("tables")} + style={{ marginRight: "1rem" }} + size="1.5rem" + > + Raw Tables + + switchTab("queries")} + style={{ marginRight: "1rem" }} + size="1.5rem" + > + Raw Queries + +
+ ); +}; + export default RepositoryAnalyticsPage;