(schema, origVal, sessVal)
| 121 | |
| 122 | // This will be executed recursively as data can be nested. |
| 123 | let parseChanges = (schema, origVal, sessVal) => { |
| 124 | let levelChanges = {}; |
| 125 | parseChanges.depth = |
| 126 | _.isUndefined(parseChanges.depth) ? 0 : (parseChanges.depth + 1); |
| 127 | |
| 128 | /* The comparator and setter */ |
| 129 | const attrChanged = (id, change, force=false) => { |
| 130 | if(isValueEqual(_.get(origVal, id), _.get(sessVal, id)) && !force) { |
| 131 | return; |
| 132 | } |
| 133 | |
| 134 | change = change || _.get(sessVal, id); |
| 135 | |
| 136 | if(stringify && (_.isArray(change) || _.isObject(change))) { |
| 137 | change = JSON.stringify(change); |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * Null values are not passed in URL params, pass it as an empty string. |
| 142 | * Nested values does not need this. |
| 143 | */ |
| 144 | if(_.isNull(change) && parseChanges.depth === 0) { |
| 145 | change = ''; |
| 146 | } |
| 147 | |
| 148 | levelChanges[id] = change; |
| 149 | }; |
| 150 | |
| 151 | schema.fields.forEach((field) => { |
| 152 | // Never include data from the field in the changes, marked as |
| 153 | // 'excluded'. |
| 154 | if (field.exclude) return; |
| 155 | /* |
| 156 | * If skipChange is true, then field will not be considered for changed |
| 157 | * data. This is helpful when 'Save' or 'Reset' should not be enabled on |
| 158 | * this field change alone. No change in other behaviour. |
| 159 | */ |
| 160 | if(field.skipChange && !includeSkipChange) return; |
| 161 | |
| 162 | /* |
| 163 | * At this point the schema assignments like top may not have been done, |
| 164 | * so - check if mode is supported by this field, or not. |
| 165 | */ |
| 166 | if (!isModeSupportedByField(field, {mode})) return; |
| 167 | |
| 168 | if( |
| 169 | typeof(field.type) === 'string' && field.type.startsWith('nested-') |
| 170 | ) { |
| 171 | /* |
| 172 | * Even if its nested, state is on same hierarchical level. |
| 173 | * Find the changes and merge. |
| 174 | */ |
| 175 | levelChanges = { |
| 176 | ...levelChanges, |
| 177 | ...parseChanges(field.schema, origVal, sessVal), |
| 178 | }; |
| 179 | } else if(isEditMode && !_.isEqual( |
| 180 | _.get(origVal, field.id), _.get(sessVal, field.id) |
no test coverage detected