Skip to content

Commit cf5d507

Browse files
committed
PR alignment with mobile libraries
1 parent 6b7aa42 commit cf5d507

3 files changed

Lines changed: 40 additions & 8 deletions

File tree

lib/js/src/manager/screen/choiceset/ChoiceCell.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3030
* POSSIBILITY OF SUCH DAMAGE.
3131
*/
32+
import { SdlArtwork } from '../../file/filetypes/SdlArtwork.js';
3233

3334
class ChoiceCell {
3435
/**
@@ -276,6 +277,27 @@ class ChoiceCell {
276277
}
277278
return true;
278279
}
280+
281+
/**
282+
* Creates a deep copy of the object
283+
* @returns {ChoiceCell} - A deep copy of the object
284+
*/
285+
clone () {
286+
const clonedParams = Object.assign({}, this); // shallow copy. copy all objects afterwards
287+
288+
if (clonedParams._artwork !== null) {
289+
clonedParams._artwork = Object.assign(new SdlArtwork(), clonedParams._artwork);
290+
}
291+
if (clonedParams._secondaryArtwork !== null) {
292+
clonedParams._secondaryArtwork = Object.assign(new SdlArtwork(), clonedParams._secondaryArtwork);
293+
}
294+
295+
if (Array.isArray(this.getVoiceCommands())) {
296+
clonedParams._voiceCommands = this.getVoiceCommands().map(vc => vc);
297+
}
298+
299+
return Object.assign(new ChoiceCell(this.getText()), clonedParams);
300+
}
279301
}
280302

281303
// MAX ID for cells - Reasoning is from Java library: cannot use Integer.MAX_INT as the value is too high.

lib/js/src/manager/screen/choiceset/_ChoiceSetManagerBase.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,7 @@ class _ChoiceSetManagerBase extends _SubManagerBase {
136136
return false;
137137
}
138138

139-
// If we're running on a connection < RPC 7.1, we need to de-duplicate cells because presenting them will fail if we have the same cell primary text.
140-
if (choices !== null && this._lifecycleManager.getSdlMsgVersion() !== null
141-
&& (this._lifecycleManager.getSdlMsgVersion().getMajorVersion() < 7
142-
|| (this._lifecycleManager.getSdlMsgVersion().getMajorVersion() === 7 && this._lifecycleManager.getSdlMsgVersion().getMinorVersion() === 0))) {
143-
// version if 7.0.0 or lower
144-
this._addUniqueNamesToCells(choices);
145-
}
146-
const choicesToUpload = choices.map(choice => choice); // shallow copy
139+
const choicesToUpload = this._getChoicesToBeUploadedWithArray(choices);
147140

148141
this._removeChoicesFromChoices(this._preloadedChoices, choicesToUpload);
149142
this._removeChoicesFromChoices(this._pendingPreloadChoices, choicesToUpload);
@@ -553,6 +546,22 @@ class _ChoiceSetManagerBase extends _SubManagerBase {
553546
.setKeypressMode(KeypressMode.RESEND_CURRENT_ENTRY);
554547
}
555548

549+
/**
550+
* Modifies the choices names depending on SDL version
551+
* @param {ChoiceCell[]} choices - The first list of choices
552+
* @returns {ChoiceCell[]} - A deep copy of the name modified choices
553+
*/
554+
_getChoicesToBeUploadedWithArray (choices) {
555+
// If we're running on a connection < RPC 7.1, we need to de-duplicate cells because presenting them will fail if we have the same cell primary text.
556+
if (choices !== null && this._lifecycleManager.getSdlMsgVersion() !== null
557+
&& (this._lifecycleManager.getSdlMsgVersion().getMajorVersion() < 7
558+
|| (this._lifecycleManager.getSdlMsgVersion().getMajorVersion() === 7 && this._lifecycleManager.getSdlMsgVersion().getMinorVersion() === 0))) {
559+
// version if 7.0.0 or lower
560+
this._addUniqueNamesToCells(choices);
561+
}
562+
return choices.map(choice => choice.clone()); // deep copy
563+
}
564+
556565
/**
557566
* Listen for DISPLAYS capability updates
558567
* @private

tests/managers/screen/choiceset/ChoiceCellTests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = function (appClient) {
1717
Validator.assertNull(choiceCell.getTertiaryText());
1818
Validator.assertNull(choiceCell.getArtwork());
1919
Validator.assertNull(choiceCell.getSecondaryArtwork());
20+
Validator.assertNull(choiceCell._getUniqueText());
2021
});
2122

2223
it('testSettersAndGetters', function () {

0 commit comments

Comments
 (0)