Skip to content

Commit c59e816

Browse files
abrilgzzdanielluo-msft
authored andcommitted
Fix last and next run date display, and prevent from editing destination target
1 parent 34bb459 commit c59e816

File tree

6 files changed

+69
-41
lines changed

6 files changed

+69
-41
lines changed

UI/web-app/src/pages/JobDetails/JobDetails.base.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -515,12 +515,27 @@ const MembershipConfiguration: React.FunctionComponent<IContentProps> = (
515515
const hoursMessage: React.CSSProperties = {
516516
fontWeight: 100
517517
}
518-
519518
const SQL_MIN_DATE = new Date('1753-01-01T00:00:00');
519+
520+
function splitDateString(value: string) {
521+
const isEmpty = value === '';
522+
if (isEmpty) {
523+
return ['-', ''];
524+
}
525+
526+
const spaceIndex = value.indexOf(' ');
527+
const datePart = value.substring(0, spaceIndex);
528+
const hoursPart = value.substring(spaceIndex + 1);
520529

521-
const lastRunFormatted = formatLastRunTime(job.lastSuccessfulRunTime, job.period);
522-
const nextRunFormatted = formatNextRunTime(job.estimatedNextRunTime, job.period, job.enabledOrNot);
530+
const parsedDate = new Date(datePart);
531+
532+
const isMinDate = parsedDate <= SQL_MIN_DATE;
533+
534+
return [isMinDate ? '' : datePart, isMinDate ? '-' : hoursPart];
535+
}
523536

537+
const lastRunDetails = splitDateString(job.lastSuccessfulRunTime);
538+
const nextRunDetails = splitDateString(job.estimatedNextRunTime);
524539

525540
return (
526541
<Stack
@@ -565,10 +580,10 @@ const MembershipConfiguration: React.FunctionComponent<IContentProps> = (
565580
/>
566581
<div className={classNames.itemData}>
567582
<Text variant="medium" block>
568-
{lastRunFormatted[0]}
583+
{lastRunDetails[0]}
569584
</Text>
570585
<Text style={hoursMessage} variant="medium" block>
571-
{lastRunFormatted[1]}
586+
{lastRunDetails[1]}
572587
</Text>
573588
</div>
574589
</Stack.Item>
@@ -580,10 +595,10 @@ const MembershipConfiguration: React.FunctionComponent<IContentProps> = (
580595
/>
581596
<div className={classNames.itemData}>
582597
<Text variant="medium" block>
583-
{nextRunFormatted[0]}
598+
{nextRunDetails[0]}
584599
</Text>
585600
<Text style={hoursMessage} variant="medium" block>
586-
{nextRunFormatted[1]}
601+
{nextRunDetails[1]}
587602
</Text>
588603
</div>
589604
</Stack.Item>

UI/web-app/src/pages/ManageMembership/ManageMembership.base.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,11 @@ export const ManageMembershipBase: React.FunctionComponent<IManageMembershipProp
318318
<></> :
319319
<div className={classNames.bottomContainer}>
320320
{currentStep !== OnboardingSteps.SelectDestination && <div className={classNames.backButtonContainer}>
321-
<DefaultButton text={strings.back} onClick={onBackStepClick} />
321+
<DefaultButton
322+
text={strings.back}
323+
onClick={onBackStepClick}
324+
disabled={isEditingExistingJob && currentStep === OnboardingSteps.RunConfiguration}
325+
/>
322326
</div>}
323327
<div className={classNames.circlesContainer}>
324328
{Array.from({ length: 4 }, (_, index) => (

UI/web-app/src/services/localization/i18n/locales/en/translations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export const strings: IStrings = {
350350
or: 'Or',
351351
and: 'And',
352352
privacyPolicy: 'Privacy Policy',
353-
hoursAgo: 'hrs ago',
354-
hoursLeft: 'hrs left',
353+
hoursAgo: '{0}, {1} hrs ago',
354+
hoursLeft: '{0}, {1} hrs left',
355355
pendingInitialSync: 'Pending initial sync',
356356
};

UI/web-app/src/services/localization/i18n/locales/es/translations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export const strings: IStrings = {
354354
or: 'O',
355355
and: 'Y',
356356
privacyPolicy: 'Política de Privacidad',
357-
hoursAgo: 'horas atrás',
358-
hoursLeft: 'horas restantes',
357+
hoursAgo: '{0}, {1} horas atrás',
358+
hoursLeft: '{0}, {1} horas restantes',
359359
pendingInitialSync: 'En espera de correr el primer sync',
360360
};

UI/web-app/src/store/jobs.api.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import {
1313
PeoplePickerPersona
1414
} from '../models';
1515
import { formatLastRunTime, formatNextRunTime } from '../utils/dateUtils';
16+
import { format } from '@fluentui/react';
17+
import { strings } from '../services/localization/i18n/locales/en/translations';
18+
import moment from 'moment';
1619

1720
export interface JobsResponse {
1821
jobs: Job[];
@@ -30,8 +33,23 @@ export const fetchJobs = createAsyncThunk<Page<Job>, PagingOptions | undefined,
3033
const mapped = jobsPage.items.map((index) => {
3134
index['enabledOrNot'] =
3235
index['status'] === SyncStatus.Idle || index['status'] === SyncStatus.InProgress ? true : false;
33-
index['lastSuccessfulRunTime'] = formatLastRunTime(index['lastSuccessfulRunTime'], index['period']).join(' ');
34-
index['estimatedNextRunTime'] = formatNextRunTime(index['estimatedNextRunTime'], index['period'], index['enabledOrNot']).join(' ');
36+
const lastRunTime = formatLastRunTime(index['lastSuccessfulRunTime']);
37+
const estimatedNextRunTime = formatNextRunTime(index['estimatedNextRunTime'], index['period'], index['enabledOrNot']);
38+
const SQLMinDateMoment = moment.utc('1753-01-01T00:00:00');
39+
40+
if(lastRunTime[0] === SQLMinDateMoment.toLocaleString()) { // Jobs that haven't run yet
41+
index['lastSuccessfulRunTime'] = "Pending initial sync";
42+
index['estimatedNextRunTime'] = "Pending initial sync";
43+
}
44+
else if (estimatedNextRunTime[0] === "-") { // Disabled jobs
45+
index['lastSuccessfulRunTime'] = `${format(strings.hoursAgo, lastRunTime[0], lastRunTime[1])}`;
46+
index['estimatedNextRunTime'] = "-";
47+
}
48+
else {
49+
index['lastSuccessfulRunTime'] = `${format(strings.hoursAgo, lastRunTime[0], lastRunTime[1])}`;
50+
index['estimatedNextRunTime'] = `${format(strings.hoursLeft, estimatedNextRunTime[0], estimatedNextRunTime[1])}`;
51+
}
52+
3553
index['arrow'] = '';
3654

3755
return index;

UI/web-app/src/utils/dateUtils.ts

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,37 @@
22
// Licensed under the MIT license.
33

44
import moment from 'moment';
5-
import { useStrings } from '../store/hooks';
5+
const SQLMinDateMoment = moment.utc('1753-01-01T00:00:00');
66

7-
export function formatLastRunTime(lastSuccessfulRunTime: string, period: number): [string, number] {
8-
// eslint-disable-next-line react-hooks/rules-of-hooks
9-
const strings = useStrings();
10-
const currentTime = moment.utc();
7+
export function formatLastRunTime(lastSuccessfulRunTime: string): [string, number] {
118
const lastRunMoment = moment.utc(lastSuccessfulRunTime);
12-
const SQL_MIN_DATE = new Date('1753-01-01T00:00:00');
13-
const hoursAgo = currentTime.diff(lastRunMoment, 'hours');
14-
const formattedDate = lastRunMoment.local().format('MM/DD/YYYY');
159

16-
if (lastRunMoment.isSame(SQL_MIN_DATE)) {
17-
return [strings.pendingInitialSync, 0];
18-
}
10+
const lastRunTime = new Date(lastSuccessfulRunTime);
11+
const today = new Date();
12+
const hoursAgo = Math.round(Math.abs(today.valueOf() - lastRunTime.valueOf()) / 36e5);
13+
14+
const formattedDate = lastRunMoment.format('MM/DD/YYYY');
1915

20-
if (hoursAgo > period) {
21-
return [formattedDate, period];
22-
} else {
23-
return [formattedDate, hoursAgo];
16+
if (lastRunMoment.isSame(SQLMinDateMoment, 'day')) {
17+
return [SQLMinDateMoment.toLocaleString(), 0];
2418
}
25-
}
2619

20+
return [formattedDate, hoursAgo];
21+
}
2722

2823
export function formatNextRunTime(lastSuccessfulRunTime: string, period: number, enabled: boolean): [string, number] {
29-
const currentTime = moment.utc();
3024
let lastRunMoment = moment.utc(lastSuccessfulRunTime);
3125
let estimatedNextRunTime = lastRunMoment.add(period, 'hours');
3226

33-
// Adjust the next run time until it is in the future
34-
while (estimatedNextRunTime.isBefore(currentTime) && enabled) {
35-
lastRunMoment = estimatedNextRunTime; // Set new base for calculation
36-
estimatedNextRunTime = lastRunMoment.add(period, 'hours');
37-
}
38-
3927
const formattedDate: string = estimatedNextRunTime.local().format('MM/DD/YYYY');
40-
const hoursLeft = Math.abs(currentTime.diff(estimatedNextRunTime, 'hours'));
28+
const lastRunTime = new Date(lastSuccessfulRunTime);
29+
const today = new Date();
30+
const hoursLeft = Math.round(Math.abs(today.valueOf() - lastRunTime.valueOf()) / 36e5);
4131

4232
if (!enabled) {
43-
return ['', 0];
44-
} else {
33+
return ['-', 0];
34+
}
35+
else {
4536
return [formattedDate, hoursLeft];
4637
}
47-
}
38+
}

0 commit comments

Comments
 (0)