From c5161887e206bb869a43952806cfbfa1d8f63c2d Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Tue, 9 May 2017 17:55:15 -0700 Subject: [PATCH 1/2] [Types] label -> name Change label to name, log a warning to console if a typeDef is registered with a label. Fixes https://github.com/nasa/openmct/issues/1568. --- API.md | 4 ++-- example/generator/plugin.js | 2 +- src/api/types/Type.js | 2 +- src/api/types/TypeRegistry.js | 22 ++++++++++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/API.md b/API.md index 619c1c6787..f2d732b9c1 100644 --- a/API.md +++ b/API.md @@ -146,7 +146,7 @@ registry. eg. ```javascript openmct.types.addType('my-type', { - label: "My Type", + name: "My Type", description: "This is a type that I added!", creatable: true }); @@ -157,7 +157,7 @@ The `addType` function accepts two arguments: for an object. * An object type specification. An object type definition supports the following attributes - * `label`: a `string` naming this object type + * `name`: a `string` naming this object type * `description`: a `string` specifying a longer-form description of this type * `initialize`: a `function` which initializes the model for new domain objects of this type. This can be used for setting default values on an object when diff --git a/example/generator/plugin.js b/example/generator/plugin.js index 07172f2641..60f4955aee 100644 --- a/example/generator/plugin.js +++ b/example/generator/plugin.js @@ -75,7 +75,7 @@ define([ }) }); openmct.types.addType("generator", { - label: "Sine Wave Generator", + name: "Sine Wave Generator", description: "For development use. Generates example streaming telemetry data using a simple sine wave algorithm.", cssClass: "icon-telemetry", creatable: true, diff --git a/src/api/types/Type.js b/src/api/types/Type.js index e837535407..6649644e71 100644 --- a/src/api/types/Type.js +++ b/src/api/types/Type.js @@ -53,7 +53,7 @@ define(function () { */ Type.prototype.toLegacyDefinition = function () { var def = {}; - def.name = this.definition.label; + def.name = this.definition.name; def.cssClass = this.definition.cssClass; def.description = this.definition.description; def.properties = this.definition.form; diff --git a/src/api/types/TypeRegistry.js b/src/api/types/TypeRegistry.js index 0e38c26be2..a307b2a5e0 100644 --- a/src/api/types/TypeRegistry.js +++ b/src/api/types/TypeRegistry.js @@ -19,6 +19,7 @@ * this source code distribution or the Licensing information page available * at runtime from the About dialog for additional information. *****************************************************************************/ +/*global console*/ define(['./Type'], function (Type) { /** @@ -52,9 +53,30 @@ define(['./Type'], function (Type) { * @memberof module:openmct.TypeRegistry# */ TypeRegistry.prototype.addType = function (typeKey, typeDef) { + this.standardizeType(typeDef); this.types[typeKey] = new Type(typeDef); }; + /** + * Takes a typeDef, standardizes it, and logs warnings about unsupported + * usage. + * @private + */ + TypeRegistry.prototype.standardizeType = function (typeDef) { + if (typeDef.label) { + console.warn( + 'DEPRECIATION WARNING typeDef: ' + typeDef.label + '. ' + + '`label` is depreciated in type definitions. Please use ' + + '`name` instead. This will cause errors in a future version ' + + 'of Open MCT. For more information, see ' + + 'https://github.com/nasa/openmct/issues/1568'); + if (!typeDef.name) { + typeDef.name = typeDef.label; + } + delete typeDef.label; + } + }; + /** * List keys for all registered types. * @method listKeys From 08a8207f643f9d668f45fd143fab73b2999f8c70 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Wed, 10 May 2017 14:39:47 -0700 Subject: [PATCH 2/2] Correct Typo, check with hasOwnProperty Update warning message with correct wording, and change check for label property such that a blank label will also trigger the deprecation warning. Addresses feedback from https://github.com/nasa/openmct/pull/1571 --- src/api/types/TypeRegistry.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/api/types/TypeRegistry.js b/src/api/types/TypeRegistry.js index a307b2a5e0..0157f23eb0 100644 --- a/src/api/types/TypeRegistry.js +++ b/src/api/types/TypeRegistry.js @@ -63,10 +63,10 @@ define(['./Type'], function (Type) { * @private */ TypeRegistry.prototype.standardizeType = function (typeDef) { - if (typeDef.label) { + if (typeDef.hasOwnProperty('label')) { console.warn( - 'DEPRECIATION WARNING typeDef: ' + typeDef.label + '. ' + - '`label` is depreciated in type definitions. Please use ' + + 'DEPRECATION WARNING typeDef: ' + typeDef.label + '. ' + + '`label` is deprecated in type definitions. Please use ' + '`name` instead. This will cause errors in a future version ' + 'of Open MCT. For more information, see ' + 'https://github.com/nasa/openmct/issues/1568');