Ghost/ghost/admin/app/transforms/product-benefits.js
Rishabh Garg 46b311b561 Wired benefits section to API (#2023)
refs https://github.com/TryGhost/Team/issues/792

- updates product benefit to use `name` instead of `label` attribute for benefit text
- updates model/serializer/validator to correctly handle benefit attributes
- added `+` button for adding new labels as the enter behavior is closing the popup(needs fix)
2021-06-28 15:19:54 +05:30

34 lines
974 B
JavaScript

import ProductBenefitItem from '../models/product-benefit-item';
import Transform from '@ember-data/serializer/transform';
import {A as emberA, isArray as isEmberArray} from '@ember/array';
export default Transform.extend({
deserialize(serialized, options) {
let benefitsItems, benefitsArray;
benefitsArray = serialized || [];
benefitsItems = benefitsArray.map((itemDetails) => {
itemDetails.isSecondary = options && options.isSecondary || false;
return ProductBenefitItem.create(itemDetails);
});
return emberA(benefitsItems);
},
serialize(deserialized) {
let benefitsArray;
if (isEmberArray(deserialized)) {
benefitsArray = deserialized.map((item) => {
let name = item.get('name').trim();
return {name};
}).compact();
} else {
benefitsArray = [];
}
return benefitsArray;
}
});