feat(edge/updates): schedule time changes [EE-5975] (#10458)

pull/10665/head
Chaim Lev-Ari 1 year ago committed by GitHub
parent 436da01bce
commit ad5a17ac34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -41,16 +41,16 @@ export function isoDateFromTimestamp(timestamp) {
return moment.unix(timestamp).format(TIME_FORMAT); return moment.unix(timestamp).format(TIME_FORMAT);
} }
export function isoDate(date) { export function isoDate(date, format = TIME_FORMAT) {
return moment(date).format(TIME_FORMAT); return moment(date).format(format);
} }
export function parseIsoDate(date) { export function parseIsoDate(date, format = TIME_FORMAT) {
return moment(date, TIME_FORMAT).toDate(); return moment(date, format).toDate();
} }
export function formatDate(date, strFormat = 'YYYY-MM-DD HH:mm:ss Z') { export function formatDate(date, strFormat = 'YYYY-MM-DD HH:mm:ss Z', outFormat = TIME_FORMAT) {
return moment(date, strFormat).format(TIME_FORMAT); return moment(date, strFormat).format(outFormat);
} }
export function getPairKey(pair, separator) { export function getPairKey(pair, separator) {

@ -1,5 +1,12 @@
import { formatDate } from '@/portainer/filters/filters';
import { FORMAT } from '../../common/ScheduledTimeField';
import { columnHelper } from './helper'; import { columnHelper } from './helper';
export const scheduledTime = columnHelper.accessor('scheduledTime', { export const scheduledTime = columnHelper.accessor('scheduledTime', {
header: 'Scheduled Time & Date', header: 'Scheduled Time & Date',
// make sure the value has the right format
cell: ({ getValue }) => formatDate(getValue(), FORMAT, FORMAT),
id: 'time',
}); });

@ -20,11 +20,13 @@ interface Props {
disabled?: boolean; disabled?: boolean;
} }
export const FORMAT = 'YYYY-MM-DD HH:mm';
export function ScheduledTimeField({ disabled }: Props) { export function ScheduledTimeField({ disabled }: Props) {
const [{ name, value }, { error }, { setValue }] = const [{ name, value }, { error }, { setValue }] =
useField<FormValues['scheduledTime']>('scheduledTime'); useField<FormValues['scheduledTime']>('scheduledTime');
const dateValue = useMemo(() => parseIsoDate(value), [value]); const dateValue = useMemo(() => parseIsoDate(value, FORMAT), [value]);
if (!value) { if (!value) {
return null; return null;
@ -35,12 +37,12 @@ export function ScheduledTimeField({ disabled }: Props) {
<FormControl label="Schedule date & time" errors={error}> <FormControl label="Schedule date & time" errors={error}>
{!disabled ? ( {!disabled ? (
<DateTimePicker <DateTimePicker
format="y-MM-dd HH:mm:ss" format="y-MM-dd HH:mm"
className="form-control [&>div]:border-0" className="form-control [&>div]:border-0"
onChange={(date) => { onChange={(date) => {
const dateToSave = const dateToSave =
date || new Date(Date.now() + 24 * 60 * 60 * 1000); date || new Date(Date.now() + 24 * 60 * 60 * 1000);
setValue(isoDate(dateToSave.valueOf())); setValue(isoDate(dateToSave.valueOf(), FORMAT));
}} }}
name={name} name={name}
value={dateValue} value={dateValue}
@ -72,16 +74,16 @@ export function timeValidation() {
) )
.test( .test(
'validDate', 'validDate',
`Scheduled time must be bigger then ${isoDate( `Scheduled time must be bigger then ${
Date.now() - 24 * 60 * 60 * 1000 (isoDate(Date.now() - 24 * 60 * 60 * 1000), FORMAT)
)}`, }`,
(value) => (value) =>
parseIsoDate(value).valueOf() > Date.now() - 24 * 60 * 60 * 1000 parseIsoDate(value).valueOf() > Date.now() - 24 * 60 * 60 * 1000
); );
} }
export function defaultValue() { export function defaultValue() {
return isoDate(Date.now() + 24 * 60 * 60 * 1000); return isoDate(Date.now(), FORMAT);
} }
function isValidDate(date: Date) { function isValidDate(date: Date) {

Loading…
Cancel
Save