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

1178.accessing null values for non admin #1406

Draft
wants to merge 6 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions src/client/app/components/ThreeDComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { selectScalingFromEntity } from '../redux/selectors/entitySelectors';
import { selectGraphState } from '../redux/slices/graphSlice';
import { ThreeDReading } from '../types/readings';
import { GraphState, MeterOrGroup } from '../types/redux/graph';
import { GroupDataByID } from '../types/redux/groups';
import { MeterDataByID } from '../types/redux/meters';
import {GroupDataByID } from '../types/redux/groups';
import {AdminMeterData, MeterDataByID } from '../types/redux/meters';
import { UnitDataById } from '../types/redux/units';
import { isValidThreeDInterval, roundTimeIntervalForFetch } from '../utils/dateRangeCompatibility';
import { AreaUnitType } from '../utils/getAreaUnitConversion';
Expand Down Expand Up @@ -157,7 +157,7 @@ function formatThreeDData(
const rateScaling = needsRateScaling ? currentSelectedRate.rate : 1;

const entity = meterOrGroup === MeterOrGroup.meters ?
meterDataById[selectedMeterOrGroupID]
meterDataById[selectedMeterOrGroupID] as AdminMeterData
:
groupDataById[selectedMeterOrGroupID];
const scaling = selectScalingFromEntity(entity, graphState.selectedAreaUnit, graphState.areaNormalization, rateScaling);
Expand Down
45 changes: 42 additions & 3 deletions src/client/app/types/redux/meters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,44 @@ export enum MeterTimeSortType {
decreasing = 'decreasing',
}

export interface MeterData {
export interface NonAdminMeterData {
id: number;
identifier: string;
name: null;
area: number;
enabled: boolean;
displayable: boolean;
meterType: string;
url: null;
timeZone: string | null;
gps: GPSPoint | null;
unitId: number;
defaultGraphicUnit: number;
note: string;
cumulative: null;
cumulativeReset: null;
cumulativeResetStart: null;
cumulativeResetEnd: null;
endOnlyTime: null;
reading: null;
readingGap: null;
readingVariation: null;
readingDuplication: null;
timeSort: null;
startTimestamp: null;
endTimestamp: null;
previousEnd: null;
areaUnit: AreaUnitType;
readingFrequency: null;
minVal: null;
maxVal: null;
minDate: null;
maxDate: null;
maxError: null;
disableChecks: null;
}

export interface AdminMeterData {
id: number;
identifier: string;
name: string;
Expand Down Expand Up @@ -59,11 +96,13 @@ export interface MeterData {
disableChecks: boolean;
}

export interface MeterDataByID extends Record<number, MeterData> { }
export type MeterData<isNonAdmin extends boolean = false> = isNonAdmin extends true ? NonAdminMeterData : AdminMeterData;

export interface MeterDataByID extends Record<number, MeterData<boolean>> {}

export interface MetersState {
hasBeenFetchedOnce: boolean;
isFetching: boolean;
submitting: number[];
byMeterID: MeterDataByID;
}
}
Loading