Scheduler with type "Immediate", click Execute does not run the command

Fixes #3092
This commit is contained in:
proddy
2026-05-25 12:28:42 +02:00
parent a406d6d911
commit ace071e974
8 changed files with 78 additions and 155 deletions

View File

@@ -297,10 +297,12 @@ const Scheduler = () => {
{tableList.map((si: ScheduleItem) => (
<Row key={si.id} item={si} onClick={() => editScheduleItem(si)}>
<Cell stiff>
<CircleIcon
color={si.active ? 'success' : 'error'}
sx={{ fontSize: ICON_SIZE, verticalAlign: 'middle' }}
/>
{si.flags !== ScheduleFlag.SCHEDULE_IMMEDIATE && (
<CircleIcon
color={si.active ? 'success' : 'error'}
sx={{ fontSize: ICON_SIZE, verticalAlign: 'middle' }}
/>
)}
</Cell>
<Cell stiff>
<Stack spacing={0.5} direction="row">

View File

@@ -1,4 +1,5 @@
import { useEffect, useState } from 'react';
import { toast } from 'react-toastify';
import AddIcon from '@mui/icons-material/Add';
import CancelIcon from '@mui/icons-material/Cancel';
@@ -20,7 +21,9 @@ import {
Typography
} from '@mui/material';
import { callAction } from '@/api/app';
import { dialogStyle } from 'CustomTheme';
import { useRequest } from 'alova/client';
import type Schema from 'async-validator';
import type { ValidateFieldsError } from 'async-validator';
import { BlockFormControlLabel, ValidatedTextField } from 'components';
@@ -128,8 +131,15 @@ const SchedulerDialog = ({
await handleSave(editItem);
};
const saveandactivate = async () => {
await handleSave({ ...editItem, active: true });
const { send: executeSchedule } = useRequest(
(id: string) => callAction({ action: 'executeSchedule', param: id }),
{ immediate: false }
).onError((error) => {
toast.error(String(error.error?.message || 'An error occurred'));
});
const execute = async () => {
await executeSchedule(editItem.name);
};
const remove = () => {
@@ -351,7 +361,7 @@ const SchedulerDialog = ({
<ValidatedTextField
fieldErrors={fieldErrors || {}}
name="name"
label={LL.NAME(0) + ' (' + LL.OPTIONAL() + ')'}
label={LL.NAME(0)}
value={editItem.name}
fullWidth
margin="normal"
@@ -388,11 +398,11 @@ const SchedulerDialog = ({
>
{creating ? LL.ADD(0) : LL.UPDATE()}
</Button>
{isImmediateSchedule && editItem.cmd !== '' && (
{isImmediateSchedule && !creating && editItem.cmd !== '' && (
<Button
startIcon={<PlayArrowIcon />}
variant="outlined"
onClick={saveandactivate}
onClick={execute}
color="success"
>
{LL.EXECUTE()}

View File

@@ -348,14 +348,14 @@ export enum DeviceEntityMask {
}
export interface ScheduleItem {
id: number; // unique index
id: number; // unique index for table
active: boolean;
deleted?: boolean;
flags: number;
time: string; // also used for Condition and On Change
cmd: string;
value: string;
name: string; // can be empty
name: string;
o_id?: number;
o_active?: boolean;
o_deleted?: boolean;

View File

@@ -232,7 +232,11 @@ export const schedulerItemValidation = (
scheduleItem: ScheduleItem
) =>
new Schema({
name: [NAME_PATTERN, uniqueNameValidator(schedule, scheduleItem.o_name)],
name: [
{ required: true, message: 'Name is required' },
NAME_PATTERN_REQUIRED,
uniqueNameValidator(schedule, scheduleItem.o_name)
],
cmd: [
{ required: true, message: 'Command is required' },
{