import React, { useMemo, useState } from 'react'; import { Button, Icon } from '@opensumi/ide-components'; import { LabelService, URI, localize, useInjectable } from '@opensumi/ide-core-browser'; import { WorkbenchEditorService } from '@opensumi/ide-editor'; import { CodeBlockStatus } from '../../common/types'; import { ChatMultiDiffResolver } from '../chat/chat-multi-diff-source'; import { ApplyStatus } from './ApplyStatus'; import styles from './change-list.module.less'; export interface FileChange { path: string; additions: number; deletions: number; status: CodeBlockStatus; } interface FileListDisplayProps { files: FileChange[]; hideActions?: boolean; onFileClick: (path: string) => void; onRejectAll: () => void; onAcceptAll: () => void; } export const FileListDisplay: React.FC = (props) => { const { files, onFileClick, onRejectAll, onAcceptAll, hideActions } = props; const [isExpanded, setIsExpanded] = useState(true); const editorService = useInjectable(WorkbenchEditorService); const labelService = useInjectable(LabelService); const fileIcons = useMemo( () => files.map((file) => { const uri = URI.parse(file.path); const iconClass = labelService.getIcon(uri); return ; }), [files], ); const totalFiles = files.length; const totalChanges = files.reduce( (acc, file) => ({ additions: acc.additions + file.additions, deletions: acc.deletions + file.deletions, }), { additions: 0, deletions: 0 }, ); const handleToggle = () => { setIsExpanded(!isExpanded); }; const renderViewChanges = (totalFiles: number) => { if (!totalFiles) { return null; } return ( { e.stopPropagation(); editorService.open( URI.from({ scheme: ChatMultiDiffResolver.CHAT_EDITING_MULTI_DIFF_SOURCE_RESOLVER_SCHEME, path: 'chat-editing-multi-diff-source', }), { label: localize('aiNative.chat.view-changes'), }, ); }} > {localize('aiNative.chat.view-changes')} ); }; const renderChangeStats = (additions: number, deletions: number) => { const parts: React.ReactNode[] = []; if (additions > 0) { parts.push( +{additions} , ); } if (deletions > 0) { if (parts.length > 0) { parts.push(' '); } parts.push( -{deletions} , ); } if (parts.length === 0) { parts.push( No changes , ); } return parts; }; return (
{renderChangeStats(totalChanges.additions, totalChanges.deletions)} {!hideActions && renderViewChanges(files.length)} {!hideActions && files.some((file) => file.status === 'pending') && (
)}
    {files.map((file, index) => (
  • onFileClick(file.path)}> {fileIcons[index] || '📄'}
    {file.path}
    {renderChangeStats(file.additions, file.deletions)}
  • ))}
); };