このコミットが含まれているのは:
2026-07-15 19:33:18 +09:00
コミット eebbd5d069
11個のファイルの変更244行の追加189行の削除
+49 -10
ファイルの表示
@@ -16,6 +16,7 @@ import { apiPost } from '@/lib/api'
import { canEditContent } from '@/lib/users'
import { loadPostImportSession,
creatableImportRows,
initialisePreviewRows,
mergeImportResults,
mergeValidatedImportRows,
processableImportRows,
@@ -53,6 +54,7 @@ const PostImportReviewPage: FC<Props> = ({ user }) => {
const [loading, setLoading] = useState (false)
const [missing, setMissing] = useState (false)
const [savingRow, setSavingRow] = useState<number | null> (null)
const [dialogMessageRow, setDialogMessageRow] = useState<PostImportRow | null> (null)
useEffect (() => {
if (sessionId == null)
@@ -102,6 +104,16 @@ const PostImportReviewPage: FC<Props> = ({ user }) => {
element?.scrollIntoView ({ block: 'center', behavior: 'smooth' })
}, [editingRow, session?.repairMode])
useEffect (() => {
if (editingRow == null)
{
setDialogMessageRow (null)
return
}
if (dialogMessageRow?.sourceRow !== editingRow.sourceRow)
setDialogMessageRow (null)
}, [editingRow, dialogMessageRow])
const updateSessionRows = (nextRows: PostImportRow[]) =>
setSession (current =>
current ? { ...current, rows: nextRows } : current)
@@ -171,7 +183,15 @@ const PostImportReviewPage: FC<Props> = ({ user }) => {
tagSources: row.tagSources,
metadataUrl: row.metadataUrl })),
changed_row: urlChanged ? editingRow.sourceRow : -1 })
updateSessionRows (mergeValidatedImportRows (nextRows, validated.rows))
const validatedRows = initialisePreviewRows (validated.rows)
const target = validatedRows.find (row => row.sourceRow === editingRow.sourceRow)
if (target != null && Object.keys (target.validationErrors).length > 0)
{
setDialogMessageRow (target)
return false
}
updateSessionRows (mergeValidatedImportRows (nextRows, validatedRows))
setDialogMessageRow (null)
setSearchParams ({ })
return true
}
@@ -193,19 +213,41 @@ const PostImportReviewPage: FC<Props> = ({ user }) => {
setLoading (true)
try
{
const validated = await apiPost<{ rows: PostImportRow[] }> ('/posts/import/validate', {
rows: session.rows
.filter (row => row.importStatus !== 'created')
.map (row => ({
sourceRow: row.sourceRow,
url: row.url,
attributes: row.attributes,
provenance: row.provenance,
tagSources: row.tagSources,
metadataUrl: row.metadataUrl })),
changed_row: -1 })
const validatedRows = initialisePreviewRows (validated.rows)
const mergedRows = mergeValidatedImportRows (session.rows, validatedRows)
const firstInvalid = mergedRows.find (row => Object.keys (row.validationErrors).length > 0)
if (firstInvalid != null)
{
setSession ({ ...session, rows: mergedRows })
setDialogMessageRow (firstInvalid)
setSearchParams ({ edit: String (firstInvalid.sourceRow) })
return
}
const result = await apiPost<{
created: number
skipped: number
failed: number
rows: PostImportResultRow[] }> ('/posts/import', {
rows: processable.map (row => ({
rows: processableImportRows (mergedRows).map (row => ({
sourceRow: row.sourceRow,
url: row.url,
attributes: row.attributes,
provenance: row.provenance,
tagSources: row.tagSources,
metadataUrl: row.metadataUrl })) })
const nextRows = mergeImportResults (session.rows, result.rows)
const nextRows = mergeImportResults (mergedRows, result.rows)
const nextSession = { ...session, rows: nextRows, repairMode: 'all' as const }
setSession (nextSession)
const saved = savePostImportSession (sessionId, nextSession, message =>
@@ -256,10 +298,8 @@ const PostImportReviewPage: FC<Props> = ({ user }) => {
<div className="flex flex-wrap items-center gap-2">
<SummaryChip label="全件" value={counts.total}/>
<SummaryChip label="登録対象" value={counts.submittable}/>
<SummaryChip label="要修正" value={counts.invalid}/>
<SummaryChip label="要確認" value={counts.invalid}/>
<SummaryChip label="スキップ予定" value={counts.skipPlanned}/>
<SummaryChip label="登録済み" value={counts.created}/>
<SummaryChip label="失敗" value={counts.failed}/>
</div>
</div>
@@ -288,9 +328,10 @@ const PostImportReviewPage: FC<Props> = ({ user }) => {
<PostImportRowDialog
open={editingRow != null}
row={editingRow}
messageRow={dialogMessageRow}
saving={savingRow != null}
onOpenChange={open => {
if (!(open))
if (!open)
setSearchParams ({ })
}}
onSave={saveDraft}/>
@@ -319,14 +360,12 @@ const PostImportFooter = (
<div className="mx-auto flex max-w-6xl flex-col gap-3 md:flex-row
md:items-center md:justify-between">
<div className="flex flex-wrap items-center gap-2 text-sm">
<PostImportStatusBadge value="pending"/>
<span> {processableCount} </span>
<PostImportStatusBadge value="ready"/>
<span> {creatableCount} </span>
<PostImportStatusBadge value="skipped"/>
<span> {skipPlannedCount} </span>
<PostImportStatusBadge value="error"/>
<span> {invalidCount} </span>
<span> {invalidCount} </span>
</div>
<div className="flex flex-col gap-2 sm:flex-row">
<Button type="button" variant="outline" onClick={onBack}>