import { DummyColumnHeader } from '@components/admin/grid/header/Dummy.js'; import { SortableHeader } from '@components/admin/grid/header/Sortable.js'; import { Button } from '@components/common/ui/Button.js'; import { Checkbox } from '@components/common/ui/Checkbox.js'; import { Input } from '@components/common/ui/Input.js'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@components/common/ui/Table.js'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import React, { useState } from 'react'; import type { JobStatus } from '../services/job/types.js'; import { IMPORT_ENTITIES } from '../services/types.js'; import type { ImportEntity, ImportMode } from '../services/types.js'; import { STATUS_FILTERS, countOf } from '../ui/gridUrl.js'; import type { GridFilters } from '../ui/gridUrl.js'; import { ChoiceSelect } from './ChoiceSelect.js'; import { formatNumber } from './format.js'; import { JobStatusBadge } from './JobStatusBadge.js'; import { entityLabel, modeLabel, statusLabel } from './labels.js'; /** A row of the list, as the GraphQL query gives it. */ export interface GridJob { uuid: string; entity: ImportEntity; mode: ImportMode; status: JobStatus; fileName: string; counts: Record | null; createdByName: string | null; createdAt: { text: string } | null; viewUrl: string; /** A worker may be writing: the job cannot be deleted. */ active: boolean; } export interface ImportGridTableProps { jobs: readonly GridJob[]; currentFilters: Array<{ key: string; operation: string; value: string }>; filters: GridFilters; selected: readonly string[]; onSelect(selected: string[]): void; /** A filter changed: the page goes to the address with it. */ onFilter(change: Partial): void; onClear(): void; onDelete(): void; } const cell = (value: number | null) => value === null ? '--' : formatNumber(value); /** * The table of past imports (spec 8.1): date, file, type, mode, status, rows, * created, updated, failed and who uploaded. A file opens its page. A job that * is at work cannot be selected, because it cannot be deleted. */ export function ImportGridTable(props: ImportGridTableProps) { const { jobs, selected, filters, currentFilters } = props; const [file, setFile] = useState(filters.file); const deletable = jobs.filter((job) => !job.active).map((job) => job.uuid); return (
setFile(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter') props.onFilter({ file }); }} /> ({ value: status, label: statusLabel(status) })) ]} onChange={(status) => props.onFilter({ status })} /> ({ value: entity, label: entityLabel(entity) }) ) ]} onChange={(entity) => props.onFilter({ entity })} />
0 && selected.length === deletable.length } disabled={deletable.length === 0} onCheckedChange={(checked) => props.onSelect(checked ? deletable : []) } /> {selected.length > 0 && ( )} {jobs.map((job) => ( props.onSelect( checked ? selected.concat([job.uuid]) : selected.filter((id) => id !== job.uuid) ) } /> {job.createdAt?.text ?? '--'} {job.fileName} {entityLabel(job.entity)} {modeLabel(job.entity, job.mode)} {cell(countOf(job.counts, 'total'))} {cell(countOf(job.counts, 'created'))} {cell(countOf(job.counts, 'updated'))} {cell(countOf(job.counts, 'failed'))} {job.createdByName ?? '--'} ))}
{jobs.length === 0 && (
{_( 'No import yet. Upload a CSV file to import products, categories, customers or customer addresses.' )}
)}
); }