このコミットが含まれているのは:
@@ -102,6 +102,44 @@ export const fieldsForCounts = (resource: CountsResource): CountField[] =>
|
||||
children: nested[key] }))
|
||||
|
||||
|
||||
export const orderedCountFields = (
|
||||
fields: CountField[],
|
||||
params: URLSearchParams,
|
||||
parent = '',
|
||||
): CountField[] => {
|
||||
const prefix = parent ? `${parent}.` : ''
|
||||
const saved = (params.get ('order') ?? '').split (',')
|
||||
const keys = [...new Set ([...saved, ...fields.map (field => `${prefix}${field.key}`)])]
|
||||
const ordered = keys.flatMap (key => {
|
||||
const field = fields.find (field => `${prefix}${field.key}` === key)
|
||||
return field == null ? [] : [field]
|
||||
})
|
||||
return parent ? ordered : [
|
||||
...ordered.filter (field => field.key === 'thumbnail'),
|
||||
...ordered.filter (field => field.key !== 'thumbnail')]
|
||||
}
|
||||
|
||||
|
||||
export const reorderCountFields = (
|
||||
fields: CountField[],
|
||||
params: URLSearchParams,
|
||||
parent: string,
|
||||
from: string,
|
||||
to: string,
|
||||
): string => {
|
||||
const ordered = orderedCountFields (fields, params, parent)
|
||||
const first = ordered.findIndex (field => field.key === from)
|
||||
const last = ordered.findIndex (field => field.key === to)
|
||||
if (first < 0 || last < 0) return params.get ('order') ?? ''
|
||||
const prefix = parent ? `${parent}.` : ''
|
||||
const current = ordered.map (field => `${prefix}${field.key}`)
|
||||
const next = [...current]
|
||||
next.splice (last, 0, ...next.splice (first, 1))
|
||||
return [...(params.get ('order') ?? '').split (',').filter (
|
||||
key => key && !current.includes (key)), ...next].join (',')
|
||||
}
|
||||
|
||||
|
||||
export const selectedCountColumns = (
|
||||
resource: CountsResource,
|
||||
params: URLSearchParams,
|
||||
@@ -110,7 +148,8 @@ export const selectedCountColumns = (
|
||||
columnsForCounts (resource).filter (key => ![
|
||||
'thumbnail', 'original_created_from', 'original_created_before']
|
||||
.includes (key))
|
||||
return columnsForCounts (resource).filter (key => selected.includes (key))
|
||||
return orderedCountFields (fieldsForCounts (resource), params)
|
||||
.map (field => field.key as CountColumn).filter (key => selected.includes (key))
|
||||
}
|
||||
|
||||
|
||||
@@ -164,14 +203,18 @@ export const normaliseCountsParams = (
|
||||
if (!['month', 'user'].includes (params.get ('axis') ?? ''))
|
||||
params.set ('axis', 'month')
|
||||
if (params.has ('columns'))
|
||||
params.set ('columns', selectedCountColumns (resource, params).join (','))
|
||||
{
|
||||
const selected = new Set (params.get ('columns')!.split (','))
|
||||
params.set ('columns', columnsForCounts (resource).filter (key => selected.has (key))
|
||||
.join (','))
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
|
||||
export const countsRequestParams = (params: URLSearchParams): URLSearchParams => {
|
||||
const result = new URLSearchParams (params)
|
||||
for (const key of ['columns', 'children', 'child_sort', 'nested_json'])
|
||||
for (const key of ['columns', 'children', 'child_sort', 'nested_json', 'order'])
|
||||
result.delete (key)
|
||||
return result
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする