github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/app/serializers/plugin.js (about) 1 import ApplicationSerializer from './application'; 2 3 // Convert a map[string]interface{} into an array of objects 4 // where the key becomes a property at propKey. 5 // This is destructive. The original object is mutated to avoid 6 // excessive copies of the originals which would otherwise just 7 // be garbage collected. 8 const unmap = (hash, propKey) => 9 Object.keys(hash) 10 .sort() 11 .map(key => { 12 const record = hash[key]; 13 record[propKey] = key; 14 return record; 15 }); 16 17 export default class Plugin extends ApplicationSerializer { 18 normalize(typeHash, hash) { 19 hash.PlainId = hash.ID; 20 21 // TODO This shouldn't hardcode `csi/` as part of the ID, 22 // but it is necessary to make the correct find request and the 23 // payload does not contain the required information to derive 24 // this identifier. 25 hash.ID = `csi/${hash.ID}`; 26 27 const nodes = hash.Nodes || {}; 28 const controllers = hash.Controllers || {}; 29 30 hash.Nodes = unmap(nodes, 'NodeID'); 31 hash.Controllers = unmap(controllers, 'NodeID'); 32 33 return super.normalize(typeHash, hash); 34 } 35 }