fix(views): pluralize unknown queue sort key warning (#157)
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
e6816d13ef
commit
e9f21c0f0b
1 changed files with 6 additions and 1 deletions
|
|
@ -161,14 +161,19 @@ local function build_queue_comparator()
|
|||
local log = require('pending.log')
|
||||
local keys = config.get().view.queue.sort or { 'status', 'priority', 'due', 'order', 'id' }
|
||||
local comparators = {}
|
||||
local unknown = {}
|
||||
for _, key in ipairs(keys) do
|
||||
local cmp = sort_key_comparators[key]
|
||||
if cmp then
|
||||
table.insert(comparators, cmp)
|
||||
else
|
||||
log.warn('unknown queue sort key: ' .. key)
|
||||
table.insert(unknown, key)
|
||||
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)
|
||||
for _, cmp in ipairs(comparators) do
|
||||
local result = cmp(a, b)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue