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

[STU-343] Edit sequence name & description #1150

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0a5a9fd
chore(sequencer): new RenameModal
LatentDream Apr 11, 2024
a8b626a
chore(sequencer): rename modal - Sequence Name and Sequence Description
LatentDream Apr 11, 2024
36539a0
chore(sequencer): better dropdown menu for test table
LatentDream Apr 11, 2024
00a0feb
chore(sequencer): formatting
LatentDream Apr 11, 2024
5506e28
chore(sequencer): patch the 'not save' when it's actually save. tmp
LatentDream Apr 11, 2024
2a335b8
chore(sequencer): handle set unsaved false in the save function
LatentDream Apr 11, 2024
206bee4
chore(sequencer): formatting
LatentDream Apr 11, 2024
82a3684
Merge branch 'main' into stu-343-edit-sequence-name-descriotion
LatentDream Apr 11, 2024
0b5e84a
[stu-343-edit-sequence-name-descriotion] refactor: setSequences, usin…
LatentDream Apr 15, 2024
ff39d3e
[stu-343-edit-sequence-name-descriotion] chore: using Immer + remove …
LatentDream Apr 15, 2024
0b2ee85
chore: format
LatentDream Apr 15, 2024
de16acb
Merge branch 'main' into stu-343-edit-sequence-name-descriotion
LatentDream Apr 15, 2024
1bc41ad
[stu-343-edit-sequence-name-descriotion] tmp: disable edit menu due t…
LatentDream Apr 15, 2024
c7206ef
[stu-343-edit-sequence-name-descriotion] Merge branch 'stu-343-edit-s…
LatentDream Apr 15, 2024
768bcc9
Revert "tmp: disable edit menu due to colision in ubuntu CI test"
LatentDream Apr 16, 2024
d420cf9
[stu-343-edit-sequence-name-descriotion] ci: adding screenshot to und…
LatentDream Apr 16, 2024
45f972a
Merge branch 'main' into stu-343-edit-sequence-name-descriotion
LatentDream Apr 16, 2024
a1c056f
[stu-343-edit-sequence-name-descriotion] Merge with lastest change
LatentDream Apr 16, 2024
173836b
fix(test_007): limit on the number of zoom out
LatentDream Apr 16, 2024
9768abd
ci: fix zoom out already max
LatentDream Apr 16, 2024
d2866b9
test(07): using RAND instead of SINE for CI problem
LatentDream Apr 16, 2024
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
12 changes: 10 additions & 2 deletions src/renderer/hooks/useTestSequencerProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ import { toastResultPromise } from "../utils/report-error";

function usePrepareStateManager(): StateManager {
const { elems, project } = useDisplayedSequenceState();
const { addNewSequence, removeSequence, sequences } = useSequencerState();
return { elems, project, addNewSequence, removeSequence, sequences };
const { addNewSequence, removeSequence, sequences, setSequences } =
useSequencerState();
return {
elems,
project,
addNewSequence,
removeSequence,
sequences,
setSequences,
};
}

