updated DateRangePicker for Meter reports in Web UI

pull/129/head
13621160019@163.com 2022-02-27 16:32:19 +08:00
parent afc36b98ea
commit ee2968be65
12 changed files with 104 additions and 27 deletions

View File

@ -24,6 +24,7 @@ import { toast } from 'react-toastify';
import ButtonIcon from '../../common/ButtonIcon';
import { APIBaseURL } from '../../../config';
import { DateRangePicker } from 'rsuite';
import { endOfDay} from 'date-fns';
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
@ -132,8 +133,12 @@ const MeterBatch = ({ setRedirect, setRedirectUrl, t }) => {
let onReportingPeriodChange = (DateRange) => {
if(DateRange == null) {
setReportingPeriodDateRange([null, null]);
setReportingPeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setReportingPeriodDateRange([DateRange[0], DateRange[1]]);
}
};

View File

@ -30,6 +30,7 @@ import { APIBaseURL } from '../../../config';
import { periodTypeOptions } from '../common/PeriodTypeOptions';
import { comparisonTypeOptions } from '../common/ComparisonTypeOptions';
import { DateRangePicker } from 'rsuite';
import { endOfDay} from 'date-fns';
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
@ -260,19 +261,25 @@ const MeterCarbon = ({ setRedirect, setRedirectUrl, t }) => {
};
let onBasePeriodChange = (DateRange) => {
console.log(DateRange);
if(DateRange == null) {
setBasePeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setBasePeriodDateRange([DateRange[0], DateRange[1]]);
}
};
let onReportingPeriodChange = (DateRange) => {
if(DateRange == null) {
if(DateRange == null) {
setReportingPeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setReportingPeriodDateRange([DateRange[0], DateRange[1]]);
if (comparisonType === 'year-over-year') {
setBasePeriodDateRange([moment(DateRange[0]).clone().subtract(1, 'years').toDate(), moment(DateRange[1]).clone().subtract(1, 'years').toDate()]);

View File

@ -30,6 +30,7 @@ import { APIBaseURL } from '../../../config';
import { periodTypeOptions } from '../common/PeriodTypeOptions';
import { comparisonTypeOptions } from '../common/ComparisonTypeOptions';
import { DateRangePicker } from 'rsuite';
import { endOfDay} from 'date-fns';
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
@ -260,19 +261,25 @@ const MeterCost = ({ setRedirect, setRedirectUrl, t }) => {
};
let onBasePeriodChange = (DateRange) => {
console.log(DateRange);
if(DateRange == null) {
setBasePeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setBasePeriodDateRange([DateRange[0], DateRange[1]]);
}
};
let onReportingPeriodChange = (DateRange) => {
if(DateRange == null) {
if(DateRange == null) {
setReportingPeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setReportingPeriodDateRange([DateRange[0], DateRange[1]]);
if (comparisonType === 'year-over-year') {
setBasePeriodDateRange([moment(DateRange[0]).clone().subtract(1, 'years').toDate(), moment(DateRange[1]).clone().subtract(1, 'years').toDate()]);

View File

@ -30,6 +30,7 @@ import { APIBaseURL } from '../../../config';
import { periodTypeOptions } from '../common/PeriodTypeOptions';
import { comparisonTypeOptions } from '../common/ComparisonTypeOptions';
import { DateRangePicker } from 'rsuite';
import { startOfDay, endOfDay, addDays, subDays } from 'date-fns';
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
@ -263,20 +264,26 @@ const MeterEnergy = ({ setRedirect, setRedirectUrl, t }) => {
// Callback fired when value changed
let onBasePeriodChange = (DateRange) => {
console.log(DateRange);
if(DateRange == null) {
setBasePeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setBasePeriodDateRange([DateRange[0], DateRange[1]]);
}
};
// Callback fired when value changed
let onReportingPeriodChange = (DateRange) => {
if(DateRange == null) {
if(DateRange == null) {
setReportingPeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setReportingPeriodDateRange([DateRange[0], DateRange[1]]);
if (comparisonType === 'year-over-year') {
setBasePeriodDateRange([moment(DateRange[0]).clone().subtract(1, 'years').toDate(), moment(DateRange[1]).clone().subtract(1, 'years').toDate()]);
@ -296,6 +303,7 @@ const MeterEnergy = ({ setRedirect, setRedirectUrl, t }) => {
setReportingPeriodDateRange([null, null]);
};
// Handler
const handleSubmit = e => {
e.preventDefault();

View File

@ -29,6 +29,7 @@ import ButtonIcon from '../../common/ButtonIcon';
import { APIBaseURL } from '../../../config';
import { periodTypeOptions } from '../common/PeriodTypeOptions';
import { DateRangePicker } from 'rsuite';
import { endOfDay} from 'date-fns';
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
@ -239,8 +240,12 @@ const MeterSubmetersBalance = ({ setRedirect, setRedirectUrl, t }) => {
let onReportingPeriodChange = (DateRange) => {
if(DateRange == null) {
setReportingPeriodDateRange([null, null]);
setReportingPeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setReportingPeriodDateRange([DateRange[0], DateRange[1]]);
}
};

View File

@ -32,6 +32,7 @@ import { toast } from 'react-toastify';
import ButtonIcon from '../../common/ButtonIcon';
import { APIBaseURL } from '../../../config';
import { DateRangePicker } from 'rsuite';
import { endOfDay} from 'date-fns';
const MeterTracking = ({ setRedirect, setRedirectUrl, t }) => {
@ -224,8 +225,12 @@ const MeterTracking = ({ setRedirect, setRedirectUrl, t }) => {
let onReportingPeriodChange = (DateRange) => {
if(DateRange == null) {
setReportingPeriodDateRange([null, null]);
setReportingPeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setReportingPeriodDateRange([DateRange[0], DateRange[1]]);
}
};

View File

@ -26,6 +26,7 @@ import { toast } from 'react-toastify';
import ButtonIcon from '../../common/ButtonIcon';
import { APIBaseURL } from '../../../config';
import { DateRangePicker } from 'rsuite';
import { endOfDay} from 'date-fns';
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
@ -229,8 +230,12 @@ const MeterTrend = ({ setRedirect, setRedirectUrl, t }) => {
let onReportingPeriodChange = (DateRange) => {
if(DateRange == null) {
setReportingPeriodDateRange([null, null]);
setReportingPeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setReportingPeriodDateRange([DateRange[0], DateRange[1]]);
}
};

View File

@ -30,6 +30,7 @@ import { APIBaseURL } from '../../../config';
import { periodTypeOptions } from '../common/PeriodTypeOptions';
import { comparisonTypeOptions } from '../common/ComparisonTypeOptions';
import { DateRangePicker } from 'rsuite';
import { endOfDay} from 'date-fns';
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
@ -242,19 +243,25 @@ const OfflineMeterCost = ({ setRedirect, setRedirectUrl, t }) => {
};
let onBasePeriodChange = (DateRange) => {
console.log(DateRange);
if(DateRange == null) {
setBasePeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setBasePeriodDateRange([DateRange[0], DateRange[1]]);
}
};
let onReportingPeriodChange = (DateRange) => {
if(DateRange == null) {
if(DateRange == null) {
setReportingPeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setReportingPeriodDateRange([DateRange[0], DateRange[1]]);
if (comparisonType === 'year-over-year') {
setBasePeriodDateRange([moment(DateRange[0]).clone().subtract(1, 'years').toDate(), moment(DateRange[1]).clone().subtract(1, 'years').toDate()]);

View File

@ -30,6 +30,7 @@ import { APIBaseURL } from '../../../config';
import { periodTypeOptions } from '../common/PeriodTypeOptions';
import { comparisonTypeOptions } from '../common/ComparisonTypeOptions';
import { DateRangePicker } from 'rsuite';
import { endOfDay} from 'date-fns';
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
@ -242,19 +243,25 @@ const OfflineMeterEnergy = ({ setRedirect, setRedirectUrl, t }) => {
};
let onBasePeriodChange = (DateRange) => {
console.log(DateRange);
if(DateRange == null) {
setBasePeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setBasePeriodDateRange([DateRange[0], DateRange[1]]);
}
};
let onReportingPeriodChange = (DateRange) => {
if(DateRange == null) {
if(DateRange == null) {
setReportingPeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setReportingPeriodDateRange([DateRange[0], DateRange[1]]);
if (comparisonType === 'year-over-year') {
setBasePeriodDateRange([moment(DateRange[0]).clone().subtract(1, 'years').toDate(), moment(DateRange[1]).clone().subtract(1, 'years').toDate()]);

View File

@ -30,6 +30,7 @@ import { APIBaseURL } from '../../../config';
import { periodTypeOptions } from '../common/PeriodTypeOptions';
import { comparisonTypeOptions } from '../common/ComparisonTypeOptions';
import { DateRangePicker } from 'rsuite';
import { endOfDay} from 'date-fns';
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
@ -240,19 +241,25 @@ const VirtualMeterCarbon = ({ setRedirect, setRedirectUrl, t }) => {
};
let onBasePeriodChange = (DateRange) => {
console.log(DateRange);
if(DateRange == null) {
setBasePeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setBasePeriodDateRange([DateRange[0], DateRange[1]]);
}
};
let onReportingPeriodChange = (DateRange) => {
if(DateRange == null) {
if(DateRange == null) {
setReportingPeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setReportingPeriodDateRange([DateRange[0], DateRange[1]]);
if (comparisonType === 'year-over-year') {
setBasePeriodDateRange([moment(DateRange[0]).clone().subtract(1, 'years').toDate(), moment(DateRange[1]).clone().subtract(1, 'years').toDate()]);

View File

@ -30,6 +30,7 @@ import { APIBaseURL } from '../../../config';
import { periodTypeOptions } from '../common/PeriodTypeOptions';
import { comparisonTypeOptions } from '../common/ComparisonTypeOptions';
import { DateRangePicker } from 'rsuite';
import { endOfDay} from 'date-fns';
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
@ -242,19 +243,25 @@ const VirtualMeterCost = ({ setRedirect, setRedirectUrl, t }) => {
};
let onBasePeriodChange = (DateRange) => {
console.log(DateRange);
if(DateRange == null) {
setBasePeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setBasePeriodDateRange([DateRange[0], DateRange[1]]);
}
};
let onReportingPeriodChange = (DateRange) => {
if(DateRange == null) {
if(DateRange == null) {
setReportingPeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setReportingPeriodDateRange([DateRange[0], DateRange[1]]);
if (comparisonType === 'year-over-year') {
setBasePeriodDateRange([moment(DateRange[0]).clone().subtract(1, 'years').toDate(), moment(DateRange[1]).clone().subtract(1, 'years').toDate()]);

View File

@ -30,6 +30,7 @@ import { APIBaseURL } from '../../../config';
import { periodTypeOptions } from '../common/PeriodTypeOptions';
import { comparisonTypeOptions } from '../common/ComparisonTypeOptions';
import { DateRangePicker } from 'rsuite';
import { endOfDay} from 'date-fns';
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
@ -242,11 +243,13 @@ const VirtualMeterEnergy = ({ setRedirect, setRedirectUrl, t }) => {
};
let onBasePeriodChange = (DateRange) => {
console.log(DateRange);
if(DateRange == null) {
setBasePeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setBasePeriodDateRange([DateRange[0], DateRange[1]]);
}
};
@ -255,6 +258,10 @@ const VirtualMeterEnergy = ({ setRedirect, setRedirectUrl, t }) => {
if(DateRange == null) {
setReportingPeriodDateRange([null, null]);
} else {
if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') {
// if the user did not change time value, set the default time to the end of day
DateRange[1] = endOfDay(DateRange[1]);
}
setReportingPeriodDateRange([DateRange[0], DateRange[1]]);
if (comparisonType === 'year-over-year') {
setBasePeriodDateRange([moment(DateRange[0]).clone().subtract(1, 'years').toDate(), moment(DateRange[1]).clone().subtract(1, 'years').toDate()]);