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

Function URLManager

frontend/src/components/Pipeline/URLManager.tsx:7–115  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5import { api } from '../../services/api';
6
7const URLManager: React.FC = () => {
8 const [newUrl, setNewUrl] = useState('');
9 const [isValidating, setIsValidating] = useState(false);
10 const { currentPipeline, updatePipeline } = usePipelineStore();
11
12 const handleAddUrl = async () => {
13 if (!newUrl.trim() || !currentPipeline) return;
14
15 // Validate URL
16 setIsValidating(true);
17 try {
18 const response = await api.post('/scraping/validate-url', { url: newUrl });
19
20 if (response.data.valid) {
21 const updatedUrls = [...currentPipeline.urls, newUrl];
22 updatePipeline(currentPipeline.id, { urls: updatedUrls });
23 setNewUrl('');
24 } else {
25 alert(`Invalid URL: ${response.data.error || 'URL is not accessible'}`);
26 }
27 } catch (error) {
28 alert('Failed to validate URL');
29 } finally {
30 setIsValidating(false);
31 }
32 };
33
34 const handleRemoveUrl = (urlToRemove: string) => {
35 if (!currentPipeline) return;
36
37 const updatedUrls = currentPipeline.urls.filter(url => url !== urlToRemove);
38 updatePipeline(currentPipeline.id, { urls: updatedUrls });
39 };
40
41 const handleKeyPress = (e: React.KeyboardEvent) => {
42 if (e.key === 'Enter') {
43 handleAddUrl();
44 }
45 };
46
47 return (
48 <div className="h-full flex flex-col p-4">
49 <h3 className="text-lg font-semibold mb-4">URL Management</h3>
50
51 {/* Add URL Form */}
52 <div className="flex space-x-2 mb-4">
53 <Input
54 type="url"
55 value={newUrl}
56 onChange={(e) => setNewUrl(e.target.value)}
57 onKeyPress={handleKeyPress}
58 placeholder="https://example.com"
59 disabled={!currentPipeline || isValidating}
60 />
61 <Button
62 onClick={handleAddUrl}
63 disabled={!newUrl.trim() || !currentPipeline || isValidating}
64 variant="primary"

Callers

nothing calls this directly

Calls 1

handleRemoveUrlFunction · 0.85

Tested by

no test coverage detected