コミットを比較
1
コミット
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
a55408dc32 |
@@ -29,14 +29,14 @@ class PostVersionsController < ApplicationController
|
||||
|
||||
count = q.except(:select, :order, :limit, :offset).count
|
||||
|
||||
ids = q.order(Arel.sql('post_versions.created_at DESC, post_versions.id DESC'))
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
.pluck('post_versions.id')
|
||||
versions = version_scope.merge(q).where(id: ids)
|
||||
# Apply visibility and pagination before joining the previous snapshots.
|
||||
page_scope = q.order(Arel.sql('post_versions.created_at DESC, post_versions.id DESC'))
|
||||
.limit(limit).offset(offset).select('post_versions.*')
|
||||
versions = version_scope.from(page_scope, :post_versions)
|
||||
.order(Arel.sql('post_versions.created_at DESC, post_versions.id DESC'))
|
||||
|
||||
render json: { versions: serialise_versions(versions, locale.language_code), count:, population_count: HistoryAccess.population_count(PostVersion) }
|
||||
render json: { versions: serialise_versions(versions, locale.language_code),
|
||||
count:, population_count: HistoryAccess.population_count(PostVersion) }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -41,10 +41,9 @@ class HistoryAccess < ActiveSupport::CurrentAttributes
|
||||
table = model.table_name
|
||||
keys = KEYS.fetch(table)
|
||||
matches = keys.map { "boundary.#{ _1 } = #{ row }.#{ _1 }" }.join(' AND ')
|
||||
boundaries = "SELECT #{ keys.join(', ') }, MAX(version_no) AS version_no FROM #{ table } " +
|
||||
"WHERE event_type = 'discard' GROUP BY #{ keys.join(', ') }"
|
||||
clauses = ["NOT EXISTS (SELECT 1 FROM (#{ boundaries }) boundary WHERE #{ matches } " +
|
||||
"AND boundary.version_no >= #{ row }.version_no)"]
|
||||
# Any discard at or after this version hides it, including after a restore.
|
||||
clauses = ["NOT EXISTS (SELECT 1 FROM #{ table } boundary WHERE #{ matches } " +
|
||||
"AND boundary.version_no >= #{ row }.version_no AND boundary.event_type = 'discard')"]
|
||||
clauses += reference_sql(table, row) if references
|
||||
clauses.map { "(#{ _1 })" }.join(' AND ')
|
||||
end
|
||||
@@ -62,8 +61,8 @@ class HistoryAccess < ActiveSupport::CurrentAttributes
|
||||
# A scalar lookup avoids MySQL's semijoin rewrite losing the JSON row correlation.
|
||||
"(SELECT 1 FROM JSON_TABLE(COALESCE(#{ document }, JSON_ARRAY()), " +
|
||||
"'$[*]' COLUMNS (reference_id BIGINT PATH '$' NULL ON EMPTY)) reference_entry " +
|
||||
"JOIN (#{ discarded_keys(table, key) }) blocked " +
|
||||
"ON reference_entry.reference_id = blocked.#{ key } LIMIT 1) IS NULL"
|
||||
"JOIN #{ table } blocked ON reference_entry.reference_id = blocked.#{ key } " +
|
||||
"WHERE blocked.event_type = 'discard' LIMIT 1) IS NULL"
|
||||
end
|
||||
|
||||
def self.list_reference(table, key, document)
|
||||
|
||||
@@ -33,6 +33,9 @@ RSpec.describe 'Post history privacy', type: :request do
|
||||
end
|
||||
PostVersion.create!(post: post_record, version_no: index + 1, event_type: event,
|
||||
title: "version #{ index + 1 }", url: post_record.url, tags: '',
|
||||
thumbnail_base: "history-#{ index + 1 }", video_ms: (index + 1) * 1000,
|
||||
original_created_from: origin - 1.year + index.days,
|
||||
original_created_before: origin - 1.year + (index + 1).days,
|
||||
tags_json: snapshots, parent_post_ids: '', created_at: origin + (index + 1).days)
|
||||
end
|
||||
end
|
||||
@@ -63,7 +66,7 @@ RSpec.describe 'Post history privacy', type: :request do
|
||||
expect(response.parsed_body.fetch('versions').first.fetch('title').fetch('prev')).to be_nil
|
||||
end
|
||||
|
||||
['anonymous', 'member', 'admin'].each do |role|
|
||||
['anonymous', 'guest', 'member', 'admin'].each do |role|
|
||||
context "as #{ role }" do
|
||||
before do
|
||||
sign_in_as(create(:user, role.to_sym)) unless role == 'anonymous'
|
||||
@@ -115,6 +118,15 @@ RSpec.describe 'Post history privacy', type: :request do
|
||||
expect(body.fetch('versions').pluck('version_no')).to eq(expected)
|
||||
restored = body.fetch('versions').find { _1.fetch('version_no') == 3 }
|
||||
expect(restored.fetch('title').fetch('prev')).to eq(role == 'admin' ? 'version 2' : nil)
|
||||
unless role == 'admin'
|
||||
fields = [
|
||||
'url', 'thumbnail_base', 'video_ms',
|
||||
'original_created_from', 'original_created_before']
|
||||
fields.each do |field|
|
||||
expect(restored.fetch(field).fetch('prev')).to be_nil
|
||||
end
|
||||
expect(restored.fetch('tags')).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
it 'uses only an authorised previous version for tag filtering' do
|
||||
@@ -124,6 +136,150 @@ RSpec.describe 'Post history privacy', type: :request do
|
||||
expect(response.parsed_body.fetch('versions').pluck('version_no')).to eq(expected)
|
||||
expect(response.parsed_body.fetch('count')).to eq(expected.length)
|
||||
end
|
||||
|
||||
it 'returns an empty history with an exact count' do
|
||||
get '/posts/versions', params: { post: other_post.id }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.parsed_body).to include('versions' => [], 'count' => 0,
|
||||
'population_count' => 4)
|
||||
end
|
||||
|
||||
it 'keeps counts and timestamp ties consistent across history pages' do
|
||||
rows = 25.times.map do |index|
|
||||
PostVersion.create!(post: post_record, version_no: index + 5, event_type: 'update',
|
||||
title: 'page snapshot', url: post_record.url, tags: '', tags_json: [],
|
||||
parent_post_ids: '', created_at: origin + 5.days)
|
||||
end
|
||||
rows << PostVersion.create!(post: other_post, version_no: 1, event_type: 'create',
|
||||
title: 'another post', url: other_post.url, tags: '', tags_json: [],
|
||||
parent_post_ids: '', created_at: origin + 5.days)
|
||||
earlier = role == 'admin' ? [4, 3, 2, 1] : [3]
|
||||
expected = rows.reverse.map { [_1.post_id, _1.version_no] } +
|
||||
earlier.map { [post_record.id, _1] }
|
||||
|
||||
expected.each_slice(7).with_index do |page_rows, index|
|
||||
get '/posts/versions', params: { page: index + 1, limit: 7 }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
body = response.parsed_body
|
||||
expect(body.fetch('count')).to eq(expected.length)
|
||||
expect(body.fetch('population_count')).to eq(30)
|
||||
expect(body.fetch('versions').map { [_1.fetch('post_id'), _1.fetch('version_no')] })
|
||||
.to eq(page_rows)
|
||||
end
|
||||
|
||||
get '/posts/versions', params: { page: 10, limit: 7 }
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.parsed_body).to include('versions' => [], 'count' => expected.length)
|
||||
end
|
||||
|
||||
it 'loads the page and its authorised diff in one data query' do
|
||||
statements = []
|
||||
listener = lambda do |_name, _start, _finish, _id, payload|
|
||||
next if ['SCHEMA', 'TRANSACTION'].include?(payload[:name])
|
||||
|
||||
statements << payload[:sql] if payload[:sql].match?(/\ASELECT/i)
|
||||
end
|
||||
ActiveSupport::Notifications.subscribed(listener, 'sql.active_record') do
|
||||
get '/posts/versions', params: { post: post_record.id, limit: 1 }
|
||||
end
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
history_queries = statements.select { _1.include?('post_versions') }
|
||||
counts, details = history_queries.partition { _1.match?(/\ASELECT COUNT\(/i) }
|
||||
expect(counts.length).to eq(2)
|
||||
expect(counts.join(' ')).not_to include('LEFT JOIN post_versions prev')
|
||||
expect(details.length).to eq(1)
|
||||
end
|
||||
|
||||
it 'hides references to a discarded parent even after its restore' do
|
||||
['discard', 'restore'].each_with_index do |event, index|
|
||||
PostVersion.create!(post: other_post, version_no: index + 1, event_type: event,
|
||||
title: 'parent snapshot', url: other_post.url, tags: '', tags_json: [],
|
||||
parent_post_ids: '', created_at: origin + index.hours)
|
||||
end
|
||||
[other_post.id.to_s, ''].each_with_index do |parents, index|
|
||||
PostVersion.create!(post: post_record, version_no: index + 5, event_type: 'update',
|
||||
title: 'parent reference', url: post_record.url, tags: '', tags_json: [],
|
||||
parent_post_ids: parents, created_at: origin + (index + 5).days)
|
||||
end
|
||||
|
||||
get '/posts/versions', params: { post: post_record.id }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
body = response.parsed_body
|
||||
expected = role == 'admin' ? [6, 5, 4, 3, 2, 1] : [6, 3]
|
||||
expect(body.fetch('versions').pluck('version_no')).to eq(expected)
|
||||
expect(body.fetch('count')).to eq(expected.length)
|
||||
previous = body.fetch('versions').first.fetch('title').fetch('prev')
|
||||
expect(previous).to eq(role == 'admin' ? 'parent reference' : nil)
|
||||
end
|
||||
|
||||
it 'keeps restored tag references private' do
|
||||
TagVersion.create!(tag:, version_no: 3, event_type: 'restore',
|
||||
name: 'private-history-tag', category: 'general', aliases: '', parent_tag_ids: '',
|
||||
names: { ja: { name: 'private-history-tag', script_code: 'Jpan',
|
||||
auto_generated: false, aliases: [] } },
|
||||
created_at: origin + 2.hours)
|
||||
PostVersion.create!(post: post_record, version_no: 5, event_type: 'update',
|
||||
title: 'restored tag reference', url: post_record.url, tags: '',
|
||||
tags_json: [{ tag_id: tag.id, version_no: 3, sections: [] }],
|
||||
parent_post_ids: '', created_at: origin + 5.days)
|
||||
|
||||
get '/posts/versions', params: { post: post_record.id }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expected = role == 'admin' ? [5, 4, 3, 2, 1] : [3]
|
||||
expect(response.parsed_body.fetch('versions').pluck('version_no')).to eq(expected)
|
||||
expect(response.parsed_body.fetch('count')).to eq(expected.length)
|
||||
end
|
||||
|
||||
it 'uses the external linkage recorded at the post snapshot time' do
|
||||
NicoTagVersion.create!(external_tag: external, version_no: 2, event_type: 'update',
|
||||
linked_tag_ids: '', created_at: origin + 5.days)
|
||||
PostVersion.create!(post: post_record, version_no: 5, event_type: 'update',
|
||||
title: 'public external reference', url: post_record.url, tags: '',
|
||||
tags_json: [{ external_tag_id: external.id }], parent_post_ids: '',
|
||||
created_at: origin + 6.days)
|
||||
|
||||
get '/posts/versions', params: { post: post_record.id, external_tag: external.id }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
body = response.parsed_body
|
||||
expected = role == 'admin' ? [5, 4] : [5]
|
||||
expect(body.fetch('versions').pluck('version_no')).to eq(expected)
|
||||
expect(body.fetch('count')).to eq(expected.length)
|
||||
latest = body.fetch('versions').first
|
||||
previous = latest.fetch('title').fetch('prev')
|
||||
expect(previous).to eq(role == 'admin' ? 'version 4' : nil)
|
||||
expect(latest.fetch('tags')).to contain_exactly(a_hash_including(
|
||||
'name' => 'nico:external-history-tag',
|
||||
'type' => role == 'admin' ? 'context' : 'added'))
|
||||
end
|
||||
|
||||
it 'hides references to historical external discard events after restore' do
|
||||
public_external = create(:external_tag)
|
||||
# Discard/restore events can remain in history despite current event validation.
|
||||
snapshots = ['create', 'discard', 'restore'].each_with_index.map do |event, index|
|
||||
{ tag_id: public_external.id, version_no: index + 1, event_type: event,
|
||||
linked_tag_ids: '', created_at: origin + index.days }
|
||||
end
|
||||
NicoTagVersion.insert_all!(snapshots)
|
||||
[5, 6].each do |number|
|
||||
PostVersion.create!(post: post_record, version_no: number, event_type: 'update',
|
||||
title: 'external discard reference', url: post_record.url, tags: '',
|
||||
tags_json: [{ external_tag_id: public_external.id }], parent_post_ids: '',
|
||||
created_at: origin + number.days)
|
||||
end
|
||||
|
||||
get '/posts/versions', params: { post: post_record.id, external_tag: public_external.id }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expected = role == 'admin' ? [6, 5] : []
|
||||
expect(response.parsed_body.fetch('versions').pluck('version_no')).to eq(expected)
|
||||
expect(response.parsed_body.fetch('count')).to eq(expected.length)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { fireEvent, screen, waitFor, within } from '@testing-library/react'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { fireEvent, screen, waitFor } from '@testing-library/react'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { textContentOf } from '@/test/text'
|
||||
import PostEditForm from '@/components/PostEditForm'
|
||||
@@ -21,99 +21,14 @@ const toastApi = vi.hoisted (() => ({
|
||||
vi.mock ('@/lib/posts', () => postsApi)
|
||||
vi.mock ('@/lib/api', () => api)
|
||||
vi.mock ('@/components/ui/use-toast', () => toastApi)
|
||||
vi.mock ('@/lib/dialogues/useDialogue', async importOriginal => ({
|
||||
...await importOriginal<typeof import ('@/lib/dialogues/useDialogue')> (),
|
||||
default: () => ({
|
||||
choice: vi.fn (),
|
||||
}),
|
||||
}))
|
||||
|
||||
describe ('PostEditForm', () => {
|
||||
beforeEach (() => {
|
||||
postsApi.updatePost.mockReset ()
|
||||
api.isApiError.mockReset ().mockReturnValue (false)
|
||||
toastApi.toast.mockClear ()
|
||||
})
|
||||
|
||||
it ('shows all conflict values before a choice and preserves edits on cancel', async () => {
|
||||
const post = buildPost ({ versionNo: 4, title: 'original title' })
|
||||
const onSave = vi.fn ()
|
||||
api.isApiError.mockReturnValue (true)
|
||||
postsApi.updatePost.mockRejectedValueOnce ({ response: {
|
||||
status: 409,
|
||||
data: { base_version_no: 4, current_version_no: 5, mergeable: false,
|
||||
changes: [
|
||||
{ field: 'title', label: 'server label', base: 'original title',
|
||||
current: 'server title', mine: '<b>my title</b>' },
|
||||
{ field: 'video_ms', base: null, current: 180_500, mine: 0 },
|
||||
{ field: 'original_created_from', base: null,
|
||||
current: '2026-01-01T00:00:00Z', mine: '2026-02-01T00:00:00Z' },
|
||||
{ field: 'original_created_before', base: '2026-01-02T00:00:00Z',
|
||||
current: '2026-01-03T00:00:00Z', mine: null },
|
||||
{ field: 'tag_names', base: ['old-tag'], current: ['tag-a', 'tag-b'],
|
||||
mine: [] },
|
||||
{ field: 'parent_post_ids', base: [2], current: [], mine: [3, 4] }] } } })
|
||||
|
||||
render (<PostEditForm post={post} onSave={onSave}/>)
|
||||
const title = screen.getAllByRole ('textbox')[0]
|
||||
fireEvent.change (title, { target: { value: '<b>my title</b>' } })
|
||||
fireEvent.submit (screen.getByRole ('button', { name: '更新' }).closest ('form')!)
|
||||
|
||||
const dialogue = within (await screen.findByRole ('dialog'))
|
||||
const table = dialogue.getByRole ('table')
|
||||
expect (within (table).getAllByRole ('columnheader').map (cell => cell.textContent))
|
||||
.toEqual (['版 4', '版 5', '編輯'])
|
||||
const rows = within (table).getAllByRole ('row').slice (1)
|
||||
expect (rows.map (row => within (row).getByRole ('rowheader').textContent))
|
||||
.toEqual (['タイトル', '動画時間', 'オリジナルの作成日時 以降',
|
||||
'オリジナルの作成日時 より前', 'タグ', '親投稿'])
|
||||
expect (rows.map (row => within (row).getAllByRole ('cell')
|
||||
.map (cell => cell.textContent))).toEqual ([
|
||||
['original title', 'server title', '<b>my title</b>'],
|
||||
['', '3:00.500', '0:00'],
|
||||
['', '2026-01-01T00:00:00Z', '2026-02-01T00:00:00Z'],
|
||||
['2026-01-02T00:00:00Z', '2026-01-03T00:00:00Z', ''],
|
||||
['old-tag', 'tag-a\ntag-b', ''], ['2', '', '3\n4']])
|
||||
expect (table.querySelector ('b')).toBeNull ()
|
||||
expect (dialogue.queryByText ('server label')).not.toBeInTheDocument ()
|
||||
expect (dialogue.queryByRole ('button', { name: '差分をマージ' }))
|
||||
.not.toBeInTheDocument ()
|
||||
expect (postsApi.updatePost).toHaveBeenCalledTimes (1)
|
||||
expect (onSave).not.toHaveBeenCalled ()
|
||||
|
||||
fireEvent.click (dialogue.getByRole ('button', { name: '取消' }))
|
||||
await waitFor (() => expect (screen.queryByRole ('dialog')).not.toBeInTheDocument ())
|
||||
expect (title).toHaveValue ('<b>my title</b>')
|
||||
await waitFor (() => expect (screen.getByRole ('button', { name: '更新' }))
|
||||
.not.toBeDisabled ())
|
||||
expect (postsApi.updatePost).toHaveBeenCalledTimes (1)
|
||||
expect (onSave).not.toHaveBeenCalled ()
|
||||
})
|
||||
|
||||
it.each ([
|
||||
{ action: '差分をマージ', mergeable: true, options: { merge: true } },
|
||||
{ action: '強制上書き', mergeable: false, options: { force: true } }]) (
|
||||
'keeps the $action flow after displaying conflict values',
|
||||
async ({ action, mergeable, options }) => {
|
||||
const post = buildPost ({ id: 8, versionNo: 4, title: 'original' })
|
||||
const onSave = vi.fn ()
|
||||
api.isApiError.mockReturnValue (true)
|
||||
postsApi.updatePost.mockRejectedValueOnce ({ response: {
|
||||
status: 409,
|
||||
data: { base_version_no: 4, current_version_no: 5, mergeable,
|
||||
changes: [{ field: 'title', base: 'original',
|
||||
current: 'server', mine: 'mine' }] } } })
|
||||
.mockResolvedValueOnce ({ ...post, versionNo: 6, title: 'mine' })
|
||||
|
||||
render (<PostEditForm post={post} onSave={onSave}/>)
|
||||
fireEvent.change (screen.getAllByRole ('textbox')[0], { target: { value: 'mine' } })
|
||||
fireEvent.submit (screen.getByRole ('button', { name: '更新' }).closest ('form')!)
|
||||
|
||||
const dialogue = within (await screen.findByRole ('dialog'))
|
||||
expect (dialogue.getByRole ('table')).toHaveTextContent ('server')
|
||||
fireEvent.click (dialogue.getByRole ('button', { name: action }))
|
||||
await waitFor (() => expect (onSave)
|
||||
.toHaveBeenCalledWith (expect.objectContaining ({ versionNo: 6 })))
|
||||
expect (postsApi.updatePost).toHaveBeenCalledTimes (2)
|
||||
expect (postsApi.updatePost).toHaveBeenLastCalledWith (
|
||||
expect.objectContaining ({ id: 8, title: 'mine' }),
|
||||
{ baseVersionNo: 4, ...options }, 'ja')
|
||||
})
|
||||
|
||||
it ('submits edited post fields with the current base version', async () => {
|
||||
const onSave = vi.fn ()
|
||||
const post = buildPost ({
|
||||
|
||||
@@ -23,27 +23,6 @@ type PostFormField =
|
||||
'parentPostIds' | 'tags' | 'videoMs'
|
||||
| 'originalCreatedAt' | 'originalCreatedFrom' | 'originalCreatedBefore'
|
||||
|
||||
type PostConflictValue = string | number | null | (string | number)[]
|
||||
|
||||
type PostConflict = {
|
||||
base_version_no: number
|
||||
current_version_no: number
|
||||
mergeable?: boolean
|
||||
changes?: {
|
||||
field: 'title' | 'video_ms' | 'original_created_from'
|
||||
| 'original_created_before' | 'tag_names' | 'parent_post_ids'
|
||||
base: PostConflictValue
|
||||
current: PostConflictValue
|
||||
mine: PostConflictValue }[] }
|
||||
|
||||
|
||||
const formatConflictValue = (field: string, value: PostConflictValue): string => {
|
||||
if (value == null) return ''
|
||||
if (Array.isArray (value)) return value.join ('\n')
|
||||
return (field === 'video_ms' && typeof value === 'number') ? msToTime (value) : String (value)
|
||||
}
|
||||
|
||||
|
||||
const groupedMessages = (...values: (string[] | undefined)[]): string[] =>
|
||||
[...new Set (values.flatMap (value => value ?? []))]
|
||||
|
||||
@@ -118,7 +97,7 @@ const PostEditForm: FC<Props> = ({ post, onSave }) => {
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
const response = isApiError<PostConflict> (e) ? e.response : undefined
|
||||
const response = isApiError<{ mergeable?: boolean }> (e) ? e.response : undefined
|
||||
|
||||
if (response?.status !== 409)
|
||||
{
|
||||
@@ -134,54 +113,11 @@ const PostEditForm: FC<Props> = ({ post, onSave }) => {
|
||||
return
|
||||
}
|
||||
|
||||
const conflict = response.data
|
||||
const fieldLabels = {
|
||||
title: label ('shared:labels.title'),
|
||||
video_ms: label ('shared:labels.duration'),
|
||||
original_created_from: <>{label ('shared:labels.originalCreatedAt')}
|
||||
{' '}{label ('shared:labels.since')}</>,
|
||||
original_created_before: <>{label ('shared:labels.originalCreatedAt')}
|
||||
{' '}{label ('shared:labels.before')}</>,
|
||||
tag_names: label ('navigation:tags'),
|
||||
parent_post_ids: label ('shared:labels.parentPosts') }
|
||||
|
||||
const action = await dialogue.choice ({
|
||||
title: label ('edit.conflictTitle'),
|
||||
description: (
|
||||
<div>
|
||||
<p>{label ('edit.conflictDescription')}</p>
|
||||
{(conflict.changes?.length ?? 0) > 0 && (
|
||||
<div className="my-3 max-h-[40dvh] overflow-auto text-left">
|
||||
<table className="w-full table-fixed text-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<td/>
|
||||
<th scope="col" className="p-1 align-top">
|
||||
{label ('history:version')} {conflict.base_version_no}
|
||||
</th>
|
||||
<th scope="col" className="p-1 align-top">
|
||||
{label ('history:version')} {conflict.current_version_no}
|
||||
</th>
|
||||
<th scope="col" className="p-1 align-top">
|
||||
{label ('shared:actions.edit')}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{conflict.changes?.map (change => (
|
||||
<tr key={change.field}>
|
||||
<th scope="row" className="p-1 align-top break-words">
|
||||
{fieldLabels[change.field]}
|
||||
</th>
|
||||
{(['base', 'current', 'mine'] as const).map (column => (
|
||||
<td key={column}
|
||||
className="p-1 align-top whitespace-pre-wrap break-words">
|
||||
{formatConflictValue (change.field, change[column])}
|
||||
</td>))}
|
||||
</tr>))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>)}
|
||||
<p>{label ('edit.conflictQuestion')}</p>
|
||||
</div>),
|
||||
cancelText: label ('shared:actions.cancel'),
|
||||
@@ -192,6 +128,7 @@ const PostEditForm: FC<Props> = ({ post, onSave }) => {
|
||||
|
||||
if (action === 'merge')
|
||||
{
|
||||
// TODO: 差分 UI
|
||||
await update ({ id: post.id, title, tags, parentPostIds,
|
||||
duration: videoFlg ? duration : null,
|
||||
originalCreatedFrom, originalCreatedBefore },
|
||||
@@ -281,4 +218,5 @@ const PostEditForm: FC<Props> = ({ post, onSave }) => {
|
||||
</form>)
|
||||
}
|
||||
|
||||
|
||||
export default PostEditForm
|
||||
|
||||
@@ -2,6 +2,7 @@ import { QueryClient } from '@tanstack/react-query'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { prefetchForURL } from '@/lib/prefetchers'
|
||||
import { postsKeys } from '@/lib/queryKeys'
|
||||
|
||||
const postsApi = vi.hoisted (() => ({
|
||||
fetchPost: vi.fn (),
|
||||
@@ -88,6 +89,42 @@ describe ('prefetchForURL', () => {
|
||||
expect (postsApi.fetchPost).toHaveBeenCalledWith ('12', 'ja')
|
||||
})
|
||||
|
||||
it.each (['/posts/changes', '/ja/posts/changes']) (
|
||||
'prefetches post history with matching filters and cache key at %s', async path => {
|
||||
const client = qc ()
|
||||
const params = { post: '12', page: 2, limit: 5 }
|
||||
const history = { versions: [], count: 7 }
|
||||
postsApi.fetchPostChanges.mockResolvedValueOnce (history)
|
||||
|
||||
await prefetchForURL (client, `${path}?id=12&page=2&limit=5`)
|
||||
|
||||
expect (postsApi.fetchPostChanges).toHaveBeenCalledExactlyOnceWith (params, 'ja')
|
||||
expect (client.getQueryData (postsKeys.changes (params, 'ja'))).toEqual (history)
|
||||
expect (client.getQueryCache ().getAll ()).toHaveLength (1)
|
||||
})
|
||||
|
||||
it ('preserves a tag filter when prefetching one post history', async () => {
|
||||
const client = qc ()
|
||||
const params = { post: '12', tag: '7', page: 1, limit: 20 }
|
||||
|
||||
await prefetchForURL (client, '/ja/posts/changes?id=12&tag=7')
|
||||
|
||||
expect (postsApi.fetchPostChanges).toHaveBeenCalledExactlyOnceWith (params, 'ja')
|
||||
expect (client.getQueryData (postsKeys.changes (params, 'ja')))
|
||||
.toEqual ({ versions: [], count: 0 })
|
||||
})
|
||||
|
||||
it ('prefetches unfiltered post history with its own cache key', async () => {
|
||||
const client = qc ()
|
||||
const params = { page: 2, limit: 5 }
|
||||
|
||||
await prefetchForURL (client, '/ja/posts/changes?page=2&limit=5')
|
||||
|
||||
expect (postsApi.fetchPostChanges).toHaveBeenCalledExactlyOnceWith (params, 'ja')
|
||||
expect (client.getQueryData (postsKeys.changes (params, 'ja')))
|
||||
.toEqual ({ versions: [], count: 0 })
|
||||
})
|
||||
|
||||
it ('prefetches tag indexes from query parameters', async () => {
|
||||
await prefetchForURL (
|
||||
qc (),
|
||||
|
||||
@@ -214,11 +214,11 @@ const prefetchPostChanges: Prefetcher = async (qc, url, locale) => {
|
||||
}
|
||||
|
||||
await qc.prefetchQuery ({
|
||||
queryKey: postsKeys.changes ({ ...(id && { id }),
|
||||
queryKey: postsKeys.changes ({ ...(id && { post: id }),
|
||||
...(tag && { tag }),
|
||||
...(externalTag && { externalTag }),
|
||||
page, limit }, locale),
|
||||
queryFn: () => fetchPostChanges ({ ...(id && { id }),
|
||||
queryFn: () => fetchPostChanges ({ ...(id && { post: id }),
|
||||
...(tag && { tag }),
|
||||
...(externalTag && { externalTag }),
|
||||
page, limit }, locale) })
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする