Skip to content

Commit

Permalink
Merge pull request #583 from Gencaster/no-delete-entry-node
Browse files Browse the repository at this point in the history
Do not allow deletion of entry node
  • Loading branch information
capital-G authored Oct 3, 2023
2 parents 5d11e7f + 5de83f0 commit fa0c6a4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
10 changes: 9 additions & 1 deletion caster-back/gencaster/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,15 @@ async def delete_edge(self, info, edge_uuid: uuid.UUID) -> None:
async def delete_node(self, info, node_uuid: uuid.UUID) -> None:
"""Deletes a given :class:`~story_graph.models.Node`."""
await graphql_check_authenticated(info)
await story_graph_models.Node.objects.filter(uuid=node_uuid).adelete()
node = await story_graph_models.Node.objects.aget(uuid=node_uuid)
if node is None:
raise Exception(f"Could not find node {node_uuid}")
if node.is_entry_node:
raise Exception(
f"Node {node_uuid} is an entry node which can not be deleted"
)
await node.adelete()
return None

@strawberry.mutation
async def create_script_cells(
Expand Down
2 changes: 1 addition & 1 deletion caster-editor/src/components/DialogAddNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const createNode = async () => {
<template #footer>
<span class="dialog-footer">
<ElButton
type="danger"
type="info"
@click="() => emit('closed')"
>Cancel</ElButton>
<ElButton
Expand Down
3 changes: 2 additions & 1 deletion caster-editor/src/components/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ import MenuTab from "./MenuTabHeader.vue";
import MenuTabEdit from "./MenuTabEdit.vue";
import MenuTabPlay from "./MenuTabPlay.vue";
import DialogExitGraph from "./DialogExitGraph.vue";
import type { GraphEdit } from "./MenuTabEdit.vue";
export type GraphMenu = Pick<Graph, "name" | "uuid" | "slugName">;
export type GraphMenu = Pick<Graph, "name" | "uuid" | "slugName"> & GraphEdit;
// Props
defineProps<{
Expand Down
20 changes: 17 additions & 3 deletions caster-editor/src/components/MenuTabEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@
</template>

<script setup lang="ts">
import type { Graph } from "@/graphql";
import type { Graph, Node } from "@/graphql";
import { useDeleteEdgeMutation, useDeleteNodeMutation } from "@/graphql";
import { useInterfaceStore } from "@/stores/InterfaceStore";
import { ElMessage } from "element-plus";
import { storeToRefs } from "pinia";
import { ref, type Ref } from "vue";
import DialogAddNode from "./DialogAddNode.vue";
export type GraphEdit = Pick<Graph, "uuid">;
export type GraphEdit = Pick<Graph, "uuid"> & {
nodes: Pick<Node, "uuid" | "isEntryNode">[];
};
defineProps<{
const props = defineProps<{
graph: GraphEdit;
}>();
Expand All @@ -44,6 +46,12 @@ const showAddNodeDialog: Ref<boolean> = ref(false);
const deleteNodeMutation = useDeleteNodeMutation();
const deleteEdgeMutation = useDeleteEdgeMutation();
const checkIfNodeEntry = (nodeUuid: string): boolean => {
return (
props.graph.nodes.find((x) => x.uuid === nodeUuid)?.isEntryNode ?? false
);
};
const removeSelection = async () => {
console.log("Removing selection");
Expand All @@ -60,6 +68,12 @@ const removeSelection = async () => {
});
selectedNodeUUIDs.value.forEach(async (nodeUuid) => {
// compare if to props.graph.nodes and find isEntryNode
if (checkIfNodeEntry(nodeUuid)) {
ElMessage.error(`Cannot delete entry node.`);
return;
}
const { error } = await deleteNodeMutation.executeMutation({
nodeUuid,
});
Expand Down

0 comments on commit fa0c6a4

Please sign in to comment.