-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ValidationIssue and ValidationFix ES6 classes
This commit also moves a bunch of stuff from /core -> /core/lib for organization
- Loading branch information
Showing
59 changed files
with
382 additions
and
379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
export class ValidationFix { | ||
constructor(props) { | ||
this.title = props.title; // Required | ||
this.onClick = props.onClick; // Optional - the function to run to apply the fix | ||
this.disabledReason = props.disabledReason; // Optional - a string explaining why the fix is unavailable, if any | ||
this.icon = props.icon; // Optional - shows 'rapid-icon-wrench' if not set | ||
this.entityIds = props.entityIds || []; // Optional - used for hover-higlighting. | ||
// this.autoArgs = props.autoArgs; // Optional - pass [actions, annotation] arglist if this fix can automatically run | ||
|
||
this.issue = null; // Generated link - added by ValidationIssue | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { Extent } from '@rapid-sdk/math'; | ||
|
||
import { ValidationFix } from './ValidationFix'; | ||
import { utilTotalExtent } from '../../util'; | ||
|
||
|
||
export class ValidationIssue { | ||
|
||
constructor(context, props) { | ||
this.context = context; | ||
|
||
this.type = props.type; // required - name of rule that created the issue (e.g. 'missing_tag') | ||
this.subtype = props.subtype; // optional - category of the issue within the type (e.g. 'relation_type' under 'missing_tag') | ||
this.severity = props.severity; // required - 'warning' or 'error' | ||
this.message = props.message; // required - function returning localized string | ||
this.reference = props.reference; // optional - function(selection) to render reference information | ||
this.entityIds = props.entityIds; // optional - array of IDs of entities involved in the issue | ||
this.loc = props.loc; // optional - [lon, lat] to zoom in on to see the issue | ||
this.data = props.data; // optional - object containing extra data for the fixes | ||
this.dynamicFixes = props.dynamicFixes; // optional - function(context) returning fixes | ||
this.hash = props.hash; // optional - string to further differentiate the issue | ||
|
||
this.id = this._generateID(); // generated - see below | ||
this.key = this._generateKey(); // generated - see below (call after generating this.id) | ||
this.autoArgs = props.autoArgs; // optional - if this issue can be autofixed, supply the autofix args at issue creation | ||
this.autoFix = null; // generated - if autofix exists, will be set below | ||
} | ||
|
||
|
||
extent(resolver) { | ||
if (this.loc) { | ||
return new Extent(this.loc); | ||
} | ||
if (this.entityIds && this.entityIds.length) { | ||
return utilTotalExtent(this.entityIds, resolver); | ||
} | ||
return null; | ||
} | ||
|
||
|
||
fixes() { | ||
// sometimes the fixes are generated dynamically | ||
let fixes = (typeof this.dynamicFixes === 'function') ? this.dynamicFixes() : []; | ||
|
||
// For warnings, create an "ignore" option | ||
if (this.severity === 'warning') { | ||
fixes.push(new ValidationFix({ | ||
title: this.context.tHtml('issues.fix.ignore_issue.title'), | ||
icon: 'rapid-icon-close', | ||
onClick: () => { | ||
this.context.validationSystem().ignoreIssue(this.id); | ||
} | ||
})); | ||
} | ||
|
||
for (const fix of fixes) { | ||
fix.id = fix.title; // the id doesn't matter as long as it's unique to this issue/fix | ||
fix.issue = this; // add a reference back to this issue for use in actions | ||
// if (fix.autoArgs) { | ||
// this.autoFix = fix; | ||
// } | ||
} | ||
return fixes; | ||
} | ||
|
||
|
||
// A unique, deterministic string hash. | ||
// Issues with identical id values are considered identical. | ||
_generateID() { | ||
let parts = [this.type]; | ||
|
||
if (this.hash) { // subclasses can pass in their own differentiator | ||
parts.push(this.hash); | ||
} | ||
|
||
if (this.subtype) { | ||
parts.push(this.subtype); | ||
} | ||
|
||
// include the entities this issue is for | ||
// (sort them so the id is deterministic) | ||
if (this.entityIds) { | ||
const entityKeys = this.entityIds.slice().sort(); | ||
parts.push.apply(parts, entityKeys); | ||
} | ||
|
||
return parts.join(':'); | ||
} | ||
|
||
|
||
// An identifier suitable for use as the second argument to d3.selection#data(). | ||
// (i.e. this should change whenever the data needs to be refreshed) | ||
_generateKey() { | ||
return this.id + ':' + Date.now().toString(); // include time of creation | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export { Category } from './Category'; | ||
export { Collection } from './Collection'; | ||
export { Difference } from './Difference'; | ||
|
||
export { | ||
ImagerySource, | ||
ImagerySourceBing, | ||
ImagerySourceCustom, | ||
ImagerySourceEsri, | ||
ImagerySourceNone | ||
} from './ImagerySource'; | ||
|
||
export { Field } from './Field'; | ||
export { Graph } from './Graph'; | ||
export { Preset } from './Preset'; | ||
export { Tree } from './Tree'; | ||
export { ValidationFix } from './ValidationFix'; | ||
export { ValidationIssue } from './ValidationIssue'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.