import type React from 'react' import { IContentItem } from '../interfaces' import { getString } from '../utils/getString' const { Card, CardBody, Spinner } = wp.components export interface IDirectoryBrowserProps { contents: IContentItem[] currentPath: string selectedFolderPath: string | null onNavigate: (path: string) => void onSelectFolder: (path: string) => void loading?: boolean repositoryName?: string } /** * Directory browser with breadcrumb navigation and folder selection */ export const DirectoryBrowser: React.FC = ({ contents, currentPath, selectedFolderPath, onNavigate, onSelectFolder, loading = false, repositoryName = '' }) => { const getBreadcrumbs = () => { if (!currentPath) { return [{ name: repositoryName || getString('directory.root'), path: '' }] } const parts = currentPath.split('/').filter(Boolean) const breadcrumbs = [{ name: repositoryName || getString('directory.root'), path: '' }] let accumulatedPath = '' for (const part of parts) { accumulatedPath += (accumulatedPath ? '/' : '') + part breadcrumbs.push({ name: part, path: accumulatedPath }) } return breadcrumbs } const breadcrumbs = getBreadcrumbs() // Only show folders (files are hidden in directory browsing mode) const folders = contents.filter(item => item.type === 'dir') return (
{/* Breadcrumb navigation */}
{breadcrumbs.map((crumb, index) => ( {index > 0 && / } ))}
{loading ? (
) : ( <> {folders.length === 0 ? (

{getString('directory.noFolders')}

) : (
onSelectFolder(currentPath)} >
onSelectFolder(currentPath)} className="github-release-browser-directory__radio" /> {getString('directory.useCurrentFolder')}
{/* Folders (selectable and navigable) */} {folders.map((item) => { const itemPath = item.path const isSelected = selectedFolderPath === itemPath return (
onSelectFolder(itemPath)} className="github-release-browser-directory__radio" onClick={(e) => e.stopPropagation()} />
) })}
)} )}
) }