@friggframework/devtools 2.0.0-next.4 → 2.0.0-next.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/frigg-cli/.eslintrc.js +141 -0
- package/frigg-cli/__tests__/jest.config.js +102 -0
- package/frigg-cli/__tests__/unit/commands/build.test.js +483 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +418 -0
- package/frigg-cli/__tests__/unit/commands/ui.test.js +592 -0
- package/frigg-cli/__tests__/utils/command-tester.js +170 -0
- package/frigg-cli/__tests__/utils/mock-factory.js +270 -0
- package/frigg-cli/__tests__/utils/test-fixtures.js +463 -0
- package/frigg-cli/__tests__/utils/test-setup.js +286 -0
- package/frigg-cli/build-command/index.js +54 -0
- package/frigg-cli/deploy-command/index.js +175 -0
- package/frigg-cli/generate-command/__tests__/generate-command.test.js +312 -0
- package/frigg-cli/generate-command/azure-generator.js +43 -0
- package/frigg-cli/generate-command/gcp-generator.js +47 -0
- package/frigg-cli/generate-command/index.js +332 -0
- package/frigg-cli/generate-command/terraform-generator.js +555 -0
- package/frigg-cli/generate-iam-command.js +115 -0
- package/frigg-cli/index.js +47 -1
- package/frigg-cli/index.test.js +1 -4
- package/frigg-cli/init-command/backend-first-handler.js +756 -0
- package/frigg-cli/init-command/index.js +93 -0
- package/frigg-cli/init-command/template-handler.js +143 -0
- package/frigg-cli/install-command/index.js +1 -4
- package/frigg-cli/package.json +51 -0
- package/frigg-cli/start-command/index.js +24 -4
- package/frigg-cli/test/init-command.test.js +180 -0
- package/frigg-cli/test/npm-registry.test.js +319 -0
- package/frigg-cli/ui-command/index.js +154 -0
- package/frigg-cli/utils/app-resolver.js +319 -0
- package/frigg-cli/utils/backend-path.js +16 -17
- package/frigg-cli/utils/npm-registry.js +167 -0
- package/frigg-cli/utils/process-manager.js +199 -0
- package/frigg-cli/utils/repo-detection.js +405 -0
- package/infrastructure/DEPLOYMENT-INSTRUCTIONS.md +268 -0
- package/infrastructure/GENERATE-IAM-DOCS.md +278 -0
- package/infrastructure/IAM-POLICY-TEMPLATES.md +176 -0
- package/infrastructure/README.md +443 -0
- package/infrastructure/WEBSOCKET-CONFIGURATION.md +105 -0
- package/infrastructure/__tests__/fixtures/mock-aws-resources.js +391 -0
- package/infrastructure/__tests__/helpers/test-utils.js +277 -0
- package/infrastructure/aws-discovery.js +1176 -0
- package/infrastructure/aws-discovery.test.js +1220 -0
- package/infrastructure/build-time-discovery.js +206 -0
- package/infrastructure/build-time-discovery.test.js +378 -0
- package/infrastructure/create-frigg-infrastructure.js +3 -5
- package/infrastructure/env-validator.js +77 -0
- package/infrastructure/frigg-deployment-iam-stack.yaml +401 -0
- package/infrastructure/iam-generator.js +836 -0
- package/infrastructure/iam-generator.test.js +172 -0
- package/infrastructure/iam-policy-basic.json +218 -0
- package/infrastructure/iam-policy-full.json +288 -0
- package/infrastructure/integration.test.js +383 -0
- package/infrastructure/run-discovery.js +110 -0
- package/infrastructure/serverless-template.js +1472 -138
- package/infrastructure/serverless-template.test.js +1759 -0
- package/management-ui/.eslintrc.js +22 -0
- package/management-ui/README.md +203 -0
- package/management-ui/components.json +21 -0
- package/management-ui/docs/phase2-integration-guide.md +320 -0
- package/management-ui/index.html +13 -0
- package/management-ui/package-lock.json +16517 -0
- package/management-ui/package.json +76 -0
- package/management-ui/packages/devtools/frigg-cli/ui-command/index.js +302 -0
- package/management-ui/postcss.config.js +6 -0
- package/management-ui/server/api/backend.js +256 -0
- package/management-ui/server/api/cli.js +315 -0
- package/management-ui/server/api/codegen.js +663 -0
- package/management-ui/server/api/connections.js +857 -0
- package/management-ui/server/api/discovery.js +185 -0
- package/management-ui/server/api/environment/index.js +1 -0
- package/management-ui/server/api/environment/router.js +378 -0
- package/management-ui/server/api/environment.js +328 -0
- package/management-ui/server/api/integrations.js +876 -0
- package/management-ui/server/api/logs.js +248 -0
- package/management-ui/server/api/monitoring.js +282 -0
- package/management-ui/server/api/open-ide.js +31 -0
- package/management-ui/server/api/project.js +1029 -0
- package/management-ui/server/api/users/sessions.js +371 -0
- package/management-ui/server/api/users/simulation.js +254 -0
- package/management-ui/server/api/users.js +362 -0
- package/management-ui/server/api-contract.md +275 -0
- package/management-ui/server/index.js +873 -0
- package/management-ui/server/middleware/errorHandler.js +93 -0
- package/management-ui/server/middleware/security.js +32 -0
- package/management-ui/server/processManager.js +296 -0
- package/management-ui/server/server.js +346 -0
- package/management-ui/server/services/aws-monitor.js +413 -0
- package/management-ui/server/services/npm-registry.js +347 -0
- package/management-ui/server/services/template-engine.js +538 -0
- package/management-ui/server/utils/cliIntegration.js +220 -0
- package/management-ui/server/utils/environment/auditLogger.js +471 -0
- package/management-ui/server/utils/environment/awsParameterStore.js +264 -0
- package/management-ui/server/utils/environment/encryption.js +278 -0
- package/management-ui/server/utils/environment/envFileManager.js +286 -0
- package/management-ui/server/utils/import-commonjs.js +28 -0
- package/management-ui/server/utils/response.js +83 -0
- package/management-ui/server/websocket/handler.js +325 -0
- package/management-ui/src/App.jsx +109 -0
- package/management-ui/src/assets/FriggLogo.svg +1 -0
- package/management-ui/src/components/AppRouter.jsx +65 -0
- package/management-ui/src/components/Button.jsx +70 -0
- package/management-ui/src/components/Card.jsx +97 -0
- package/management-ui/src/components/EnvironmentCompare.jsx +400 -0
- package/management-ui/src/components/EnvironmentEditor.jsx +372 -0
- package/management-ui/src/components/EnvironmentImportExport.jsx +469 -0
- package/management-ui/src/components/EnvironmentSchema.jsx +491 -0
- package/management-ui/src/components/EnvironmentSecurity.jsx +463 -0
- package/management-ui/src/components/ErrorBoundary.jsx +73 -0
- package/management-ui/src/components/IntegrationCard.jsx +481 -0
- package/management-ui/src/components/IntegrationCardEnhanced.jsx +770 -0
- package/management-ui/src/components/IntegrationExplorer.jsx +379 -0
- package/management-ui/src/components/IntegrationStatus.jsx +336 -0
- package/management-ui/src/components/Layout.jsx +716 -0
- package/management-ui/src/components/LoadingSpinner.jsx +113 -0
- package/management-ui/src/components/RepositoryPicker.jsx +248 -0
- package/management-ui/src/components/SessionMonitor.jsx +350 -0
- package/management-ui/src/components/StatusBadge.jsx +208 -0
- package/management-ui/src/components/UserContextSwitcher.jsx +212 -0
- package/management-ui/src/components/UserSimulation.jsx +327 -0
- package/management-ui/src/components/Welcome.jsx +434 -0
- package/management-ui/src/components/codegen/APIEndpointGenerator.jsx +637 -0
- package/management-ui/src/components/codegen/APIModuleSelector.jsx +227 -0
- package/management-ui/src/components/codegen/CodeGenerationWizard.jsx +247 -0
- package/management-ui/src/components/codegen/CodePreviewEditor.jsx +316 -0
- package/management-ui/src/components/codegen/DynamicModuleForm.jsx +271 -0
- package/management-ui/src/components/codegen/FormBuilder.jsx +737 -0
- package/management-ui/src/components/codegen/IntegrationGenerator.jsx +855 -0
- package/management-ui/src/components/codegen/ProjectScaffoldWizard.jsx +797 -0
- package/management-ui/src/components/codegen/SchemaBuilder.jsx +303 -0
- package/management-ui/src/components/codegen/TemplateSelector.jsx +586 -0
- package/management-ui/src/components/codegen/index.js +10 -0
- package/management-ui/src/components/connections/ConnectionConfigForm.jsx +362 -0
- package/management-ui/src/components/connections/ConnectionHealthMonitor.jsx +182 -0
- package/management-ui/src/components/connections/ConnectionTester.jsx +200 -0
- package/management-ui/src/components/connections/EntityRelationshipMapper.jsx +292 -0
- package/management-ui/src/components/connections/OAuthFlow.jsx +204 -0
- package/management-ui/src/components/connections/index.js +5 -0
- package/management-ui/src/components/index.js +21 -0
- package/management-ui/src/components/monitoring/APIGatewayMetrics.jsx +222 -0
- package/management-ui/src/components/monitoring/LambdaMetrics.jsx +169 -0
- package/management-ui/src/components/monitoring/MetricsChart.jsx +197 -0
- package/management-ui/src/components/monitoring/MonitoringDashboard.jsx +393 -0
- package/management-ui/src/components/monitoring/SQSMetrics.jsx +246 -0
- package/management-ui/src/components/monitoring/index.js +6 -0
- package/management-ui/src/components/monitoring/monitoring.css +218 -0
- package/management-ui/src/components/theme-provider.jsx +52 -0
- package/management-ui/src/components/theme-toggle.jsx +39 -0
- package/management-ui/src/components/ui/badge.tsx +36 -0
- package/management-ui/src/components/ui/button.test.jsx +56 -0
- package/management-ui/src/components/ui/button.tsx +57 -0
- package/management-ui/src/components/ui/card.tsx +76 -0
- package/management-ui/src/components/ui/dropdown-menu.tsx +199 -0
- package/management-ui/src/components/ui/select.tsx +157 -0
- package/management-ui/src/components/ui/skeleton.jsx +15 -0
- package/management-ui/src/hooks/useFrigg.jsx +601 -0
- package/management-ui/src/hooks/useSocket.jsx +58 -0
- package/management-ui/src/index.css +193 -0
- package/management-ui/src/lib/utils.ts +6 -0
- package/management-ui/src/main.jsx +10 -0
- package/management-ui/src/pages/CodeGeneration.jsx +14 -0
- package/management-ui/src/pages/Connections.jsx +252 -0
- package/management-ui/src/pages/ConnectionsEnhanced.jsx +633 -0
- package/management-ui/src/pages/Dashboard.jsx +311 -0
- package/management-ui/src/pages/Environment.jsx +314 -0
- package/management-ui/src/pages/IntegrationConfigure.jsx +669 -0
- package/management-ui/src/pages/IntegrationDiscovery.jsx +567 -0
- package/management-ui/src/pages/IntegrationTest.jsx +742 -0
- package/management-ui/src/pages/Integrations.jsx +253 -0
- package/management-ui/src/pages/Monitoring.jsx +17 -0
- package/management-ui/src/pages/Simulation.jsx +155 -0
- package/management-ui/src/pages/Users.jsx +492 -0
- package/management-ui/src/services/api.js +41 -0
- package/management-ui/src/services/apiModuleService.js +193 -0
- package/management-ui/src/services/websocket-handlers.js +120 -0
- package/management-ui/src/test/api/project.test.js +273 -0
- package/management-ui/src/test/components/Welcome.test.jsx +378 -0
- package/management-ui/src/test/mocks/server.js +178 -0
- package/management-ui/src/test/setup.js +61 -0
- package/management-ui/src/test/utils/test-utils.jsx +134 -0
- package/management-ui/src/utils/repository.js +98 -0
- package/management-ui/src/utils/repository.test.js +118 -0
- package/management-ui/src/workflows/phase2-integration-workflows.js +884 -0
- package/management-ui/tailwind.config.js +63 -0
- package/management-ui/tsconfig.json +37 -0
- package/management-ui/tsconfig.node.json +10 -0
- package/management-ui/vite.config.js +26 -0
- package/management-ui/vitest.config.js +38 -0
- package/package.json +20 -9
- package/infrastructure/app-handler-helpers.js +0 -57
- package/infrastructure/backend-utils.js +0 -90
- package/infrastructure/routers/auth.js +0 -26
- package/infrastructure/routers/integration-defined-routers.js +0 -37
- package/infrastructure/routers/middleware/loadUser.js +0 -15
- package/infrastructure/routers/middleware/requireLoggedInUser.js +0 -12
- package/infrastructure/routers/user.js +0 -41
- package/infrastructure/routers/websocket.js +0 -55
- package/infrastructure/workers/integration-defined-workers.js +0 -24
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import React, { useState, useCallback, useMemo } from 'react';
|
|
2
|
+
import { Card } from '../Card';
|
|
3
|
+
import { Button } from '../Button';
|
|
4
|
+
|
|
5
|
+
const CodePreviewEditor = ({ code, metadata, onChange }) => {
|
|
6
|
+
const [selectedFile, setSelectedFile] = useState(null);
|
|
7
|
+
const [editableCode, setEditableCode] = useState({});
|
|
8
|
+
const [showPreview, setShowPreview] = useState(true);
|
|
9
|
+
|
|
10
|
+
// Extract files from metadata or code
|
|
11
|
+
const files = useMemo(() => {
|
|
12
|
+
if (metadata?.files) {
|
|
13
|
+
return metadata.files;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// If no files in metadata, create a single file from code
|
|
17
|
+
if (typeof code === 'string') {
|
|
18
|
+
return [{ name: 'index.js', content: code }];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// If code is an object with multiple files
|
|
22
|
+
if (typeof code === 'object' && code !== null) {
|
|
23
|
+
return Object.entries(code).map(([name, content]) => ({
|
|
24
|
+
name: name.endsWith('.js') ? name : `${name}.js`,
|
|
25
|
+
content: typeof content === 'string' ? content : JSON.stringify(content, null, 2)
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return [];
|
|
30
|
+
}, [code, metadata]);
|
|
31
|
+
|
|
32
|
+
// Initialize selected file
|
|
33
|
+
React.useEffect(() => {
|
|
34
|
+
if (files.length > 0 && !selectedFile) {
|
|
35
|
+
setSelectedFile(files[0].name);
|
|
36
|
+
}
|
|
37
|
+
}, [files, selectedFile]);
|
|
38
|
+
|
|
39
|
+
const handleCodeChange = useCallback((fileName, newContent) => {
|
|
40
|
+
setEditableCode(prev => ({
|
|
41
|
+
...prev,
|
|
42
|
+
[fileName]: newContent
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
// Notify parent component of changes
|
|
46
|
+
if (onChange) {
|
|
47
|
+
const updatedFiles = files.map(file =>
|
|
48
|
+
file.name === fileName
|
|
49
|
+
? { ...file, content: newContent }
|
|
50
|
+
: file
|
|
51
|
+
);
|
|
52
|
+
onChange(updatedFiles);
|
|
53
|
+
}
|
|
54
|
+
}, [files, onChange]);
|
|
55
|
+
|
|
56
|
+
const getCurrentContent = useCallback((fileName) => {
|
|
57
|
+
return editableCode[fileName] ?? files.find(f => f.name === fileName)?.content ?? '';
|
|
58
|
+
}, [editableCode, files]);
|
|
59
|
+
|
|
60
|
+
const getFileIcon = (fileName) => {
|
|
61
|
+
const ext = fileName.split('.').pop()?.toLowerCase();
|
|
62
|
+
switch (ext) {
|
|
63
|
+
case 'js':
|
|
64
|
+
return '📄';
|
|
65
|
+
case 'json':
|
|
66
|
+
return '📋';
|
|
67
|
+
case 'md':
|
|
68
|
+
return '📝';
|
|
69
|
+
case 'yml':
|
|
70
|
+
case 'yaml':
|
|
71
|
+
return '⚙️';
|
|
72
|
+
case 'env':
|
|
73
|
+
return '🔐';
|
|
74
|
+
default:
|
|
75
|
+
return '📄';
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const getLanguage = (fileName) => {
|
|
80
|
+
const ext = fileName.split('.').pop()?.toLowerCase();
|
|
81
|
+
switch (ext) {
|
|
82
|
+
case 'js':
|
|
83
|
+
return 'javascript';
|
|
84
|
+
case 'json':
|
|
85
|
+
return 'json';
|
|
86
|
+
case 'md':
|
|
87
|
+
return 'markdown';
|
|
88
|
+
case 'yml':
|
|
89
|
+
case 'yaml':
|
|
90
|
+
return 'yaml';
|
|
91
|
+
case 'env':
|
|
92
|
+
return 'bash';
|
|
93
|
+
default:
|
|
94
|
+
return 'text';
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const formatCode = (content, language) => {
|
|
99
|
+
// Simple syntax highlighting for demonstration
|
|
100
|
+
// In a real implementation, you'd use a proper syntax highlighter like Prism.js
|
|
101
|
+
if (language === 'javascript') {
|
|
102
|
+
return content
|
|
103
|
+
.replace(/(\/\/.*$)/gm, '<span style="color: #008000;">$1</span>')
|
|
104
|
+
.replace(/(\/\*[\s\S]*?\*\/)/g, '<span style="color: #008000;">$1</span>')
|
|
105
|
+
.replace(/\b(const|let|var|function|class|if|else|for|while|return|import|export|require|module)\b/g, '<span style="color: #0000FF;">$1</span>')
|
|
106
|
+
.replace(/(['"`])((?:(?!\1)[^\\]|\\.)*)(\1)/g, '<span style="color: #A31515;">$1$2$3</span>');
|
|
107
|
+
}
|
|
108
|
+
return content;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const downloadFile = (fileName) => {
|
|
112
|
+
const content = getCurrentContent(fileName);
|
|
113
|
+
const blob = new Blob([content], { type: 'text/plain' });
|
|
114
|
+
const url = URL.createObjectURL(blob);
|
|
115
|
+
const a = document.createElement('a');
|
|
116
|
+
a.href = url;
|
|
117
|
+
a.download = fileName;
|
|
118
|
+
document.body.appendChild(a);
|
|
119
|
+
a.click();
|
|
120
|
+
document.body.removeChild(a);
|
|
121
|
+
URL.revokeObjectURL(url);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const downloadAll = () => {
|
|
125
|
+
const zip = files.map(file => ({
|
|
126
|
+
name: file.name,
|
|
127
|
+
content: getCurrentContent(file.name)
|
|
128
|
+
}));
|
|
129
|
+
|
|
130
|
+
// In a real implementation, you'd use a library like JSZip
|
|
131
|
+
const contents = zip.map(file => `// File: ${file.name}\n${file.content}`).join('\n\n' + '='.repeat(50) + '\n\n');
|
|
132
|
+
const blob = new Blob([contents], { type: 'text/plain' });
|
|
133
|
+
const url = URL.createObjectURL(blob);
|
|
134
|
+
const a = document.createElement('a');
|
|
135
|
+
a.href = url;
|
|
136
|
+
a.download = `${metadata?.name || 'generated-code'}.txt`;
|
|
137
|
+
document.body.appendChild(a);
|
|
138
|
+
a.click();
|
|
139
|
+
document.body.removeChild(a);
|
|
140
|
+
URL.revokeObjectURL(url);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
if (files.length === 0) {
|
|
144
|
+
return (
|
|
145
|
+
<Card className="p-8">
|
|
146
|
+
<div className="text-center text-gray-500">
|
|
147
|
+
<svg className="w-12 h-12 mx-auto mb-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
148
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
|
149
|
+
</svg>
|
|
150
|
+
<p>No code generated yet</p>
|
|
151
|
+
<p className="text-sm mt-1">Configure your settings and generate code to see a preview</p>
|
|
152
|
+
</div>
|
|
153
|
+
</Card>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<div className="space-y-4">
|
|
159
|
+
{/* Header */}
|
|
160
|
+
<div className="flex justify-between items-center">
|
|
161
|
+
<h3 className="text-lg font-medium">Code Preview & Editor</h3>
|
|
162
|
+
<div className="flex space-x-2">
|
|
163
|
+
<div className="flex border rounded-md">
|
|
164
|
+
<button
|
|
165
|
+
onClick={() => setShowPreview(true)}
|
|
166
|
+
className={`px-3 py-1 text-sm ${showPreview ? 'bg-blue-600 text-white' : 'text-gray-600'}`}
|
|
167
|
+
>
|
|
168
|
+
Preview
|
|
169
|
+
</button>
|
|
170
|
+
<button
|
|
171
|
+
onClick={() => setShowPreview(false)}
|
|
172
|
+
className={`px-3 py-1 text-sm ${!showPreview ? 'bg-blue-600 text-white' : 'text-gray-600'}`}
|
|
173
|
+
>
|
|
174
|
+
Edit
|
|
175
|
+
</button>
|
|
176
|
+
</div>
|
|
177
|
+
<Button onClick={downloadAll} size="sm">
|
|
178
|
+
Download All
|
|
179
|
+
</Button>
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
|
|
183
|
+
<div className="grid grid-cols-1 lg:grid-cols-4 gap-4">
|
|
184
|
+
{/* File Explorer */}
|
|
185
|
+
<div className="lg:col-span-1">
|
|
186
|
+
<Card className="p-4">
|
|
187
|
+
<h4 className="font-medium mb-3">Files ({files.length})</h4>
|
|
188
|
+
<div className="space-y-1">
|
|
189
|
+
{files.map((file) => (
|
|
190
|
+
<div
|
|
191
|
+
key={file.name}
|
|
192
|
+
onClick={() => setSelectedFile(file.name)}
|
|
193
|
+
className={`flex items-center justify-between p-2 rounded cursor-pointer transition-colors ${
|
|
194
|
+
selectedFile === file.name
|
|
195
|
+
? 'bg-blue-100 text-blue-800'
|
|
196
|
+
: 'hover:bg-gray-100'
|
|
197
|
+
}`}
|
|
198
|
+
>
|
|
199
|
+
<div className="flex items-center">
|
|
200
|
+
<span className="mr-2">{getFileIcon(file.name)}</span>
|
|
201
|
+
<span className="text-sm truncate">{file.name}</span>
|
|
202
|
+
</div>
|
|
203
|
+
<button
|
|
204
|
+
onClick={(e) => {
|
|
205
|
+
e.stopPropagation();
|
|
206
|
+
downloadFile(file.name);
|
|
207
|
+
}}
|
|
208
|
+
className="text-gray-400 hover:text-gray-600"
|
|
209
|
+
title="Download file"
|
|
210
|
+
>
|
|
211
|
+
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
212
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 10v6m0 0l-3-3m3 3l3-3M3 17V7a2 2 0 012-2h6l2 2h6a2 2 0 012 2v10a2 2 0 01-2 2H5a2 2 0 01-2-2z" />
|
|
213
|
+
</svg>
|
|
214
|
+
</button>
|
|
215
|
+
</div>
|
|
216
|
+
))}
|
|
217
|
+
</div>
|
|
218
|
+
</Card>
|
|
219
|
+
</div>
|
|
220
|
+
|
|
221
|
+
{/* Code Display */}
|
|
222
|
+
<div className="lg:col-span-3">
|
|
223
|
+
{selectedFile && (
|
|
224
|
+
<Card className="p-0 overflow-hidden">
|
|
225
|
+
<div className="bg-gray-50 px-4 py-2 border-b flex justify-between items-center">
|
|
226
|
+
<div className="flex items-center">
|
|
227
|
+
<span className="mr-2">{getFileIcon(selectedFile)}</span>
|
|
228
|
+
<span className="font-medium">{selectedFile}</span>
|
|
229
|
+
<span className="ml-2 text-sm text-gray-500">
|
|
230
|
+
({getLanguage(selectedFile)})
|
|
231
|
+
</span>
|
|
232
|
+
</div>
|
|
233
|
+
<div className="text-sm text-gray-500">
|
|
234
|
+
{getCurrentContent(selectedFile).split('\n').length} lines
|
|
235
|
+
</div>
|
|
236
|
+
</div>
|
|
237
|
+
|
|
238
|
+
<div className="p-0">
|
|
239
|
+
{showPreview ? (
|
|
240
|
+
<pre className="p-4 bg-gray-900 text-gray-100 overflow-x-auto text-sm">
|
|
241
|
+
<code
|
|
242
|
+
dangerouslySetInnerHTML={{
|
|
243
|
+
__html: formatCode(getCurrentContent(selectedFile), getLanguage(selectedFile))
|
|
244
|
+
}}
|
|
245
|
+
/>
|
|
246
|
+
</pre>
|
|
247
|
+
) : (
|
|
248
|
+
<textarea
|
|
249
|
+
value={getCurrentContent(selectedFile)}
|
|
250
|
+
onChange={(e) => handleCodeChange(selectedFile, e.target.value)}
|
|
251
|
+
className="w-full h-96 p-4 font-mono text-sm border-0 resize-none focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
252
|
+
style={{ tabSize: 2 }}
|
|
253
|
+
/>
|
|
254
|
+
)}
|
|
255
|
+
</div>
|
|
256
|
+
</Card>
|
|
257
|
+
)}
|
|
258
|
+
</div>
|
|
259
|
+
</div>
|
|
260
|
+
|
|
261
|
+
{/* File Stats */}
|
|
262
|
+
<Card className="p-4">
|
|
263
|
+
<h4 className="font-medium mb-2">Generation Summary</h4>
|
|
264
|
+
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 text-center">
|
|
265
|
+
<div>
|
|
266
|
+
<div className="text-2xl font-bold text-blue-600">{files.length}</div>
|
|
267
|
+
<div className="text-sm text-gray-500">Files</div>
|
|
268
|
+
</div>
|
|
269
|
+
<div>
|
|
270
|
+
<div className="text-2xl font-bold text-green-600">
|
|
271
|
+
{files.reduce((total, file) => total + getCurrentContent(file.name).split('\n').length, 0)}
|
|
272
|
+
</div>
|
|
273
|
+
<div className="text-sm text-gray-500">Lines</div>
|
|
274
|
+
</div>
|
|
275
|
+
<div>
|
|
276
|
+
<div className="text-2xl font-bold text-purple-600">
|
|
277
|
+
{Math.round(files.reduce((total, file) => total + getCurrentContent(file.name).length, 0) / 1024)}K
|
|
278
|
+
</div>
|
|
279
|
+
<div className="text-sm text-gray-500">Characters</div>
|
|
280
|
+
</div>
|
|
281
|
+
<div>
|
|
282
|
+
<div className="text-2xl font-bold text-orange-600">
|
|
283
|
+
{metadata?.type || 'Generated'}
|
|
284
|
+
</div>
|
|
285
|
+
<div className="text-sm text-gray-500">Type</div>
|
|
286
|
+
</div>
|
|
287
|
+
</div>
|
|
288
|
+
</Card>
|
|
289
|
+
|
|
290
|
+
{/* Validation Messages */}
|
|
291
|
+
{metadata?.validationErrors && metadata.validationErrors.length > 0 && (
|
|
292
|
+
<Card className="p-4 border-red-200 bg-red-50">
|
|
293
|
+
<h4 className="font-medium text-red-800 mb-2">Validation Errors</h4>
|
|
294
|
+
<ul className="list-disc list-inside text-sm text-red-700 space-y-1">
|
|
295
|
+
{metadata.validationErrors.map((error, index) => (
|
|
296
|
+
<li key={index}>{error}</li>
|
|
297
|
+
))}
|
|
298
|
+
</ul>
|
|
299
|
+
</Card>
|
|
300
|
+
)}
|
|
301
|
+
|
|
302
|
+
{/* Tips */}
|
|
303
|
+
<Card className="p-4 bg-blue-50 border-blue-200">
|
|
304
|
+
<h4 className="font-medium text-blue-800 mb-2">💡 Tips</h4>
|
|
305
|
+
<ul className="text-sm text-blue-700 space-y-1">
|
|
306
|
+
<li>• Switch between Preview and Edit modes to review or modify generated code</li>
|
|
307
|
+
<li>• Download individual files or all files as a bundle</li>
|
|
308
|
+
<li>• Changes made in edit mode will be included in the final generation</li>
|
|
309
|
+
<li>• Use the file explorer to navigate between generated files</li>
|
|
310
|
+
</ul>
|
|
311
|
+
</Card>
|
|
312
|
+
</div>
|
|
313
|
+
);
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
export default CodePreviewEditor;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import { Card } from '../Card';
|
|
3
|
+
import { Button } from '../Button';
|
|
4
|
+
|
|
5
|
+
const DynamicModuleForm = ({ moduleDetails, onSubmit, initialValues = {} }) => {
|
|
6
|
+
const [formValues, setFormValues] = useState(initialValues);
|
|
7
|
+
const [errors, setErrors] = useState({});
|
|
8
|
+
|
|
9
|
+
// Initialize form values when module details change
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (moduleDetails?.requiredFields) {
|
|
12
|
+
const defaultValues = {};
|
|
13
|
+
moduleDetails.requiredFields.forEach(field => {
|
|
14
|
+
defaultValues[field.name] = initialValues[field.name] || field.default || '';
|
|
15
|
+
});
|
|
16
|
+
setFormValues(prev => ({ ...defaultValues, ...prev }));
|
|
17
|
+
}
|
|
18
|
+
}, [moduleDetails, initialValues]);
|
|
19
|
+
|
|
20
|
+
const handleInputChange = (fieldName, value) => {
|
|
21
|
+
setFormValues(prev => ({
|
|
22
|
+
...prev,
|
|
23
|
+
[fieldName]: value
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
// Clear error for this field
|
|
27
|
+
if (errors[fieldName]) {
|
|
28
|
+
setErrors(prev => {
|
|
29
|
+
const newErrors = { ...prev };
|
|
30
|
+
delete newErrors[fieldName];
|
|
31
|
+
return newErrors;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const validateForm = () => {
|
|
37
|
+
const newErrors = {};
|
|
38
|
+
|
|
39
|
+
if (!moduleDetails?.requiredFields) return true;
|
|
40
|
+
|
|
41
|
+
moduleDetails.requiredFields.forEach(field => {
|
|
42
|
+
if (field.required && !formValues[field.name]) {
|
|
43
|
+
newErrors[field.name] = `${field.label} is required`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Additional validation based on field type
|
|
47
|
+
if (formValues[field.name]) {
|
|
48
|
+
switch (field.type) {
|
|
49
|
+
case 'url':
|
|
50
|
+
if (!isValidUrl(formValues[field.name])) {
|
|
51
|
+
newErrors[field.name] = `${field.label} must be a valid URL`;
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
case 'email':
|
|
55
|
+
if (!isValidEmail(formValues[field.name])) {
|
|
56
|
+
newErrors[field.name] = `${field.label} must be a valid email`;
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
case 'number':
|
|
60
|
+
if (isNaN(formValues[field.name])) {
|
|
61
|
+
newErrors[field.name] = `${field.label} must be a number`;
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
setErrors(newErrors);
|
|
69
|
+
return Object.keys(newErrors).length === 0;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const handleSubmit = (e) => {
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
if (validateForm()) {
|
|
75
|
+
onSubmit(formValues);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const isValidUrl = (string) => {
|
|
80
|
+
try {
|
|
81
|
+
new URL(string);
|
|
82
|
+
return true;
|
|
83
|
+
} catch (_) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const isValidEmail = (email) => {
|
|
89
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const renderField = (field) => {
|
|
93
|
+
const fieldId = `field-${field.name}`;
|
|
94
|
+
const hasError = !!errors[field.name];
|
|
95
|
+
|
|
96
|
+
switch (field.type) {
|
|
97
|
+
case 'password':
|
|
98
|
+
return (
|
|
99
|
+
<div key={field.name} className="space-y-2">
|
|
100
|
+
<label htmlFor={fieldId} className="block text-sm font-medium text-gray-700">
|
|
101
|
+
{field.label}
|
|
102
|
+
{field.required && <span className="text-red-500 ml-1">*</span>}
|
|
103
|
+
</label>
|
|
104
|
+
<input
|
|
105
|
+
id={fieldId}
|
|
106
|
+
type="password"
|
|
107
|
+
value={formValues[field.name] || ''}
|
|
108
|
+
onChange={(e) => handleInputChange(field.name, e.target.value)}
|
|
109
|
+
placeholder={field.placeholder || `Enter ${field.label.toLowerCase()}`}
|
|
110
|
+
className={`w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 ${
|
|
111
|
+
hasError
|
|
112
|
+
? 'border-red-300 focus:ring-red-500'
|
|
113
|
+
: 'border-gray-300 focus:ring-blue-500'
|
|
114
|
+
}`}
|
|
115
|
+
/>
|
|
116
|
+
{hasError && (
|
|
117
|
+
<p className="text-sm text-red-600">{errors[field.name]}</p>
|
|
118
|
+
)}
|
|
119
|
+
{field.hint && (
|
|
120
|
+
<p className="text-sm text-gray-500">{field.hint}</p>
|
|
121
|
+
)}
|
|
122
|
+
</div>
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
case 'select':
|
|
126
|
+
return (
|
|
127
|
+
<div key={field.name} className="space-y-2">
|
|
128
|
+
<label htmlFor={fieldId} className="block text-sm font-medium text-gray-700">
|
|
129
|
+
{field.label}
|
|
130
|
+
{field.required && <span className="text-red-500 ml-1">*</span>}
|
|
131
|
+
</label>
|
|
132
|
+
<select
|
|
133
|
+
id={fieldId}
|
|
134
|
+
value={formValues[field.name] || ''}
|
|
135
|
+
onChange={(e) => handleInputChange(field.name, e.target.value)}
|
|
136
|
+
className={`w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 ${
|
|
137
|
+
hasError
|
|
138
|
+
? 'border-red-300 focus:ring-red-500'
|
|
139
|
+
: 'border-gray-300 focus:ring-blue-500'
|
|
140
|
+
}`}
|
|
141
|
+
>
|
|
142
|
+
<option value="">Select {field.label}</option>
|
|
143
|
+
{field.options?.map(option => (
|
|
144
|
+
<option key={option.value} value={option.value}>
|
|
145
|
+
{option.label}
|
|
146
|
+
</option>
|
|
147
|
+
))}
|
|
148
|
+
</select>
|
|
149
|
+
{hasError && (
|
|
150
|
+
<p className="text-sm text-red-600">{errors[field.name]}</p>
|
|
151
|
+
)}
|
|
152
|
+
</div>
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
case 'boolean':
|
|
156
|
+
return (
|
|
157
|
+
<div key={field.name} className="space-y-2">
|
|
158
|
+
<label className="flex items-center space-x-3">
|
|
159
|
+
<input
|
|
160
|
+
type="checkbox"
|
|
161
|
+
checked={formValues[field.name] || false}
|
|
162
|
+
onChange={(e) => handleInputChange(field.name, e.target.checked)}
|
|
163
|
+
className="h-4 w-4 text-blue-600 rounded focus:ring-blue-500"
|
|
164
|
+
/>
|
|
165
|
+
<span className="text-sm font-medium text-gray-700">
|
|
166
|
+
{field.label}
|
|
167
|
+
{field.required && <span className="text-red-500 ml-1">*</span>}
|
|
168
|
+
</span>
|
|
169
|
+
</label>
|
|
170
|
+
{field.hint && (
|
|
171
|
+
<p className="text-sm text-gray-500 ml-7">{field.hint}</p>
|
|
172
|
+
)}
|
|
173
|
+
</div>
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
case 'textarea':
|
|
177
|
+
return (
|
|
178
|
+
<div key={field.name} className="space-y-2">
|
|
179
|
+
<label htmlFor={fieldId} className="block text-sm font-medium text-gray-700">
|
|
180
|
+
{field.label}
|
|
181
|
+
{field.required && <span className="text-red-500 ml-1">*</span>}
|
|
182
|
+
</label>
|
|
183
|
+
<textarea
|
|
184
|
+
id={fieldId}
|
|
185
|
+
value={formValues[field.name] || ''}
|
|
186
|
+
onChange={(e) => handleInputChange(field.name, e.target.value)}
|
|
187
|
+
placeholder={field.placeholder || `Enter ${field.label.toLowerCase()}`}
|
|
188
|
+
rows={field.rows || 3}
|
|
189
|
+
className={`w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 ${
|
|
190
|
+
hasError
|
|
191
|
+
? 'border-red-300 focus:ring-red-500'
|
|
192
|
+
: 'border-gray-300 focus:ring-blue-500'
|
|
193
|
+
}`}
|
|
194
|
+
/>
|
|
195
|
+
{hasError && (
|
|
196
|
+
<p className="text-sm text-red-600">{errors[field.name]}</p>
|
|
197
|
+
)}
|
|
198
|
+
</div>
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
default:
|
|
202
|
+
return (
|
|
203
|
+
<div key={field.name} className="space-y-2">
|
|
204
|
+
<label htmlFor={fieldId} className="block text-sm font-medium text-gray-700">
|
|
205
|
+
{field.label}
|
|
206
|
+
{field.required && <span className="text-red-500 ml-1">*</span>}
|
|
207
|
+
</label>
|
|
208
|
+
<input
|
|
209
|
+
id={fieldId}
|
|
210
|
+
type={field.type || 'text'}
|
|
211
|
+
value={formValues[field.name] || ''}
|
|
212
|
+
onChange={(e) => handleInputChange(field.name, e.target.value)}
|
|
213
|
+
placeholder={field.placeholder || `Enter ${field.label.toLowerCase()}`}
|
|
214
|
+
className={`w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 ${
|
|
215
|
+
hasError
|
|
216
|
+
? 'border-red-300 focus:ring-red-500'
|
|
217
|
+
: 'border-gray-300 focus:ring-blue-500'
|
|
218
|
+
}`}
|
|
219
|
+
/>
|
|
220
|
+
{hasError && (
|
|
221
|
+
<p className="text-sm text-red-600">{errors[field.name]}</p>
|
|
222
|
+
)}
|
|
223
|
+
{field.hint && (
|
|
224
|
+
<p className="text-sm text-gray-500">{field.hint}</p>
|
|
225
|
+
)}
|
|
226
|
+
</div>
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
if (!moduleDetails) {
|
|
232
|
+
return (
|
|
233
|
+
<Card className="p-6">
|
|
234
|
+
<p className="text-gray-500 text-center">No module selected</p>
|
|
235
|
+
</Card>
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const requiredFields = moduleDetails.requiredFields || [];
|
|
240
|
+
const optionalFields = moduleDetails.optionalFields || [];
|
|
241
|
+
|
|
242
|
+
return (
|
|
243
|
+
<form onSubmit={handleSubmit} className="space-y-6">
|
|
244
|
+
{requiredFields.length > 0 && (
|
|
245
|
+
<div>
|
|
246
|
+
<h4 className="text-lg font-medium text-gray-900 mb-4">Required Configuration</h4>
|
|
247
|
+
<div className="space-y-4">
|
|
248
|
+
{requiredFields.map(field => renderField(field))}
|
|
249
|
+
</div>
|
|
250
|
+
</div>
|
|
251
|
+
)}
|
|
252
|
+
|
|
253
|
+
{optionalFields.length > 0 && (
|
|
254
|
+
<div>
|
|
255
|
+
<h4 className="text-lg font-medium text-gray-900 mb-4">Optional Configuration</h4>
|
|
256
|
+
<div className="space-y-4">
|
|
257
|
+
{optionalFields.map(field => renderField(field))}
|
|
258
|
+
</div>
|
|
259
|
+
</div>
|
|
260
|
+
)}
|
|
261
|
+
|
|
262
|
+
<div className="flex justify-end space-x-3">
|
|
263
|
+
<Button type="submit" className="bg-blue-600 hover:bg-blue-700">
|
|
264
|
+
Generate Configuration
|
|
265
|
+
</Button>
|
|
266
|
+
</div>
|
|
267
|
+
</form>
|
|
268
|
+
);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
export default DynamicModuleForm;
|