fix(views): pluralize unknown queue sort key warning
Problem: multiple unknown sort keys each triggered a separate warning. Solution: collect unknown keys and emit a single warning with the correct singular/plural label, joined by `, `.
This commit is contained in:
parent
5ab0aa78a1
commit
ddf1af79da
1 changed files with 6 additions and 1 deletions
|
|
@ -161,14 +161,19 @@ local function build_queue_comparator()
|
||||||
local log = require('pending.log')
|
local log = require('pending.log')
|
||||||
local keys = config.get().view.queue.sort or { 'status', 'priority', 'due', 'order', 'id' }
|
local keys = config.get().view.queue.sort or { 'status', 'priority', 'due', 'order', 'id' }
|
||||||
local comparators = {}
|
local comparators = {}
|
||||||
|
local unknown = {}
|
||||||
for _, key in ipairs(keys) do
|
for _, key in ipairs(keys) do
|
||||||
local cmp = sort_key_comparators[key]
|
local cmp = sort_key_comparators[key]
|
||||||
if cmp then
|
if cmp then
|
||||||
table.insert(comparators, cmp)
|
table.insert(comparators, cmp)
|
||||||
else
|
else
|
||||||
log.warn('unknown queue sort key: ' .. key)
|
table.insert(unknown, key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if #unknown > 0 then
|
||||||
|
local label = #unknown == 1 and 'unknown queue sort key: ' or 'unknown queue sort keys: '
|
||||||
|
log.warn(label .. table.concat(unknown, ', '))
|
||||||
|
end
|
||||||
return function(a, b)
|
return function(a, b)
|
||||||
for _, cmp in ipairs(comparators) do
|
for _, cmp in ipairs(comparators) do
|
||||||
local result = cmp(a, b)
|
local result = cmp(a, b)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue