mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 05:37:51 +00:00
Fix ID -> Id ordering bug
This commit is contained in:
parent
34346dd3d0
commit
be01094463
@ -19,6 +19,16 @@ renameObjectKey = (object, key, newKey) ->
|
|||||||
exports.getKeyName = (key) ->
|
exports.getKeyName = (key) ->
|
||||||
nameFromMap = KEY_DISPLAY_MAP[key]
|
nameFromMap = KEY_DISPLAY_MAP[key]
|
||||||
return nameFromMap if nameFromMap?
|
return nameFromMap if nameFromMap?
|
||||||
|
|
||||||
|
# Prevent modifying a value that is part of
|
||||||
|
# the map values.
|
||||||
|
# This is really an heuristic, as making sure
|
||||||
|
# the client actually refers to that value means
|
||||||
|
# converting the value to lowercase-underscore-cased
|
||||||
|
# and do the check, but that seems overkill.
|
||||||
|
if _.values(KEY_DISPLAY_MAP).indexOf(key) isnt -1
|
||||||
|
return key
|
||||||
|
|
||||||
key = key.replace('_', ' ')
|
key = key.replace('_', ' ')
|
||||||
return _.str.titleize(key)
|
return _.str.titleize(key)
|
||||||
|
|
||||||
@ -63,5 +73,5 @@ exports.getDefaultContentsOrdering = (contents) ->
|
|||||||
|
|
||||||
exports.normaliseOrdering = (ordering, contents) ->
|
exports.normaliseOrdering = (ordering, contents) ->
|
||||||
if not _.isEmpty(ordering)
|
if not _.isEmpty(ordering)
|
||||||
return _.map(ordering, _.str.titleize)
|
return _.map(ordering, exports.getKeyName)
|
||||||
return exports.getDefaultContentsOrdering(contents)
|
return exports.getDefaultContentsOrdering(contents)
|
||||||
|
@ -146,3 +146,13 @@ describe 'Table Helpers:', ->
|
|||||||
result = tableHelpers.normaliseOrdering(null, [ OBJECTS.valid ])
|
result = tableHelpers.normaliseOrdering(null, [ OBJECTS.valid ])
|
||||||
for key, value of OBJECTS.valid
|
for key, value of OBJECTS.valid
|
||||||
expect(result.indexOf(key)).to.not.equal(-1)
|
expect(result.indexOf(key)).to.not.equal(-1)
|
||||||
|
|
||||||
|
it 'should not give precendence to names from the map', ->
|
||||||
|
ordering = [ 'id', 'ip_address', 'name' ]
|
||||||
|
result = tableHelpers.normaliseOrdering(ordering, {})
|
||||||
|
expect(result).to.deep.equal([ 'ID', 'IP Address', 'Name' ])
|
||||||
|
|
||||||
|
it 'should preverse a string that is the result of a map lookup', ->
|
||||||
|
ordering = [ 'ID', 'IP Address' ]
|
||||||
|
result = tableHelpers.normaliseOrdering(ordering, {})
|
||||||
|
expect(result).to.deep.equal(ordering)
|
||||||
|
Loading…
Reference in New Issue
Block a user