Skip to content

Commit 8b1f60a

Browse files
authored
rework yjs-store-db syncing (#205)
* rework yjs-store-db syncing * fix update dimension for paste/cut; do not moveIntoScope when already in it * fix: update parent node's children in cutEnd
1 parent 44e2dc2 commit 8b1f60a

File tree

20 files changed

+1334
-993
lines changed

20 files changed

+1334
-993
lines changed

api/src/resolver.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
users,
88
} from "./resolver_user";
99
import {
10-
addPod,
1110
createRepo,
1211
deletePod,
1312
deleteRepo,
@@ -73,7 +72,6 @@ export const resolvers = {
7372
updateRepo,
7473
deleteRepo,
7574
clearUser: () => {},
76-
addPod,
7775
updatePod,
7876
deletePod,
7977
addCollaborator,

api/src/resolver_repo.ts

Lines changed: 52 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -284,83 +284,69 @@ export async function deleteCollaborator(
284284
return true;
285285
}
286286

287-
export async function addPod(_, { repoId, parent, index, input }, { userId }) {
288-
// make sure the repo is writable by this user
287+
export async function updatePod(_, { id, repoId, input }, { userId }) {
289288
if (!userId) throw new Error("Not authenticated.");
290289
await ensureRepoEditAccess({ repoId, userId });
291-
292-
// update all other records
293-
await prisma.pod.updateMany({
290+
// if repoId has id, just update
291+
let pod_found = await prisma.pod.findFirst({
294292
where: {
293+
id,
295294
repo: {
296295
id: repoId,
297296
},
298-
index: {
299-
gte: index,
300-
},
301-
parent:
302-
parent === "ROOT"
303-
? null
304-
: {
305-
id: parent,
306-
},
307-
},
308-
data: {
309-
index: {
310-
increment: 1,
311-
},
312297
},
313298
});
314-
315-
let { id: podId } = input;
316-
const pod = await prisma.pod.create({
317-
data: {
318-
id: podId,
319-
...input,
320-
// In case of [], create will throw an error. Thus I have to pass undefined.
321-
children: input.children.length > 0 ? input.children : undefined,
322-
index,
323-
repo: {
324-
connect: {
325-
id: repoId,
299+
if (pod_found) {
300+
// if repoId doesn't have id, create it IF input.parent exists
301+
const pod = await prisma.pod.update({
302+
where: {
303+
id,
304+
},
305+
data: {
306+
...input,
307+
parent:
308+
input.parent && input.parent !== "ROOT"
309+
? {
310+
connect: {
311+
id: input.parent,
312+
},
313+
}
314+
: undefined,
315+
children: {
316+
connect: input.children?.map((id) => ({ id })),
326317
},
327318
},
328-
parent:
329-
parent === "ROOT"
330-
? undefined
331-
: {
332-
connect: {
333-
id: parent,
334-
},
335-
},
336-
},
337-
});
338-
339-
return true;
340-
}
341-
342-
export async function updatePod(_, { id, input }, { userId }) {
343-
if (!userId) throw new Error("Not authenticated.");
344-
await ensurePodEditAccess({ id, userId });
345-
const pod = await prisma.pod.update({
346-
where: {
347-
id,
348-
},
349-
data: {
350-
...input,
351-
parent:
352-
input.parent && input.parent !== "ROOT"
353-
? {
354-
connect: {
355-
id: input.parent,
356-
},
357-
}
358-
: undefined,
359-
children: {
360-
connect: input.children?.map((id) => ({ id })),
319+
});
320+
} else {
321+
// if repoId doesn't have id, create it IF input.parent exists, otherwise throw error.
322+
await prisma.pod.create({
323+
data: {
324+
id,
325+
...input,
326+
// Dummy index because it is a required field for historical reasons.
327+
index: 0,
328+
parent:
329+
input.parent && input.parent !== "ROOT"
330+
? {
331+
connect: {
332+
id: input.parent,
333+
},
334+
}
335+
: undefined,
336+
// In case of [], create will throw an error. Thus I have to pass undefined.
337+
// children: input.children.length > 0 ? input.children : undefined,
338+
children: {
339+
connect: input.children?.map((id) => ({ id })),
340+
},
341+
repo: {
342+
connect: {
343+
id: repoId,
344+
},
345+
},
361346
},
362-
},
363-
});
347+
});
348+
}
349+
364350
return true;
365351
}
366352

api/src/typedefs.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ export const typeDefs = gql`
116116
createRepo: Repo
117117
updateRepo(id: ID, name: String): Boolean
118118
deleteRepo(id: ID): Boolean
119-
addPod(repoId: String, parent: String, index: Int, input: PodInput): Boolean
120119
deletePod(id: String, toDelete: [String]): Boolean
121-
updatePod(id: String, input: PodInput): Boolean
120+
updatePod(id: String, repoId: String, input: PodInput): Boolean
122121
clearUser: Boolean
123122
clearRepo: Boolean
124123
clearPod: Boolean

ui/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"@emotion/styled": "^11.10.5",
1111
"@mui/icons-material": "^5.10.9",
1212
"@mui/material": "^5.10.10",
13+
"@reactflow/node-resizer": "^1.2.0",
1314
"@remirror/extension-react-tables": "^2.2.9",
1415
"@remirror/extension-sub": "^2.0.9",
1516
"@remirror/extension-text-highlight": "^2.0.10",
@@ -41,7 +42,7 @@
4142
"react-resizable": "^3.0.4",
4243
"react-router-dom": "^6.4.2",
4344
"react-scripts": "5.0.1",
44-
"reactflow": "^11.3.0",
45+
"reactflow": "^11.4.0",
4546
"remirror": "^2.0.21",
4647
"slate": "^0.82.1",
4748
"slate-history": "^0.66.0",

ui/src/App.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,22 @@
7474
.my-underline {
7575
text-decoration: wavy underline red;
7676
}
77+
78+
.react-flow__node-scope.active {
79+
box-shadow: 0px 0px 12px 0px rgba(100, 100, 100, 0.9);
80+
}
81+
82+
.react-flow__node-scope.selected,
83+
.react-flow__node-scope:hover {
84+
box-shadow: 0px 0px 8px 0px rgba(100, 100, 100, 0.5);
85+
}
86+
87+
.react-flow__node-scope.selected {
88+
border-width: 2px;
89+
}
90+
91+
.react-flow__node.cutting {
92+
/* box-shadow: 0px 0px 8px 0px rgba(100, 100, 100, 0.5); */
93+
/* a dashed red border */
94+
border: 2px dashed red;
95+
}

0 commit comments

Comments
 (0)