Closed AlexanderGeere closed 1 month ago
The entryObject method can be simplified by assigning a const field and then checking and shortcircuiting on field, fieldEntry, fieldEntry.value not being an object.
@simon-leech can you give me an example where the objectMergeFromEntry requires a lookup on type? This should be removed since the type is by definition not unique like the field.
function entryObject(entry) {
const field = entry.objectAssignFromField || entry.objectMergeFromField || entry.json_field
// entry must have a lookup field
if (!field) return;
const fieldEntry = entry.location.infoj.find(_entry => _entry.field === field)
// info must contain a matching fieldEntry
if (!fieldEntry) return;
// fieldEntry must have an object type value.
if (fieldEntry.value !== 'object') return;
// Lookup for json value field entry
if(entry.json_field) {
if(!entry.key){
console.warn('json_field requires entry.key to be specified')
return;
}
entry.value = fieldEntry.value[entry.key]
}
if (entry.objectAssignFromField) {
Object.assign(entry, fieldEntry.value)
}
if (entry.objectMergeFromField) {
mapp.utils.merge(entry, fieldEntry.value)
// // Find the entry to merge.
// let fieldEntry = entry.location.infoj.find(_entry => _entry.type === entry.objectMergeFromEntry)
// // Only merge the entry.merge object.
// fieldEntry
// && fieldEntry.merge instanceof Object
// && mapp.utils.merge(entry, fieldEntry.merge)
}
}
I changed key
to json_key
as this is better descriptive.
The update json query and multiple promises are not required.
At the beginning of the location update you can iterate through the json_field, json_key, newValues and assign the value to the json fieldEntry.newValue object.
this.infoj
.filter(entry => entry.json_field)
.filter(entry => entry.json_key)
.filter(entry => typeof entry.newValue !== 'undefined')
.forEach(entry => {
const fieldEntry = this.infoj.find(_entry => _entry.field === entry.json_field)
fieldEntry.newValue ??= fieldEntry.value || {}
fieldEntry.newValue[entry.json_key] = entry.newValue
delete entry.newValue
})
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code
What
Query for updating the values within a
json
field.How
Uses concatenation within sql to add the existing json field.
Why
We willl need this for the entering data directly from the report on a table.
Test space
bugs_testing/ui_elements
- scratch layer.public.scratch
, thejson_field
value.