()
| 148 | const extensions = useExtensions(); |
| 149 | |
| 150 | const undo = () => { |
| 151 | if (undoStack.length === 0) return; |
| 152 | const a = undoStack[undoStack.length - 1]; |
| 153 | setUndoStack((prev) => prev.filter((_, i) => i !== prev.length - 1)); |
| 154 | |
| 155 | if (a.bulk) { |
| 156 | for (const element of a.elements) { |
| 157 | if (element.type === ObjectType.TABLE) { |
| 158 | updateTable(element.id, element.undo); |
| 159 | } else if (element.type === ObjectType.AREA) { |
| 160 | updateArea(element.id, element.undo); |
| 161 | } else if (element.type === ObjectType.NOTE) { |
| 162 | updateNote(element.id, element.undo); |
| 163 | } |
| 164 | } |
| 165 | setRedoStack((prev) => [...prev, a]); |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | if (a.action === Action.ADD) { |
| 170 | if (a.element === ObjectType.TABLE) { |
| 171 | deleteTable(a.data.table.id, false); |
| 172 | } else if (a.element === ObjectType.AREA) { |
| 173 | deleteArea(areas[areas.length - 1].id, false); |
| 174 | } else if (a.element === ObjectType.NOTE) { |
| 175 | deleteNote(notes[notes.length - 1].id, false); |
| 176 | } else if (a.element === ObjectType.RELATIONSHIP) { |
| 177 | deleteRelationship(a.data.relationship.id, false); |
| 178 | } else if (a.element === ObjectType.TYPE) { |
| 179 | deleteType(a.data.type.id, false); |
| 180 | } else if (a.element === ObjectType.ENUM) { |
| 181 | deleteEnum(a.data.enum.id, false); |
| 182 | } |
| 183 | setRedoStack((prev) => [...prev, a]); |
| 184 | } else if (a.action === Action.MOVE) { |
| 185 | if (a.element === ObjectType.TABLE) { |
| 186 | const { x, y } = tables.find((t) => t.id === a.id); |
| 187 | setRedoStack((prev) => [...prev, { ...a, x, y }]); |
| 188 | updateTable(a.id, { x: a.x, y: a.y }); |
| 189 | } else if (a.element === ObjectType.AREA) { |
| 190 | setRedoStack((prev) => [ |
| 191 | ...prev, |
| 192 | { ...a, x: areas[a.id].x, y: areas[a.id].y }, |
| 193 | ]); |
| 194 | updateArea(a.id, { x: a.x, y: a.y }); |
| 195 | } else if (a.element === ObjectType.NOTE) { |
| 196 | setRedoStack((prev) => [ |
| 197 | ...prev, |
| 198 | { ...a, x: notes[a.id].x, y: notes[a.id].y }, |
| 199 | ]); |
| 200 | updateNote(a.id, { x: a.x, y: a.y }); |
| 201 | } |
| 202 | } else if (a.action === Action.DELETE) { |
| 203 | if (a.element === ObjectType.TABLE) { |
| 204 | a.data.relationship.forEach((x) => addRelationship(x, false)); |
| 205 | addTable(a.data, false); |
| 206 | } else if (a.element === ObjectType.RELATIONSHIP) { |
| 207 | addRelationship(a.data, false); |
nothing calls this directly
no test coverage detected