-
Notifications
You must be signed in to change notification settings - Fork 318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Max min values #1396
base: development
Are you sure you want to change the base?
Max min values #1396
Changes from all commits
92afc55
8953030
4edc46d
c29b70c
a9380c9
e72f18e
fb0b593
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ import '../../styles/modal.css'; | |
import { tooltipBaseStyle } from '../../styles/modalStyle'; | ||
import { TrueFalseType } from '../../types/items'; | ||
import { MeterData, MeterTimeSortType, MeterType } from '../../types/redux/meters'; | ||
import { UnitRepresentType } from '../../types/redux/units'; | ||
import { DisableChecksType, UnitRepresentType } from '../../types/redux/units'; | ||
import { GPSPoint, isValidGPSInput } from '../../utils/calibration'; | ||
import { AreaUnitType } from '../../utils/getAreaUnitConversion'; | ||
import { getGPSString, nullToEmptyString } from '../../utils/input'; | ||
|
@@ -67,6 +67,17 @@ export default function EditMeterModalComponent(props: EditMeterModalComponentPr | |
|
||
const [validMeter, setValidMeter] = useState(isValidMeter(localMeterEdits)); | ||
|
||
useEffect(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unclear on the relationship of this useEffect and handleUnitChange. They seem to do similar work. I tried commenting this out and it did not seem to matter. It is not in create unit. I may be missing something so let me know. Also, a comment on what this is doing would be nice. For example, it is getting the min/max reading value from the unit to make that the starting value for the meter when a unit is selected. |
||
const selectedUnit = unitDataById[localMeterEdits.unitId]; | ||
if (selectedUnit) { | ||
setLocalMeterEdits(edits => ({ | ||
...edits, | ||
minVal: selectedUnit.minVal, | ||
maxVal: selectedUnit.maxVal | ||
})); | ||
} | ||
}, [localMeterEdits.unitId, unitDataById]); | ||
|
||
useEffect(() => { setValidMeter(isValidMeter(localMeterEdits)); }, [localMeterEdits]); | ||
/* End State */ | ||
|
||
|
@@ -76,6 +87,20 @@ export default function EditMeterModalComponent(props: EditMeterModalComponentPr | |
} | ||
}, [localMeterEdits.cumulative]); | ||
|
||
const handleUnitChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const selectedUnitId = Number(e.target.value); | ||
const selectedUnit = unitDataById[selectedUnitId]; | ||
if (selectedUnit) { | ||
setLocalMeterEdits({ | ||
...localMeterEdits, | ||
unitId: selectedUnitId, | ||
minVal: selectedUnit.minVal, | ||
maxVal: selectedUnit.maxVal, | ||
disableChecks: selectedUnit.disableChecks | ||
}); | ||
} | ||
}; | ||
|
||
// Save changes | ||
// Currently using the old functionality which is to compare inherited prop values to state values | ||
// If there is a difference between props and state, then a change was made | ||
|
@@ -279,7 +304,7 @@ export default function EditMeterModalComponent(props: EditMeterModalComponentPr | |
name='unitId' | ||
type='select' | ||
value={localMeterEdits.unitId} | ||
onChange={e => handleNumberChange(e)}> | ||
onChange={handleUnitChange}> | ||
{Array.from(compatibleUnits).map(unit => { | ||
return (<option value={unit.id} key={unit.id}>{unit.identifier}</option>); | ||
})} | ||
|
@@ -599,7 +624,7 @@ export default function EditMeterModalComponent(props: EditMeterModalComponentPr | |
<Row xs='1' lg='2'> | ||
{/* minVal input */} | ||
<Col><FormGroup> | ||
<Label for='minVal'>{translate('meter.minVal')}</Label> | ||
<Label for='minVal'>{translate('minVal')}</Label> | ||
<Input | ||
id='minVal' | ||
name='minVal' | ||
|
@@ -615,7 +640,7 @@ export default function EditMeterModalComponent(props: EditMeterModalComponentPr | |
</FormGroup></Col> | ||
{/* maxVal input */} | ||
<Col><FormGroup> | ||
<Label for='maxVal'>{translate('meter.maxVal')}</Label> | ||
<Label for='maxVal'>{translate('maxVal')}</Label> | ||
<Input | ||
id='maxVal' | ||
name='maxVal' | ||
|
@@ -687,16 +712,16 @@ export default function EditMeterModalComponent(props: EditMeterModalComponentPr | |
</FormGroup></Col> | ||
{/* DisableChecks input */} | ||
<Col><FormGroup> | ||
<Label for='disableChecks'>{translate('meter.disableChecks')}</Label> | ||
<Label for='disableChecks'>{translate('disableChecks')}</Label> | ||
<Input | ||
id='disableChecks' | ||
name='disableChecks' | ||
type='select' | ||
value={localMeterEdits?.disableChecks?.toString()} | ||
onChange={e => handleBooleanChange(e)} | ||
invalid={localMeterEdits?.disableChecks && localMeterEdits.unitId === -99}> | ||
{Object.keys(TrueFalseType).map(key => { | ||
return (<option value={key} key={key}>{translate(`TrueFalseType.${key}`)}</option>); | ||
value={localMeterEdits.disableChecks} | ||
onChange={e => handleStringChange(e)}> | ||
{Object.keys(DisableChecksType).map(key => { | ||
return (<option value={key} key={key} > | ||
{translate(`DisableChecksType.${key}`)}</option>); | ||
})} | ||
</Input> | ||
</FormGroup></Col> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,12 @@ import '../../styles/modal.css'; | |
import { TrueFalseType } from '../../types/items'; | ||
import TooltipMarkerComponent from '../TooltipMarkerComponent'; | ||
import TooltipHelpComponent from '../../components/TooltipHelpComponent'; | ||
import { UnitRepresentType, DisplayableType, UnitType } from '../../types/redux/units'; | ||
import { UnitRepresentType, DisplayableType, UnitType, DisableChecksType } from '../../types/redux/units'; | ||
import { tooltipBaseStyle } from '../../styles/modalStyle'; | ||
import { unitsApi } from '../../redux/api/unitsApi'; | ||
import { useTranslate } from '../../redux/componentHooks'; | ||
import { showSuccessNotification, showErrorNotification } from '../../utils/notifications'; | ||
import { MAX_VAL, MIN_VAL } from '../../redux/selectors/adminSelectors'; | ||
|
||
/** | ||
* Defines the create unit modal form | ||
|
@@ -38,7 +39,10 @@ export default function CreateUnitModalComponent() { | |
// The client code makes the id for the selected unit and default graphic unit be -99 | ||
// so it can tell it is not yet assigned and do the correct logic for that case. | ||
// The units API expects these values to be undefined on call so that the database can assign their values. | ||
id: -99 | ||
id: -99, | ||
minVal: MIN_VAL, | ||
maxVal: MAX_VAL, | ||
disableChecks: DisableChecksType.reject_none | ||
}; | ||
|
||
/* State */ | ||
|
@@ -267,6 +271,48 @@ export default function CreateUnitModalComponent() { | |
</FormFeedback> | ||
</FormGroup></Col> | ||
</Row> | ||
<Row xs='1' lg='2'> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The min/max exist on create/edit unit pages but not in UnitsDetailComponent.tsx. I think that is fine but the "Edit Unit" button on that page should become "Details/Edit Unit" to mirror meter where it both shows more info and allows editing. I could not put a comment in that file so doing here. |
||
{/* minVal input */} | ||
<Col><FormGroup> | ||
<Label for='minVal'>{translate('minVal')}</Label> | ||
<Input id='minVal' name='minVal' type='number' | ||
onChange={e => handleNumberChange(e)} | ||
min={MIN_VAL} | ||
max={state.maxVal} | ||
defaultValue={state.minVal} | ||
invalid={state?.minVal < MIN_VAL || state?.minVal > state?.maxVal} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This invalid check conditions should be added to validUnit setting so the save is disabled as done for other checks. |
||
<FormFeedback> | ||
<FormattedMessage id="error.bounds" values={{ min: MIN_VAL, max: state.maxVal }} /> | ||
</FormFeedback> | ||
</FormGroup></Col> | ||
{/* maxVal input */} | ||
<Col><FormGroup> | ||
<Label for='maxVal'>{translate('maxVal')}</Label> | ||
<Input id='maxVal' name='maxVal' type='number' | ||
onChange={e => handleNumberChange(e)} | ||
min={state.minVal} | ||
max={MAX_VAL} | ||
defaultValue={state.maxVal} | ||
invalid={state?.maxVal > MAX_VAL || state?.minVal > state?.maxVal} /> | ||
<FormFeedback> | ||
<FormattedMessage id="error.bounds" values={{ min: state.minVal, max: MAX_VAL }} /> | ||
</FormFeedback> | ||
</FormGroup></Col> | ||
</Row> | ||
<Row xs='1' lg='2'> | ||
{/* DisableChecks input */} | ||
<Col><FormGroup> | ||
<Label for='disableChecks'>{translate('disableChecks')}</Label> | ||
<Input id='disableChecks' name='disableChecks' type='select' | ||
onChange={e => handleStringChange(e)} | ||
defaultValue={state.disableChecks}> | ||
{Object.keys(DisableChecksType).map(key => { | ||
return (<option value={key} key={key} > | ||
{translate(`DisableChecksType.${key}`)}</option>); | ||
})} | ||
</Input> | ||
</FormGroup></Col> | ||
</Row> | ||
{/* Note input */} | ||
<FormGroup> | ||
<Label for='note'>{translate('note')}</Label> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change from defaultValue to value made it impossible to type in a negative value. The arrows still allow. This issue is on min, edit meter as well as edit unit.