このコミットが含まれているのは:
@@ -5,6 +5,8 @@ import { creatableImportRows,
|
||||
mergeImportResults,
|
||||
mergeValidatedImportRows,
|
||||
processableImportRows,
|
||||
resultRepairMode,
|
||||
resultRowMessages,
|
||||
resultSummaryCounts,
|
||||
retryImportRow,
|
||||
reviewSummaryCounts } from '@/lib/postImportSession'
|
||||
@@ -131,6 +133,22 @@ describe ('post import row state', () => {
|
||||
importErrors: undefined })
|
||||
})
|
||||
|
||||
it ('deduplicates messages and keeps repair mode only for repairable rows', () => {
|
||||
const repairable = buildPostImportRow ({
|
||||
sourceRow: 1,
|
||||
importStatus: 'pending',
|
||||
validationErrors: { title: ['invalid'], base: ['duplicate'] },
|
||||
importErrors: { base: ['duplicate'], url: ['network'] } })
|
||||
const complete = buildPostImportRow ({
|
||||
sourceRow: 2,
|
||||
importStatus: 'created',
|
||||
createdPostId: 2 })
|
||||
|
||||
expect (resultRowMessages (repairable)).toEqual (['invalid', 'duplicate', 'network'])
|
||||
expect (resultRepairMode ([repairable, complete])).toBe ('failed')
|
||||
expect (resultRepairMode ([complete])).toBe ('all')
|
||||
})
|
||||
|
||||
it ('copies reset snapshot values instead of sharing mutable records', () => {
|
||||
const row = buildPostImportRow ({ fieldWarnings: { title: ['warning'] } })
|
||||
const initialised = initialisePreviewRows ([row])[0]
|
||||
|
||||
@@ -7,6 +7,9 @@ const hasSkipReason = (row: PostImportRow): boolean =>
|
||||
const hasValidationErrors = (row: PostImportRow): boolean =>
|
||||
Object.keys (row.validationErrors ?? { }).length > 0
|
||||
|
||||
const isRepairableImportStatus = (row: PostImportRow): boolean =>
|
||||
row.importStatus === 'failed' || row.importStatus === 'pending'
|
||||
|
||||
const buildResetSnapshot = (row: PostImportRow) => ({
|
||||
url: row.url,
|
||||
attributes: { ...row.attributes },
|
||||
@@ -67,6 +70,20 @@ export const resultSummaryCounts = (rows: PostImportRow[]) =>
|
||||
{ created: 0, skipped: 0, failed: 0 })
|
||||
|
||||
|
||||
export const resultRepairMode = (
|
||||
rows: PostImportRow[],
|
||||
): 'all' | 'failed' =>
|
||||
rows.some (row => hasValidationErrors (row) || isRepairableImportStatus (row))
|
||||
? 'failed'
|
||||
: 'all'
|
||||
|
||||
|
||||
export const resultRowMessages = (row: PostImportRow): string[] =>
|
||||
[...new Set ([
|
||||
...Object.values (row.validationErrors ?? { }).flat (),
|
||||
...Object.values (row.importErrors ?? { }).flat ()])]
|
||||
|
||||
|
||||
export const mergeValidatedImportRows = (
|
||||
current: PostImportRow[],
|
||||
validated: PostImportRow[],
|
||||
|
||||
新しい課題から参照
ユーザをブロックする