このコミットが含まれているのは:
@@ -16,6 +16,10 @@ const rowChanged = (
|
||||
|| JSON.stringify (previous.provenance) !== JSON.stringify (next.provenance)
|
||||
|| JSON.stringify (previous.tagSources ?? { }) !== JSON.stringify (next.tagSources ?? { })
|
||||
|
||||
const buildResetSnapshot = (row: PostImportRow) => ({
|
||||
url: row.url,
|
||||
attributes: row.attributes })
|
||||
|
||||
|
||||
export const processableImportRows = (rows: PostImportRow[]): PostImportRow[] =>
|
||||
rows.filter (row => {
|
||||
@@ -111,7 +115,11 @@ export const mergeValidatedImportRows = (
|
||||
: previous.baseWarnings,
|
||||
validationErrors: row.validationErrors,
|
||||
status: row.status,
|
||||
metadataUrl: row.metadataUrl }
|
||||
metadataUrl: row.metadataUrl,
|
||||
resetSnapshot:
|
||||
row.metadataUrl !== previous.metadataUrl
|
||||
? buildResetSnapshot (row)
|
||||
: previous.resetSnapshot }
|
||||
})
|
||||
}
|
||||
|
||||
@@ -154,6 +162,7 @@ export const mergePreviewImportRows = (
|
||||
tagSources: mergedTagSources,
|
||||
skipReason: row.skipReason,
|
||||
existingPostId: row.existingPostId,
|
||||
resetSnapshot: row.resetSnapshot,
|
||||
createdPostId: previous.createdPostId,
|
||||
importStatus: previous.importStatus,
|
||||
importErrors: previous.importErrors }
|
||||
@@ -214,3 +223,8 @@ export const retryImportRow = (
|
||||
row.sourceRow === sourceRow && row.importStatus === 'failed'
|
||||
? { ...row, importStatus: 'pending', importErrors: undefined }
|
||||
: row)
|
||||
|
||||
export const initialisePreviewRows = (rows: PostImportRow[]): PostImportRow[] =>
|
||||
rows.map (row => ({
|
||||
...row,
|
||||
resetSnapshot: buildResetSnapshot (row) }))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { PostImportOrigin,
|
||||
PostImportResetSnapshot,
|
||||
PostImportRow,
|
||||
PostImportSession,
|
||||
PostImportStatus,
|
||||
@@ -137,6 +138,24 @@ const hasOnlyKeys = (
|
||||
): boolean =>
|
||||
Object.keys (value).every (key => allowedKeys.includes (key))
|
||||
|
||||
const sanitiseResetSnapshot = (value: unknown): PostImportResetSnapshot | null => {
|
||||
if (!(isPlainObject (value)))
|
||||
return null
|
||||
if (typeof value.url !== 'string')
|
||||
return null
|
||||
if (!(isPlainObject (value.attributes)))
|
||||
return null
|
||||
if (!(hasOnlyKeys (value.attributes, ATTRIBUTE_KEYS)))
|
||||
return null
|
||||
if (!(Object.values (value.attributes).every (entry =>
|
||||
typeof entry === 'string' || typeof entry === 'number')))
|
||||
return null
|
||||
|
||||
return {
|
||||
url: value.url,
|
||||
attributes: value.attributes as Record<string, string | number> }
|
||||
}
|
||||
|
||||
|
||||
const sanitiseRow = (value: unknown): PostImportRow | null => {
|
||||
if (!(isPlainObject (value)))
|
||||
@@ -166,8 +185,11 @@ const sanitiseRow = (value: unknown): PostImportRow | null => {
|
||||
|
||||
const validationErrors = ensureStringListRecord (value.validationErrors)
|
||||
const fieldWarnings = ensureStringListRecord (value.fieldWarnings)
|
||||
const resetSnapshot = sanitiseResetSnapshot (value.resetSnapshot)
|
||||
if (validationErrors == null || fieldWarnings == null)
|
||||
return null
|
||||
if (resetSnapshot == null)
|
||||
return null
|
||||
|
||||
const importErrors =
|
||||
value.importErrors == null
|
||||
@@ -215,6 +237,7 @@ const sanitiseRow = (value: unknown): PostImportRow | null => {
|
||||
existingPostId:
|
||||
isPositiveInteger (value.existingPostId) ? Number (value.existingPostId) : undefined,
|
||||
metadataUrl: typeof value.metadataUrl === 'string' ? value.metadataUrl : undefined,
|
||||
resetSnapshot,
|
||||
createdPostId:
|
||||
isPositiveInteger (value.createdPostId) ? Number (value.createdPostId) : undefined,
|
||||
importStatus: value.importStatus }
|
||||
|
||||
@@ -9,6 +9,10 @@ export type PostImportSkipReason = 'existing'
|
||||
export type PostImportResultStatus = 'created' | 'skipped' | 'failed'
|
||||
export type PostImportAttributeValue = string | number
|
||||
|
||||
export type PostImportResetSnapshot = {
|
||||
url: string
|
||||
attributes: Record<string, PostImportAttributeValue> }
|
||||
|
||||
export type PostImportRow = {
|
||||
sourceRow: number
|
||||
url: string
|
||||
@@ -23,6 +27,7 @@ export type PostImportRow = {
|
||||
skipReason?: PostImportSkipReason
|
||||
existingPostId?: number
|
||||
metadataUrl?: string
|
||||
resetSnapshot: PostImportResetSnapshot
|
||||
createdPostId?: number
|
||||
importStatus?: PostImportStatus }
|
||||
|
||||
|
||||
新しい課題から参照
ユーザをブロックする