From 5af69c6308dce1c9829b27cf544b03829c1c4609 Mon Sep 17 00:00:00 2001 From: Paul Bizouard Date: Wed, 1 Jun 2022 01:14:00 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20bug=20not=20displaying=20c?= =?UTF-8?q?haracteristics=20on=20multi-profiles=20models?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Roster/UnitModelsTable.js | 62 ++++++++++++++++++++---- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/src/components/Roster/UnitModelsTable.js b/src/components/Roster/UnitModelsTable.js index 23a8623..a4d3168 100644 --- a/src/components/Roster/UnitModelsTable.js +++ b/src/components/Roster/UnitModelsTable.js @@ -15,16 +15,17 @@ class UnitModelsTable extends React.Component { name: PropTypes.string.isRequired, }), categories: PropTypes.array.isRequired, - selections: PropTypes.array.isRequired, + selections: PropTypes.array, profiles: PropTypes.array.isRequired, }).isRequired, - rosterType: PropTypes.string.isRequired, + rosterType: PropTypes.string, onlyModel: PropTypes.string, showOnlyIds: PropTypes.arrayOf(PropTypes.string).isRequired, }; static defaultProps = { onlyModel: 'false', + rosterType: '' }; static getModelCharacteristic(model, profiles, characteristicName) { @@ -287,7 +288,7 @@ class UnitModelsTable extends React.Component { profile => profile.$.typeName === 'Weapon', ).length ) - return ''; + return null; return modelAttributs.$.name; }), ), @@ -303,7 +304,7 @@ class UnitModelsTable extends React.Component { profile => profile.$.typeName === 'Weapon', ).length ) - return ''; + return null; return modelAttributs.$.name; }), ), @@ -423,9 +424,53 @@ class UnitModelsTable extends React.Component { // If multiples submodels with different characteristics, do not regroup them but display new line for each if (UnitModelsTable.hasDifferentSubModelsCharacteristics(model)) { - return models.filter(selection => selection.selections).map( - selection => - selection.selections[0].selection + const modelFromCharacteristics = models.filter(selection => selection.profiles).map(profile => profile.profiles[0].profile + .filter( + subModel => + subModel.$.typeName === 'Unit' || profile.$.typeName === 'Model' + ) + .map(subModel => { + if (modelsDone.includes(subModel.$.name)) return null; + modelsDone.push(subModel.$.name); + return [ + + + + + {subModel.$.number && subModel.$.number !== '1' && ( + ({subModel.$.number}) + )} + + {this.props.onlyModel !== 'true' ? ( + + ) : ( + null + )} + + + {this.characteristicsName.map(value => + this.renderCharacteristic( + subModel, + value, + model.profiles ? model.profiles[0].profile : null, + ), + )} + , + ]; + }, this), this); + if (modelFromCharacteristics.length) return modelFromCharacteristics; + + + return models.filter(selection => selection.selections).map(selection => selection.selections[0].selection .filter( subModel => subModel.$.type === 'model' && subModel.$.entryGroupId, @@ -467,8 +512,7 @@ class UnitModelsTable extends React.Component { )} , ]; - }, this), - this, + }, this), this, ); }