Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
LatentDream committed Feb 26, 2024
1 parent 6695eb9 commit d148062
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 41 deletions.
16 changes: 11 additions & 5 deletions captain/internal/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def __init__(self):

# Manager for Test Sequencer activities
class TSManager(WSManager):

def __init__(self):
self.runner: asyncio.Runner | None = None # holds the running sequencer
super().__init__()
Expand All @@ -35,11 +34,18 @@ def kill_runner(self, *args, **kwargs):
# Current Task can't be kill, but a PoisonPill in queue will stop the next task
logger.error(f"Error while killing TS Runner: {e}")
self.runner = None
asyncio.run(self.ws.broadcast(
TestSequenceMessage(
MsgState.ERROR.value, "", False, -1, False, "Test sequence was interrupted"
asyncio.run(
self.ws.broadcast(
TestSequenceMessage(
MsgState.ERROR.value,
"",
False,
-1,
False,
"Test sequence was interrupted",
)
)
))
)


# Manager for flowchart activities (main manager)
Expand Down
2 changes: 1 addition & 1 deletion captain/types/test_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TestSequenceMessage(dict):
the expected format of the front-end.
"""

state: str
state: str
target_id: str
result: bool
time_taken: float
Expand Down
5 changes: 4 additions & 1 deletion captain/utils/test_sequencer/handle_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

lock = Lock()


def _handle_subscribe(_data: TestSequenceRun, _ts_manager: TSManager):
logger.info("TEST SEQUENCER WS CONNECTION TEST PASSED")

Expand All @@ -35,7 +36,9 @@ def _handle_export(data: TestSequenceRun, ts_manager: TSManager):
ts_manager.runner = None


event_to_handle: dict[TestSequenceEvents, Callable[[TestSequenceRun, TSManager], None]] = {
event_to_handle: dict[
TestSequenceEvents, Callable[[TestSequenceRun, TSManager], None]
] = {
"subscribe": _handle_subscribe,
"run": _handle_run,
"stop": ts_manager.kill_runner,
Expand Down
10 changes: 8 additions & 2 deletions src/renderer/context/testSequencerWS.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ export function TestSequencerWSProvider({
}: {
children?: React.ReactNode;
}) {
const { websocketId, setRunning, setElems, setIsLocked, setIsLoading, setBackendState } =
useTestSequencerState();
const {
websocketId,
setRunning,
setElems,
setIsLocked,
setIsLoading,
setBackendState,
} = useTestSequencerState();
const { sendJsonMessage, lastJsonMessage, readyState } = useWebSocket(
`${TS_SOCKET_URL}/${websocketId}`,
{
Expand Down
41 changes: 27 additions & 14 deletions src/renderer/hooks/useToggleSettingModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,35 @@ export const editorSettingsModal = atom<boolean>(false);
export const deviceSettingsModal = atom<boolean>(false);
export const depManagerModal = atom<boolean>(false);


export function useToggleSettingModal() {
const [isKeyboardShortcutOpen, setIsKeyboardShortcutOpen] = useAtom(keyboardShortcutModal);
const [isKeyboardShortcutOpen, setIsKeyboardShortcutOpen] = useAtom(
keyboardShortcutModal,
);
const [isEnvVarModalOpen, setIsEnvVarModalOpen] = useAtom(envVarModal);
const [isNodeSettingsOpen, setIsNodeSettingsOpen] = useAtom(nodeSettingsModal);
const [isDebugSettingsOpen, setIsDebugSettingsOpen] = useAtom(debugSettingsModal);
const [isEditorSettingsOpen, setIsEditorSettingsOpen] =useAtom(editorSettingsModal);
const [isDeviceSettingsOpen, setIsDeviceSettingsOpen] = useAtom(deviceSettingsModal);
const [isDepManagerModalOpen, setIsDepManagerModalOpen] = useAtom(depManagerModal);
const [isNodeSettingsOpen, setIsNodeSettingsOpen] =
useAtom(nodeSettingsModal);
const [isDebugSettingsOpen, setIsDebugSettingsOpen] =
useAtom(debugSettingsModal);
const [isEditorSettingsOpen, setIsEditorSettingsOpen] =
useAtom(editorSettingsModal);
const [isDeviceSettingsOpen, setIsDeviceSettingsOpen] =
useAtom(deviceSettingsModal);
const [isDepManagerModalOpen, setIsDepManagerModalOpen] =
useAtom(depManagerModal);
return {
isKeyboardShortcutOpen, setIsKeyboardShortcutOpen,
isEnvVarModalOpen, setIsEnvVarModalOpen,
isNodeSettingsOpen, setIsNodeSettingsOpen,
isDebugSettingsOpen, setIsDebugSettingsOpen,
isEditorSettingsOpen, setIsEditorSettingsOpen,
isDeviceSettingsOpen, setIsDeviceSettingsOpen,
isDepManagerModalOpen, setIsDepManagerModalOpen,
isKeyboardShortcutOpen,
setIsKeyboardShortcutOpen,
isEnvVarModalOpen,
setIsEnvVarModalOpen,
isNodeSettingsOpen,
setIsNodeSettingsOpen,
isDebugSettingsOpen,
setIsDebugSettingsOpen,
isEditorSettingsOpen,
setIsEditorSettingsOpen,
isDeviceSettingsOpen,
setIsDeviceSettingsOpen,
isDepManagerModalOpen,
setIsDepManagerModalOpen,
};
}
23 changes: 16 additions & 7 deletions src/renderer/routes/flow_chart/views/ControlBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,22 @@ import { useActiveTab, TabName } from "@/renderer/hooks/useActiveTab";
import { useToggleSettingModal } from "@/renderer/hooks/useToggleSettingModal";

const ControlBar = () => {
const { isKeyboardShortcutOpen, setIsKeyboardShortcutOpen,
isEnvVarModalOpen, setIsEnvVarModalOpen,
isNodeSettingsOpen, setIsNodeSettingsOpen,
isDebugSettingsOpen, setIsDebugSettingsOpen,
isEditorSettingsOpen, setIsEditorSettingsOpen,
isDeviceSettingsOpen, setIsDeviceSettingsOpen,
isDepManagerModalOpen, setIsDepManagerModalOpen } = useToggleSettingModal();
const {
isKeyboardShortcutOpen,
setIsKeyboardShortcutOpen,
isEnvVarModalOpen,
setIsEnvVarModalOpen,
isNodeSettingsOpen,
setIsNodeSettingsOpen,
isDebugSettingsOpen,
setIsDebugSettingsOpen,
isEditorSettingsOpen,
setIsEditorSettingsOpen,
isDeviceSettingsOpen,
setIsDeviceSettingsOpen,
isDepManagerModalOpen,
setIsDepManagerModalOpen,
} = useToggleSettingModal();
const { activeTab } = useActiveTab();

const handleCheckForUpdates = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Props = {

export const ImportTestModal = ({ isModalOpen, handleModalOpen }: Props) => {
const [checked, setChecked] = useState<boolean>(false);
const { setIsDepManagerModalOpen } = useToggleSettingModal ();
const { setIsDepManagerModalOpen } = useToggleSettingModal();
const openFilePicker = useTestImport();
const { setIsLocked } = useTestSequencerState();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { DataTable } from "./data-table/DataTable";
import { SummaryTable } from "./SummaryTable";
import { CloudPanel } from "./CloudPanel";
import { useTestSequencerState } from "@/renderer/hooks/useTestSequencerState";
import { testSequenceRunRequest, testSequenceStopRequest } from "../models/models";
import {
testSequenceRunRequest,
testSequenceStopRequest,
} from "../models/models";
import { TestSequenceElement } from "@/renderer/types/testSequencer";
import { ImportTestModal } from "./ImportTestModal";
import LockableButton from "./lockable/LockedButtons";
Expand Down Expand Up @@ -110,9 +113,15 @@ const TestSequencerView = () => {
className="mt-4 w-full gap-2"
isLocked={_.isEmpty(tree)}
isException={backendState === "TEST_SET_START"}
onClick={backendState === "TEST_SET_START" ? handleClickStopTest : handleClickRunTest}
onClick={
backendState === "TEST_SET_START"
? handleClickStopTest
: handleClickRunTest
}
>
{backendState === "TEST_SET_START" ? "Stop Test Sequence" : "Run Test Sequence"}
{backendState === "TEST_SET_START"
? "Stop Test Sequence"
: "Run Test Sequence"}
</LockableButton>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ const mapStatusToDisplay: { [k in StatusTypes] } = {
) : (
<HoverCard>
<HoverCardTrigger>
<p className="z-20 relative text text-red-500 underline underline-offset-2">FAIL</p>
<p className="text relative z-20 text-red-500 underline underline-offset-2">
FAIL
</p>
</HoverCardTrigger>
<HoverCardContent className="w-256">
<h2 className="text-muted-foreground">Error Message:</h2>
Expand Down
5 changes: 2 additions & 3 deletions src/renderer/routes/test_sequencer_panel/models/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export const testSequenceRunRequest: (tree: TestRootNode) => TestSequenceRun = (
};
};

export const testSequenceStopRequest: (tree: TestRootNode) => TestSequenceRun = (
export const testSequenceStopRequest: (
tree: TestRootNode,
) => {
) => TestSequenceRun = (tree: TestRootNode) => {
return {
event: "stop",
data: tree,
Expand All @@ -32,7 +32,6 @@ export const testSequenceStopRequest: (tree: TestRootNode) => TestSequenceRun =
};
};


export const testSequenceExportCloud: (
tree: TestRootNode,
hardware_id: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ export const createLockedEntity: CreateLockedEntity = (ComponentToDisable) => {
? props.isLocked || value.isLocked
: value.isLocked;
const isException =
typeof props.isException !== "undefined"
? props.isException
: false;
typeof props.isException !== "undefined" ? props.isException : false;
const disabled = isLocked && !isException;
return (
<ComponentToDisable disabled={disabled} {...props}>
Expand Down

0 comments on commit d148062

Please sign in to comment.