import React, { useEffect, useState } from 'react' import { useComponents } from '../../contexts/ComponentContext' import { FaPlus, FaSearch, FaRegEdit, FaTrashAlt, FaEye, FaEyeSlash, FaFilter, FaCalendarAlt, FaExternalLinkAlt, FaCog, FaSyncAlt, } from 'react-icons/fa' import Widget from '@/components/common/Widget' import { ROUTES_ENUM } from '@/routes/route.constant' import { useLocalization } from '@/utils/hooks/useLocalization' import { Loading } from '../../components/shared' import PageTitle from '@/components/shared/PageTitle' import { Button } from '@/components/ui' import Dialog from '@/components/ui/Dialog' import ComponentEditor from './ComponentEditor' import { parseComponentDependencies } from '@/contexts/componentRuntime' import { usePermission } from '@/utils/hooks/usePermission' import { COMPONENT_PERMISSION } from '@/constants/permission.constant' const ComponentManager: React.FC = () => { const { components, loading, componentErrors, updateComponent, deleteComponent, refreshComponents, } = useComponents() const [searchTerm, setSearchTerm] = useState('') const [filterActive, setFilterActive] = useState<'all' | 'active' | 'inactive'>('all') const [isRefreshing, setIsRefreshing] = useState(false) const [editorComponentId, setEditorComponentId] = useState(undefined) // Calculate statistics const totalComponents = components?.length || 0 const activeComponents = components?.filter((c) => c.isActive).length || 0 const inactiveComponents = totalComponents - activeComponents const { translate } = useLocalization() const { checkPermission } = usePermission() const canCreate = checkPermission(COMPONENT_PERMISSION.CREATE) const canUpdate = checkPermission(COMPONENT_PERMISSION.UPDATE) const canDelete = checkPermission(COMPONENT_PERMISSION.DELETE) useEffect(() => { void refreshComponents() }, [refreshComponents]) const handleRefresh = async () => { setIsRefreshing(true) try { await refreshComponents() } finally { setIsRefreshing(false) } } const filteredComponents = components?.filter((component) => { const matchesSearch = component.name.toLowerCase().includes(searchTerm.toLowerCase()) || (component.description || '').toLowerCase().includes(searchTerm.toLowerCase()) const matchesFilter = filterActive === 'all' || (filterActive === 'active' && component.isActive) || (filterActive === 'inactive' && !component.isActive) return matchesSearch && matchesFilter }) const handleToggleActive = async (id: string, isActive: boolean) => { try { const component = components?.find((c) => c.id === id) if (component) { await updateComponent(id, { ...component, isActive }) } } catch (err) { console.error('Failed to toggle component status:', err) } } const handleDelete = async (id: string) => { if (window.confirm(translate('::App.DeveloperKitComponent.ConfirmDelete'))) { try { await deleteComponent(id) } catch (err) { console.error('Failed to delete component:', err) } } } return (
{/* Filters */}
setSearchTerm(e.target.value)} />
{canCreate && (
)}
{/* Components List */} {loading ? (
) : filteredComponents?.length > 0 ? (
{filteredComponents.map((component) => (
{/* Sol taraf */}

{component.name}

{parseComponentDependencies(component.dependencies).join(', ') || translate('::App.DeveloperKitComponent.NoDependencies')}

{component.routePath}

{component.description && (

{component.description}

)} {componentErrors[component.name] && (

{componentErrors[component.name]}

)}
{/* Sağ taraf */} {component.lastModificationTime && (
{new Date(component.lastModificationTime).toLocaleDateString() ?? ''}
)}
{/* Actions */}
{canUpdate && ( )} {canDelete && ( )}
))}
) : (

{searchTerm || filterActive !== 'all' ? translate('::App.EmptyFiltered.FilteredTitle') : translate('::App.EmptyInitial.InitialTitle')}

{searchTerm || filterActive !== 'all' ? translate('::App.DeveloperKit.EmptyFilteredDescription') : translate('::App.EmptyInitial.InitialDescription')}

{canCreate && !searchTerm && filterActive === 'all' && ( )}
)} setEditorComponentId(undefined)} onRequestClose={() => setEditorComponentId(undefined)} > setEditorComponentId(undefined)} onSaved={refreshComponents} />
) } export default ComponentManager