-
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
Conversation
create unit changes
edit unit changes
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.
Thanks to @lawsj, @mmehta2669 & @Rakesh-Ranga-Buram for working on this issue. Review and testing found it generally works but I have made several comments where issues where found. One comment that could not be easily placed into the code was:
src/server/util/compareUnits.js needs to have expectUnitToBeEquivalent updated to test min/max. src/server/test/db/unitTests.js & src/server/test/web/unitsTest.js need to be updated so it properly tests these values (and not just default values for all of them).
Please let me know if anything is not clear or you have thoughts.
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 comment
The 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.
@@ -267,6 +270,34 @@ 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 comment
The 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.
src/server/models/Unit.js
Outdated
@@ -19,7 +19,7 @@ class Unit { | |||
* @param {*} preferredDisplay True if this unit is always displayed. If not, the user needs to ask to see (for future enhancement). | |||
* @param {*} note Note about this unit. | |||
*/ | |||
constructor(id, name, identifier = name, unitRepresent, secInRate = 3600, typeOfUnit, suffix = '', displayable, preferredDisplay, note) { | |||
constructor(id, name, identifier = name, unitRepresent, secInRate = 3600, typeOfUnit, suffix = '', displayable, preferredDisplay, note, minVal, maxVal) { |
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.
This changed the signature of the unit constructor. There are a number of places where new Unit(...)
is done but was not updated. The value of min/maxVal is undefined in these cases and that is causing issues. For example, I believe that is why a number of tests are failing. The two options are:
- Give the two new parameters default values of the min/max on the create page. I think this would be okay in this case.
- Change all the calls to have the desired min/max value. This is a little safer but since I think (almost) all cases that would be changed the min/max would not matter the default would be used. Given this, either solution can be used.
I tested doing this and it fixed the failing tests after other fixes applied. On my machine without the change all the tests seem to run so I'm unsure why only 14 ran on GitHub for the PR. Hopefully that will go away but needs to be verified (or addressed if still an issue).
@@ -427,8 +427,8 @@ async function insertMeters(metersToInsert, conn) { | |||
await conn.none(query); | |||
} | |||
const conditionSet = { | |||
minVal: meter.minVal, | |||
maxVal: meter.maxVal, | |||
minVal: minVal, |
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.
I'm not sure what this is supposed to be but minVal & maxVal variables are not defined.
@@ -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, |
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.
See other comment. minVal & maxVal are undefined.
@@ -19,7 +19,7 @@ class Unit { | |||
* @param {*} preferredDisplay True if this unit is always displayed. If not, the user needs to ask to see (for future enhancement). | |||
* @param {*} note Note about this unit. |
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 JSDoc needs to be updated.
@@ -82,7 +82,9 @@ export const NoUnit: UnitData = { | |||
suffix: '', | |||
displayable: DisplayableType.none, | |||
preferredDisplay: false, | |||
note: '' | |||
note: '', | |||
minVal: -Infinity, |
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.
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.
preferredDisplay: boolean; | ||
note: string; | ||
} | ||
// export interface UnitEditData { |
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.
Since this interface seems not to be used it should be removed rather than commented out.
@@ -339,8 +339,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", |
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.
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.
@@ -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 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.
Description
This code is related to the create and edit unit changes to incorporate the max and min value checks, and also the changes to make the max and min value associated with the unit to reflect when unit is selected on meter(both create and edit).
Partly Addresses #1307
(In general, OED likes to have at least one issue associated with each pull request. Replace [issue] with the OED GitHub issue number. In the preview you will see an issue description if you hover over that number. You can create one yourself before doing this pull request. This is where details are normally given on what is being addressed. Note you should not use the word "Fixes" if it does not completely address the issue since the issue would automatically be closed on merging the pull request. In that case use "Partly Addresses #[issue].)
Type of change
(Check the ones that apply by placing an "x" instead of the space in the [ ] so it becomes [x])
Checklist
(Note what you have done by placing an "x" instead of the space in the [ ] so it becomes [x]. It is hoped you do all of them.)
Limitations
The work related to the trinary changes related to disable checks is still pending