-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeveloperDashboard.jsx
More file actions
183 lines (169 loc) · 7.62 KB
/
Copy pathDeveloperDashboard.jsx
File metadata and controls
183 lines (169 loc) · 7.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
function DeveloperDashboard() {
const { useState, useCallback, useEffect } = React;
const [activeTab, setActiveTab] = useState('component_manager');
const [newComponentName, setNewComponentName] = useState('');
const [generatedCode, setGeneratedCode] = useState('');
const [scriptTag, setScriptTag] = useState('');
const [manifest, setManifest] = useState({ components: [], tests: [] });
const [selectedComponent, setSelectedComponent] = useState('');
const [generatedTestCode, setGeneratedTestCode] = useState('');
useEffect(() => {
// In a real application, we would fetch a manifest.json file here.
// For now, we will use a hardcoded list of components.
setManifest({
components: ['JulesIntrospector.jsx', 'TestComponent.jsx'],
tests: ['JulesIntrospector.test.jsx']
});
}, []);
const componentTemplate = (name) => `
function ${name}() {
const { useState, useEffect } = React;
return (
<div>
<h1>${name} Component</h1>
<p>This is a new component generated by the Developer Dashboard.</p>
</div>
);
}
// --- Self-Rendering Logic ---
const container = document.getElementById('root');
if (container) {
const root = ReactDOM.createRoot(container);
root.render(React.createElement(${name}));
}
`;
const testTemplate = (name) => `
function ${name}Test() {
const { useEffect } = React;
useEffect(() => {
let success = false;
let message = '${name} did not render correctly';
try {
const component = document.querySelector('h1');
if (component && component.textContent === "${name} Component") {
success = true;
message = '${name} rendered correctly';
}
} catch (e) {
message = \`An error occurred during the test: \${e.message}\`;
}
window.parent.postMessage({
type: 'test-complete',
detail: { success, message }
}, '*');
}, []);
return React.createElement(${name});
}
// --- Self-Rendering Logic ---
const container = document.getElementById('root');
if (container) {
const root = ReactDOM.createRoot(container);
root.render(React.createElement(${name}Test));
}
`;
const handleGenerateCode = useCallback(() => {
if (!newComponentName) {
alert('Please enter a component name.');
return;
}
const componentName = newComponentName.trim();
const boilerplate = componentTemplate(componentName);
setGeneratedCode(boilerplate);
setScriptTag(`<script type="text/babel" src="src/${componentName}.jsx"></script>`);
}, [newComponentName]);
const handleGenerateTestCode = useCallback(() => {
if (!selectedComponent) {
alert('Please select a component to test.');
return;
}
const componentName = selectedComponent.replace('.jsx', '');
const boilerplate = testTemplate(componentName);
setGeneratedTestCode(boilerplate);
}, [selectedComponent]);
const componentsWithoutTests = manifest.components.filter(
c => !manifest.tests.includes(c.replace('.jsx', '.test.jsx'))
);
return (
<div className="min-h-screen bg-gray-900 text-white font-sans p-8">
<h1 className="text-4xl md:text-5xl font-extrabold text-center mb-8">Developer Dashboard</h1>
<div className="flex justify-center border-b border-gray-700 mb-6">
<button onClick={() => setActiveTab('component_manager')} className={`py-3 px-6 text-lg font-medium ${activeTab === 'component_manager' ? 'border-b-4 border-blue-500 text-blue-400' : 'text-gray-500 hover:text-gray-300'}`}>Component Manager</button>
<button onClick={() => setActiveTab('test_generator')} className={`py-3 px-6 text-lg font-medium ${activeTab === 'test_generator' ? 'border-b-4 border-blue-500 text-blue-400' : 'text-gray-500 hover:text-gray-300'}`}>Test Generator</button>
</div>
<div className="w-full max-w-6xl mx-auto">
{activeTab === 'component_manager' && (
<div>
<h2 className="text-3xl font-bold mb-4">Component Manager</h2>
<div className="bg-gray-800 p-6 rounded-lg">
<h3 className="text-2xl font-semibold mb-4">Create New Component</h3>
<div className="flex items-center space-x-4 mb-4">
<input
type="text"
placeholder="Enter Component Name"
value={newComponentName}
onChange={(e) => setNewComponentName(e.target.value)}
className="bg-gray-700 text-white rounded-md px-4 py-2 w-full max-w-md focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
<button onClick={handleGenerateCode} className="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-6 rounded-md">Generate Code</button>
</div>
{generatedCode && (
<div className="mt-6">
<h4 className="text-xl font-semibold mb-2">Generated Component Code</h4>
<p className="text-sm text-gray-400 mb-2">Copy this code and save it in a new file under `src/<ComponentName>.jsx`</p>
<textarea
readOnly
value={generatedCode}
className="w-full h-72 p-4 font-mono text-sm bg-gray-700 text-white rounded-md border border-gray-600"
/>
<h4 className="text-xl font-semibold mt-6 mb-2">Script Tag for index.html</h4>
<p className="text-sm text-gray-400 mb-2">To run this component, replace the existing component script tag in `index.html` with this one:</p>
<textarea
readOnly
value={scriptTag}
className="w-full p-4 font-mono text-sm bg-gray-700 text-white rounded-md border border-gray-600"
/>
</div>
)}
</div>
</div>
)}
{activeTab === 'test_generator' && (
<div>
<h2 className="text-3xl font-bold mb-4">Test Generator</h2>
<div className="bg-gray-800 p-6 rounded-lg">
<h3 className="text-2xl font-semibold mb-4">Generate Test for Component</h3>
<div className="flex items-center space-x-4 mb-4">
<select
value={selectedComponent}
onChange={(e) => setSelectedComponent(e.target.value)}
className="bg-gray-700 text-white rounded-md px-4 py-2 w-full max-w-md focus:outline-none focus:ring-2 focus:ring-blue-500"
>
<option value="">Select a component...</option>
{componentsWithoutTests.map(file => <option key={file} value={file}>{file}</option>)}
</select>
<button onClick={handleGenerateTestCode} className="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-6 rounded-md">Generate Test Code</button>
</div>
{generatedTestCode && (
<div className="mt-6">
<h4 className="text-xl font-semibold mb-2">Generated Test Code</h4>
<p className="text-sm text-gray-400 mb-2">Copy this code and save it in a new file under `src/<ComponentName>.test.jsx`</p>
<textarea
readOnly
value={generatedTestCode}
className="w-full h-72 p-4 font-mono text-sm bg-gray-700 text-white rounded-md border border-gray-600"
/>
</div>
)}
</div>
</div>
)}
</div>
</div>
);
}
// --- Self-Rendering Logic ---
const container = document.getElementById('root');
if (container) {
const root = ReactDOM.createRoot(container);
root.render(React.createElement(DeveloperDashboard));
}