Skip to content

Commit

Permalink
Merge pull request #34 from oss-slu/Rakesh_disable_changes
Browse files Browse the repository at this point in the history
Disable changes
  • Loading branch information
Rakesh-Ranga-Buram authored Dec 7, 2024
2 parents a9380c9 + e72f18e commit fb0b593
Show file tree
Hide file tree
Showing 31 changed files with 203 additions and 57 deletions.
21 changes: 10 additions & 11 deletions src/client/app/components/meters/CreateMeterModalComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import TimeZoneSelect from '../TimeZoneSelect';
import TooltipHelpComponent from '../TooltipHelpComponent';
import TooltipMarkerComponent from '../TooltipMarkerComponent';
import { selectUnitDataById } from '../../redux/api/unitsApi';
import { DisableChecksType } from '../../types/redux/units';

interface CreateMeterModalProps {
onCreateMeter?: (meterIdentifier: string) => void; // Define the type of the callback function
Expand Down Expand Up @@ -104,7 +105,8 @@ export default function CreateMeterModalComponent(props: CreateMeterModalProps):
...details,
unitId: selectedUnitId,
minVal: selectedUnit.minVal,
maxVal: selectedUnit.maxVal
maxVal: selectedUnit.maxVal,
disableChecks: selectedUnit.disableChecks
}));
}
};
Expand Down Expand Up @@ -632,17 +634,14 @@ export default function CreateMeterModalComponent(props: CreateMeterModalProps):
</FormFeedback>
</FormGroup></Col>
<Col><FormGroup>
<Label for='disableChecks'>{translate('meter.disableChecks')}</Label>
<Label for='disableChecks'>{translate('disableChecks')}</Label>
<Input id='disableChecks' name='disableChecks' type='select'
defaultValue={meterDetails.disableChecks?.toString()}
onChange={e => handleBooleanChange(e)}>
{
Object.keys(TrueFalseType).map(key =>
<option value={key} key={key}>
{translate(`TrueFalseType.${key}`)}
</option>
)
}
value={meterDetails.disableChecks}
onChange={e => handleStringChange(e)}>
{Object.keys(DisableChecksType).map(key => {
return (<option value={key} key={key} >
{translate(`DisableChecksType.${key}`)}</option>);
})}
</Input>
</FormGroup></Col>
</Row>
Expand Down
17 changes: 9 additions & 8 deletions src/client/app/components/meters/EditMeterModalComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -95,7 +95,8 @@ export default function EditMeterModalComponent(props: EditMeterModalComponentPr
...localMeterEdits,
unitId: selectedUnitId,
minVal: selectedUnit.minVal,
maxVal: selectedUnit.maxVal
maxVal: selectedUnit.maxVal,
disableChecks: selectedUnit.disableChecks
});
}
};
Expand Down Expand Up @@ -711,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>
Expand Down
19 changes: 17 additions & 2 deletions src/client/app/components/unit/CreateUnitModalComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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';
Expand Down Expand Up @@ -41,7 +41,8 @@ export default function CreateUnitModalComponent() {
// The units API expects these values to be undefined on call so that the database can assign their values.
id: -99,
minVal: MIN_VAL,
maxVal: MAX_VAL
maxVal: MAX_VAL,
disableChecks: DisableChecksType.reject_none
};

