mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
update pkg, fix changes-number, sort by name(required)
This commit is contained in:
@@ -30,7 +30,7 @@
|
|||||||
"@mui/material": "^5.15.20",
|
"@mui/material": "^5.15.20",
|
||||||
"@table-library/react-table-library": "4.1.7",
|
"@table-library/react-table-library": "4.1.7",
|
||||||
"@types/lodash-es": "^4.17.12",
|
"@types/lodash-es": "^4.17.12",
|
||||||
"@types/node": "^20.14.7",
|
"@types/node": "^20.14.8",
|
||||||
"@types/react": "^18.3.3",
|
"@types/react": "^18.3.3",
|
||||||
"@types/react-dom": "^18.3.0",
|
"@types/react-dom": "^18.3.0",
|
||||||
"@types/react-router-dom": "^5.3.3",
|
"@types/react-router-dom": "^5.3.3",
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import { useI18nContext } from 'i18n/i18n-react';
|
|||||||
import * as EMSESP from './api';
|
import * as EMSESP from './api';
|
||||||
import SettingsCustomEntitiesDialog from './CustomEntitiesDialog';
|
import SettingsCustomEntitiesDialog from './CustomEntitiesDialog';
|
||||||
import { DeviceValueTypeNames, DeviceValueUOM_s } from './types';
|
import { DeviceValueTypeNames, DeviceValueUOM_s } from './types';
|
||||||
import type { EntityItem } from './types';
|
import type { Entities, EntityItem } from './types';
|
||||||
import { entityItemValidation } from './validators';
|
import { entityItemValidation } from './validators';
|
||||||
|
|
||||||
const CustomEntities: FC = () => {
|
const CustomEntities: FC = () => {
|
||||||
@@ -56,7 +56,7 @@ const CustomEntities: FC = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { send: writeEntities } = useRequest(
|
const { send: writeEntities } = useRequest(
|
||||||
(data: { id: number; entity_ids: string[] }) => EMSESP.writeCustomEntities(data),
|
(data: Entities) => EMSESP.writeCustomEntities(data),
|
||||||
{ immediate: false }
|
{ immediate: false }
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -236,7 +236,11 @@ const CustomEntities: FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Table
|
<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}
|
theme={entity_theme}
|
||||||
layout={{ custom: true }}
|
layout={{ custom: true }}
|
||||||
>
|
>
|
||||||
@@ -295,7 +299,7 @@ const CustomEntities: FC = () => {
|
|||||||
onClose={onDialogClose}
|
onClose={onDialogClose}
|
||||||
onSave={onDialogSave}
|
onSave={onDialogSave}
|
||||||
selectedItem={selectedEntityItem}
|
selectedItem={selectedEntityItem}
|
||||||
validator={entityItemValidation()}
|
validator={entityItemValidation(entities, selectedEntityItem)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -130,7 +130,8 @@ const CustomEntitiesDialog = ({
|
|||||||
<TextField
|
<TextField
|
||||||
name="value"
|
name="value"
|
||||||
label={LL.DEFAULT(0) + ' ' + LL.VALUE(0)}
|
label={LL.DEFAULT(0) + ' ' + LL.VALUE(0)}
|
||||||
value={editItem.value}
|
type="string"
|
||||||
|
value={editItem.value as string}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={updateFormValue}
|
onChange={updateFormValue}
|
||||||
fullWidth
|
fullWidth
|
||||||
@@ -177,7 +178,8 @@ const CustomEntitiesDialog = ({
|
|||||||
label={LL.ID_OF(LL.TYPE(1))}
|
label={LL.ID_OF(LL.TYPE(1))}
|
||||||
margin="normal"
|
margin="normal"
|
||||||
fullWidth
|
fullWidth
|
||||||
value={editItem.type_id}
|
type="string"
|
||||||
|
value={editItem.type_id as string}
|
||||||
onChange={updateFormValue}
|
onChange={updateFormValue}
|
||||||
inputProps={{ style: { textTransform: 'uppercase' } }}
|
inputProps={{ style: { textTransform: 'uppercase' } }}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ const Scheduler: FC = () => {
|
|||||||
data={{
|
data={{
|
||||||
nodes: schedule
|
nodes: schedule
|
||||||
.filter((si) => !si.deleted)
|
.filter((si) => !si.deleted)
|
||||||
.sort((a, b) => a.cmd.localeCompare(b.cmd))
|
.sort((a, b) => a.name.localeCompare(b.name))
|
||||||
}}
|
}}
|
||||||
theme={schedule_theme}
|
theme={schedule_theme}
|
||||||
layout={{ custom: true }}
|
layout={{ custom: true }}
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ export const readCustomEntities = () =>
|
|||||||
return (data as Entities).entities.map((ei: EntityItem) => ({
|
return (data as Entities).entities.map((ei: EntityItem) => ({
|
||||||
...ei,
|
...ei,
|
||||||
o_id: ei.id,
|
o_id: ei.id,
|
||||||
|
o_ram: ei.ram,
|
||||||
o_device_id: ei.device_id,
|
o_device_id: ei.device_id,
|
||||||
o_type_id: ei.type_id,
|
o_type_id: ei.type_id,
|
||||||
o_offset: ei.offset,
|
o_offset: ei.offset,
|
||||||
@@ -141,9 +142,10 @@ export const readCustomEntities = () =>
|
|||||||
o_value_type: ei.value_type,
|
o_value_type: ei.value_type,
|
||||||
o_name: ei.name,
|
o_name: ei.name,
|
||||||
o_writeable: ei.writeable,
|
o_writeable: ei.writeable,
|
||||||
|
o_value: ei.value,
|
||||||
o_deleted: ei.deleted
|
o_deleted: ei.deleted
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
export const writeCustomEntities = (data: { id: number; entity_ids: string[] }) =>
|
export const writeCustomEntities = (data: Entities) =>
|
||||||
alovaInstance.Post('/rest/customEntities', data);
|
alovaInstance.Post('/rest/customEntities', data);
|
||||||
|
|||||||
@@ -2,7 +2,13 @@ import Schema from 'async-validator';
|
|||||||
import type { InternalRuleItem } from 'async-validator';
|
import type { InternalRuleItem } from 'async-validator';
|
||||||
import { IP_OR_HOSTNAME_VALIDATOR } from 'validators/shared';
|
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 = {
|
export const GPIO_VALIDATOR = {
|
||||||
validator(
|
validator(
|
||||||
@@ -297,10 +303,10 @@ export const schedulerItemValidation = (
|
|||||||
) =>
|
) =>
|
||||||
new Schema({
|
new Schema({
|
||||||
name: [
|
name: [
|
||||||
|
{ required: true, message: 'Name is required' },
|
||||||
{
|
{
|
||||||
required: true,
|
|
||||||
type: 'string',
|
type: 'string',
|
||||||
pattern: /^[a-zA-Z0-9_\\.]{0,15}$/,
|
pattern: /^[a-zA-Z0-9_\\.]{1,15}$/,
|
||||||
message: "Must be <15 characters: alpha numeric, '_' or '.'"
|
message: "Must be <15 characters: alpha numeric, '_' or '.'"
|
||||||
},
|
},
|
||||||
...[uniqueNameValidator(schedule, scheduleItem.o_name)]
|
...[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({
|
new Schema({
|
||||||
name: [
|
name: [
|
||||||
{ required: true, message: 'Name is required' },
|
{ required: true, message: 'Name is required' },
|
||||||
@@ -324,7 +350,8 @@ export const entityItemValidation = () =>
|
|||||||
type: 'string',
|
type: 'string',
|
||||||
pattern: /^[a-zA-Z0-9_\\.]{1,15}$/,
|
pattern: /^[a-zA-Z0-9_\\.]{1,15}$/,
|
||||||
message: "Must be <15 characters: alpha numeric, '_' or '.'"
|
message: "Must be <15 characters: alpha numeric, '_' or '.'"
|
||||||
}
|
},
|
||||||
|
...[uniqueCustomNameValidator(entity, entityItem.o_name)]
|
||||||
],
|
],
|
||||||
device_id: [
|
device_id: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1760,12 +1760,12 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@types/node@npm:^20.14.7":
|
"@types/node@npm:^20.14.8":
|
||||||
version: 20.14.7
|
version: 20.14.8
|
||||||
resolution: "@types/node@npm:20.14.7"
|
resolution: "@types/node@npm:20.14.8"
|
||||||
dependencies:
|
dependencies:
|
||||||
undici-types: "npm:~5.26.4"
|
undici-types: "npm:~5.26.4"
|
||||||
checksum: 10c0/6211ffe86f769a58617e3bdca58610256021ef54bd99d2c442ee6109196cd6ee8e0bcd1cfac0e39bf4bb353f8900fa5fae540485a03816bd91ad1f86a0e18512
|
checksum: 10c0/06d4643fa3b179b41fe19f9c75c240278ca1f7a313b3b837bc36ea119499c7ad77f06bbe72694ac04aa91ec77fe747baa09b889f4c435450c1724a26bd55f160
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@@ -1996,7 +1996,7 @@ __metadata:
|
|||||||
"@trivago/prettier-plugin-sort-imports": "npm:^4.3.0"
|
"@trivago/prettier-plugin-sort-imports": "npm:^4.3.0"
|
||||||
"@types/babel__core": "npm:^7"
|
"@types/babel__core": "npm:^7"
|
||||||
"@types/lodash-es": "npm:^4.17.12"
|
"@types/lodash-es": "npm:^4.17.12"
|
||||||
"@types/node": "npm:^20.14.7"
|
"@types/node": "npm:^20.14.8"
|
||||||
"@types/react": "npm:^18.3.3"
|
"@types/react": "npm:^18.3.3"
|
||||||
"@types/react-dom": "npm:^18.3.0"
|
"@types/react-dom": "npm:^18.3.0"
|
||||||
"@types/react-router-dom": "npm:^5.3.3"
|
"@types/react-router-dom": "npm:^5.3.3"
|
||||||
|
|||||||
Reference in New Issue
Block a user