Skip to content

Commit 43a9de7

Browse files
Make repo page have three tabs: tables, queries and charts
1 parent 6444c5b commit 43a9de7

File tree

3 files changed

+120
-9
lines changed

3 files changed

+120
-9
lines changed

examples/nextjs-import-airbyte-github-export-seafowl/components/EmbeddedQuery/TabButton.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
import type { ButtonHTMLAttributes } from "react";
1+
import type { ButtonHTMLAttributes, CSSProperties } from "react";
22

33
import TabButtonStyle from "./TabButton.module.css";
44

55
interface TabButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
66
active: boolean;
77
onClick: () => void;
8+
size?: CSSProperties["fontSize"];
89
}
910

1011
export const TabButton = ({
1112
active,
1213
onClick,
1314
disabled: alwaysDisabled,
1415
children,
16+
size,
1517
...rest
1618
}: React.PropsWithChildren<TabButtonProps>) => {
1719
const className = [
@@ -29,7 +31,11 @@ export const TabButton = ({
2931
className={className}
3032
{...rest}
3133
>
32-
{children}
34+
{typeof size !== "undefined" ? (
35+
<span style={{ fontSize: size }}>{children}</span>
36+
) : (
37+
children
38+
)}
3339
</button>
3440
);
3541
};

examples/nextjs-import-airbyte-github-export-seafowl/components/RepositoryAnalytics/ImportedRepoMetadata.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ export const ImportedRepoMetadata = ({
4646
/>
4747
</li>
4848
</ul>
49-
<SeafowlEmbeddedQuery
50-
importedRepository={importedRepository}
51-
tableName={"stargazers"}
52-
makeQuery={makeStargazersTableQuery}
53-
/>
5449
</div>
5550
);
5651
};

examples/nextjs-import-airbyte-github-export-seafowl/pages/[github_namespace]/[github_repository].tsx

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,50 @@ import { useRouter } from "next/router";
77
import type { ImportedRepository } from "../../types";
88

99
import { 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

1255
const useImportedRepoFromURL = () => {
1356
const { query } = useRouter();
@@ -43,12 +86,79 @@ const useImportedRepoFromURL = () => {
4386
const 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+
54164
export default RepositoryAnalyticsPage;

0 commit comments

Comments
 (0)