/* State */
Expand Down Expand Up @@ -298,6 +299,20 @@ export default function CreateUnitModalComponent() {
</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>
Expand Down
21 changes: 17 additions & 4 deletions src/client/app/components/unit/EditUnitModalComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useAppSelector } from '../../redux/reduxHooks';
import '../../styles/modal.css';
import { tooltipBaseStyle } from '../../styles/modalStyle';
import { TrueFalseType } from '../../types/items';
import { DisplayableType, UnitData, UnitRepresentType, UnitType } from '../../types/redux/units';
import { DisableChecksType, DisplayableType, UnitData, UnitRepresentType, UnitType } from '../../types/redux/units';
import { conversionArrow } from '../../utils/conversionArrow';
import { showErrorNotification, showSuccessNotification } from '../../utils/notifications';
import ConfirmActionModalComponent from '../ConfirmActionModalComponent';
Expand Down Expand Up @@ -196,7 +196,8 @@ export default function EditUnitModalComponent(props: EditUnitModalComponentProp
|| props.unit.suffix != state.suffix
|| props.unit.note != state.note
|| props.unit.minVal != state.minVal
|| props.unit.maxVal != state.maxVal;
|| props.unit.maxVal != state.maxVal
|| props.unit.disableChecks != state.disableChecks;
} else {
// Tell user that not going to update due to input issues.
showErrorNotification(`${translate('unit.input.error')}`);
Expand Down Expand Up @@ -429,7 +430,6 @@ export default function EditUnitModalComponent(props: EditUnitModalComponentProp
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>
Expand All @@ -443,14 +443,27 @@ export default function EditUnitModalComponent(props: EditUnitModalComponentProp
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>
<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)}
value={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('unit')}</Label>
Expand Down
4 changes: 2 additions & 2 deletions src/client/app/redux/selectors/adminSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { selectAllMeters, selectMeterById } from '../../redux/api/metersApi';
import { selectAdminPreferences } from '../../redux/slices/adminSlice';
import { ConversionData } from '../../types/redux/conversions';
import { MeterData, MeterTimeSortType } from '../../types/redux/meters';
import { UnitData, UnitType } from '../../types/redux/units';
import { DisableChecksType, UnitData, UnitType } from '../../types/redux/units';
import { unitsCompatibleWithUnit } from '../../utils/determineCompatibleUnits';
import { AreaUnitType } from '../../utils/getAreaUnitConversion';
import { noUnitTranslated, potentialGraphicUnits } from '../../utils/input';
Expand Down Expand Up @@ -312,7 +312,7 @@ export const selectDefaultCreateMeterValues = createAppSelector(
minDate: adminPreferences.defaultMeterMinimumDate,
maxDate: adminPreferences.defaultMeterMaximumDate,
maxError: adminPreferences.defaultMeterMaximumErrors,
disableChecks: adminPreferences.defaultMeterDisableChecks
disableChecks: DisableChecksType.reject_none
};
return defaultValues;
}
Expand Down
5 changes: 3 additions & 2 deletions src/client/app/redux/slices/adminSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { durationFormat } from '../../utils/durationFormat';
import { AreaUnitType } from '../../utils/getAreaUnitConversion';
import { preferencesApi } from '../api/preferencesApi';
import { selectOEDVersion } from '../../redux/api/versionApi';
import { DisableChecksType } from '../../types/redux/units';

