@@ -7,7 +7,50 @@ import { useRouter } from "next/router";
77import type { ImportedRepository } from "../../types" ;
88
99import { ImportedRepoMetadata } from "../../components/RepositoryAnalytics/ImportedRepoMetadata" ;
10- import { useMemo } from "react" ;
10+ import { useCallback , useMemo } from "react" ;
11+
12+ import {
13+ EmbeddedQueryPreviews ,
14+ EmbeddedTablePreviews ,
15+ EmbeddedQueryPreviewHeadingAndDescription ,
16+ EmbeddedTablePreviewHeadingAndDescription ,
17+ } from "../../components/EmbeddedQuery/EmbeddedPreviews" ;
18+
19+ import { useQueriesToExport } from "../../lib/config/queries-to-export" ;
20+ import { useTablesToExport } from "../../lib/config/github-tables" ;
21+ import { getQueryParamAsString } from "../../lib/util" ;
22+ import { TabButton } from "../../components/EmbeddedQuery/TabButton" ;
23+
24+ type ActiveTab = "charts" | "tables" | "queries" ;
25+
26+ const useActiveTab = ( defaultTab : ActiveTab ) => {
27+ const router = useRouter ( ) ;
28+
29+ const activeTab =
30+ getQueryParamAsString < ActiveTab > ( router . query , "activeTab" ) ?? defaultTab ;
31+
32+ const switchTab = useCallback (
33+ ( nextTab : ActiveTab ) => {
34+ if ( nextTab === activeTab ) {
35+ return ;
36+ }
37+
38+ return router . push ( {
39+ pathname : router . pathname ,
40+ query : {
41+ ...router . query ,
42+ activeTab : nextTab ,
43+ } ,
44+ } ) ;
45+ } ,
46+ [ router . query ]
47+ ) ;
48+
49+ return {
50+ activeTab,
51+ switchTab,
52+ } ;
53+ } ;
1154
1255const useImportedRepoFromURL = ( ) => {
1356 const { query } = useRouter ( ) ;
@@ -43,12 +86,79 @@ const useImportedRepoFromURL = () => {
4386const RepositoryAnalyticsPage = ( ) => {
4487 const importedRepository = useImportedRepoFromURL ( ) ;
4588
89+ const tablesToExport = useTablesToExport ( importedRepository ) ;
90+ const queriesToExport = useQueriesToExport ( importedRepository ) ;
91+
92+ const { activeTab, switchTab } = useActiveTab ( "charts" ) ;
93+
4694 return (
4795 < BaseLayout sidebar = { < Sidebar /> } >
4896 < ImportedRepoMetadata importedRepository = { importedRepository } />
49- < Charts importedRepository = { importedRepository } />
97+ < PageTabs activeTab = { activeTab } switchTab = { switchTab } />
98+
99+ < TabPane active = { activeTab === "charts" } >
100+ < Charts importedRepository = { importedRepository } />
101+ </ TabPane >
102+
103+ < TabPane active = { activeTab === "tables" } >
104+ < EmbeddedTablePreviewHeadingAndDescription exportComplete = { true } />
105+ < EmbeddedTablePreviews
106+ useLoadingOrCompleted = { ( ) => ( { loading : false , completed : true } ) }
107+ tablesToExport = { tablesToExport }
108+ splitgraphRepository = { importedRepository . splitgraphRepository }
109+ splitgraphNamespace = { importedRepository . splitgraphNamespace }
110+ />
111+ </ TabPane >
112+
113+ < TabPane active = { activeTab === "queries" } >
114+ < EmbeddedQueryPreviewHeadingAndDescription exportComplete = { true } />
115+ < EmbeddedQueryPreviews
116+ useLoadingOrCompleted = { ( ) => ( { loading : false , completed : true } ) }
117+ queriesToExport = { queriesToExport }
118+ splitgraphRepository = { importedRepository . splitgraphRepository }
119+ splitgraphNamespace = { importedRepository . splitgraphNamespace }
120+ />
121+ </ TabPane >
50122 </ BaseLayout >
51123 ) ;
52124} ;
53125
126+ const TabPane = ( { active, children } : { active : boolean ; children : any } ) => {
127+ return < div style = { { display : active ? "block" : "none" } } > { children } </ div > ;
128+ } ;
129+
130+ const PageTabs = ( {
131+ activeTab,
132+ switchTab,
133+ } : ReturnType < typeof useActiveTab > ) => {
134+ return (
135+ < div >
136+ < TabButton
137+ active = { activeTab === "charts" }
138+ onClick = { ( ) => switchTab ( "charts" ) }
139+ style = { { marginRight : "1rem" } }
140+ size = "1.5rem"
141+ >
142+ Charts
143+ </ TabButton >
144+ < TabButton
145+ active = { activeTab === "tables" }
146+ onClick = { ( ) => switchTab ( "tables" ) }
147+ style = { { marginRight : "1rem" } }
148+ size = "1.5rem"
149+ >
150+ Raw Tables
151+ </ TabButton >
152+ < TabButton
153+ active = { activeTab === "queries" }
154+ onClick = { ( ) => switchTab ( "queries" ) }
155+ style = { { marginRight : "1rem" } }
156+ size = "1.5rem"
157+ >
158+ Raw Queries
159+ </ TabButton >
160+ </ div >
161+ ) ;
162+ } ;
163+
54164export default RepositoryAnalyticsPage ;
0 commit comments