このコミットが含まれているのは:
2026-10-28 21:13:08 +09:00
コミット 49721e6915
17個のファイルの変更、170行の追加、48行の削除
+23 -5
ファイルの表示
@@ -1,6 +1,6 @@
import { countsFieldLabel } from '@/lib/countsDefinitions'
import { apiDownload, apiGet } from '@/lib/api'
import { currentViewingLocale } from '@/lib/locales'
import { currentViewingLocale, localeLanguage } from '@/lib/locales'
import { readCountState, encodeCountState } from '@/lib/queryState'
@@ -99,7 +99,7 @@ export type CountSort = { key: string; direction: 'asc' | 'desc' }
export type CountField = { key: string; label: string; children?: CountField[]
labelValues?: Record<string, string>
multipleValues?: boolean
nameLocale?: { code: string; languageCode: string; scriptCode: string } }
nameLocale?: { code: string; languageCode: string; scriptCode?: string } }
export type CountRecord = Record<string, unknown>
export const countColumns: Record<string, string> = {
@@ -233,7 +233,8 @@ export const selectedCountColumns = (
const defaults: Record<CountsResource, string[]> = {
posts: ['title', 'url', 'tags', 'parents', 'video_ms'],
tags: [...(definition?.nameColumns ?? []).filter (field =>
field.nameLocale?.code === currentViewingLocale ()).map (field => field.key),
field.nameLocale?.languageCode === localeLanguage (currentViewingLocale ()))
.map (field => field.key),
'category', 'parents'],
nico_tags: ['name', 'linked_tags'],
tag_descriptions: ['language_code', 'body', 'source_language_code'],
@@ -356,14 +357,31 @@ export const normaliseCountsParams = (
definition?: CountsDefinition,
): URLSearchParams => {
const params = new URLSearchParams (source)
const nameScope = params.get ('name_scope')
if (definition?.conditionAliases != null && (nameScope == null || nameScope === 'locale'))
{
const predicates = new Map ((definition.conditionAliases ?? [])
.map (entry => [entry.key, entry.value]))
for (const [key, value] of params)
if (/^conditions\.\d+\.field$/.test (key)) params.set (key, value.replace (
/(?:name|aliases)_[a-z0-9_]+/g, field => predicates.get (field) ?? field))
params.set ('name_scope', 'language')
}
const aliasesByKey = new Map ((definition?.columnAliases ?? [])
.map (entry => [entry.key, entry.value]))
for (const key of ['columns', 'children', 'order', 'sort', 'child_sort'])
if (params.has (key)) params.set (key, params.get (key)!.replace (
/(?:name|aliases)_[a-z0-9_]+/g, field => aliasesByKey.get (field) ?? field))
if (definition?.nameColumns != null)
{
const names = definition.nameColumns.filter (field => !field.multipleValues)
.map (field => field.key)
const current = definition.nameColumns.find (field =>
!field.multipleValues && field.nameLocale?.code === currentViewingLocale ())?.key
!field.multipleValues
&& field.nameLocale?.languageCode === localeLanguage (currentViewingLocale ()))?.key
const aliases = definition.nameColumns.find (field =>
field.multipleValues && field.nameLocale?.code === currentViewingLocale ())?.key
field.multipleValues
&& field.nameLocale?.languageCode === localeLanguage (currentViewingLocale ()))?.key
const rootKey = (key: string) => (key === 'name' && current != null) ? current
: ((key === 'aliases' && aliases != null) ? aliases : key)
const childKeys = (key: string): string[] => {
+5 -5
ファイルの表示
@@ -27,11 +27,14 @@ export type CountsFieldMetadata = {
setType?: 'tag_reference'; inputTypes?: string[]
labelValues?: Record<string, string>
nameLocale?: CountField['nameLocale']
legacy?: boolean
choices?: { value: string; label: string }[] }
export type CountsDefinition = {
fields: CountsFieldMetadata[]
outputFields?: CountField[]
nameColumns?: CountField[]
columnAliases?: { key: string; value: string }[]
conditionAliases?: { key: string; value: string }[]
filterFields?: CountsFieldMetadata[]
defaults?: { definition: string; mode: string; params: { key: string; value: string }[] }[]
axes: { latest: string[]; history: string[] }
@@ -53,12 +56,9 @@ const localiseCountsDefinition = (
const heading = (name: CountField['nameLocale'], aliasesFlg: boolean) => {
if (name == null) return null
const language = languageUIMessage (name.languageCode, locale).text
const scripts = new Set ((definition.nameColumns ?? [])
.filter (field => field.nameLocale?.languageCode === name.languageCode)
.map (field => field.nameLocale!.scriptCode.toLowerCase ()))
const label = aliasesFlg ? 'counts:localeAliases' : 'counts:localeName'
return { label: scripts.size > 1 ? `${label}WithScript` : label,
labelValues: { language, script: name.scriptCode } }
return { label: name.scriptCode == null ? label : `${label}WithScript`,
labelValues: { language, script: name.scriptCode ?? '' } }
}
const columns = (fields: CountField[]): CountField[] => fields.map (field => ({
...field, ...heading (field.nameLocale, field.multipleValues === true),