export const defaultAdminState: AdminState = {
displayTitle: '',
Expand All @@ -34,7 +35,7 @@ export const defaultAdminState: AdminState = {
defaultMeterMaximumDate: moment(0).utc().add(5000, 'years').format('YYYY-MM-DD HH:mm:ssZ'),
defaultMeterReadingGap: 0,
defaultMeterMaximumErrors: 75,
defaultMeterDisableChecks: false,
defaultMeterDisableChecks: DisableChecksType.reject_none,
defaultHelpUrl: ''
};

Expand Down Expand Up @@ -127,7 +128,7 @@ export const adminSlice = createSlice({
state.defaultMeterMaximumErrors = action.payload;
state.submitted = false;
},
updateDefaultMeterDisableChecks: (state, action: PayloadAction<boolean>) => {
updateDefaultMeterDisableChecks: (state, action: PayloadAction<DisableChecksType>) => {
state.defaultMeterDisableChecks = action.payload;
state.submitted = false;
},
Expand Down
15 changes: 12 additions & 3 deletions src/client/app/translations/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,10 @@ const LocaleTranslationData = {
"meter.minDate": "Minimum Reading Date Check",
"meter.maxDate": "Maximum Reading Date Check",
"meter.maxError": "Maximum Number of Errors Check",
"meter.disableChecks": "Disable Checks",
"disableChecks": "Disable Checks",
"DisableChecksType.reject_bad": "No, only reject the bad reading(s)",
"DisableChecksType.reject_all": "No, reject all readings in batch",
"DisableChecksType.reject_none": "Yes, do not check values",
"meter.failed.to.create.meter": "Failed to create a meter with message: ",
"meter.failed.to.edit.meter": "Failed to edit meter with message: ",
"meter.hidden": "At least one meter is not visible to you",
Expand Down Expand Up @@ -865,7 +868,10 @@ const LocaleTranslationData = {
"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}",
"meter.disableChecks": "Disable Checks\u{26A1}",
"disableChecks": "Disable Checks\u{26A1}",
"DisableChecksType.reject_bad": "No, only reject the bad reading(s)\u{26A1}",
"DisableChecksType.reject_all": "No, reject all readings in batch\u{26A1}",
"DisableChecksType.reject_none": "Yes, do not check values\u{26A1}",
"meter.failed.to.create.meter": "Failed to create a meter with message: \u{26A1}",
"meter.failed.to.edit.meter": "Failed to edit meter with message: \u{26A1}",
"meter.hidden": "At least one meter is not visible to you\u{26A1}",
Expand Down Expand Up @@ -1387,7 +1393,10 @@ const LocaleTranslationData = {
"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",
"meter.disableChecks": "Desactivar revisiones",
"disableChecks": "Desactivar revisiones",
"DisableChecksType.reject_bad": "No, only reject the bad reading(s)\u{26A1}",
"DisableChecksType.reject_all": "No, reject all readings in batch\u{26A1}",
"DisableChecksType.reject_none": "Yes, do not check values\u{26A1}",
"meter.failed.to.create.meter": "No se pudo crear un medidor con mensaje: ",
"meter.failed.to.edit.meter": "No se pudo editar un medidor con mensaje: ",
"meter.hidden": "Al menos un medidor no es visible para tí.",
Expand Down
4 changes: 2 additions & 2 deletions src/client/app/types/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { LanguageTypes } from './redux/i18n';
import { AreaUnitType } from '../utils/getAreaUnitConversion';
import { MeterData } from './redux/meters';
import { GroupData } from './redux/groups';
import { UnitData } from './redux/units';
import { DisableChecksType, UnitData } from './redux/units';

/**
* The type of options displayed in Select components.
Expand Down Expand Up @@ -63,7 +63,7 @@ export interface PreferenceRequestItem {
defaultMeterMaximumDate: string;
defaultMeterReadingGap: number;
defaultMeterMaximumErrors: number;
defaultMeterDisableChecks: boolean;
defaultMeterDisableChecks: DisableChecksType;
defaultHelpUrl: string;
}

Expand Down
3 changes: 2 additions & 1 deletion src/client/app/types/redux/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { ChartTypes } from './graph';
import { LanguageTypes } from './i18n';
import { AreaUnitType } from '../../utils/getAreaUnitConversion';
import { DisableChecksType } from './units';


export interface AdminState {
Expand All @@ -27,6 +28,6 @@ export interface AdminState {
defaultMeterMaximumDate: string;
defaultMeterReadingGap: number;
defaultMeterMaximumErrors: number;
defaultMeterDisableChecks: boolean;
defaultMeterDisableChecks: DisableChecksType;
defaultHelpUrl: string;
}
3 changes: 2 additions & 1 deletion src/client/app/types/redux/meters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { GPSPoint } from 'utils/calibration';
// import { ActionType } from './actions';
import { AreaUnitType } from 'utils/getAreaUnitConversion';
import { DisableChecksType } from './units';

// The relates to the JS object Meter.types for the same use in src/server/models/Meter.js.
// They should be kept in sync.
Expand Down Expand Up @@ -56,7 +57,7 @@ export interface MeterData {
minDate: string;
maxDate: string;
maxError: number;
disableChecks: boolean;
disableChecks: DisableChecksType;
}

export interface MeterDataByID extends Record<number, MeterData> { }
Expand Down
6 changes: 6 additions & 0 deletions src/client/app/types/redux/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export enum UnitRepresentType {
raw = 'raw'
}

export enum DisableChecksType {
reject_bad = 'reject_bad',
reject_all = 'reject_all',
reject_none = 'reject_none'
}
export interface UnitData {
id: number;
name: string;
Expand All @@ -33,6 +38,7 @@ export interface UnitData {
note: string;
maxVal: number;
minVal: number;
disableChecks: DisableChecksType;
}

// export interface UnitEditData {
Expand Down
5 changes: 3 additions & 2 deletions src/client/app/utils/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { GPSPoint } from './calibration';
import { UnitData, DisplayableType, UnitRepresentType, UnitType, UnitDataById } from '../types/redux/units';
import { UnitData, DisplayableType, UnitRepresentType, UnitType, UnitDataById, DisableChecksType } from '../types/redux/units';
import translate from './translate';
import { LanguageTypes } from 'types/redux/i18n';
/**
Expand Down Expand Up @@ -84,7 +84,8 @@ export const NoUnit: UnitData = {
preferredDisplay: false,
note: '',
minVal: -Infinity,
maxVal: Infinity
maxVal: Infinity,
disableChecks: DisableChecksType.reject_none
};

/**
Expand Down
2 changes: 2 additions & 0 deletions src/server/migrations/1.0.0-2.0.0/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ module.exports = {
await db.none(sqlFile('../migrations/1.0.0-2.0.0/sql/cik/alter_cik_table.sql'));
await db.none(sqlFile('../migrations/1.0.0-2.0.0/sql/units/alter_units_table.sql'));
await db.none(sqlFile('../migrations/1.0.0-2.0.0/sql/units/alter_units_table_add_columns.sql'));
await db.none(sqlFile('../migrations/1.0.0-2.0.0/sql/units/add_disable_checks_types.sql'));
await db.none(sqlFile('../migrations/1.0.0-2.0.0/sql/meter/alter_meter_disable_checks.sql'));
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

-- Add a temporary column with the new type
ALTER TABLE meters
ADD COLUMN disable_checks_temp disable_checks_type NOT NULL DEFAULT 'reject_none';

-- Update the temporary column based on the current boolean values in disable_checks
UPDATE meters
SET disable_checks_temp =
CASE
WHEN disable_checks = true THEN 'reject_none'::disable_checks_type
WHEN disable_checks = false THEN 'reject_all'::disable_checks_type
END;

-- Drop the old column
ALTER TABLE meters
DROP COLUMN disable_checks;

-- Rename the temporary column to the original column name
ALTER TABLE meters
RENAME COLUMN disable_checks_temp TO disable_checks;

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */


DO $$ BEGIN
CREATE TYPE disable_checks_type AS ENUM('reject_bad', 'reject_all', 'reject_none');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
Loading

0 comments on commit fb0b593

Please sign in to comment.