Add basic listing of server schedules
This commit is contained in:
parent
f9ec96c70a
commit
32e9fb0346
21 changed files with 508 additions and 79 deletions
|
@ -23,8 +23,7 @@ rules:
|
|||
- always-multiline
|
||||
"react-hooks/rules-of-hooks":
|
||||
- error
|
||||
"react-hooks/exhaustive-deps":
|
||||
- warn
|
||||
"react-hooks/exhaustive-deps": 0
|
||||
"@typescript-eslint/explicit-function-return-type": 0
|
||||
"@typescript-eslint/explicit-member-accessibility": 0
|
||||
"@typescript-eslint/no-unused-vars": 0
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
export interface Schedule {
|
||||
id: number;
|
||||
name: string;
|
||||
cron: {
|
||||
dayOfWeek: string;
|
||||
dayOfMonth: string;
|
||||
hour: string;
|
||||
minute: string;
|
||||
};
|
||||
isActive: boolean;
|
||||
isProcessing: boolean;
|
||||
lastRunAt: Date | null;
|
||||
nextRunAt: Date | null;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
|
||||
tasks: Task[];
|
||||
}
|
||||
|
||||
export interface Task {
|
||||
id: number;
|
||||
sequenceId: number;
|
||||
action: string;
|
||||
payload: string;
|
||||
timeOffset: number;
|
||||
isQueued: boolean;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export const rawDataToServerTask = (data: any): Task => ({
|
||||
id: data.id,
|
||||
sequenceId: data.sequence_id,
|
||||
action: data.action,
|
||||
payload: data.payload,
|
||||
timeOffset: data.time_offset,
|
||||
isQueued: data.is_queued,
|
||||
createdAt: new Date(data.created_at),
|
||||
updatedAt: new Date(data.updated_at),
|
||||
});
|
||||
|
||||
export const rawDataToServerSchedule = (data: any): Schedule => ({
|
||||
id: data.id,
|
||||
name: data.name,
|
||||
cron: {
|
||||
dayOfWeek: data.cron.day_of_week,
|
||||
dayOfMonth: data.cron.day_of_month,
|
||||
hour: data.cron.hour,
|
||||
minute: data.cron.minute,
|
||||
},
|
||||
isActive: data.is_active,
|
||||
isProcessing: data.is_processing,
|
||||
lastRunAt: data.last_run_at ? new Date(data.last_run_at) : null,
|
||||
nextRunAt: data.next_run_at ? new Date(data.next_run_at) : null,
|
||||
createdAt: new Date(data.created_at),
|
||||
updatedAt: new Date(data.updated_at),
|
||||
|
||||
tasks: (data.relationships?.tasks?.data || []).map((row: any) => rawDataToServerTask(row.attributes)),
|
||||
});
|
||||
|
||||
export default (uuid: string): Promise<Schedule[]> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get(`/api/client/servers/${uuid}/schedules`, {
|
||||
params: {
|
||||
include: ['tasks'],
|
||||
},
|
||||
})
|
||||
.then(({ data }) => resolve((data.data || []).map((row: any) => rawDataToServerSchedule(row.attributes))))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
|
@ -8,7 +8,7 @@ type Props = Readonly<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElemen
|
|||
showFlashes?: string | boolean;
|
||||
}>;
|
||||
|
||||
export default ({ title, borderColor, showFlashes, children, ...props }: Props) => (
|
||||
const ContentBox = ({ title, borderColor, showFlashes, children, ...props }: Props) => (
|
||||
<div {...props}>
|
||||
{title && <h2 className={'text-neutral-300 mb-4 px-4'}>{title}</h2>}
|
||||
{showFlashes &&
|
||||
|
@ -24,3 +24,5 @@ export default ({ title, borderColor, showFlashes, children, ...props }: Props)
|
|||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
export default ContentBox;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React from 'react';
|
||||
import { Field, FieldProps } from 'formik';
|
||||
import { Field as FormikField, FieldProps } from 'formik';
|
||||
import classNames from 'classnames';
|
||||
|
||||
interface OwnProps {
|
||||
|
@ -11,8 +11,8 @@ interface OwnProps {
|
|||
|
||||
type Props = OwnProps & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'name'>;
|
||||
|
||||
export default ({ id, name, label, description, validate, className, ...props }: Props) => (
|
||||
<Field name={name} validate={validate}>
|
||||
const Field = ({ id, name, label, description, validate, className, ...props }: Props) => (
|
||||
<FormikField name={name} validate={validate}>
|
||||
{
|
||||
({ field, form: { errors, touched } }: FieldProps) => (
|
||||
<React.Fragment>
|
||||
|
@ -37,5 +37,7 @@ export default ({ id, name, label, description, validate, className, ...props }:
|
|||
</React.Fragment>
|
||||
)
|
||||
}
|
||||
</Field>
|
||||
</FormikField>
|
||||
);
|
||||
|
||||
export default Field;
|
||||
|
|
|
@ -9,7 +9,7 @@ interface Props {
|
|||
className?: string;
|
||||
}
|
||||
|
||||
export default ({ size, centered, className }: Props) => (
|
||||
const Spinner = ({ size, centered, className }: Props) => (
|
||||
centered ?
|
||||
<div className={classNames(`flex justify-center ${className}`, { 'm-20': size === 'large', 'm-6': size !== 'large' })}>
|
||||
<div
|
||||
|
@ -27,3 +27,5 @@ export default ({ size, centered, className }: Props) => (
|
|||
})}
|
||||
/>
|
||||
);
|
||||
|
||||
export default Spinner;
|
||||
|
|
|
@ -10,7 +10,7 @@ interface Props {
|
|||
backgroundOpacity?: number;
|
||||
}
|
||||
|
||||
export default ({ size, fixed, visible, backgroundOpacity }: Props) => (
|
||||
const SpinnerOverlay = ({ size, fixed, visible, backgroundOpacity }: Props) => (
|
||||
<CSSTransition timeout={150} classNames={'fade'} in={visible} unmountOnExit={true}>
|
||||
<div
|
||||
className={classNames('z-50 pin-t pin-l flex items-center justify-center w-full h-full rounded', {
|
||||
|
@ -23,3 +23,5 @@ export default ({ size, fixed, visible, backgroundOpacity }: Props) => (
|
|||
</div>
|
||||
</CSSTransition>
|
||||
);
|
||||
|
||||
export default SpinnerOverlay;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import React, { Suspense } from 'react';
|
||||
import Spinner from '@/components/elements/Spinner';
|
||||
|
||||
export default ({ children }: { children?: React.ReactNode }) => (
|
||||
const SuspenseSpinner = ({ children }: { children?: React.ReactNode }) => (
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className={'mx-4 w-3/4 mr-4 flex items-center justify-center'}>
|
||||
|
@ -12,3 +12,5 @@ export default ({ children }: { children?: React.ReactNode }) => (
|
|||
{children}
|
||||
</Suspense>
|
||||
);
|
||||
|
||||
export default SuspenseSpinner;
|
||||
|
|
|
@ -9,7 +9,7 @@ interface Props {
|
|||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export default ({ icon, title, children, className }: Props) => (
|
||||
const TitledGreyBox = ({ icon, title, children, className }: Props) => (
|
||||
<div className={`rounded shadow-md bg-neutral-700 ${className}`}>
|
||||
<div className={'bg-neutral-900 rounded-t p-3 border-b border-black'}>
|
||||
<p className={'text-sm uppercase'}>
|
||||
|
@ -21,3 +21,5 @@ export default ({ icon, title, children, className }: Props) => (
|
|||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
export default TitledGreyBox;
|
||||
|
|
|
@ -135,7 +135,7 @@ export default ({ databaseId, className, onDelete }: Props) => {
|
|||
</Modal>
|
||||
<div className={classNames('grey-row-box no-hover', className)}>
|
||||
<div className={'icon'}>
|
||||
<FontAwesomeIcon icon={faDatabase}/>
|
||||
<FontAwesomeIcon icon={faDatabase} fixedWidth={true}/>
|
||||
</div>
|
||||
<div className={'flex-1 ml-4'}>
|
||||
<p className={'text-lg'}>{database.name}</p>
|
||||
|
|
|
@ -1,3 +1,83 @@
|
|||
import React from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import getServerSchedules, { Schedule } from '@/api/server/schedules/getServerSchedules';
|
||||
import { ServerContext } from '@/state/server';
|
||||
import Spinner from '@/components/elements/Spinner';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faCalendarAlt } from '@fortawesome/free-solid-svg-icons/faCalendarAlt';
|
||||
import classNames from 'classnames';
|
||||
import format from 'date-fns/format';
|
||||
import FlashMessageRender from '@/components/FlashMessageRender';
|
||||
import { Actions, useStoreActions } from 'easy-peasy';
|
||||
import { ApplicationStore } from '@/state';
|
||||
import { httpErrorToHuman } from '@/api/http';
|
||||
|
||||
export default () => null;
|
||||
export default () => {
|
||||
const { id, uuid } = ServerContext.useStoreState(state => state.server.data!);
|
||||
const [ schedules, setSchedules ] = useState<Schedule[] | null>(null);
|
||||
|
||||
const { addError, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
||||
|
||||
useEffect(() => {
|
||||
clearFlashes('schedules');
|
||||
getServerSchedules(uuid)
|
||||
.then(schedules => setSchedules(schedules))
|
||||
.catch(error => {
|
||||
addError({ message: httpErrorToHuman(error), key: 'schedules' });
|
||||
console.error(error);
|
||||
});
|
||||
}, [ uuid, setSchedules ]);
|
||||
|
||||
return (
|
||||
<div className={'my-10 mb-6'}>
|
||||
<FlashMessageRender byKey={'schedules'} className={'mb-4'}/>
|
||||
{!schedules ?
|
||||
<Spinner size={'large'} centered={true}/>
|
||||
:
|
||||
schedules.map(schedule => (
|
||||
<Link key={schedule.id} to={`/servers/${id}/schedules/${schedule.id}`} className={'grey-row-box'}>
|
||||
<div className={'icon'}>
|
||||
<FontAwesomeIcon icon={faCalendarAlt} fixedWidth={true}/>
|
||||
</div>
|
||||
<div className={'flex-1 ml-4'}>
|
||||
<p>{schedule.name}</p>
|
||||
<p className={'text-xs text-neutral-400'}>
|
||||
Last run at: {schedule.lastRunAt ? format(schedule.lastRunAt, 'MMM Do [at] h:mma') : 'never'}
|
||||
</p>
|
||||
</div>
|
||||
<div className={'flex items-center mx-8'}>
|
||||
<div>
|
||||
<p className={'font-medium text-center'}>{schedule.cron.minute}</p>
|
||||
<p className={'text-2xs text-neutral-500 uppercase'}>Minute</p>
|
||||
</div>
|
||||
<div className={'ml-4'}>
|
||||
<p className={'font-medium text-center'}>{schedule.cron.hour}</p>
|
||||
<p className={'text-2xs text-neutral-500 uppercase'}>Hour</p>
|
||||
</div>
|
||||
<div className={'ml-4'}>
|
||||
<p className={'font-medium text-center'}>{schedule.cron.dayOfMonth}</p>
|
||||
<p className={'text-2xs text-neutral-500 uppercase'}>Day (Month)</p>
|
||||
</div>
|
||||
<div className={'ml-4'}>
|
||||
<p className={'font-medium text-center'}>*</p>
|
||||
<p className={'text-2xs text-neutral-500 uppercase'}>Month</p>
|
||||
</div>
|
||||
<div className={'ml-4'}>
|
||||
<p className={'font-medium text-center'}>{schedule.cron.dayOfWeek}</p>
|
||||
<p className={'text-2xs text-neutral-500 uppercase'}>Day (Week)</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p className={classNames('py-1 px-3 rounded text-xs uppercase', {
|
||||
'bg-green-600': schedule.isActive,
|
||||
'bg-neutral-400': !schedule.isActive,
|
||||
})}>
|
||||
{schedule.isActive ? 'Active' : 'Inactive'}
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -13,6 +13,7 @@ import { CSSTransition } from 'react-transition-group';
|
|||
import SuspenseSpinner from '@/components/elements/SuspenseSpinner';
|
||||
import FileEditContainer from '@/components/server/files/FileEditContainer';
|
||||
import SettingsContainer from '@/components/server/settings/SettingsContainer';
|
||||
import ScheduleContainer from '@/components/server/schedules/ScheduleContainer';
|
||||
|
||||
const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>) => {
|
||||
const server = ServerContext.useStoreState(state => state.server.data);
|
||||
|
@ -35,7 +36,7 @@ const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>)
|
|||
<NavLink to={`${match.url}/files`}>File Manager</NavLink>
|
||||
<NavLink to={`${match.url}/databases`}>Databases</NavLink>
|
||||
{/* <NavLink to={`${match.url}/users`}>User Management</NavLink> */}
|
||||
{/* <NavLink to={`${match.url}/schedules`}>Schedules</NavLink> */}
|
||||
<NavLink to={`${match.url}/schedules`}>Schedules</NavLink>
|
||||
<NavLink to={`${match.url}/settings`}>Settings</NavLink>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -63,7 +64,7 @@ const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>)
|
|||
/>
|
||||
<Route path={`${match.path}/databases`} component={DatabasesContainer} exact/>
|
||||
{/* <Route path={`${match.path}/users`} component={UsersContainer} exact/> */}
|
||||
{/* <Route path={`${match.path}/schedules`} component={ScheduleContainer} exact/> */}
|
||||
<Route path={`${match.path}/schedules`} component={ScheduleContainer} exact/>
|
||||
<Route path={`${match.path}/settings`} component={SettingsContainer} exact/>
|
||||
</Switch>
|
||||
</React.Fragment>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue