mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 00:39:50 +03:00
update pkg, fix changes-number, sort by name(required)
This commit is contained in:
@@ -33,7 +33,7 @@ import { useI18nContext } from 'i18n/i18n-react';
|
||||
import * as EMSESP from './api';
|
||||
import SettingsCustomEntitiesDialog from './CustomEntitiesDialog';
|
||||
import { DeviceValueTypeNames, DeviceValueUOM_s } from './types';
|
||||
import type { EntityItem } from './types';
|
||||
import type { Entities, EntityItem } from './types';
|
||||
import { entityItemValidation } from './validators';
|
||||
|
||||
const CustomEntities: FC = () => {
|
||||
@@ -56,7 +56,7 @@ const CustomEntities: FC = () => {
|
||||
});
|
||||
|
||||
const { send: writeEntities } = useRequest(
|
||||
(data: { id: number; entity_ids: string[] }) => EMSESP.writeCustomEntities(data),
|
||||
(data: Entities) => EMSESP.writeCustomEntities(data),
|
||||
{ immediate: false }
|
||||
);
|
||||
|
||||
@@ -236,7 +236,11 @@ const CustomEntities: FC = () => {
|
||||
|
||||
return (
|
||||
<Table
|
||||
data={{ nodes: entities.filter((ei) => !ei.deleted) }}
|
||||
data={{
|
||||
nodes: entities
|
||||
.filter((ei) => !ei.deleted)
|
||||
.sort((a, b) => a.name.localeCompare(b.name))
|
||||
}}
|
||||
theme={entity_theme}
|
||||
layout={{ custom: true }}
|
||||
>
|
||||
@@ -295,7 +299,7 @@ const CustomEntities: FC = () => {
|
||||
onClose={onDialogClose}
|
||||
onSave={onDialogSave}
|
||||
selectedItem={selectedEntityItem}
|
||||
validator={entityItemValidation()}
|
||||
validator={entityItemValidation(entities, selectedEntityItem)}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
@@ -130,7 +130,8 @@ const CustomEntitiesDialog = ({
|
||||
<TextField
|
||||
name="value"
|
||||
label={LL.DEFAULT(0) + ' ' + LL.VALUE(0)}
|
||||
value={editItem.value}
|
||||
type="string"
|
||||
value={editItem.value as string}
|
||||
variant="outlined"
|
||||
onChange={updateFormValue}
|
||||
fullWidth
|
||||
@@ -177,7 +178,8 @@ const CustomEntitiesDialog = ({
|
||||
label={LL.ID_OF(LL.TYPE(1))}
|
||||
margin="normal"
|
||||
fullWidth
|
||||
value={editItem.type_id}
|
||||
type="string"
|
||||
value={editItem.type_id as string}
|
||||
onChange={updateFormValue}
|
||||
inputProps={{ style: { textTransform: 'uppercase' } }}
|
||||
InputProps={{
|
||||
|
||||
@@ -244,7 +244,7 @@ const Scheduler: FC = () => {
|
||||
data={{
|
||||
nodes: schedule
|
||||
.filter((si) => !si.deleted)
|
||||
.sort((a, b) => a.cmd.localeCompare(b.cmd))
|
||||
.sort((a, b) => a.name.localeCompare(b.name))
|
||||
}}
|
||||
theme={schedule_theme}
|
||||
layout={{ custom: true }}
|
||||
|
||||
@@ -133,6 +133,7 @@ export const readCustomEntities = () =>
|
||||
return (data as Entities).entities.map((ei: EntityItem) => ({
|
||||
...ei,
|
||||
o_id: ei.id,
|
||||
o_ram: ei.ram,
|
||||
o_device_id: ei.device_id,
|
||||
o_type_id: ei.type_id,
|
||||
o_offset: ei.offset,
|
||||
@@ -141,9 +142,10 @@ export const readCustomEntities = () =>
|
||||
o_value_type: ei.value_type,
|
||||
o_name: ei.name,
|
||||
o_writeable: ei.writeable,
|
||||
o_value: ei.value,
|
||||
o_deleted: ei.deleted
|
||||
}));
|
||||
}
|
||||
});
|
||||
export const writeCustomEntities = (data: { id: number; entity_ids: string[] }) =>
|
||||
export const writeCustomEntities = (data: Entities) =>
|
||||
alovaInstance.Post('/rest/customEntities', data);
|
||||
|
||||
@@ -2,7 +2,13 @@ import Schema from 'async-validator';
|
||||
import type { InternalRuleItem } from 'async-validator';
|
||||
import { IP_OR_HOSTNAME_VALIDATOR } from 'validators/shared';
|
||||
|
||||
import type { AnalogSensor, DeviceValue, ScheduleItem, Settings } from './types';
|
||||
import type {
|
||||
AnalogSensor,
|
||||
DeviceValue,
|
||||
EntityItem,
|
||||
ScheduleItem,
|
||||
Settings
|
||||
} from './types';
|
||||
|
||||
export const GPIO_VALIDATOR = {
|
||||
validator(
|
||||
@@ -297,10 +303,10 @@ export const schedulerItemValidation = (
|
||||
) =>
|
||||
new Schema({
|
||||
name: [
|
||||
{ required: true, message: 'Name is required' },
|
||||
{
|
||||
required: true,
|
||||
type: 'string',
|
||||
pattern: /^[a-zA-Z0-9_\\.]{0,15}$/,
|
||||
pattern: /^[a-zA-Z0-9_\\.]{1,15}$/,
|
||||
message: "Must be <15 characters: alpha numeric, '_' or '.'"
|
||||
},
|
||||
...[uniqueNameValidator(schedule, scheduleItem.o_name)]
|
||||
@@ -316,7 +322,27 @@ export const schedulerItemValidation = (
|
||||
]
|
||||
});
|
||||
|
||||
export const entityItemValidation = () =>
|
||||
export const uniqueCustomNameValidator = (
|
||||
entity: EntityItem[],
|
||||
o_name?: string
|
||||
) => ({
|
||||
validator(
|
||||
rule: InternalRuleItem,
|
||||
name: string,
|
||||
callback: (error?: string) => void
|
||||
) {
|
||||
if (
|
||||
(o_name === undefined || o_name !== name) &&
|
||||
entity.find((ei) => ei.name === name)
|
||||
) {
|
||||
callback('Name already in use');
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export const entityItemValidation = (entity: EntityItem[], entityItem: EntityItem) =>
|
||||
new Schema({
|
||||
name: [
|
||||
{ required: true, message: 'Name is required' },
|
||||
@@ -324,7 +350,8 @@ export const entityItemValidation = () =>
|
||||
type: 'string',
|
||||
pattern: /^[a-zA-Z0-9_\\.]{1,15}$/,
|
||||
message: "Must be <15 characters: alpha numeric, '_' or '.'"
|
||||
}
|
||||
},
|
||||
...[uniqueCustomNameValidator(entity, entityItem.o_name)]
|
||||
],
|
||||
device_id: [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user