Skip to content

Commit b41428c

Browse files
committed
feat: enhance client usage in multiple components to support project-specific data handling
1 parent 63e3b7f commit b41428c

5 files changed

Lines changed: 41 additions & 4 deletions

File tree

apps/studio/src/components/ObjectDataForm.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import { useState, useEffect } from 'react';
44
import { useClient } from '@objectstack/client-react';
5+
import { useParams } from '@tanstack/react-router';
6+
import { useScopedClient } from '@/hooks/useObjectStackClient';
57
import { Button } from "@/components/ui/button";
68
import { Input } from "@/components/ui/input";
79
import { Textarea } from "@/components/ui/textarea";
@@ -21,7 +23,10 @@ interface ObjectDataFormProps {
2123
}
2224

2325
export function ObjectDataForm({ objectApiName, record, onSuccess, onCancel }: ObjectDataFormProps) {
24-
const client = useClient();
26+
const unscopedClient = useClient();
27+
const params = useParams({ strict: false }) as { projectId?: string };
28+
const scopedClient = useScopedClient(params.projectId);
29+
const client: any = scopedClient ?? unscopedClient;
2530
const [def, setDef] = useState<any>(null);
2631
const [formData, setFormData] = useState<any>({});
2732
const [loading, setLoading] = useState(false);

apps/studio/src/components/ObjectSchemaInspector.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import { useState, useEffect } from 'react';
44
import { useClient } from '@objectstack/client-react';
5+
import { useParams } from '@tanstack/react-router';
6+
import { useScopedClient } from '@/hooks/useObjectStackClient';
57
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card";
68
import { Badge } from "@/components/ui/badge";
79
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
@@ -65,7 +67,10 @@ function CopyButton({ text }: { text: string }) {
6567
}
6668

6769
export function ObjectSchemaInspector({ objectApiName }: ObjectSchemaInspectorProps) {
68-
const client = useClient();
70+
const unscopedClient = useClient();
71+
const params = useParams({ strict: false }) as { projectId?: string };
72+
const scopedClient = useScopedClient(params.projectId);
73+
const client: any = scopedClient ?? unscopedClient;
6974
const [def, setDef] = useState<any>(null);
7075
const [loading, setLoading] = useState(true);
7176
const [searchQuery, setSearchQuery] = useState('');

apps/studio/src/plugins/built-in/default-plugin.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import { useState, useEffect } from 'react';
1414
import { defineStudioPlugin } from '@objectstack/spec/studio';
1515
import { useClient } from '@objectstack/client-react';
16+
import { useParams } from '@tanstack/react-router';
17+
import { useScopedClient } from '@/hooks/useObjectStackClient';
1618
import { MetadataInspector } from '@/components/MetadataInspector';
1719
import { CodeExporter } from '@/components/CodeExporter';
1820
import type { CodeExporterProps } from '@/components/CodeExporter';
@@ -39,7 +41,10 @@ function PreviewViewerComponent({ metadataType, metadataName, packageId }: Metad
3941
// ─── Code Viewer (Code Exporter) ─────────────────────────────────────
4042

4143
function CodeViewerComponent({ metadataType, metadataName, data, packageId }: MetadataViewerProps) {
42-
const client = useClient();
44+
const unscopedClient = useClient();
45+
const params = useParams({ strict: false }) as { projectId?: string };
46+
const scopedClient = useScopedClient(params.projectId);
47+
const client: any = scopedClient ?? unscopedClient;
4348
const [definition, setDefinition] = useState<Record<string, unknown> | null>(data ?? null);
4449
const [loading, setLoading] = useState(!data);
4550

apps/studio/src/plugins/built-in/tool-playground-plugin.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import { useState, useEffect, useRef } from 'react';
1414
import { defineStudioPlugin } from '@objectstack/spec/studio';
1515
import { useClient } from '@objectstack/client-react';
16+
import { useParams } from '@tanstack/react-router';
17+
import { useScopedClient } from '@/hooks/useObjectStackClient';
1618
import type { StudioPlugin, MetadataViewerProps } from '../types';
1719
import type { Tool } from '@objectstack/spec/ai';
1820
import {
@@ -347,7 +349,10 @@ function ExecutionItem({ entry }: ExecutionItemProps) {
347349
* Tool Playground Viewer Component
348350
*/
349351
function ToolPlaygroundViewer({ metadataType, metadataName, data, packageId }: MetadataViewerProps) {
350-
const client = useClient();
352+
const unscopedClient = useClient();
353+
const params = useParams({ strict: false }) as { projectId?: string };
354+
const scopedClient = useScopedClient(params.projectId);
355+
const client: any = scopedClient ?? unscopedClient;
351356
const [tool, setTool] = useState<Tool | null>(data ?? null);
352357
const [loading, setLoading] = useState(!data);
353358
const [executing, setExecuting] = useState(false);

packages/runtime/src/multi-project-plugin.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,27 @@ function extractMetadataItems(bundle: any): ExtractedItem[] {
114114
pushAll('flow', bundle?.flows);
115115
pushAll('agent', bundle?.agents);
116116
pushAll('app', bundle?.apps);
117+
pushAll('action', bundle?.actions);
117118

118119
return items;
119120
}
120121

122+
/**
123+
* Rewrite a dataset's `object` to the namespaced FQN so seed rows target
124+
* the object the metadata layer actually registered. Bundle authors write
125+
* the short name (`task`) because the namespace lives on the manifest;
126+
* `extractMetadataItems` does the equivalent rewrite for objects.
127+
*/
128+
function namespaceDatasets(bundle: any): any[] {
129+
const ns = bundle?.manifest?.namespace as string | undefined;
130+
const datasets = Array.isArray(bundle?.data) ? bundle.data : [];
131+
if (!ns || RESERVED_NS.has(ns)) return datasets;
132+
return datasets.map((ds: any) => {
133+
if (!ds?.object || ds.object.includes('__')) return ds;
134+
return { ...ds, object: `${ns}__${ds.object}` };
135+
});
136+
}
137+
121138
function createTemplateSeeder(
122139
kernelManager: KernelManager,
123140
templates: Record<string, ProjectTemplate>,

0 commit comments

Comments
 (0)