mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-30 17:00:35 +02:00
Delete relations that become empty (#2270)
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
iD.actions.DeleteMember = function(relationId, memberIndex) {
|
||||
return function(graph) {
|
||||
return graph.replace(graph.entity(relationId).removeMember(memberIndex));
|
||||
var relation = graph.entity(relationId)
|
||||
.removeMember(memberIndex);
|
||||
|
||||
graph = graph.replace(relation);
|
||||
|
||||
if (relation.isDegenerate())
|
||||
graph = iD.actions.DeleteRelation(relation.id)(graph);
|
||||
|
||||
return graph;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -17,6 +17,10 @@ iD.ui.RawMemberEditor = function(context) {
|
||||
context.perform(
|
||||
iD.actions.DeleteMember(d.relation.id, d.index),
|
||||
t('operations.delete_member.annotation'));
|
||||
|
||||
if (!context.hasEntity(d.relation.id)) {
|
||||
context.enter(iD.modes.Browse(context));
|
||||
}
|
||||
}
|
||||
|
||||
function rawMemberEditor(selection) {
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
describe("iD.actions.DeleteMember", function () {
|
||||
it("removes the member at the specified index", function () {
|
||||
var node = iD.Node(),
|
||||
relation = iD.Relation({members: [{id: node.id}]}),
|
||||
action = iD.actions.DeleteMember(relation.id, 0),
|
||||
graph = action(iD.Graph([node, relation]));
|
||||
expect(graph.entity(relation.id).members).to.eql([]);
|
||||
var a = iD.Node({id: 'a'}),
|
||||
b = iD.Node({id: 'b'}),
|
||||
r = iD.Relation({members: [{id: 'a'}, {id: 'b'}]}),
|
||||
action = iD.actions.DeleteMember(r.id, 0),
|
||||
graph = action(iD.Graph([a, b, r]));
|
||||
expect(graph.entity(r.id).members).to.eql([{id: 'b'}]);
|
||||
});
|
||||
|
||||
it("deletes relations that become degenerate", function () {
|
||||
var a = iD.Node({id: 'a'}),
|
||||
r = iD.Relation({id: 'r', members: [{id: 'a'}]}),
|
||||
action = iD.actions.DeleteMember(r.id, 0),
|
||||
graph = action(iD.Graph([a, r]));
|
||||
expect(graph.hasEntity('r')).to.be.undefined;
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user