Skip to content

Commit de6f502

Browse files
feat: Delete decks from the ship map configuration
Ollixx/issue239
2 parents 0f723db + 71057a9 commit de6f502

File tree

4 files changed

+71
-29
lines changed

4 files changed

+71
-29
lines changed

client/app/data/plugins/deck.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ export const deck = t.router({
6565
}),
6666
delete: t.procedure
6767
.input(
68-
z.object({ pluginId: z.string(), shipId: z.string(), index: z.number() }),
68+
z.object({
69+
pluginId: z.string(),
70+
shipId: z.string(),
71+
deckId: z.string(),
72+
}),
6973
)
7074
.send(({ ctx, input }) => {
7175
inputAuth(ctx);
@@ -75,7 +79,10 @@ export const deck = t.router({
7579
);
7680
if (!ship) return;
7781

78-
ship.removeDeck(input.index);
82+
const deckIndex = ship.decks.findIndex(
83+
(deck) => deck.name === input.deckId,
84+
);
85+
ship.removeDeck(deckIndex);
7986

8087
pubsub.publish.plugin.ship.get({
8188
pluginId: input.pluginId,

client/app/routes/config+/$pluginId.ships+/$shipId+/shipMap.$deckName/route.tsx

-26
Original file line numberDiff line numberDiff line change
@@ -258,32 +258,6 @@ export default function DeckConfig() {
258258
>
259259
{addingEdges ? "Done Adding Edges" : "Add Edges"}
260260
</Button>
261-
<Button
262-
onClick={async (event) => {
263-
event.preventDefault();
264-
event.stopPropagation();
265-
const deckname = await prompt({
266-
header: "Change the current deck's name",
267-
body: "Give this deck a distinct name",
268-
defaultValue: deck.name,
269-
inputProps: { className: "input-error" },
270-
});
271-
if (typeof deckname === "string") {
272-
const result = await q.plugin.ship.deck.update.netSend({
273-
pluginId,
274-
shipId,
275-
deckId: deck.name,
276-
newName: deckname,
277-
});
278-
if (result) {
279-
deck.name = deckname;
280-
navigate(`../${result.name}`);
281-
}
282-
}
283-
}}
284-
>
285-
Rename Deck
286-
</Button>
287261
</div>
288262
<div>
289263
{addingNodes && <p>Click on map to add node</p>}

client/app/routes/config+/$pluginId.ships+/$shipId+/shipMap/route.tsx

+59
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useNavigate, useParams, Outlet } from "@remix-run/react";
33
import type { DragEndEvent } from "@dnd-kit/core";
44
import { q } from "@client/context/AppContext";
55
import { SortableList } from "@client/components/ui/SortableItem";
6+
import { useConfirm, usePrompt } from "@thorium/ui/AlertDialog";
67

78
export default function ShipMap() {
89
const { pluginId, shipId, deckName } = useParams() as {
@@ -11,6 +12,8 @@ export default function ShipMap() {
1112
deckName: string;
1213
};
1314
const navigate = useNavigate();
15+
const confirm = useConfirm();
16+
const prompt = usePrompt();
1417
const [data] = q.plugin.ship.get.useNetRequest({ pluginId, shipId });
1518

1619
async function handleDragEnd({
@@ -53,6 +56,62 @@ export default function ShipMap() {
5356
>
5457
Add Deck
5558
</Button>
59+
<div className="grid gap-2 grid-cols-2 mt-2">
60+
<Button
61+
className=""
62+
disabled={deckName && deckName.length > 0 ? false : true}
63+
title={
64+
deckName && deckName.length > 0
65+
? ""
66+
: "Select a deck to be able to rename it"
67+
}
68+
onClick={async (event) => {
69+
event.preventDefault();
70+
event.stopPropagation();
71+
const deckname = await prompt({
72+
header: "Change the current deck's name",
73+
body: "Give this deck a distinct name",
74+
defaultValue: deckName,
75+
inputProps: { className: "input-error" },
76+
});
77+
if (typeof deckname === "string") {
78+
const result = await q.plugin.ship.deck.update.netSend({
79+
pluginId,
80+
shipId,
81+
deckId: deckName,
82+
newName: deckname,
83+
});
84+
if (result) {
85+
navigate(`${result.name}`);
86+
}
87+
}
88+
}}
89+
>
90+
Rename Deck
91+
</Button>
92+
<Button
93+
className="btn-error"
94+
disabled={deckName ? false : true}
95+
onClick={async (event) => {
96+
event.preventDefault();
97+
event.stopPropagation();
98+
if (
99+
await confirm({
100+
header: `Are you sure you want to delete deck '${deckName}'?`,
101+
})
102+
) {
103+
await q.plugin.ship.deck.delete.netSend({
104+
pluginId,
105+
shipId,
106+
deckId: deckName,
107+
});
108+
navigate(`.`);
109+
}
110+
}}
111+
>
112+
Delete Deck
113+
</Button>
114+
</div>
56115
</div>
57116
<Outlet />
58117
</>

server/src/inputs/__test__/shipDecksPlugin.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ describe("ship decks plugin input", () => {
3939
mockDataContext.server.plugins[0].aspects.ships[0].decks.length,
4040
).toEqual(2);
4141

42+
const deckIndexToDelete =
43+
mockDataContext.server.plugins[0].aspects.ships[0].decks[0].name;
4244
await router.plugin.ship.deck.delete({
4345
pluginId: "Test Plugin",
4446
shipId: "Test Template",
45-
index: 0,
47+
deckId: deckIndexToDelete,
4648
});
4749

4850
expect(

0 commit comments

Comments
 (0)