mirror of https://github.com/portainer/portainer
feat(edge/updates): schedule time changes [EE-5975] (#10458)
parent
436da01bce
commit
ad5a17ac34
|
@ -41,16 +41,16 @@ export function isoDateFromTimestamp(timestamp) {
|
|||
return moment.unix(timestamp).format(TIME_FORMAT);
|
||||
}
|
||||
|
||||
export function isoDate(date) {
|
||||
return moment(date).format(TIME_FORMAT);
|
||||
export function isoDate(date, format = TIME_FORMAT) {
|
||||
return moment(date).format(format);
|
||||
}
|
||||
|
||||
export function parseIsoDate(date) {
|
||||
return moment(date, TIME_FORMAT).toDate();
|
||||
export function parseIsoDate(date, format = TIME_FORMAT) {
|
||||
return moment(date, format).toDate();
|
||||
}
|
||||
|
||||
export function formatDate(date, strFormat = 'YYYY-MM-DD HH:mm:ss Z') {
|
||||
return moment(date, strFormat).format(TIME_FORMAT);
|
||||
export function formatDate(date, strFormat = 'YYYY-MM-DD HH:mm:ss Z', outFormat = TIME_FORMAT) {
|
||||
return moment(date, strFormat).format(outFormat);
|
||||
}
|
||||
|
||||
export function getPairKey(pair, separator) {
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
import { formatDate } from '@/portainer/filters/filters';
|
||||
|
||||
import { FORMAT } from '../../common/ScheduledTimeField';
|
||||
|
||||
import { columnHelper } from './helper';
|
||||
|
||||
export const scheduledTime = columnHelper.accessor('scheduledTime', {
|
||||
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;
|
||||
}
|
||||
|
||||
export const FORMAT = 'YYYY-MM-DD HH:mm';
|
||||
|
||||
export function ScheduledTimeField({ disabled }: Props) {
|
||||
const [{ name, value }, { error }, { setValue }] =
|
||||
useField<FormValues['scheduledTime']>('scheduledTime');
|
||||
|
||||
const dateValue = useMemo(() => parseIsoDate(value), [value]);
|
||||
const dateValue = useMemo(() => parseIsoDate(value, FORMAT), [value]);
|
||||
|
||||
if (!value) {
|
||||
return null;
|
||||
|
@ -35,12 +37,12 @@ export function ScheduledTimeField({ disabled }: Props) {
|
|||
<FormControl label="Schedule date & time" errors={error}>
|
||||
{!disabled ? (
|
||||
<DateTimePicker
|
||||
format="y-MM-dd HH:mm:ss"
|
||||
format="y-MM-dd HH:mm"
|
||||
className="form-control [&>div]:border-0"
|
||||
onChange={(date) => {
|
||||
const dateToSave =
|
||||
date || new Date(Date.now() + 24 * 60 * 60 * 1000);
|
||||
setValue(isoDate(dateToSave.valueOf()));
|
||||
setValue(isoDate(dateToSave.valueOf(), FORMAT));
|
||||
}}
|
||||
name={name}
|
||||
value={dateValue}
|
||||
|
@ -72,16 +74,16 @@ export function timeValidation() {
|
|||
)
|
||||
.test(
|
||||
'validDate',
|
||||
`Scheduled time must be bigger then ${isoDate(
|
||||
Date.now() - 24 * 60 * 60 * 1000
|
||||
)}`,
|
||||
`Scheduled time must be bigger then ${
|
||||
(isoDate(Date.now() - 24 * 60 * 60 * 1000), FORMAT)
|
||||
}`,
|
||||
(value) =>
|
||||
parseIsoDate(value).valueOf() > Date.now() - 24 * 60 * 60 * 1000
|
||||
);
|
||||
}
|
||||
|
||||
export function defaultValue() {
|
||||
return isoDate(Date.now() + 24 * 60 * 60 * 1000);
|
||||
return isoDate(Date.now(), FORMAT);
|
||||
}
|
||||
|
||||
function isValidDate(date: Date) {
|
||||
|
|
Loading…
Reference in New Issue