Show "Cancel task" button on running tasks
[MAILPOET-5755]
This commit is contained in:
committed by
Ján Mikláš
parent
ef2101ef46
commit
e2c6f61ecd
@@ -85,23 +85,25 @@ function QueueStatus({ statusData }: Props): JSX.Element {
|
|||||||
/>
|
/>
|
||||||
<h5>{MailPoet.I18n.t('scheduledTasks')}</h5>
|
<h5>{MailPoet.I18n.t('scheduledTasks')}</h5>
|
||||||
<TasksList
|
<TasksList
|
||||||
showScheduledAt
|
type="scheduled"
|
||||||
tasks={status.latestTasks.filter((task) => task.status === 'scheduled')}
|
tasks={status.latestTasks.filter((task) => task.status === 'scheduled')}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<h5>{MailPoet.I18n.t('cancelledTasks')}</h5>
|
<h5>{MailPoet.I18n.t('cancelledTasks')}</h5>
|
||||||
<TasksList
|
<TasksList
|
||||||
showCancelledAt
|
type="cancelled"
|
||||||
tasks={status.latestTasks.filter((task) => task.status === 'cancelled')}
|
tasks={status.latestTasks.filter((task) => task.status === 'cancelled')}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<h5>{MailPoet.I18n.t('runningTasks')}</h5>
|
<h5>{MailPoet.I18n.t('runningTasks')}</h5>
|
||||||
<TasksList
|
<TasksList
|
||||||
|
type="running"
|
||||||
tasks={status.latestTasks.filter((task) => task.status === null)}
|
tasks={status.latestTasks.filter((task) => task.status === null)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<h5>{MailPoet.I18n.t('completedTasks')}</h5>
|
<h5>{MailPoet.I18n.t('completedTasks')}</h5>
|
||||||
<TasksList
|
<TasksList
|
||||||
|
type="completed"
|
||||||
tasks={status.latestTasks.filter((task) => task.status === 'completed')}
|
tasks={status.latestTasks.filter((task) => task.status === 'completed')}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
@@ -3,8 +3,7 @@ import parseDate from 'date-fns/parse';
|
|||||||
import { CancelTaskButton, RescheduleTaskButton } from './tasks-list-actions';
|
import { CancelTaskButton, RescheduleTaskButton } from './tasks-list-actions';
|
||||||
|
|
||||||
export type Props = {
|
export type Props = {
|
||||||
showScheduledAt: boolean;
|
type: string;
|
||||||
showCancelledAt: boolean;
|
|
||||||
task: {
|
task: {
|
||||||
id: number;
|
id: number;
|
||||||
type: string;
|
type: string;
|
||||||
@@ -23,11 +22,12 @@ export type Props = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function TasksListDataRow({
|
function TasksListDataRow({ type, task }: Props): JSX.Element {
|
||||||
showScheduledAt = false,
|
const showScheduledAt = type === 'scheduled';
|
||||||
showCancelledAt = false,
|
const showCancelledAt = type === 'cancelled';
|
||||||
task,
|
const canCancelTask = type === 'scheduled' || type === 'running';
|
||||||
}: Props): JSX.Element {
|
const canRescheduleTask = type === 'cancelled';
|
||||||
|
|
||||||
let scheduled: Date;
|
let scheduled: Date;
|
||||||
if (showScheduledAt) {
|
if (showScheduledAt) {
|
||||||
scheduled = parseDate(task.scheduledAt, 'yyyy-MM-dd HH:mm:ss', new Date());
|
scheduled = parseDate(task.scheduledAt, 'yyyy-MM-dd HH:mm:ss', new Date());
|
||||||
@@ -102,12 +102,12 @@ function TasksListDataRow({
|
|||||||
updated,
|
updated,
|
||||||
)}`}</abbr>
|
)}`}</abbr>
|
||||||
</td>
|
</td>
|
||||||
{showScheduledAt ? (
|
{canCancelTask ? (
|
||||||
<td>
|
<td>
|
||||||
<CancelTaskButton task={task} />
|
<CancelTaskButton task={task} />
|
||||||
</td>
|
</td>
|
||||||
) : null}
|
) : null}
|
||||||
{showCancelledAt ? (
|
{canRescheduleTask ? (
|
||||||
<td>
|
<td>
|
||||||
<RescheduleTaskButton task={task} />
|
<RescheduleTaskButton task={task} />
|
||||||
</td>
|
</td>
|
||||||
|
@@ -1,28 +1,25 @@
|
|||||||
import { MailPoet } from 'mailpoet';
|
import { MailPoet } from 'mailpoet';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
showScheduledAt?: boolean;
|
type: string;
|
||||||
showCancelledAt?: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function TasksListLabelsRow({
|
function TasksListLabelsRow({ type }: Props): JSX.Element {
|
||||||
showScheduledAt = false,
|
const hasAction = ['scheduled', 'running', 'cancelled'].includes(type);
|
||||||
showCancelledAt = false,
|
|
||||||
}: Props): JSX.Element {
|
|
||||||
return (
|
return (
|
||||||
<tr>
|
<tr>
|
||||||
<th className="row-title">Id</th>
|
<th className="row-title">Id</th>
|
||||||
<th className="row-title">{MailPoet.I18n.t('email')}</th>
|
<th className="row-title">{MailPoet.I18n.t('email')}</th>
|
||||||
<th className="row-title">{MailPoet.I18n.t('subscriber')}</th>
|
<th className="row-title">{MailPoet.I18n.t('subscriber')}</th>
|
||||||
<th className="row-title">{MailPoet.I18n.t('priority')}</th>
|
<th className="row-title">{MailPoet.I18n.t('priority')}</th>
|
||||||
{showScheduledAt ? (
|
{type === 'scheduled' ? (
|
||||||
<th className="row-title">{MailPoet.I18n.t('scheduledAt')}</th>
|
<th className="row-title">{MailPoet.I18n.t('scheduledAt')}</th>
|
||||||
) : null}
|
) : null}
|
||||||
{showCancelledAt ? (
|
{type === 'cancelled' ? (
|
||||||
<th className="row-title">{MailPoet.I18n.t('cancelledAt')}</th>
|
<th className="row-title">{MailPoet.I18n.t('cancelledAt')}</th>
|
||||||
) : null}
|
) : null}
|
||||||
<th className="row-title">{MailPoet.I18n.t('updatedAt')}</th>
|
<th className="row-title">{MailPoet.I18n.t('updatedAt')}</th>
|
||||||
{showScheduledAt || showCancelledAt ? (
|
{hasAction ? (
|
||||||
<th className="row-title">{MailPoet.I18n.t('action')}</th>
|
<th className="row-title">{MailPoet.I18n.t('action')}</th>
|
||||||
) : null}
|
) : null}
|
||||||
</tr>
|
</tr>
|
||||||
|
@@ -6,34 +6,27 @@ import {
|
|||||||
import { TasksListLabelsRow } from './tasks-list-labels-row';
|
import { TasksListLabelsRow } from './tasks-list-labels-row';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
showScheduledAt?: boolean;
|
|
||||||
showCancelledAt?: boolean;
|
|
||||||
tasks: TasksListLabelsRowProps['task'][];
|
tasks: TasksListLabelsRowProps['task'][];
|
||||||
|
type: string;
|
||||||
};
|
};
|
||||||
function TasksList({
|
function TasksList({ tasks, type }: Props): JSX.Element {
|
||||||
showScheduledAt = false,
|
let colsCount = 5;
|
||||||
showCancelledAt = false,
|
if (type === 'running') {
|
||||||
tasks,
|
colsCount += 1;
|
||||||
}: Props): JSX.Element {
|
}
|
||||||
const colsCount = showScheduledAt || showCancelledAt ? 7 : 5;
|
if (type === 'scheduled' || type === 'cancelled') {
|
||||||
|
colsCount += 2;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<table className="widefat fixed striped">
|
<table className="widefat fixed striped">
|
||||||
<thead>
|
<thead>
|
||||||
<TasksListLabelsRow
|
<TasksListLabelsRow type={type} />
|
||||||
showScheduledAt={showScheduledAt}
|
|
||||||
showCancelledAt={showCancelledAt}
|
|
||||||
/>
|
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{tasks.length ? (
|
{tasks.length ? (
|
||||||
tasks.map((task) => (
|
tasks.map((task) => (
|
||||||
<TasksListDataRow
|
<TasksListDataRow key={task.id} task={task} type={type} />
|
||||||
key={task.id}
|
|
||||||
task={task}
|
|
||||||
showScheduledAt={showScheduledAt}
|
|
||||||
showCancelledAt={showCancelledAt}
|
|
||||||
/>
|
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
<tr className="mailpoet-listing-no-items">
|
<tr className="mailpoet-listing-no-items">
|
||||||
@@ -42,10 +35,7 @@ function TasksList({
|
|||||||
)}
|
)}
|
||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<TasksListLabelsRow
|
<TasksListLabelsRow type={type} />
|
||||||
showScheduledAt={showScheduledAt}
|
|
||||||
showCancelledAt={showCancelledAt}
|
|
||||||
/>
|
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user