Skip to content

Commit 9e1549d

Browse files
ldanilekConvex, Inc.
authored and
Convex, Inc.
committed
component-picker in dashboard (#27906)
GitOrigin-RevId: 8f7f3752a5933e536caad54558c6690b7234ef3d
1 parent eaf8b49 commit 9e1549d

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

npm-packages/system-udfs/convex/_generated/api.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type * as _system_cli_tables from "../_system/cli/tables.js";
2323
import type * as _system_frontend_addDocument from "../_system/frontend/addDocument.js";
2424
import type * as _system_frontend_clearTablePage from "../_system/frontend/clearTablePage.js";
2525
import type * as _system_frontend_common from "../_system/frontend/common.js";
26+
import type * as _system_frontend_components from "../_system/frontend/components.js";
2627
import type * as _system_frontend_convexSiteUrl from "../_system/frontend/convexSiteUrl.js";
2728
import type * as _system_frontend_createTable from "../_system/frontend/createTable.js";
2829
import type * as _system_frontend_deleteDocuments from "../_system/frontend/deleteDocuments.js";
@@ -76,6 +77,7 @@ declare const fullApi: ApiFromModules<{
7677
"_system/frontend/addDocument": typeof _system_frontend_addDocument;
7778
"_system/frontend/clearTablePage": typeof _system_frontend_clearTablePage;
7879
"_system/frontend/common": typeof _system_frontend_common;
80+
"_system/frontend/components": typeof _system_frontend_components;
7981
"_system/frontend/convexSiteUrl": typeof _system_frontend_convexSiteUrl;
8082
"_system/frontend/createTable": typeof _system_frontend_createTable;
8183
"_system/frontend/deleteDocuments": typeof _system_frontend_deleteDocuments;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { queryPrivateSystem } from "../secretSystemTables";
2+
import { Doc, Id } from "../../_generated/dataModel";
3+
4+
export const list = queryPrivateSystem({
5+
args: {},
6+
handler: async function ({ db }) {
7+
const componentDocs = await db.query("_components").collect();
8+
const idToDoc = new Map<Id<"_components">, Doc<"_components">>(
9+
componentDocs.map((doc) => [doc._id, doc]),
10+
);
11+
const idToPath = new Map<string, string>();
12+
function computeIdToPath(doc: Doc<"_components">): string {
13+
if (idToPath.has(doc._id)) {
14+
return idToPath.get(doc._id)!;
15+
}
16+
let path = "";
17+
if (!doc.parent) {
18+
// Root component
19+
path = "";
20+
} else {
21+
const parentPath = computeIdToPath(idToDoc.get(doc.parent)!);
22+
if (parentPath.length === 0) {
23+
path = doc.name!;
24+
} else {
25+
path = `${parentPath}/${doc.name!}`;
26+
}
27+
}
28+
idToPath.set(doc._id, path);
29+
return path;
30+
}
31+
return componentDocs.map((doc) => ({
32+
id: doc._id,
33+
name: doc.name,
34+
path: computeIdToPath(doc),
35+
args: Object.fromEntries(doc.args ?? []),
36+
}));
37+
},
38+
});

npm-packages/system-udfs/convex/schema.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ export default defineSchema({
245245
v.literal("hidden"),
246246
),
247247
}),
248+
_components: defineTable({
249+
definitionId: v.id("_component_definitions"),
250+
parent: v.union(v.id("_components"), v.null()),
251+
name: v.union(v.string(), v.null()),
252+
args: v.union(v.array(v.any()), v.null()),
253+
}),
248254
_modules: defineTable({
249255
path: v.string(),
250256
latestVersion: v.int64(),

0 commit comments

Comments
 (0)