diff --git a/index.html b/index.html
index b0e46d55d..5cd8ff735 100644
--- a/index.html
+++ b/index.html
@@ -77,6 +77,7 @@
+
diff --git a/js/id/actions/delete_relation.js b/js/id/actions/delete_relation.js
new file mode 100644
index 000000000..48c62f1e1
--- /dev/null
+++ b/js/id/actions/delete_relation.js
@@ -0,0 +1,13 @@
+// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteRelationAction.as
+iD.actions.DeleteRelation = function(relationId) {
+ return function(graph) {
+ var relation = graph.entity(relationId);
+
+ graph.parentRelations(relation)
+ .forEach(function(parent) {
+ graph = graph.replace(parent.removeMember(relationId));
+ });
+
+ return graph.remove(relation);
+ };
+};
diff --git a/js/id/operations/delete.js b/js/id/operations/delete.js
index d631a2ed7..33c638ce0 100644
--- a/js/id/operations/delete.js
+++ b/js/id/operations/delete.js
@@ -3,7 +3,11 @@ iD.operations.Delete = function(selection, context) {
var operation = function() {
var entity = context.entity(entityId),
- action = {way: iD.actions.DeleteWay, node: iD.actions.DeleteNode}[entity.type],
+ action = {
+ way: iD.actions.DeleteWay,
+ node: iD.actions.DeleteNode,
+ relation: iD.actions.DeleteRelation
+ }[entity.type],
annotation = t('operations.delete.annotation.' + context.geometry(entityId));
context.perform(
@@ -12,9 +16,7 @@ iD.operations.Delete = function(selection, context) {
};
operation.available = function() {
- var entity = context.entity(entityId);
- return selection.length === 1 &&
- (entity.type === 'way' || entity.type === 'node');
+ return selection.length === 1;
};
operation.enabled = function() {
diff --git a/test/index.html b/test/index.html
index 16f86b781..120938b5f 100644
--- a/test/index.html
+++ b/test/index.html
@@ -74,6 +74,7 @@
+
@@ -141,6 +142,7 @@
+
diff --git a/test/index_packaged.html b/test/index_packaged.html
index 588c8e0a3..1764e5a9e 100644
--- a/test/index_packaged.html
+++ b/test/index_packaged.html
@@ -36,6 +36,7 @@
+
diff --git a/test/spec/actions/delete_relation.js b/test/spec/actions/delete_relation.js
new file mode 100644
index 000000000..c96909f3f
--- /dev/null
+++ b/test/spec/actions/delete_relation.js
@@ -0,0 +1,17 @@
+describe("iD.actions.DeleteRelation", function () {
+ it("removes the relation from the graph", function () {
+ var relation = iD.Relation(),
+ action = iD.actions.DeleteRelation(relation.id),
+ graph = action(iD.Graph([relation]));
+ expect(graph.entity(relation.id)).to.be.undefined;
+ });
+
+ it("removes the relation from parent relations", function () {
+ var a = iD.Relation(),
+ b = iD.Relation(),
+ parent = iD.Relation({members: [{ id: a.id }, { id: b.id }]}),
+ action = iD.actions.DeleteRelation(a.id),
+ graph = action(iD.Graph([a, b, parent]));
+ expect(graph.entity(parent.id).members).to.eql([{ id: b.id }]);
+ });
+});