(changesToReport, previews)
| 202 | * @return {object} |
| 203 | */ |
| 204 | export function segmentPreviewChanges(changesToReport, previews) { |
| 205 | // Build a map of `{ path => previewTitle` } |
| 206 | // for easier lookup of change to preview |
| 207 | const pathToPreview = {} |
| 208 | previews.forEach(function (preview) { |
| 209 | preview.toggled_on.forEach(function (path) { |
| 210 | pathToPreview[path] = preview.title |
| 211 | }) |
| 212 | }) |
| 213 | const schemaChanges = [] |
| 214 | const changesByPreview = {} |
| 215 | |
| 216 | changesToReport.forEach(function (change) { |
| 217 | // For each change, see if its path _or_ one of its ancestors |
| 218 | // is covered by a preview. If it is, mark this change as belonging to a preview |
| 219 | const pathParts = change.path.split('.') |
| 220 | let testPath = null |
| 221 | let previewTitle = null |
| 222 | let previewChanges = null |
| 223 | while (pathParts.length > 0 && !previewTitle) { |
| 224 | testPath = pathParts.join('.') |
| 225 | previewTitle = pathToPreview[testPath] |
| 226 | // If that path didn't find a match, then we'll |
| 227 | // check the next ancestor. |
| 228 | pathParts.pop() |
| 229 | } |
| 230 | if (previewTitle) { |
| 231 | previewChanges = |
| 232 | changesByPreview[previewTitle] || |
| 233 | (changesByPreview[previewTitle] = { |
| 234 | title: previewTitle, |
| 235 | changes: [], |
| 236 | }) |
| 237 | previewChanges.changes.push(change) |
| 238 | } else { |
| 239 | schemaChanges.push(change) |
| 240 | } |
| 241 | }) |
| 242 | return { schemaChangesToReport: schemaChanges, previewChangesToReport: changesByPreview } |
| 243 | } |
| 244 | |
| 245 | // We only want to report changes to schema structure. |
| 246 | // Deprecations are covered by "upcoming changes." |
no outgoing calls
no test coverage detected