diff --git a/interface/src/project/SettingsScheduler.tsx b/interface/src/project/SettingsScheduler.tsx
index f73cac661..4aec15e25 100644
--- a/interface/src/project/SettingsScheduler.tsx
+++ b/interface/src/project/SettingsScheduler.tsx
@@ -13,6 +13,7 @@ import {
ToggleButton,
ToggleButtonGroup,
Checkbox,
+ Grid,
TextField,
Divider
} from '@mui/material';
@@ -51,7 +52,6 @@ import { useI18nContext } from 'i18n/i18n-react';
import * as EMSESP from './api';
function makeid() {
- // TODO finish this!
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
@@ -330,7 +330,7 @@ const SettingsScheduler: FC = () => {
const addScheduleItem = () => {
setCreating(true);
setScheduleItem({
- id: '',
+ id: makeid(),
active: false,
deleted: false,
flags: 0,
@@ -342,7 +342,9 @@ const SettingsScheduler: FC = () => {
};
const updateScheduleItem = () => {
- setSchedule([...schedule.filter((si) => creating || si.o_id !== scheduleItem.o_id), scheduleItem]);
+ if (scheduleItem) {
+ setSchedule([...schedule.filter((si) => creating || si.o_id !== scheduleItem.o_id), scheduleItem]);
+ }
setScheduleItem(undefined);
};
@@ -366,7 +368,7 @@ const SettingsScheduler: FC = () => {
{LL.TIME()}
{LL.COMMAND()}
{LL.VALUE(0)}
- {LL.NAME()}
+ {LL.NAME(0)}
@@ -409,7 +411,7 @@ const SettingsScheduler: FC = () => {
if (scheduleItem) {
try {
setFieldErrors(undefined);
- await validate(schedulerItemValidation(schedule, scheduleItem.o_id), scheduleItem);
+ await validate(schedulerItemValidation(schedule, scheduleItem), scheduleItem);
updateScheduleItem();
} catch (errors: any) {
setFieldErrors(errors);
@@ -419,7 +421,7 @@ const SettingsScheduler: FC = () => {
const closeDialog = () => {
setScheduleItem(undefined);
- setFieldErrors();
+ setFieldErrors(undefined);
};
const renderEditSchedule = () => {
@@ -431,7 +433,7 @@ const SettingsScheduler: FC = () => {
{creating ? LL.ADD(0) + ' ' + LL.NEW() : LL.EDIT()} {LL.SCHEDULE()}
-
+
{
)}
+ }
+ label={LL.ACTIVE()}
+ />
- }
- label={LL.ACTIVE()}
- />
-
- {isTimer && (
-
- {LL.SCHEDULER_HELP_2()}
-
- )}
+
+
+
+ {isTimer && (
+
+ {LL.SCHEDULER_HELP_2()}
+
+ )}
+
})
});
-export const schedulerItemValidation = (schedule: ScheduleItem[], o_id: string) =>
+export const schedulerItemValidation = (schedule: ScheduleItem[], scheduleItem: ScheduleItem) =>
new Schema({
name: [
{
@@ -93,7 +93,7 @@ export const schedulerItemValidation = (schedule: ScheduleItem[], o_id: string)
pattern: /^[a-zA-Z0-9_\\.]{1,15}$/,
message: "Must be 1-15 characters: alpha numeric, '_' or '.'"
},
- ...[uniqueNameValidator(schedule, o_id)]
+ ...[uniqueNameValidator(schedule, scheduleItem.o_name)]
],
cmd: [
{ required: true, message: 'Command is required' },
@@ -101,9 +101,9 @@ export const schedulerItemValidation = (schedule: ScheduleItem[], o_id: string)
]
});
-export const uniqueNameValidator = (schedule: ScheduleItem[], o_name: string) => ({
+export const uniqueNameValidator = (schedule: ScheduleItem[], o_name?: string) => ({
validator(rule: InternalRuleItem, name: string, callback: (error?: string) => void) {
- if (name && o_name !== name && schedule.find((si) => si.name === name)) {
+ if (name && o_name && o_name !== name && schedule.find((si) => si.name === name)) {
callback('Name already in use');
} else {
callback();