Skip to content
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

Draft
wants to merge 16 commits into
base: development
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
edit unit changes
Joijanae Laws authored and Joijanae Laws committed Nov 26, 2024
commit 8953030322285deb35f10dcf80dc6553b28f458d
30 changes: 27 additions & 3 deletions src/client/app/components/meters/EditMeterModalComponent.tsx
Original file line number Diff line number Diff line change
@@ -67,6 +67,17 @@ export default function EditMeterModalComponent(props: EditMeterModalComponentPr

const [validMeter, setValidMeter] = useState(isValidMeter(localMeterEdits));

useEffect(() => {
Copy link
Member

Choose a reason for hiding this comment

The 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,19 @@ 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
});
}
};

// 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 +303,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 +623,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 +639,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'
35 changes: 34 additions & 1 deletion src/client/app/components/unit/EditUnitModalComponent.tsx
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ import { conversionArrow } from '../../utils/conversionArrow';
import { showErrorNotification, showSuccessNotification } from '../../utils/notifications';
import ConfirmActionModalComponent from '../ConfirmActionModalComponent';
import TooltipMarkerComponent from '../TooltipMarkerComponent';
import { MAX_VAL, MIN_VAL } from '../../redux/selectors/adminSelectors';

interface EditUnitModalComponentProps {
show: boolean;
@@ -193,7 +194,9 @@ export default function EditUnitModalComponent(props: EditUnitModalComponentProp
|| props.unit.preferredDisplay != state.preferredDisplay
|| props.unit.secInRate != state.secInRate
|| props.unit.suffix != state.suffix
|| props.unit.note != state.note;
|| props.unit.note != state.note
|| props.unit.minVal != state.minVal
|| props.unit.maxVal != state.maxVal;
} else {
// Tell user that not going to update due to input issues.
showErrorNotification(`${translate('unit.input.error')}`);
@@ -418,6 +421,36 @@ export default function EditUnitModalComponent(props: EditUnitModalComponentProp
</FormFeedback>
</FormGroup></Col>
</Row>
<Row xs='1' lg='2'>
{/* 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}
required value={state.minVal}
invalid={state?.minVal < MIN_VAL || state?.minVal > state?.maxVal} />
<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}
required value={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>
{/* Note input */}
<FormGroup>
<Label for='note'>{translate('unit')}</Label>
12 changes: 6 additions & 6 deletions src/client/app/translations/data.ts
Original file line number Diff line number Diff line change
@@ -334,8 +334,8 @@ const LocaleTranslationData = {
"meter.enabled": "Updates:",
"meter.endOnlyTime": "Only End Times:",
"meter.endTimeStamp": "End Time Stamp:",
"meter.minVal": "Minimum Reading Value Check",
"meter.maxVal": "Maximum Reading Value Check",
"minVal": "Minimum Reading Value Check",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be placed alphabetically in all languages. Also, it does not follow the key naming conventions. I know the old value was something similar to this but lets use min.value. Similar for max.

"maxVal": "Maximum Reading Value Check",
"meter.minDate": "Minimum Reading Date Check",
"meter.maxDate": "Maximum Reading Date Check",
"meter.maxError": "Maximum Number of Errors Check",
@@ -846,8 +846,8 @@ const LocaleTranslationData = {
"meter.enabled": "Mises à Jour du Mèters",
"meter.endOnlyTime": "End Only Time:\u{26A1}",
"meter.endTimeStamp": "End Time Stamp:\u{26A1}",
"meter.minVal": "Minimum Reading Value Check\u{26A1}",
"meter.maxVal": "Maximum Reading Value Check\u{26A1}",
"minVal": "Minimum Reading Value Check\u{26A1}",
"maxVal": "Maximum Reading Value Check\u{26A1}",
"meter.minDate": "Minimum Reading Date Check\u{26A1}",
"meter.maxDate": "Maximum Reading Date Check\u{26A1}",
"meter.maxError": "Maximum Number of Errors Check\u{26A1}",
@@ -1359,8 +1359,8 @@ const LocaleTranslationData = {
"meter.enabled": "Medidor activado",
"meter.endOnlyTime": "Solo tiempos finales.",
"meter.endTimeStamp": "Marca de tiempo al final:",
"meter.minVal": "Revisión del valor mínimo de lectura",
"meter.maxVal": "Revisión del valor máximo de lectura",
"minVal": "Revisión del valor mínimo de lectura",
"maxVal": "Revisión del valor máximo de lectura",
"meter.minDate": "Revisión de la fecha mínima de lectura",
"meter.maxDate": "Revisión de la fecha máxima de lectura",
"meter.maxError": "Revisión del número máximo de errores",
4 changes: 3 additions & 1 deletion src/client/app/utils/input.ts
Original file line number Diff line number Diff line change
@@ -82,7 +82,9 @@ export const NoUnit: UnitData = {
suffix: '',
displayable: DisplayableType.none,
preferredDisplay: false,
note: ''
note: '',
minVal: -Infinity,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other places use adminSelectors to get the max/min allowed. I think it makes sense to do that here if possible. My only concern is this is outside a React component but it may work fine since not altering a value.

maxVal: Infinity
};

/**
4 changes: 2 additions & 2 deletions src/server/services/csvPipeline/uploadReadings.js
Original file line number Diff line number Diff line change
@@ -189,8 +189,8 @@ async function uploadReadings(req, res, filepath, conn) {
const mapRowToModel = row => { return row; }; // STUB function to satisfy the parameter of loadCsvInput.

const conditionSet = {
minVal: meter.minVal,
maxVal: meter.maxVal,
minVal: minVal,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other comment. minVal & maxVal are undefined.

maxVal: maxVal,
minDate: meter.minDate,
maxDate: meter.maxDate,
threshold: meter.readingGap,
4 changes: 2 additions & 2 deletions src/server/services/eGauge/readEgaugeData.js
Original file line number Diff line number Diff line change
@@ -43,8 +43,8 @@ async function readEgaugeData(meter, conn) {
isEndOnly = false, //true
shouldUpdate = false,
conditionSet = {
minVal: meter.minVal,
maxVal: meter.maxVal,
minVal: minVal,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another place min/maxVal not set.

maxVal: maxVal,
minDate: meter.minDate,
maxDate: meter.maxDate,
threshold: readingGap,
4 changes: 2 additions & 2 deletions src/server/services/obvius/loadLogfileToReadings.js
Original file line number Diff line number Diff line change
@@ -113,8 +113,8 @@ async function loadLogfileToReadings(serialNumber, ipAddress, logfile, conn) {
// Unsure if previous values should not change but going to assume want the latest one sent.
shouldUpdate = true,
conditionSet = {
minVal: meter.minVal,
maxVal: meter.maxVal,
minVal: minVal,
maxVal: maxVal,
minDate: meter.minDate,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another place where min/maxVal is not set.

maxDate: meter.maxDate,
threshold: readingGap,
4 changes: 2 additions & 2 deletions src/server/services/readMamacData.js
Original file line number Diff line number Diff line change
@@ -106,8 +106,8 @@ async function readMamacData(meter, conn) {
// Previous Mamac values should not change.
shouldUpdate = false,
conditionSet = {
minVal: meter.minVal,
maxVal: meter.maxVal,
minVal: minVal,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another place min/maxVal not set.

maxVal: maxVal,
minDate: meter.minDate,
maxDate: meter.maxDate,
threshold: readingGap,
4 changes: 2 additions & 2 deletions src/server/util/insertData.js
Original file line number Diff line number Diff line change
@@ -427,8 +427,8 @@ async function insertMeters(metersToInsert, conn) {
await conn.none(query);
}
const conditionSet = {
minVal: meter.minVal,
maxVal: meter.maxVal,
minVal: minVal,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what this is supposed to be but minVal & maxVal variables are not defined.

maxVal: maxVal,
minDate: meter.minDate,
maxDate: meter.maxDate,
threshold: meter.readingGap,