* getIssues * Gets all issues that match the given options * This is called by many other places * * @param {Object} options - Object containing: * { * what: 'all', // 'all' or 'edited' * where: 'all', // 'all' or 'visible' * inc
(options)
| 251 | * @return {Array} An Array containing the issues |
| 252 | */ |
| 253 | getIssues(options) { |
| 254 | // Note that we use `staging.graph` here, not `cache.graph` or `stable.graph`, |
| 255 | // because that is the Graph that the calling code will be using. |
| 256 | const opts = Object.assign({ what: 'all', where: 'all', includeIgnored: false, includeDisabledRules: false }, options); |
| 257 | const context = this.context; |
| 258 | const visibleExtent = context.viewport.visibleExtent(); |
| 259 | const graph = context.systems.editor.staging.graph; |
| 260 | let seen = new Set(); |
| 261 | let results = []; |
| 262 | |
| 263 | // Filter the issue set to include only what the calling code wants to see. |
| 264 | const filter = (issue) => { |
| 265 | if (!issue) return false; |
| 266 | if (seen.has(issue.id)) return false; |
| 267 | if (this._resolvedIssueIDs.has(issue.id)) return false; |
| 268 | if (opts.includeDisabledRules === 'only' && !this._disabledRuleIDs.has(issue.type)) return false; |
| 269 | if (!opts.includeDisabledRules && this._disabledRuleIDs.has(issue.type)) return false; |
| 270 | |
| 271 | if (opts.includeIgnored === 'only' && !this._ignoredIssueIDs.has(issue.id)) return false; |
| 272 | if (!opts.includeIgnored && this._ignoredIssueIDs.has(issue.id)) return false; |
| 273 | |
| 274 | // This issue may involve an entity that doesn't exist in `staging.graph`. |
| 275 | // This can happen because validation is async and rendering the issue lists is async. |
| 276 | if ((issue.entityIds || []).some(id => !graph.hasEntity(id))) return false; |
| 277 | |
| 278 | if (opts.where === 'visible') { |
| 279 | const extent = issue.extent(graph); |
| 280 | if (!visibleExtent.intersects(extent)) return false; |
| 281 | } |
| 282 | |
| 283 | return true; |
| 284 | }; |
| 285 | |
| 286 | |
| 287 | // Collect head issues - present in the user edits |
| 288 | if (this._head.issues.size) { |
| 289 | for (const issue of this._head.issues.values()) { |
| 290 | // In the head cache, only count features that the user is responsible for - iD#8632 |
| 291 | // For example, a user can undo some work and an issue will still present in the |
| 292 | // head graph, but we don't want to credit the user for causing that issue. |
| 293 | const userModified = (issue.entityIds || []).some(entityID => this._completeDiff.has(entityID)); |
| 294 | if (opts.what === 'edited' && !userModified) continue; // present in head but user didn't touch it |
| 295 | |
| 296 | if (!filter(issue)) continue; |
| 297 | seen.add(issue.id); |
| 298 | results.push(issue); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | // Collect base issues - present before user edits |
| 303 | if (this._base.issues.size && opts.what === 'all') { |
| 304 | for (const issue of this._base.issues.values()) { |
| 305 | if (!filter(issue)) continue; |
| 306 | seen.add(issue.id); |
| 307 | results.push(issue); |
| 308 | } |
| 309 | } |
| 310 |
no test coverage detected