From 7e6a4f74fc90ec5400c3150447dff7af2f1e7723 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Mon, 25 Mar 2019 21:24:11 -0700 Subject: [PATCH] Address inflector deprecations --- ui/app/helpers/pluralize.js | 7 ++++--- ui/app/serializers/application.js | 8 ++++---- ui/app/utils/format-duration.js | 5 +++-- ui/package.json | 1 + 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ui/app/helpers/pluralize.js b/ui/app/helpers/pluralize.js index fcab84cbe..3ec48e205 100644 --- a/ui/app/helpers/pluralize.js +++ b/ui/app/helpers/pluralize.js @@ -1,7 +1,8 @@ import Helper from '@ember/component/helper'; +import { pluralize } from 'ember-inflector'; -export function pluralize([term, count]) { - return count === 1 ? term : term.pluralize(); +export function pluralizeHelper([term, count]) { + return count === 1 ? term : pluralize(term); } -export default Helper.helper(pluralize); +export default Helper.helper(pluralizeHelper); diff --git a/ui/app/serializers/application.js b/ui/app/serializers/application.js index 8a296faea..34c6f6069 100644 --- a/ui/app/serializers/application.js +++ b/ui/app/serializers/application.js @@ -2,6 +2,7 @@ import { copy } from '@ember/object/internals'; import { get } from '@ember/object'; import { makeArray } from '@ember/array'; import JSONSerializer from 'ember-data/serializers/json'; +import { pluralize, singularize } from 'ember-inflector'; import removeRecord from '../utils/remove-record'; export default JSONSerializer.extend({ @@ -12,11 +13,10 @@ export default JSONSerializer.extend({ }, keyForRelationship(attr, relationshipType) { - const key = `${attr - .singularize() + const key = `${singularize(attr) .camelize() .capitalize()}ID`; - return relationshipType === 'hasMany' ? key.pluralize() : key; + return relationshipType === 'hasMany' ? pluralize(key) : key; }, // Modeled after the pushPayload for ember-data/serializers/rest @@ -68,6 +68,6 @@ export default JSONSerializer.extend({ }, modelNameFromPayloadKey(key) { - return key.dasherize().singularize(); + return singularize(key.dasherize()); }, }); diff --git a/ui/app/utils/format-duration.js b/ui/app/utils/format-duration.js index 11856bf44..feed6b262 100644 --- a/ui/app/utils/format-duration.js +++ b/ui/app/utils/format-duration.js @@ -1,4 +1,5 @@ import moment from 'moment'; +import { pluralize } from 'ember-inflector'; /** * Metadata for all unit types @@ -26,10 +27,10 @@ const pluralizeUnits = (amount, unit, longForm) => { if (longForm && unit.longSuffix) { // Long form means always using full words (seconds insteand of s) which means // pluralization is necessary. - suffix = amount === 1 ? unit.longSuffix : unit.longSuffix.pluralize(); + suffix = amount === 1 ? unit.longSuffix : pluralize(unit.longSuffix); } else { // In the normal case, only pluralize based on the pluralizable flag - suffix = amount === 1 || !unit.pluralizable ? unit.suffix : unit.suffix.pluralize(); + suffix = amount === 1 || !unit.pluralizable ? unit.suffix : pluralize(unit.suffix); } // A space should go between the value and the unit when the unit is a full word diff --git a/ui/package.json b/ui/package.json index 58fb276f8..08d646286 100644 --- a/ui/package.json +++ b/ui/package.json @@ -67,6 +67,7 @@ "ember-export-application-global": "^2.0.0", "ember-fetch": "^3.4.3", "ember-freestyle": "~0.10.0", + "ember-inflector": "^3.0.0", "ember-inline-svg": "^0.2.1", "ember-load-initializers": "^1.1.0", "ember-maybe-import-regenerator": "^0.1.6",