e9e52e0dfe
This doesn’t include Ember Data, as we are still back on 3.12. Most changes are deprecation updates, linting fixes, and dependencies. It can be read commit-by-commit, though many of them are mechanical and skimmable. For the new linting exclusions, I’ve added them to the Tech Debt list. The decrease in test count is because linting is no longer included in ember test. There’s a new deprecation warning in the logs that can be fixed by updating Ember Power Select but when I tried that it caused it to render incorrectly, so I decided to ignore it for now and address it separately.
39 lines
1 KiB
JavaScript
39 lines
1 KiB
JavaScript
import { get, computed } from '@ember/object';
|
|
import { attr } from '@ember-data/model';
|
|
import Fragment from 'ember-data-model-fragments/fragment';
|
|
import flat from 'flat';
|
|
|
|
const { unflatten } = flat;
|
|
|
|
export default class NodeAttributes extends Fragment {
|
|
@attr() nodeAttributes;
|
|
|
|
@computed('nodeAttributes')
|
|
get attributesStructured() {
|
|
const original = this.nodeAttributes;
|
|
|
|
if (!original) {
|
|
return undefined;
|
|
}
|
|
|
|
// `unflatten` doesn't sort keys before unflattening, so manual preprocessing is necessary.
|
|
const attrs = Object.keys(original)
|
|
.sort()
|
|
.reduce((obj, key) => {
|
|
obj[key] = original[key];
|
|
return obj;
|
|
}, {});
|
|
return unflatten(attrs, { overwrite: true });
|
|
}
|
|
|
|
unknownProperty(key) {
|
|
// Returns the exact value in index 0 and the subtree in index 1
|
|
//
|
|
// ex: nodeAttrs.get('driver.docker')
|
|
// [ "1", { version: "17.05.0-ce", volumes: { enabled: "1" } } ]
|
|
if (this.attributesStructured) {
|
|
return get(this.attributesStructured, key);
|
|
}
|
|
}
|
|
}
|