/** * SharePoint node config - connection selector, path, search query. * Uses SharepointBrowseTree (FolderTree-style) for file selection. */ import React, { useEffect, useState, useCallback } from 'react'; import type { NodeConfigRendererProps } from './types'; import { fetchConnections, fetchBrowse, type UserConnection, type BrowseEntry } from '../../../api/automation2Api'; import { SharepointBrowseTree } from '../../FolderTree/SharepointBrowseTree'; export const SharePointNodeConfig: React.FC = ({ params, updateParam, instanceId, request, nodeType = 'sharepoint.findFile', }) => { const [connections, setConnections] = useState([]); const [browseExpanded, setBrowseExpanded] = useState(false); const [copySourceExpanded, setCopySourceExpanded] = useState(false); const [copyDestExpanded, setCopyDestExpanded] = useState(false); const [connectionsLoading, setConnectionsLoading] = useState(false); const connectionId = (params.connectionId as string) ?? ''; const pathParam = 'path'; const path = (params.path as string) ?? (params.filePath as string) ?? ''; useEffect(() => { if (instanceId && request) { setConnectionsLoading(true); fetchConnections(request, instanceId) .then(setConnections) .catch(() => setConnections([])) .finally(() => setConnectionsLoading(false)); } }, [instanceId, request]); const loadChildren = useCallback( async (pathToLoad: string): Promise => { if (!instanceId || !request || !connectionId) return []; const r = await fetchBrowse(request, instanceId, connectionId, 'sharepoint', pathToLoad); return r?.items ?? []; }, [instanceId, request, connectionId] ); const selectPath = useCallback( (p: string) => { updateParam(pathParam, p); setBrowseExpanded(false); }, [updateParam, pathParam] ); const selectSourcePath = useCallback( (p: string) => { updateParam('sourcePath', p); setCopySourceExpanded(false); }, [updateParam] ); const selectDestPath = useCallback( (p: string) => { updateParam('destPath', p); setCopyDestExpanded(false); }, [updateParam] ); const needsPath = !['sharepoint.findFile'].includes(nodeType); const needsSearch = nodeType === 'sharepoint.findFile'; const needsSiteId = false; const hasPathInput = ['sharepoint.readFile', 'sharepoint.uploadFile', 'sharepoint.downloadFile', 'sharepoint.copyFile'].includes(nodeType); return ( <>
{needsSearch && (
updateParam('searchQuery', e.target.value)} placeholder="/sites/SiteName/Shared Documents or search term" />
)} {needsPath && nodeType === 'sharepoint.listFiles' && (
updateParam('path', e.target.value)} placeholder="/ or /sites/SiteName/Shared Documents/Folder" />
)} {needsPath && ['sharepoint.readFile', 'sharepoint.uploadFile', 'sharepoint.downloadFile'].includes(nodeType) && (
updateParam('path', e.target.value)} placeholder={ nodeType === 'sharepoint.downloadFile' ? '/sites/SiteName/Shared Documents/file.pdf' : nodeType === 'sharepoint.uploadFile' ? '/sites/.../Shared Documents/TargetFolder/' : 'File or folder path' } />
)} {needsSiteId && (
updateParam('siteId', e.target.value)} placeholder="SharePoint site ID" />
)} {nodeType === 'sharepoint.copyFile' && ( <>
updateParam('sourcePath', e.target.value)} placeholder="/sites/.../folder/file.pdf" />
updateParam('destPath', e.target.value)} placeholder="/sites/.../target-folder/" />
{connectionId && ( <>
setCopySourceExpanded((e.target as HTMLDetailsElement).open)} style={{ marginTop: 12, border: '1px solid var(--border-color, #e0e0e0)', borderRadius: 6, background: 'var(--bg-secondary, #f8f9fa)', overflow: 'hidden', }} > 📂 Source file durchsuchen
setCopyDestExpanded((e.target as HTMLDetailsElement).open)} style={{ marginTop: 8, border: '1px solid var(--border-color, #e0e0e0)', borderRadius: 6, background: 'var(--bg-secondary, #f8f9fa)', overflow: 'hidden', }} > 📂 Zielordner durchsuchen
{}} onSelectFolder={selectDestPath} selectedPath={(params.destPath as string) || null} />
)} )} {connectionId && needsPath && hasPathInput && !['sharepoint.copyFile'].includes(nodeType) && (
setBrowseExpanded((e.target as HTMLDetailsElement).open)} style={{ marginTop: 12, border: '1px solid var(--border-color, #e0e0e0)', borderRadius: 6, background: 'var(--bg-secondary, #f8f9fa)', overflow: 'hidden', }} > 📂 SharePoint durchsuchen
)} ); };