Skip to content

Commit

Permalink
fix: hook collection update
Browse files Browse the repository at this point in the history
  • Loading branch information
dineug committed Apr 23, 2024
1 parent de2f061 commit e1c685e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
14 changes: 6 additions & 8 deletions packages/erd-editor/src/engine/modules/relationship/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const identificationHook: CO = function* (channel, state) {
const collection = query(collections).collection('relationshipEntities');
const relationships = collection.selectByIds(doc.relationshipIds);

for (const { id, end, identification } of relationships) {
for (const relationship of relationships) {
const { end, identification } = relationship;
const table = query(collections)
.collection('tableEntities')
.selectById(end.tableId);
Expand All @@ -63,9 +64,7 @@ const identificationHook: CO = function* (channel, state) {
continue;
}

collection.updateOne(id, relationship => {
relationship.identification = value;
});
relationship.identification = value;
}
},
10,
Expand All @@ -81,7 +80,8 @@ const startRelationshipHook: CO = function* (channel, state) {
const collection = query(collections).collection('relationshipEntities');
const relationships = collection.selectByIds(doc.relationshipIds);

for (const { id, end, startRelationshipType } of relationships) {
for (const relationship of relationships) {
const { end, startRelationshipType } = relationship;
const table = query(collections)
.collection('tableEntities')
.selectById(end.tableId);
Expand All @@ -104,9 +104,7 @@ const startRelationshipHook: CO = function* (channel, state) {
continue;
}

collection.updateOne(id, relationship => {
relationship.startRelationshipType = value;
});
relationship.startRelationshipType = value;
}
},
10,
Expand Down
24 changes: 13 additions & 11 deletions packages/erd-editor/src/engine/modules/table-column/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ const changeColumnNotNullHook: CO = function* (channel, state) {
const isNotNull = bHas(column.options, ColumnOption.notNull);
if (isNotNull) return;

collection.updateOne(id, column => {
column.options = column.options | ColumnOption.notNull;
});
column.options = column.options | ColumnOption.notNull;
}
);
};
Expand All @@ -50,11 +48,13 @@ const addColumnForeignKeyHook: CO = function* (channel, state) {
} = state;
if (!relationshipIds.includes(id)) return;

query(collections)
const columns = query(collections)
.collection('tableColumnEntities')
.updateMany(end.columnIds, column => {
column.ui.keys = column.ui.keys | ColumnUIKey.foreignKey;
});
.selectByIds(end.columnIds);

for (const column of columns) {
column.ui.keys = column.ui.keys | ColumnUIKey.foreignKey;
}
}
);
};
Expand All @@ -76,11 +76,13 @@ const removeColumnForeignKeyHook: CO = function* (channel, state) {
.selectById(id);
if (!relationship) return;

query(collections)
const columns = query(collections)
.collection('tableColumnEntities')
.updateMany(relationship.end.columnIds, column => {
column.ui.keys = column.ui.keys & ~ColumnUIKey.foreignKey;
});
.selectByIds(relationship.end.columnIds);

for (const column of columns) {
column.ui.keys = column.ui.keys & ~ColumnUIKey.foreignKey;
}
}
);
};
Expand Down
1 change: 1 addition & 0 deletions packages/erd-editor/src/utils/draw-relationship/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const directionNameToDirection: Record<string, number> = {
[DirectionName.right]: Direction.right,
};

// TODO: concurrent
export function relationshipSort(state: RootState) {
const {
doc: { tableIds, relationshipIds },
Expand Down

0 comments on commit e1c685e

Please sign in to comment.