fix(adminui): preserve un-edited Modbus tag fields across edit (review)
Capture the original ModbusTagDefinition as _source in ModbusTagRow and
rewrite ToDefinition() to use 'with {}', so StringByteOrder, ArrayCount,
Deadband, UnitId, and CoalesceProhibited survive a load→edit→save cycle.
This commit is contained in:
+22
-6
@@ -490,20 +490,36 @@ else
|
||||
public int StringLength { get; set; }
|
||||
public bool WriteIdempotent { get; set; }
|
||||
|
||||
public ModbusTagRow Clone() => (ModbusTagRow)MemberwiseClone();
|
||||
// Original record (null for newly-added rows). Preserves fields the editor doesn't expose
|
||||
// (StringByteOrder, ArrayCount, Deadband, UnitId, CoalesceProhibited) across a load→save.
|
||||
private ModbusTagDefinition? _source;
|
||||
|
||||
public ModbusTagRow Clone() => (ModbusTagRow)MemberwiseClone(); // _source is an immutable record ref — safe to share
|
||||
|
||||
public static ModbusTagRow FromDefinition(ModbusTagDefinition d) => new()
|
||||
{
|
||||
Name = d.Name, Region = d.Region, Address = d.Address, DataType = d.DataType,
|
||||
Writable = d.Writable, ByteOrder = d.ByteOrder, BitIndex = d.BitIndex,
|
||||
StringLength = d.StringLength, WriteIdempotent = d.WriteIdempotent,
|
||||
_source = d,
|
||||
};
|
||||
|
||||
public ModbusTagDefinition ToDefinition() => new(
|
||||
Name: Name.Trim(), Region: Region, Address: (ushort)Math.Clamp(Address, 0, 65535),
|
||||
DataType: DataType, Writable: Writable, ByteOrder: ByteOrder,
|
||||
BitIndex: (byte)Math.Clamp(BitIndex, 0, 255), StringLength: (ushort)Math.Clamp(StringLength, 0, 65535),
|
||||
WriteIdempotent: WriteIdempotent);
|
||||
public ModbusTagDefinition ToDefinition()
|
||||
{
|
||||
var baseDef = _source ?? new ModbusTagDefinition(Name.Trim(), Region, 0, DataType);
|
||||
return baseDef with
|
||||
{
|
||||
Name = Name.Trim(),
|
||||
Region = Region,
|
||||
Address = (ushort)Math.Clamp(Address, 0, 65535),
|
||||
DataType = DataType,
|
||||
Writable = Writable,
|
||||
ByteOrder = ByteOrder,
|
||||
BitIndex = (byte)Math.Clamp(BitIndex, 0, 255),
|
||||
StringLength = (ushort)Math.Clamp(StringLength, 0, 65535),
|
||||
WriteIdempotent = WriteIdempotent,
|
||||
};
|
||||
}
|
||||
|
||||
public static string? ValidateRow(ModbusTagRow row, IReadOnlyList<ModbusTagRow> all, int? editIndex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user