In order to track the modified fields and display them to the user, I need to identify which key corresponds to the changed field and create a new key-value pair for user visibility.
log: [
0: {type: "Changed", fields_changed: Array(2), date_modification: Timestamp, modified_by: "ID_USER"}
1: {type: "Changed", fields_changed: Array(4), date_modification: Timestamp, modified_by: "ID_USER"}
2: {type: "Changed", fields_changed: Array(2), date_modification: Timestamp, modified_by: "ID_USER"}
3: {type: "Changed", fields_changed: Array(4), date_modification: Timestamp, modified_by: "ID_USER"}
]
fields_changed: [
0: {key: "name", value: "New name"}
1: {key: "age", value: 22}
]
To achieve this, I will use fieldsNames
to match the field names and generate an updated log object for user viewing.
const fieldsNames = [
{key: 'name', field_name: 'Name'},
{key: 'age', field_name: 'Age'},
]
This process will result in a revised log list where field keys are replaced with corresponding field names.
Example:
fields_changed: [
0: {key: "name", value: "New name", field_name: "Nome"}
1: {key: "age", value: 22, field_name: "Age"}
]
A new key called field_name
will be added within each object of the fields_changed
list to indicate the name of the modified field that can be shown to the user.
This method ensures that the fields_changed
list is updated as illustrated above.
For user clarity on the changes made, I plan to iterate through fields_changed
and extract the associated field_name
string representing the field name.