Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allow deletion of entry node #583

Merged
merged 8 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading