fix: added start and end time info text to educate user better around the schedule timelines (#5837)

* fix: added start and end time info text to educate user better around the schedule timelines

* fix: changed the start and endtime info text

* fix: changed the start and endtime info text

* fix: comment resolved
This commit is contained in:
SagarRajput-7 2024-09-06 11:50:02 +05:30 committed by GitHub
parent 7a10fe2b8c
commit 4eb533fff8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 153 additions and 8 deletions

View File

@ -77,6 +77,18 @@
color: var(--bg-vanilla-400); color: var(--bg-vanilla-400);
} }
} }
.formItemWithBullet {
margin-bottom: 0;
}
.scheduleTimeInfoText {
margin-top: 8px;
margin-bottom: 20px;
font-size: 12px;
font-weight: 400;
color: var(--bg-vanilla-400);
}
} }
.alert-rule-tags { .alert-rule-tags {
@ -543,5 +555,13 @@
background: var(--bg-vanilla-100); background: var(--bg-vanilla-100);
} }
} }
.scheduleTimeInfoText {
color: var(--bg-slate-300);
}
.alert-rule-info {
color: var(--bg-slate-300);
}
} }
} }

View File

@ -41,7 +41,7 @@ import {
getAlertOptionsFromIds, getAlertOptionsFromIds,
getDurationInfo, getDurationInfo,
getEndTime, getEndTime,
handleTimeConvertion, handleTimeConversion,
isScheduleRecurring, isScheduleRecurring,
recurrenceOptions, recurrenceOptions,
recurrenceOptionWithSubmenu, recurrenceOptionWithSubmenu,
@ -52,6 +52,10 @@ dayjs.locale('en');
dayjs.extend(utc); dayjs.extend(utc);
dayjs.extend(timezone); dayjs.extend(timezone);
const TIME_FORMAT = 'HH:mm';
const DATE_FORMAT = 'Do MMM YYYY';
const ORDINAL_FORMAT = 'Do';
interface PlannedDowntimeFormData { interface PlannedDowntimeFormData {
name: string; name: string;
startTime: dayjs.Dayjs | string; startTime: dayjs.Dayjs | string;
@ -105,6 +109,10 @@ export function PlannedDowntimeForm(
?.unit || 'm', ?.unit || 'm',
); );
const [formData, setFormData] = useState<PlannedDowntimeFormData>(
initialValues?.schedule as PlannedDowntimeFormData,
);
const [recurrenceType, setRecurrenceType] = useState<string | null>( const [recurrenceType, setRecurrenceType] = useState<string | null>(
(initialValues.schedule?.recurrence?.repeatType as string) || (initialValues.schedule?.recurrence?.repeatType as string) ||
recurrenceOptions.doesNotRepeat.value, recurrenceOptions.doesNotRepeat.value,
@ -131,7 +139,7 @@ export function PlannedDowntimeForm(
.filter((alert) => alert !== undefined) as string[], .filter((alert) => alert !== undefined) as string[],
name: values.name, name: values.name,
schedule: { schedule: {
startTime: handleTimeConvertion( startTime: handleTimeConversion(
values.startTime, values.startTime,
timezoneInitialValue, timezoneInitialValue,
values.timezone, values.timezone,
@ -139,7 +147,7 @@ export function PlannedDowntimeForm(
), ),
timezone: values.timezone, timezone: values.timezone,
endTime: values.endTime endTime: values.endTime
? handleTimeConvertion( ? handleTimeConversion(
values.endTime, values.endTime,
timezoneInitialValue, timezoneInitialValue,
values.timezone, values.timezone,
@ -196,14 +204,14 @@ export function PlannedDowntimeForm(
? `${values.recurrence?.duration}${durationUnit}` ? `${values.recurrence?.duration}${durationUnit}`
: undefined, : undefined,
endTime: !isEmpty(values.endTime) endTime: !isEmpty(values.endTime)
? handleTimeConvertion( ? handleTimeConversion(
values.endTime, values.endTime,
timezoneInitialValue, timezoneInitialValue,
values.timezone, values.timezone,
!isEditMode, !isEditMode,
) )
: undefined, : undefined,
startTime: handleTimeConvertion( startTime: handleTimeConversion(
values.startTime, values.startTime,
timezoneInitialValue, timezoneInitialValue,
values.timezone, values.timezone,
@ -300,6 +308,116 @@ export function PlannedDowntimeForm(
}), }),
); );
const getTimezoneFormattedTime = (
time: string | dayjs.Dayjs,
timeZone?: string,
isEditMode?: boolean,
format?: string,
): string => {
if (!time) {
return '';
}
if (!timeZone) {
return dayjs(time).format(format);
}
return dayjs(time).tz(timeZone, isEditMode).format(format);
};
const startTimeText = useMemo((): string => {
let startTime = formData?.startTime;
if (recurrenceType !== recurrenceOptions.doesNotRepeat.value) {
startTime = formData?.recurrence?.startTime || formData?.startTime || '';
}
if (!startTime) {
return '';
}
if (formData.timezone) {
startTime = handleTimeConversion(
startTime,
timezoneInitialValue,
formData?.timezone,
!isEditMode,
);
}
const daysOfWeek = formData?.recurrence?.repeatOn;
const formattedStartTime = getTimezoneFormattedTime(
startTime,
formData.timezone,
!isEditMode,
TIME_FORMAT,
);
const formattedStartDate = getTimezoneFormattedTime(
startTime,
formData.timezone,
!isEditMode,
DATE_FORMAT,
);
const ordinalFormat = getTimezoneFormattedTime(
startTime,
formData.timezone,
!isEditMode,
ORDINAL_FORMAT,
);
const formattedDaysOfWeek = daysOfWeek?.join(', ');
switch (recurrenceType) {
case 'daily':
return `Scheduled from ${formattedStartDate}, daily starting at ${formattedStartTime}.`;
case 'monthly':
return `Scheduled from ${formattedStartDate}, monthly on the ${ordinalFormat} starting at ${formattedStartTime}.`;
case 'weekly':
return `Scheduled from ${formattedStartDate}, weekly ${
formattedDaysOfWeek ? `on [${formattedDaysOfWeek}]` : ''
} starting at ${formattedStartTime}`;
default:
return `Scheduled for ${formattedStartDate} starting at ${formattedStartTime}.`;
}
}, [formData, recurrenceType, isEditMode, timezoneInitialValue]);
const endTimeText = useMemo((): string => {
let endTime = formData?.endTime;
if (recurrenceType !== recurrenceOptions.doesNotRepeat.value) {
endTime = formData?.recurrence?.endTime || '';
if (!isEditMode && !endTime) {
endTime = formData?.endTime || '';
}
}
if (!endTime) {
return '';
}
if (formData.timezone) {
endTime = handleTimeConversion(
endTime,
timezoneInitialValue,
formData?.timezone,
!isEditMode,
);
}
const formattedEndTime = getTimezoneFormattedTime(
endTime,
formData.timezone,
!isEditMode,
TIME_FORMAT,
);
const formattedEndDate = getTimezoneFormattedTime(
endTime,
formData.timezone,
!isEditMode,
DATE_FORMAT,
);
return `Scheduled to end maintenance on ${formattedEndDate} at ${formattedEndTime}.`;
}, [formData, recurrenceType, isEditMode, timezoneInitialValue]);
return ( return (
<Modal <Modal
title={ title={
@ -323,6 +441,7 @@ export function PlannedDowntimeForm(
onFinish={onFinish} onFinish={onFinish}
onValuesChange={(): void => { onValuesChange={(): void => {
setRecurrenceType(form.getFieldValue('recurrence')?.repeatType as string); setRecurrenceType(form.getFieldValue('recurrence')?.repeatType as string);
setFormData(form.getFieldsValue());
}} }}
autoComplete="off" autoComplete="off"
> >
@ -333,7 +452,7 @@ export function PlannedDowntimeForm(
label="Starts from" label="Starts from"
name="startTime" name="startTime"
rules={formValidationRules} rules={formValidationRules}
className="formItemWithBullet" className={!isEmpty(startTimeText) ? 'formItemWithBullet' : ''}
getValueProps={(value): any => ({ getValueProps={(value): any => ({
value: value ? dayjs(value).tz(timezoneInitialValue) : undefined, value: value ? dayjs(value).tz(timezoneInitialValue) : undefined,
})} })}
@ -348,6 +467,9 @@ export function PlannedDowntimeForm(
popupClassName="datePicker" popupClassName="datePicker"
/> />
</Form.Item> </Form.Item>
{!isEmpty(startTimeText) && (
<div className="scheduleTimeInfoText">{startTimeText}</div>
)}
<Form.Item <Form.Item
label="Repeats every" label="Repeats every"
name={['recurrence', 'repeatType']} name={['recurrence', 'repeatType']}
@ -411,7 +533,7 @@ export function PlannedDowntimeForm(
required: recurrenceType === recurrenceOptions.doesNotRepeat.value, required: recurrenceType === recurrenceOptions.doesNotRepeat.value,
}, },
]} ]}
className="formItemWithBullet" className={!isEmpty(endTimeText) ? 'formItemWithBullet' : ''}
getValueProps={(value): any => ({ getValueProps={(value): any => ({
value: value ? dayjs(value).tz(timezoneInitialValue) : undefined, value: value ? dayjs(value).tz(timezoneInitialValue) : undefined,
})} })}
@ -426,6 +548,9 @@ export function PlannedDowntimeForm(
popupClassName="datePicker" popupClassName="datePicker"
/> />
</Form.Item> </Form.Item>
{!isEmpty(endTimeText) && (
<div className="scheduleTimeInfoText">{endTimeText}</div>
)}
<div> <div>
<div className="alert-rule-form"> <div className="alert-rule-form">
<Typography style={{ marginBottom: 8 }}>Silence Alerts</Typography> <Typography style={{ marginBottom: 8 }}>Silence Alerts</Typography>

View File

@ -262,7 +262,7 @@ export function formatWithTimezone(
return `${parsedDate?.substring(0, 19)}${targetOffset}`; return `${parsedDate?.substring(0, 19)}${targetOffset}`;
} }
export function handleTimeConvertion( export function handleTimeConversion(
dateValue: string | dayjs.Dayjs, dateValue: string | dayjs.Dayjs,
timezoneInit?: string, timezoneInit?: string,
timezone?: string, timezone?: string,