Add "duplicate" option to Custom Entities #2266

This commit is contained in:
MichaelDvP
2024-12-05 18:41:41 +01:00
parent 5f42709eab
commit a218c7a781
20 changed files with 213 additions and 173 deletions

View File

@@ -83,7 +83,7 @@ const CustomEntities = () => {
const entity_theme = useTheme({
Table: `
--data-table-library_grid-template-columns: repeat(1, minmax(60px, 1fr)) minmax(80px, auto) 80px 80px 80px 90px;
--data-table-library_grid-template-columns: repeat(1, minmax(60px, 1fr)) minmax(80px, auto) 80px 80px 80px 120px;
`,
BaseRow: `
font-size: 14px;
@@ -195,6 +195,25 @@ const CustomEntities = () => {
});
};
const onDialogDup = (item: EntityItem) => {
setCreating(true);
setSelectedEntityItem({
id: Math.floor(Math.random() * (Math.floor(200) - 100) + 100),
name: item.name + '_',
ram: item.ram,
device_id: item.device_id,
type_id: item.type_id,
offset: item.offset,
factor: item.factor,
uom: item.uom,
value_type: item.value_type,
writeable: item.writeable,
deleted: false,
value: item.value
});
setDialogOpen(true);
};
const addEntityItem = () => {
setCreating(true);
setSelectedEntityItem({
@@ -220,7 +239,7 @@ const CustomEntities = () => {
: typeof value === 'number'
? new Intl.NumberFormat().format(value) +
(uom === 0 ? '' : ' ' + DeviceValueUOM_s[uom])
: (value as string);
: (value as string) + (uom === 0 ? '' : ' ' + DeviceValueUOM_s[uom]);
}
function showHex(value: number, digit: number) {
@@ -296,6 +315,7 @@ const CustomEntities = () => {
creating={creating}
onClose={onDialogClose}
onSave={onDialogSave}
onDup={onDialogDup}
selectedItem={selectedEntityItem}
validator={entityItemValidation(entities, selectedEntityItem)}
/>

View File

@@ -34,6 +34,7 @@ interface CustomEntitiesDialogProps {
creating: boolean;
onClose: () => void;
onSave: (ei: EntityItem) => void;
onDup: (ei: EntityItem) => void;
selectedItem: EntityItem;
validator: Schema;
}
@@ -43,6 +44,7 @@ const CustomEntitiesDialog = ({
creating,
onClose,
onSave,
onDup,
selectedItem,
validator
}: CustomEntitiesDialogProps) => {
@@ -91,6 +93,10 @@ const CustomEntitiesDialog = ({
onSave(editItem);
};
const dup = () => {
onDup(editItem);
};
return (
<Dialog sx={dialogStyle} open={open} onClose={handleClose}>
<DialogTitle>
@@ -128,18 +134,36 @@ const CustomEntitiesDialog = ({
</TextField>
</Grid>
{editItem.ram === 1 && (
<Grid>
<TextField
name="value"
label={LL.DEFAULT(0) + ' ' + LL.VALUE(0)}
type="string"
value={editItem.value as string}
variant="outlined"
onChange={updateFormValue}
fullWidth
margin="normal"
/>
</Grid>
<>
<Grid>
<TextField
name="value"
label={LL.DEFAULT(0) + ' ' + LL.VALUE(0)}
type="string"
value={editItem.value as string}
variant="outlined"
onChange={updateFormValue}
fullWidth
margin="normal"
/>
</Grid>
<Grid>
<TextField
name="uom"
label={LL.UNIT()}
value={editItem.uom}
margin="normal"
onChange={updateFormValue}
select
>
{DeviceValueUOM_s.map((val, i) => (
<MenuItem key={val} value={i}>
{val}
</MenuItem>
))}
</TextField>
</Grid>
</>
)}
{editItem.ram === 0 && (
<>
@@ -255,7 +279,7 @@ const CustomEntitiesDialog = ({
<TextField
name="factor"
label={LL.FACTOR()}
value={numberValue(editItem.factor)}
value={numberValue(editItem.factor as number)}
variant="outlined"
onChange={updateFormValue}
sx={{ width: '11ch' }}
@@ -292,15 +316,41 @@ const CustomEntitiesDialog = ({
fieldErrors={fieldErrors}
name="factor"
label="Bytes"
value={numberValue(editItem.factor)}
value={numberValue(editItem.factor as number)}
sx={{ width: '11ch' }}
variant="outlined"
onChange={updateFormValue}
margin="normal"
type="number"
slotProps={{
htmlInput: { step: '1', min: '1', max: '255' }
}}
/>
</Grid>
)}
{editItem.value_type === DeviceValueType.BOOL && (
<Grid>
<ValidatedTextField
fieldErrors={fieldErrors}
name="factor"
label="Mask"
value={editItem.factor as string}
sx={{ width: '11ch' }}
variant="outlined"
onChange={updateFormValue}
margin="normal"
type="string"
slotProps={{
input: {
startAdornment: (
<InputAdornment position="start">0x</InputAdornment>
)
},
htmlInput: { style: { textTransform: 'uppercase' } }
}}
/>
</Grid>
)}
</>
)}
</Grid>
@@ -316,6 +366,15 @@ const CustomEntitiesDialog = ({
>
{LL.REMOVE()}
</Button>
<Button
sx={{ ml: 1 }}
startIcon={<AddIcon />}
variant="outlined"
color="primary"
onClick={dup}
>
{LL.DUPLICATE()}
</Button>
</Box>
)}
<Button

View File

@@ -34,7 +34,7 @@ export function formatValue(
if (value === undefined || typeof value === 'boolean') {
return '';
}
return value as string;
return (value as string) + (uom === undefined || uom === 0 ? '' : ' ' + DeviceValueUOM_s[uom]);
}
switch (uom) {

View File

@@ -368,7 +368,7 @@ export interface EntityItem {
device_id: number | string;
type_id: number | string;
offset: number;
factor: number;
factor: number | string;
uom: number;
value_type: number;
value?: unknown;
@@ -380,7 +380,7 @@ export interface EntityItem {
o_device_id?: number | string;
o_type_id?: number | string;
o_offset?: number;
o_factor?: number;
o_factor?: number | string;
o_uom?: number;
o_value_type?: number;
o_deleted?: boolean;

View File

@@ -383,8 +383,7 @@ export const entityItemValidation = (entity: EntityItem[], entityItem: EntityIte
{ type: 'number', min: 0, max: 255, message: 'Must be between 0 and 255' }
],
factor: [
{ required: true, message: 'is required' },
{ type: 'number', message: 'Must be a number' }
{ required: true, message: 'is required' }
]
});

View File

@@ -343,6 +343,7 @@ const cz: Translation = {
NO_DATA: 'Žádná data nejsou k dispozici',
DASHBOARD_1: 'Přizpůsobte si dashboard označením EMS entit jako Oblíbené pomocí modulu Přizpůsobení',
DEVELOPER_MODE: 'Režim vývojáře',
DUPLICATE: 'Duplicate', // TODO translate
UPGRADE: 'Upgrade' // TODO translate
};

View File

@@ -343,7 +343,8 @@ const de: Translation = {
NO_DATA: 'Keine Daten verfügbar',
DASHBOARD_1: 'Passen Sie Ihr Dashboard an, indem Sie EMS-Entitäten mithilfe des Moduls „Anpassungen“ als Favorit markieren',
DEVELOPER_MODE: 'Entwicklermodus',
UPGRADE: 'Upgrade' // TODO translate
DUPLICATE: 'Kopieren',
UPGRADE: 'Aktualisieren'
};
export default de;

View File

@@ -343,6 +343,7 @@ const en: Translation = {
NO_DATA: 'No data available',
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module',
DEVELOPER_MODE: 'Developer Mode',
DUPLICATE: 'Duplicate',
UPGRADE: 'Upgrade'
};

View File

@@ -343,6 +343,7 @@ const fr: Translation = {
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate
DUPLICATE: 'Duplicate', // TODO translate
UPGRADE: 'Upgrade' // TODO translate
};

View File

@@ -343,6 +343,7 @@ const it: Translation = {
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate
DUPLICATE: 'Duplicate', // TODO translate
UPGRADE: 'Upgrade' // TODO translate
};

View File

@@ -343,6 +343,7 @@ const nl: Translation = {
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate
DUPLICATE: 'Duplicate', // TODO translate
UPGRADE: 'Upgrade' // TODO translate
};

View File

@@ -343,6 +343,7 @@ const no: Translation = {
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate
DUPLICATE: 'Duplicate', // TODO translate
UPGRADE: 'Upgrade' // TODO translate
};

View File

@@ -343,6 +343,7 @@ const pl: BaseTranslation = {
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate
DUPLICATE: 'Duplicate', // TODO translate
UPGRADE: 'Upgrade' // TODO translate
};

View File

@@ -343,6 +343,7 @@ const sk: Translation = {
NO_DATA: 'Nie sú k dispozícii žiadne údaje',
DASHBOARD_1: 'Prispôsobte si svoj informačný panel tak, že označíte entity EMS ako Obľúbené pomocou modulu Prispôsobenia',
DEVELOPER_MODE: 'Developer Mode', // TODO translate
DUPLICATE: 'Duplicate', // TODO translate
UPGRADE: 'Upgrade' // TODO translate
};

View File

@@ -343,6 +343,7 @@ const sv: Translation = {
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate
DUPLICATE: 'Duplicate', // TODO translate
UPGRADE: 'Upgrade' // TODO translate
};

View File

@@ -343,6 +343,7 @@ const tr: Translation = {
NO_DATA: 'No data available', // TODO translate
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
DEVELOPER_MODE: 'Developer Mode', // TODO translate
DUPLICATE: 'Duplicate', // TODO translate
UPGRADE: 'Upgrade' // TODO translate
};