MCPcopy Create free account
hub / github.com/ScrapeGraphAI/scrapecraft / SchemaEditor

Function SchemaEditor

frontend/src/components/Pipeline/SchemaEditor.tsx:12–167  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10}
11
12const SchemaEditor: React.FC = () => {
13 const { currentPipeline, updatePipeline } = usePipelineStore();
14 const [fields, setFields] = useState<SchemaField[]>([]);
15 const [newField, setNewField] = useState<SchemaField>({
16 name: '',
17 type: 'str',
18 description: ''
19 });
20
21 useEffect(() => {
22 // Convert schema object to fields array
23 if (currentPipeline?.schema) {
24 const schemaFields = Object.entries(currentPipeline.schema).map(([name, type]) => ({
25 name,
26 type: typeof type === 'string' ? type : 'str',
27 description: ''
28 }));
29 setFields(schemaFields);
30 }
31 }, [currentPipeline?.schema]);
32
33 const handleAddField = () => {
34 if (!newField.name.trim() || !currentPipeline) return;
35
36 const updatedFields = [...fields, newField];
37 setFields(updatedFields);
38
39 // Update pipeline schema
40 const schema = updatedFields.reduce((acc, field) => ({
41 ...acc,
42 [field.name]: field.type
43 }), {});
44
45 updatePipeline(currentPipeline.id, { schema });
46
47 // Reset form
48 setNewField({ name: '', type: 'str', description: '' });
49 };
50
51 const handleRemoveField = (index: number) => {
52 if (!currentPipeline) return;
53
54 const updatedFields = fields.filter((_, i) => i !== index);
55 setFields(updatedFields);
56
57 // Update pipeline schema
58 const schema = updatedFields.reduce((acc, field) => ({
59 ...acc,
60 [field.name]: field.type
61 }), {});
62
63 updatePipeline(currentPipeline.id, { schema });
64 };
65
66 const fieldTypes = [
67 { value: 'str', label: 'String' },
68 { value: 'int', label: 'Integer' },
69 { value: 'float', label: 'Float' },

Callers

nothing calls this directly

Calls 1

handleRemoveFieldFunction · 0.85

Tested by

no test coverage detected