Skip to content

Commit fa0c6a4

Browse files
authored
Merge pull request #583 from Gencaster/no-delete-entry-node
Do not allow deletion of entry node
2 parents 5d11e7f + 5de83f0 commit fa0c6a4

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

caster-back/gencaster/schema.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,15 @@ async def delete_edge(self, info, edge_uuid: uuid.UUID) -> None:
294294
async def delete_node(self, info, node_uuid: uuid.UUID) -> None:
295295
"""Deletes a given :class:`~story_graph.models.Node`."""
296296
await graphql_check_authenticated(info)
297-
await story_graph_models.Node.objects.filter(uuid=node_uuid).adelete()
297+
node = await story_graph_models.Node.objects.aget(uuid=node_uuid)
298+
if node is None:
299+
raise Exception(f"Could not find node {node_uuid}")
300+
if node.is_entry_node:
301+
raise Exception(
302+
f"Node {node_uuid} is an entry node which can not be deleted"
303+
)
304+
await node.adelete()
305+
return None
298306

299307
@strawberry.mutation
300308
async def create_script_cells(

caster-editor/src/components/DialogAddNode.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const createNode = async () => {
7171
<template #footer>
7272
<span class="dialog-footer">
7373
<ElButton
74-
type="danger"
74+
type="info"
7575
@click="() => emit('closed')"
7676
>Cancel</ElButton>
7777
<ElButton

caster-editor/src/components/Menu.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ import MenuTab from "./MenuTabHeader.vue";
5757
import MenuTabEdit from "./MenuTabEdit.vue";
5858
import MenuTabPlay from "./MenuTabPlay.vue";
5959
import DialogExitGraph from "./DialogExitGraph.vue";
60+
import type { GraphEdit } from "./MenuTabEdit.vue";
6061
61-
export type GraphMenu = Pick<Graph, "name" | "uuid" | "slugName">;
62+
export type GraphMenu = Pick<Graph, "name" | "uuid" | "slugName"> & GraphEdit;
6263
6364
// Props
6465
defineProps<{

caster-editor/src/components/MenuTabEdit.vue

+17-3
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@
2121
</template>
2222

2323
<script setup lang="ts">
24-
import type { Graph } from "@/graphql";
24+
import type { Graph, Node } from "@/graphql";
2525
import { useDeleteEdgeMutation, useDeleteNodeMutation } from "@/graphql";
2626
import { useInterfaceStore } from "@/stores/InterfaceStore";
2727
import { ElMessage } from "element-plus";
2828
import { storeToRefs } from "pinia";
2929
import { ref, type Ref } from "vue";
3030
import DialogAddNode from "./DialogAddNode.vue";
3131
32-
export type GraphEdit = Pick<Graph, "uuid">;
32+
export type GraphEdit = Pick<Graph, "uuid"> & {
33+
nodes: Pick<Node, "uuid" | "isEntryNode">[];
34+
};
3335
34-
defineProps<{
36+
const props = defineProps<{
3537
graph: GraphEdit;
3638
}>();
3739
@@ -44,6 +46,12 @@ const showAddNodeDialog: Ref<boolean> = ref(false);
4446
const deleteNodeMutation = useDeleteNodeMutation();
4547
const deleteEdgeMutation = useDeleteEdgeMutation();
4648
49+
const checkIfNodeEntry = (nodeUuid: string): boolean => {
50+
return (
51+
props.graph.nodes.find((x) => x.uuid === nodeUuid)?.isEntryNode ?? false
52+
);
53+
};
54+
4755
const removeSelection = async () => {
4856
console.log("Removing selection");
4957
@@ -60,6 +68,12 @@ const removeSelection = async () => {
6068
});
6169
6270
selectedNodeUUIDs.value.forEach(async (nodeUuid) => {
71+
// compare if to props.graph.nodes and find isEntryNode
72+
if (checkIfNodeEntry(nodeUuid)) {
73+
ElMessage.error(`Cannot delete entry node.`);
74+
return;
75+
}
76+
6377
const { error } = await deleteNodeMutation.executeMutation({
6478
nodeUuid,
6579
});

0 commit comments

Comments
 (0)