export function useSaveSequence() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ContextMenu,
ContextMenuContent,
ContextMenuItem,
ContextMenuSeparator,
ContextMenuTrigger,
} from "@/renderer/components/ui/context-menu";
import {
Expand Down Expand Up @@ -40,14 +41,16 @@ import {
import { parseInt, map } from "lodash";
import { ChevronDownIcon, ChevronUpIcon, TrashIcon } from "lucide-react";
import LockableButton from "@/renderer/routes/test_sequencer_panel/components/lockable/LockedButtons";
import { useState } from "react";
import { useRef, useState } from "react";
import { DraggableRowSequence } from "@/renderer/routes/test_sequencer_panel/components/dnd/DraggableRowSequence";
import { getCompletionTime, getSuccessRate, mapStatusToDisplay } from "./utils";
import useWithPermission from "@/renderer/hooks/useWithPermission";
import { useImportSequences } from "@/renderer/hooks/useTestSequencerProject";
import { useSequencerModalStore } from "@/renderer/stores/modal";
import { useSequencerStore } from "@/renderer/stores/sequencer";
import { useShallow } from "zustand/react/shallow";
import { RenameModal } from "../modals/RenameModal";
import { toast } from "sonner";

export function SequenceTable() {
const { project, isLocked } = useDisplayedSequenceState();
Expand Down Expand Up @@ -255,8 +258,82 @@ export function SequenceTable() {
);
};

const onRenameSequence = (idx: number) => {
const sequence = sequences[idx];
renameForIdx.current = idx;
setRenameTarget(sequence.project.name);
setInitialName(sequence.project.name);
setIsRenameNameModalOpen(true);
};

const handleRenameSequence = (newName: string) => {
// make sure the new name is unique
if (sequences.some((seq) => seq.project.name === newName)) {
toast.error("Sequence name must be unique");
return;
}
setSequences(
[...sequences].map((seq, idx) => {
if (idx === renameForIdx.current) {
return {
...seq,
project: { ...seq.project, name: newName },
testSequenceUnsaved: true,
};
}
return seq;
}),
);
setIsRenameNameModalOpen(false);
};
const [isRenameNameModalOpen, setIsRenameNameModalOpen] = useState(false);
const [isRenameDescModalOpen, setIsRenameDescModalOpen] = useState(false);
const [renameTarget, setRenameTarget] = useState("");
const [initialName, setInitialName] = useState("");
const renameForIdx = useRef(-1);

const onRenameDescription = (idx: number) => {
const sequence = sequences[idx];
renameForIdx.current = idx;
setRenameTarget(sequence.project.name);
setInitialName(sequence.project.description);
setIsRenameDescModalOpen(true);
};

const handleRenameDescription = (newDescription: string) => {
setSequences(
[...sequences].map((seq, idx) => {
if (idx === renameForIdx.current) {
return {
...seq,
project: { ...seq.project, description: newDescription },
testSequenceUnsaved: true,
};
}
return seq;
}),
);
LatentDream marked this conversation as resolved.
Show resolved Hide resolved
setIsRenameDescModalOpen(false);
};

return (
<div className="flex flex-col">
<RenameModal
title="Rename sequence"
isModalOpen={isRenameNameModalOpen}
setModalOpen={setIsRenameNameModalOpen}
initialName={initialName}
handleSubmit={handleRenameSequence}
target={renameTarget}
/>
<RenameModal
title="Edit description"
isModalOpen={isRenameDescModalOpen}
setModalOpen={setIsRenameDescModalOpen}
initialName={initialName}
handleSubmit={handleRenameDescription}
target={renameTarget}
/>
<div className="m-1 flex items-center py-0">
{isAdmin() ? (
<LockableButton
Expand Down Expand Up @@ -336,6 +413,21 @@ export function SequenceTable() {
/>
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem
onClick={() => {
onRenameSequence(row.index);
}}
>
Rename sequence
</ContextMenuItem>
<ContextMenuItem
onClick={() => {
onRenameDescription(row.index);
}}
>
Edit description
</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem
onClick={() => {
onRemoveSequence([row.index]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ContextMenu,
ContextMenuContent,
ContextMenuItem,
ContextMenuSeparator,
ContextMenuTrigger,
} from "@/renderer/components/ui/context-menu";
import {
Expand Down Expand Up @@ -454,42 +455,43 @@ export function TestTable() {
Add Conditional
</ContextMenuItem>
{row.original.type === "test" && (
<ContextMenuItem
onClick={() => {
openRenameTestModal(row.original.id);
}}
>
Rename Test
</ContextMenuItem>
<>
<ContextMenuSeparator />
<ContextMenuItem
onClick={() => {
setOpenPyTestFileModal(true);
setTestToDisplay(row.original as Test);
}}
>
Consult Code
</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem
onClick={() => {
openRenameTestModal(row.original.id);
}}
>
Rename Test
</ContextMenuItem>
<ContextMenuItem
onClick={() => {
toggleExportToCloud(row.original.id);
}}
>
{row.original.exportToCloud
? "Disable export to Cloud"
: "Enable export to Cloud"}
</ContextMenuItem>
</>
)}
<ContextMenuSeparator />
<ContextMenuItem
onClick={() => onRemoveTest([parseInt(row.id)])}
>
{row.original.type === "test"
? "Remove Test"
: "Remove Conditional"}
</ContextMenuItem>
{row.original.type === "test" && (
<ContextMenuItem
onClick={() => {
setOpenPyTestFileModal(true);
setTestToDisplay(row.original as Test);
}}
>
Consult Code
</ContextMenuItem>
)}
{row.original.type === "test" && (
<ContextMenuItem
onClick={() => {
toggleExportToCloud(row.original.id);
}}
>
{row.original.exportToCloud
? "Disable export to Cloud"
: "Enable export to Cloud"}
</ContextMenuItem>
)}
</ContextMenuContent>
</ContextMenu>
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { TestSequenceContainer } from "@/renderer/types/test-sequencer";
export const DraggableRowSequence = ({
isSelected,
row,
...props
}: {
isSelected: boolean;
row: Row<TestSequenceContainer>;
Expand Down Expand Up @@ -80,6 +81,7 @@ export const DraggableRowSequence = ({
className={"relative" + (isSelected ? " bg-primary-foreground" : "")}
onClick={() => handleDisplaySequence(row.index)}
ref={drag}
{...props}
>
{/* capture drag on above */}
<div ref={dropAbove} className="absolute top-0 z-10 h-1/2 w-full" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Button } from "@/renderer/components/ui/button";
import { Dialog, DialogContent } from "@/renderer/components/ui/dialog";
import { Input } from "@/renderer/components/ui/input";
import { useEffect, useState } from "react";

export const RenameModal = ({
title,
isModalOpen,
setModalOpen,
initialName,
handleSubmit,
target,
}: {
title: string;
isModalOpen: boolean;
setModalOpen: (value: boolean) => void;
initialName: string;
handleSubmit: (newName: string) => void;
target: string;
}) => {
const [newName, setNewName] = useState<string>(initialName);
itsjoeoui marked this conversation as resolved.
Show resolved Hide resolved
useEffect(() => {
setNewName(initialName);
}, [initialName]);

return (
<Dialog open={isModalOpen} onOpenChange={setModalOpen}>
<DialogContent>
<h2 className="text-lg font-bold text-accent1">{title}</h2>
<div className="pb-1 text-muted-foreground">
<h2>{target}</h2>
</div>
<Input
placeholder="New Name"
value={newName}
onChange={(e) => setNewName(e.target.value)}
/>
<Button onClick={() => handleSubmit(newName)}>Rename</Button>
</DialogContent>
</Dialog>
);
};
16 changes: 16 additions & 0 deletions src/renderer/routes/test_sequencer_panel/utils/SequenceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type StateManager = {
removeSequence: (name: string) => void;
project: TestSequencerProject | null;
sequences: TestSequenceContainer[];
setSequences: (sequences: TestSequenceContainer[]) => void;
};

export async function createSequence(
Expand Down Expand Up @@ -82,6 +83,15 @@ export async function saveSequence(
if (isSync.isErr()) {
return isSync;
}
// Set the sequence as saved
stateManager.setSequences(
[...stateManager.sequences].map((seq) => {
LatentDream marked this conversation as resolved.
Show resolved Hide resolved
if (seq.project.name === sequence.name) {
return { ...seq, testSequenceUnsaved: false };
}
return seq;
}),
);
return ok(undefined);
}

Expand Down Expand Up @@ -110,6 +120,12 @@ export async function saveSequences(
if (res.isErr()) {
return err(res.error);
}
stateManager.setSequences(
[...stateManager.sequences].map((seq) => ({
LatentDream marked this conversation as resolved.
Show resolved Hide resolved
...seq,
testSequenceUnsaved: false,
})),
);
});
return ok(undefined);
}
Expand Down
Loading