import React, { Fragment } from 'react' import { __ } from '@wordpress/i18n' import { humanTimeDiff } from '@wordpress/date' import classnames from 'classnames' import { getSnippetDisplayName, getSnippetType } from '../../../utils/snippets/snippets' import { stripTags, truncateChars } from '../../../utils/text' import { Badge } from '../../common/Badge' import { Button } from '../../common/Button' import { CloudStatusBadge } from '../../common/cloud/CloudStatusBadge' import { Tooltip } from '../../common/Tooltip' import { CloudAvailableIcon } from '../../common/icons/cloud/CloudAvailableIcon' import { CloudSyncedIcon } from '../../common/icons/cloud/CloudSyncedIcon' import { FEATURED_SNIPPET_ID } from './demoCloudSnippets' import { hasReached } from './types' import type { DemoStage } from './types' import type { ListTableColumn } from '../../common/ListTable' import type { CloudSnippetSchema } from '../../../types/schema/CloudSnippetSchema' /** * Whether a row should render as already downloaded. Only the featured snippet * changes state, and only once the walkthrough has downloaded it. */ const isSynced = (snippet: CloudSnippetSchema, stage: DemoStage): boolean => FEATURED_SNIPPET_ID === snippet.id && hasReached(stage, 'synced') const StateColumn: React.FC<{ snippet: CloudSnippetSchema, stage: DemoStage }> = ({ snippet, stage }) => { const synced = isSynced(snippet, stage) const label = synced ? __('Synced to Cloud', 'code-snippets') : __('Available in Cloud', 'code-snippets') const Icon = () => {synced ? : } return }>{label} } const TagsColumn: React.FC<{ snippet: CloudSnippetSchema }> = ({ snippet }) => snippet.tags.map((tag, index) => {tag}{index < snippet.tags.length - 1 ? ', ' : ''}) interface ActionsColumnProps { snippet: CloudSnippetSchema stage: DemoStage onPreview: (snippet: CloudSnippetSchema) => void } const ActionsColumn: React.FC = ({ snippet, stage, onPreview }) => { const featured = FEATURED_SNIPPET_ID === snippet.id return (
{isSynced(snippet, stage) ? : }
) } interface ColumnParams { stage: DemoStage onPreview: (snippet: CloudSnippetSchema) => void } // eslint-disable-next-line max-lines-per-function -- the column set reads as one table definition. export const cloudLibraryDemoColumns = ( { stage, onPreview }: ColumnParams ): ListTableColumn[] => [ { id: 'state', title: , render: snippet => }, { id: 'name', title: __('Snippet Name', 'code-snippets'), isPrimary: true, sortedValue: snippet => getSnippetDisplayName(snippet).toLowerCase(), render: snippet => {snippet.name} }, { id: 'type', title: __('Type', 'code-snippets'), sortedValue: snippet => getSnippetType(snippet), render: snippet => }, { id: 'status', title: __('Status', 'code-snippets'), sortedValue: snippet => snippet.status, render: snippet => }, { id: 'desc', title: __('Description', 'code-snippets'), render: snippet =>
{truncateChars(stripTags(snippet.description))}
}, { id: 'tags', title: __('Tags', 'code-snippets'), render: snippet => }, { id: 'date', title: __('Updated', 'code-snippets'), sortedValue: snippet => new Date(snippet.updated).toISOString(), render: snippet => }, { id: 'actions', title: {__('Actions', 'code-snippets')}, render: snippet => } ]