Skip to content

Commit cc4e8c0

Browse files
emmaling27Convex, Inc.
authored andcommitted
Revert "Dashboard uses indexes system UDF" (#39151)
Reverts get-convex/convex#39048 GitOrigin-RevId: 31ac1a5c80044d4688c009f4a898e3b3769f0447
1 parent 6a92b09 commit cc4e8c0

File tree

5 files changed

+41
-40
lines changed

5 files changed

+41
-40
lines changed

npm-packages/dashboard-common/src/features/data/components/DataContent.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,9 @@ import {
5050
PanelGroup,
5151
} from "react-resizable-panels";
5252
import { cn } from "@ui/cn";
53-
53+
import { useTableIndexes } from "@common/features/data/lib/api";
5454
import { getDefaultIndex } from "@common/features/data/components/DataFilters/IndexFilters";
5555
import { useMount } from "react-use";
56-
import { api } from "system-udfs/convex/_generated/api";
57-
import { useNents } from "@common/lib/useNents";
5856

5957
export function DataContent({
6058
tableName,
@@ -181,12 +179,7 @@ export function DataContent({
181179
const selectedDocumentId = rowsThatAreSelected.values().next().value;
182180
const selectedDocument = data.find((row) => row._id === selectedDocumentId);
183181
const defaultDocument = useDefaultDocument(tableName);
184-
const { selectedNent } = useNents();
185-
const indexes =
186-
useQuery(api._system.frontend.indexes.default, {
187-
tableName,
188-
componentId: selectedNent?.id ? selectedNent.id : null,
189-
}) ?? undefined;
182+
const { indexes } = useTableIndexes(tableName);
190183
const sortField =
191184
(
192185
indexes?.find((index) => index.name === filters?.index?.name)?.fields as

npm-packages/dashboard-common/src/features/data/components/DataFilters/DataFilters.stories.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ const deployment: ConnectedDeployment = {};
1616
const mockClient = mockConvexReactClient()
1717
.registerQueryFake(udfs.listById.default, ({ ids }) => ids.map(() => null))
1818
.registerQueryFake(udfs.getVersion.default, () => "0.19.0")
19-
.registerQueryFake(udfs.components.list, () => [])
20-
.registerQueryFake(
21-
udfs.indexes.default,
22-
({ tableName: _tableName, componentId: _componentId }) => [],
23-
);
19+
.registerQueryFake(udfs.components.list, () => []);
2420

2521
export default {
2622
component: DataFilters,

npm-packages/dashboard-common/src/features/data/components/DataFilters/DataFilters.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ import {
3737
} from "@common/features/data/components/Table/utils/validators";
3838
import { useFilterHistory } from "@common/features/data/lib/useTableFilters";
3939
import { cn } from "@ui/cn";
40+
import { useTableIndexes } from "@common/features/data/lib/api";
4041
import { DeploymentInfoContext } from "@common/lib/deploymentContext";
41-
import { useNents } from "@common/lib/useNents";
42-
import { useQuery } from "convex/react";
43-
import { api } from "system-udfs/convex/_generated/api";
4442
import { IndexFilterState } from "./IndexFilterEditor";
4543
import { IndexFilters, getDefaultIndex } from "./IndexFilters";
4644

@@ -77,12 +75,7 @@ export function DataFilters({
7775
showFilters: boolean;
7876
setShowFilters: React.Dispatch<React.SetStateAction<boolean>>;
7977
}) {
80-
const { selectedNent } = useNents();
81-
const indexes =
82-
useQuery(api._system.frontend.indexes.default, {
83-
tableName,
84-
componentId: selectedNent?.id ? selectedNent.id : null,
85-
}) ?? undefined;
78+
const { indexes } = useTableIndexes(tableName);
8679
const {
8780
isDirty,
8881
hasInvalidFilters,

npm-packages/dashboard-common/src/features/data/components/IndexList.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import React from "react";
2-
import { Index } from "@common/features/data/lib/api";
2+
import { Index, useTableIndexes } from "@common/features/data/lib/api";
3+
import { Callout } from "@ui/Callout";
34
import { Spinner } from "@ui/Spinner";
45
import { Tooltip } from "@ui/Tooltip";
5-
import { useQuery } from "convex/react";
6-
import { api } from "system-udfs/convex/_generated/api";
7-
import { useNents } from "@common/lib/useNents";
86

97
function IndexRow({ index }: { index: Index }) {
108
const { type, fields } = getIndexDescription(index);
@@ -68,12 +66,11 @@ export function IndexesList({ indexes }: { indexes?: Index[] }) {
6866
}
6967

7068
export function IndexList({ tableName }: { tableName: string }) {
71-
const { selectedNent } = useNents();
72-
const indexes =
73-
useQuery(api._system.frontend.indexes.default, {
74-
tableName,
75-
componentId: selectedNent?.id ? selectedNent.id : null,
76-
}) ?? undefined;
69+
const { indexes, hadError } = useTableIndexes(tableName);
7770

78-
return <IndexesList indexes={indexes} />;
71+
return hadError ? (
72+
<Callout variant="error">Encountered an error loading indexes.</Callout>
73+
) : (
74+
<IndexesList indexes={indexes} />
75+
);
7976
}

npm-packages/dashboard-common/src/features/data/lib/api.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { useCallback, useContext } from "react";
2-
import { useSWRConfig } from "swr";
2+
import useSWR, { useSWRConfig } from "swr";
33
import {
44
useDeploymentUrl,
55
useAdminKey,
66
useDeploymentAuthHeader,
7+
deploymentAuthMiddleware,
8+
useDeploymentIsDisconnected,
79
} from "@common/lib/deploymentApi";
10+
import { deploymentFetch } from "@common/lib/fetching";
11+
import { useNents } from "@common/lib/useNents";
812
import { DeploymentInfoContext } from "@common/lib/deploymentContext";
913

1014
export function useDeleteTables(): (
@@ -46,7 +50,7 @@ export const useInvalidateShapes = () => {
4650
};
4751

4852
export type Index = {
49-
table?: string;
53+
table: string;
5054
name: string;
5155
fields:
5256
| string[]
@@ -61,9 +65,27 @@ export type Index = {
6165
};
6266
backfill: {
6367
state: "in_progress" | "done";
64-
stats?: {
65-
numDocsIndexed: number;
66-
totalDocs: number;
67-
};
6868
};
6969
};
70+
71+
export function useTableIndexes(tableName: string): {
72+
indexes?: Index[];
73+
hadError: boolean;
74+
} {
75+
const { selectedNent } = useNents();
76+
const query = selectedNent ? `?componentId=${selectedNent.id}` : "";
77+
const isDisconnected = useDeploymentIsDisconnected();
78+
const { data, error } = useSWR<{ indexes: Index[] }>(
79+
isDisconnected ? null : `/api/get_indexes${query}`,
80+
deploymentFetch,
81+
{
82+
use: [deploymentAuthMiddleware],
83+
shouldRetryOnError: false,
84+
},
85+
);
86+
87+
return {
88+
hadError: !!error,
89+
indexes: data?.indexes.filter((index) => index.table === tableName),
90+
};
91+
}

0 commit comments

Comments
 (0)