import React from 'react' import { __, _x, sprintf } from '@wordpress/i18n' import type { UseSelection } from '../../../../hooks/useSelection' import type { ImportableSnippetSchema } from '../../../../types/schema/ImportableSnippetSchema' const DESC_MAX_LENGTH = 50 const truncateDescription = (description: string | undefined): string => { if (!description) { return __('No description', 'code-snippets') } return DESC_MAX_LENGTH < description.length // translators: %s: truncated snippet description. ? sprintf(_x('%s…', 'import snippet description', 'code-snippets'), description.substring(0, DESC_MAX_LENGTH)) : description } export interface SnippetSelectionTableProps { snippets: ImportableSnippetSchema[] selection: UseSelection } export const SnippetSelectionTable: React.FC = ({ snippets, selection: { selectedItems, isAllSelected, toggleItem, selectAll } }) => {snippets.map(snippet => )}
{__('Name', 'code-snippets')} {__('Type', 'code-snippets')} {__('Description', 'code-snippets')} {__('Tags', 'code-snippets')}
toggleItem(snippet.table_data.id)} /> {snippet.table_data.title} {snippet.source_file &&
{sprintf( // translators: %s: source file name. _x('from %s', 'import snippet source file', 'code-snippets'), snippet.source_file )}
}
{snippet.table_data.type} {truncateDescription(snippet.table_data.description)} {snippet.table_data.tags || '—'}