Skip to content

Commit 7e1ae87

Browse files
Only poll unique export taskIds, and do the polling from one hook instead of each component
Previously, the API always returned a unique taskId for each table being exported, but a recent change optimized it to return one taskId for the set of tables being exported, but still one taskId for each query being exported. Also previously, this demo code rendered a loading component for each table, and each component had its own hook for polling the taskId of that table. But now that multiple tables can share a taskId, it doesn't make sense for each component to poll for its own taskId. Now, we track the set of taskIds separately from the set of completed tables, and we only poll for unique taskIds, which we do in a hook instead of in each component. And each table preview checks the set of completed tables to know whether it's been completed.
1 parent ad51097 commit 7e1ae87

10 files changed

Lines changed: 197 additions & 217 deletions

File tree

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ import {
99
SplitgraphEmbeddedQuery,
1010
SeafowlEmbeddedQuery,
1111
} from "../RepositoryAnalytics/ImportedRepoMetadata";
12-
import {
13-
useStepperDebug,
14-
useFindMatchingExportTable,
15-
} from "../ImportExportStepper/StepperContext";
12+
import { useStepperDebug } from "../ImportExportStepper/StepperContext";
13+
import { useFindMatchingExportTable } from "../ImportExportStepper/export-hooks";
1614

1715
import type { ExportTable } from "../ImportExportStepper/stepper-states";
1816

examples/nextjs-import-airbyte-github-export-seafowl/components/ImportExportStepper/DebugPanel.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ export const DebugPanel = () => {
66
return (
77
<div>
88
<pre style={{ minWidth: "80%", minHeight: "300px" }}>
9-
{JSON.stringify(state, null, 2)}
9+
{JSON.stringify(
10+
state,
11+
(_key, value) => (value instanceof Set ? Array.from(value) : value),
12+
2
13+
)}
1014
</pre>
1115
</div>
1216
);

examples/nextjs-import-airbyte-github-export-seafowl/components/ImportExportStepper/ExportLoadingBars.module.css

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/nextjs-import-airbyte-github-export-seafowl/components/ImportExportStepper/ExportLoadingBars.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

examples/nextjs-import-airbyte-github-export-seafowl/components/ImportExportStepper/ExportPanel.tsx

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useStepper } from "./StepperContext";
22
import styles from "./ExportPanel.module.css";
3-
import { ExportLoadingBars } from "./ExportLoadingBars";
43

54
import { splitgraphTablesToExportToSeafowl } from "../../lib/config/github-tables";
65
import {
@@ -16,29 +15,20 @@ import type {
1615
import { useMemo, useCallback } from "react";
1716
import { StepTitle } from "./StepTitle";
1817
import { StepDescription } from "./StepDescription";
19-
import {
20-
SeafowlEmbeddedQuery,
21-
SplitgraphEmbeddedQuery,
22-
makeSplitgraphQueryHref,
23-
makeSeafowlQueryHref,
24-
} from "../RepositoryAnalytics/ImportedRepoMetadata";
18+
import { makeSplitgraphQueryHref } from "../RepositoryAnalytics/ImportedRepoMetadata";
2519
import type { ExportTable } from "./stepper-states";
2620

2721
import { ExportEmbedPreviewTableOrQuery } from "../EmbeddedQuery/EmbeddedQuery";
22+
import { usePollExportTasks } from "./export-hooks";
2823

2924
export const ExportPanel = () => {
3025
const [
31-
{
32-
stepperState,
33-
exportError,
34-
splitgraphRepository,
35-
splitgraphNamespace,
36-
exportedTablesCompleted,
37-
repository: githubRepositoryFromStepper,
38-
},
26+
{ stepperState, exportError, splitgraphRepository, splitgraphNamespace },
3927
dispatch,
4028
] = useStepper();
4129

30+
usePollExportTasks();
31+
4232
const queriesToExport = useMemo<ExportQueryInput[]>(
4333
() =>
4434
makeQueriesToExport({
@@ -239,7 +229,6 @@ ${genericDemoQuery}
239229
splitgraphNamespace={splitgraphNamespace}
240230
/>
241231
)}
242-
{stepperState === "awaiting_export" && <ExportLoadingBars />}
243232
</div>
244233
);
245234
};

examples/nextjs-import-airbyte-github-export-seafowl/components/ImportExportStepper/ExportTableLoadingBar.module.css

Lines changed: 0 additions & 17 deletions
This file was deleted.

examples/nextjs-import-airbyte-github-export-seafowl/components/ImportExportStepper/ExportTableLoadingBar.tsx

Lines changed: 0 additions & 97 deletions
This file was deleted.
Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { createContext, useContext, useMemo } from "react";
1+
import { createContext, useContext } from "react";
22
import {
33
StepperState,
44
StepperAction,
55
useStepperReducer,
66
} from "./stepper-states";
7-
import type { ExportTable } from "./stepper-states";
87

98
// Define the context
109
const StepperContext = createContext<
@@ -35,46 +34,3 @@ export const useStepper = () => {
3534
};
3635

3736
export const useStepperDebug = () => useStepper()[0].debug;
38-
39-
/**
40-
* Given a function to match a candidate `ExportTable` to (presumably) an `ExportTableInput`,
41-
* determine if the table (which could also be a query - it's keyed by `destinationSchema`
42-
* and `destinationTable`) is currently exporting (`loading`) or has exported (`completed`).
43-
*
44-
* Return `{ loading, completed, unstarted }`, where:
45-
*
46-
* * `loading` is `true` if there is a match in the `exportedTablesLoading` set,
47-
* * `completed` is `true` if there is a match in the `exportedTablesCompleted` set
48-
* (or if `stepperState` is `export_complete`),
49-
* * `unstarted` is `true` if there is no match in either set.
50-
*
51-
*/
52-
export const useFindMatchingExportTable = (
53-
isMatch: (candidateTable: ExportTable) => boolean
54-
) => {
55-
const [{ stepperState, exportedTablesLoading, exportedTablesCompleted }] =
56-
useStepper();
57-
58-
const matchingCompletedTable = useMemo(
59-
() => Array.from(exportedTablesCompleted).find(isMatch),
60-
[exportedTablesCompleted, isMatch]
61-
);
62-
const matchingLoadingTable = useMemo(
63-
() => Array.from(exportedTablesLoading).find(isMatch),
64-
[exportedTablesLoading, isMatch]
65-
);
66-
67-
// If the state is export_complete, we might have loaded the page directly
68-
// and thus we don't have the sets of exportedTablesCompleted, but we know they exist
69-
const exportFullyCompleted = stepperState === "export_complete";
70-
71-
const completed = matchingCompletedTable ?? (exportFullyCompleted || false);
72-
const loading = matchingLoadingTable ?? false;
73-
const unstarted = !completed && !loading;
74-
75-
return {
76-
completed,
77-
loading,
78-
unstarted,
79-
};
80-
};

0 commit comments

Comments
 (0)