Permalink
Browse files

Update unit info form to display current Unit details

Also fix form issue with using the wrong name field callback
  • Loading branch information...
markerikson committed Jan 1, 2018
1 parent 50aaf10 commit b08a2482bb2b6b990582d2bd939a901c88b185f6
Showing with 33 additions and 6 deletions.
  1. +13 −5 src/features/unitInfo/UnitInfo/UnitInfoForm.jsx
  2. +20 −1 src/features/unitInfo/unitInfoSelectors.js
@@ -13,7 +13,7 @@ import ColorPickerButton from "common/components/ColorPicker/ColorPickerButton";
import {getEntitiesSession} from "features/entities/entitySelectors";
import {selectUnitInfo} from "../unitInfoSelectors";
import {selectCurrentUnitInfo} from "../unitInfoSelectors";
import {updateUnitInfo, setUnitColor} from "../unitInfoActions";
@@ -24,7 +24,7 @@ const mapState = (state) => {
const factions = Faction.all().toRefArray();
const unitInfo = selectUnitInfo(state);
const unitInfo = selectCurrentUnitInfo(state);
return {
factions,
@@ -59,8 +59,13 @@ class UnitInfoForm extends Component {
render() {
const {unitInfo, updateUnitInfo, factions} = this.props;
const {name, affiliation, color} = unitInfo;
const {unitInfo, factions} = this.props;
const isDisplayingUnit = Boolean(unitInfo);
let name = "", affiliation = null, color = null;
if(isDisplayingUnit) {
({name, affiliation, color} = unitInfo);
}
const displayFactions = factions.map(faction => {
return {
@@ -77,12 +82,13 @@ class UnitInfoForm extends Component {
<FormEditWrapper
singleValue={true}
value={ {name} }
onChange={updateUnitInfo}
onChange={this.onNameChanged}
passIsEditing={false}
>
<input
placeholder="Name"
name="name"
disabled={!isDisplayingUnit}
/>
</FormEditWrapper>
</Form.Field>
@@ -94,13 +100,15 @@ class UnitInfoForm extends Component {
selection
options={displayFactions}
value={affiliation}
disabled={!isDisplayingUnit}
onChange={this.onAffiliationChanged}
/>
</Form.Field>
<Form.Field name="color">
<label>Color</label>
<ColorPickerButton
value={color}
disabled={!isDisplayingUnit}
onClick={this.onColorClicked}
/>
</Form.Field>
@@ -1,2 +1,21 @@
import {createSelector} from "reselect";
import {getEntitiesSession} from "features/entities/entitySelectors";
export const selectUnitInfo = state => state.unitInfo;
export const selectUnitInfo = state => state.unitInfo;
export const selectCurrentUnitInfo = createSelector(
getEntitiesSession,
(session) => {
const {Unit} = session;
const currentUnitModel = Unit.all().first();
let currentUnitInfo = null;
if(currentUnitModel) {
currentUnitInfo = currentUnitModel.ref;
}
return currentUnitInfo;
}
)

0 comments on commit b08a248

Please sign in to comment.