Skip to content

Commit

Permalink
Make ValidationIssue and ValidationFix ES6 classes
Browse files Browse the repository at this point in the history
This commit also moves a bunch of stuff from /core -> /core/lib for organization
  • Loading branch information
bhousel committed May 30, 2023
1 parent b865f0e commit 695f472
Show file tree
Hide file tree
Showing 59 changed files with 382 additions and 379 deletions.
2 changes: 1 addition & 1 deletion modules/core/ImagerySystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ImagerySourceCustom,
ImagerySourceEsri,
ImagerySourceNone
} from './ImagerySource';
} from './lib/ImagerySource';


/**
Expand Down
5 changes: 1 addition & 4 deletions modules/core/PresetSystem.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { utilArrayUniq } from '@rapid-sdk/util';

import { osmNodeGeometriesForTags, osmSetAreaKeys, osmSetPointTags, osmSetVertexTags } from '../osm/tags';
import { Category } from './preset/Category.js';
import { Collection } from './preset/Collection.js';
import { Field } from './preset/Field.js';
import { Preset } from './preset/Preset.js';
import { Category, Collection, Field, Preset } from './lib';
import { uiFields } from '../ui/fields';

const VERBOSE = true; // warn about v6 preset featues we don't support currently
Expand Down
6 changes: 3 additions & 3 deletions modules/core/ValidationSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EventEmitter } from '@pixi/utils';
import { Extent } from '@rapid-sdk/math';
import { utilArrayChunk, utilArrayGroupBy, utilEntityAndDeepMemberIDs } from '@rapid-sdk/util';

import { Difference } from './Difference';
import { Difference } from './lib/Difference';
import { modeSelect } from '../modes/select';
import * as Validations from '../validations/index';

Expand Down Expand Up @@ -31,8 +31,8 @@ export class ValidationSystem extends EventEmitter {
this._resolvedIssueIDs = new Set();
this._completeDiff = new Map(); // complete diff base -> head of what the user changed
this._headIsCurrent = false;
this._deferredRIC = new Map(); // Map(handle -> Promise.reject)
this._deferredST = new Set(); // Set(handles)
this._deferredRIC = new Map(); // Deferred `requestIdleCallback` - Map(handle -> Promise.reject)
this._deferredST = new Set(); // Deferred `setTimeout` - Set(handles)
this._headPromise = null; // Promise fulfilled when validation is performed up to headGraph snapshot
this._errorOverrides = [];
this._warningOverrides = [];
Expand Down
4 changes: 1 addition & 3 deletions modules/core/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { easeLinear as d3_easeLinear } from 'd3-ease';
import { select as d3_select } from 'd3-selection';
import { utilArrayDifference, utilArrayGroupBy, utilArrayUnion, utilObjectOmit, utilSessionMutex } from '@rapid-sdk/util';

import { Graph } from './Graph';
import { Difference } from './Difference';
import { Difference, Graph, Tree } from './lib';
import { osmEntity } from '../osm/entity';
import { Tree } from './Tree';
import { uiLoading } from '../ui/loading';
import { utilRebind } from '../util';

Expand Down
19 changes: 2 additions & 17 deletions modules/core/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './lib/index';

export { coreContext } from './context';
export { coreHistory } from './history';
export { coreRapidContext } from './rapid_context';
Expand All @@ -13,20 +15,3 @@ export { PresetSystem } from './PresetSystem';
export { StorageSystem } from './StorageSystem';
export { UrlHashSystem } from './UrlHashSystem';
export { ValidationSystem } from './ValidationSystem';

export { Difference } from './Difference';
export { Graph } from './Graph';
export { Tree } from './Tree';

export {
ImagerySource,
ImagerySourceBing,
ImagerySourceCustom,
ImagerySourceEsri,
ImagerySourceNone
} from './ImagerySource';

export { Category } from './preset/Category';
export { Collection } from './preset/Collection';
export { Field } from './preset/Field';
export { Preset } from './preset/Preset';
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.
13 changes: 13 additions & 0 deletions modules/core/lib/ValidationFix.js
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
}
}
96 changes: 96 additions & 0 deletions modules/core/lib/ValidationIssue.js
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
}
}
18 changes: 18 additions & 0 deletions modules/core/lib/index.js
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';
2 changes: 1 addition & 1 deletion modules/core/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { actionDiscardTags } from '../actions/discard_tags';
import { actionMergeRemoteChanges } from '../actions/merge_remote_changes';
import { actionNoop } from '../actions/noop';
import { actionRevert } from '../actions/revert';
import { Graph } from '../core/Graph';
import { Graph } from './lib';
import { utilRebind } from '../util';


Expand Down
1 change: 0 additions & 1 deletion modules/core/validation/index.js

This file was deleted.

101 changes: 0 additions & 101 deletions modules/core/validation/models.js

This file was deleted.

3 changes: 2 additions & 1 deletion modules/osm/changeset.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { osmEntity } from './entity';
import { Extent } from '@rapid-sdk/math';

import { osmEntity } from './entity';


export function osmChangeset() {
if (!(this instanceof osmChangeset)) {
Expand Down
1 change: 1 addition & 0 deletions modules/osm/entity.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { utilArrayUnion, utilUnicodeCharsTruncated } from '@rapid-sdk/util';

import { osmIsInterestingTag } from './tags';


Expand Down
2 changes: 1 addition & 1 deletion modules/osm/intersection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { utilArrayDifference, utilArrayUniq } from '@rapid-sdk/util';
import { actionDeleteRelation } from '../actions/delete_relation';
import { actionReverse } from '../actions/reverse';
import { actionSplit } from '../actions/split';
import { Graph } from '../core/Graph';
import { Graph } from '../core/lib';
import { osmEntity } from './entity';


Expand Down
2 changes: 1 addition & 1 deletion modules/services/ServiceEsri.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { select as d3_select } from 'd3-selection';
import { Tiler } from '@rapid-sdk/math';
import { utilQsString } from '@rapid-sdk/util';

import { Graph, Tree } from '../core';
import { Graph, Tree } from '../core/lib';
import { osmNode, osmRelation, osmWay } from '../osm';
import { utilRebind } from '../util';

Expand Down
2 changes: 1 addition & 1 deletion modules/services/ServiceMapWithAI.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { dispatch as d3_dispatch } from 'd3-dispatch';
import { xml as d3_xml } from 'd3-fetch';
import { Tiler } from '@rapid-sdk/math';

import { Graph, Tree } from '../core';
import { Graph, Tree } from '../core/lib';
import { osmEntity, osmNode, osmWay } from '../osm';
import { utilRebind } from '../util';

Expand Down
2 changes: 1 addition & 1 deletion modules/ui/feature_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { select as d3_select } from 'd3-selection';
import { Extent, geoSphericalDistance } from '@rapid-sdk/math';
import * as sexagesimal from '@mapbox/sexagesimal';

import { Graph } from '../core/Graph';
import { Graph } from '../core/lib';
import { modeSelect } from '../modes/select';
import { osmEntity } from '../osm/entity';
import { uiIcon } from './icon';
Expand Down
2 changes: 1 addition & 1 deletion modules/ui/sections/background_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { select as d3_select } from 'd3-selection';
import { easeCubicInOut as d3_easeCubicInOut } from 'd3-ease';

import { uiTooltip } from '../tooltip';
import { ImagerySource } from '../../core/ImagerySource';
import { ImagerySource } from '../../core/lib';
import { uiIcon } from '../icon';
import { uiCmd } from '../cmd';
import { uiSettingsCustomBackground } from '../settings/custom_background';
Expand Down
2 changes: 1 addition & 1 deletion modules/ui/sections/entity_issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export function uiSectionEntityIssues(context) {
let fixLists = containers.selectAll('.issue-fix-list');

let fixes = fixLists.selectAll('.issue-fix-item')
.data(d => (d.fixes ? d.fixes(context) : []), d => d.id);
.data(d => (d.fixes ? d.fixes() : []), d => d.id);

fixes.exit()
.remove();
Expand Down
Loading

0 comments on commit 695f472

Please sign in to comment.