github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/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).map(key => {
    10      const record = hash[key];
    11      record[propKey] = key;
    12      return record;
    13    });
    14  
    15  export default ApplicationSerializer.extend({
    16    normalize(typeHash, hash) {
    17      hash.PlainId = hash.ID;
    18  
    19      // TODO This shouldn't hardcode `csi/` as part of the ID,
    20      // but it is necessary to make the correct find request and the
    21      // payload does not contain the required information to derive
    22      // this identifier.
    23      hash.ID = `csi/${hash.ID}`;
    24  
    25      const nodes = hash.Nodes || {};
    26      const controllers = hash.Controllers || {};
    27  
    28      hash.Nodes = unmap(nodes, 'NodeID');
    29      hash.Controllers = unmap(controllers, 'NodeID');
    30  
    31      return this._super(typeHash, hash);
    32    },
    33  });