-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
224 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
...cation/components/ClientNotFoundModal.tsx → ...components/Modals/ClientNotFoundModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...components/ClientNotFoundModal.vscode.tsx → ...nts/Modals/ClientNotFoundModal.vscode.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { useSelector } from "@xstate/react"; | ||
import { | ||
useDevToolsActorRef, | ||
useDevToolsSelector, | ||
} from "../../machines/devtoolsMachine"; | ||
import { ClientNotFoundModal } from "./ClientNotFoundModal"; | ||
import { PortNotOpenModal } from "./PortNotOpenModal"; | ||
import { UnknownErrorModal } from "./UnknownErrorModal"; | ||
|
||
export function Modals() { | ||
const { send } = useDevToolsActorRef(); | ||
|
||
let modalHandled = false; | ||
const modals: React.ReactNode[] = []; | ||
|
||
const openPortNotOpenModal = useDevToolsSelector( | ||
(state) => state.context.listening === false | ||
); | ||
modals.push( | ||
<PortNotOpenModal | ||
key="portNotOpen" | ||
open={!modalHandled && openPortNotOpenModal} | ||
/> | ||
); | ||
modalHandled ||= openPortNotOpenModal; | ||
|
||
const reconnectActor = useDevToolsSelector( | ||
(state) => state.children.reconnect | ||
); | ||
const openClientNotFoundModal = useSelector( | ||
reconnectActor, | ||
(state) => state?.status === "active" && state.value === "notFound" | ||
); | ||
modals.push( | ||
<ClientNotFoundModal | ||
key="clientNotFound" | ||
open={!modalHandled && openClientNotFoundModal} | ||
onClose={() => {}} | ||
onRetry={() => send({ type: "connection.retry" })} | ||
/> | ||
); | ||
modalHandled ||= openClientNotFoundModal; | ||
|
||
const isErrorState = useDevToolsSelector( | ||
(state) => state.value.initialization === "error" | ||
); | ||
modals.push( | ||
<UnknownErrorModal | ||
key="unknownError" | ||
open={!modalHandled && isErrorState} | ||
/> | ||
); | ||
|
||
return <>{modals}</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { UnknownErrorModal as PortNotOpenModal } from "./UnknownErrorModal"; |
74 changes: 74 additions & 0 deletions
74
src/application/components/Modals/PortNotOpenModal.vscode.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { expectTypeOf } from "expect-type"; | ||
import { Button } from "../Button"; | ||
import { GitHubIssueLink, SECTIONS, LABELS } from "../GitHubIssueLink"; | ||
import { Modal } from "../Modal"; | ||
import IconGitHubSolid from "@apollo/icons/small/IconGitHubSolid.svg"; | ||
import { Disclosure } from "../Disclosure"; | ||
import { useDevToolsSelector } from "../../machines/devtoolsMachine"; | ||
|
||
expectTypeOf<typeof import("./PortNotOpenModal.jsx")>().toMatchTypeOf< | ||
typeof import("./PortNotOpenModal.vscode.jsx") | ||
>(); | ||
|
||
interface ErrorModalProps { | ||
open: boolean; | ||
} | ||
|
||
export function PortNotOpenModal({ open }: ErrorModalProps) { | ||
const port = useDevToolsSelector( | ||
(state) => state.context.port ?? "<default port>" | ||
); | ||
return ( | ||
<Modal open={open} onClose={() => false} size="xl"> | ||
<Modal.Header> | ||
<Modal.Title>DevTools Server not running on port {port}</Modal.Title> | ||
</Modal.Header>{" "} | ||
<Modal.Description> | ||
The Apollo Client DevTools Server is currently not running. This can | ||
have one of the following reasons: | ||
</Modal.Description> | ||
<Modal.Body> | ||
<div className="mt-4 flex flex-col gap-2"> | ||
<Disclosure> | ||
<Disclosure.Button> | ||
Another instance of the DevTools is already running on port {port} | ||
</Disclosure.Button> | ||
<Disclosure.Panel>TODO</Disclosure.Panel> | ||
</Disclosure> | ||
<Disclosure> | ||
<Disclosure.Button> | ||
Another program is already running on port {port} | ||
</Disclosure.Button> | ||
<Disclosure.Panel>TODO</Disclosure.Panel> | ||
</Disclosure> | ||
<Disclosure> | ||
<Disclosure.Button> | ||
The DevTools were stopped manually | ||
</Disclosure.Button> | ||
<Disclosure.Panel>TODO</Disclosure.Panel> | ||
</Disclosure> | ||
</div> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Button | ||
asChild | ||
size="md" | ||
variant="secondary" | ||
icon={<IconGitHubSolid />} | ||
> | ||
<GitHubIssueLink | ||
className="no-underline" | ||
labels={[LABELS.bug]} | ||
body={` | ||
${SECTIONS.defaultDescription} | ||
${SECTIONS.apolloClientVersion} | ||
${SECTIONS.devtoolsVersion} | ||
`} | ||
> | ||
<span>Create an issue</span> | ||
</GitHubIssueLink> | ||
</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Button } from "../Button"; | ||
import { GitHubIssueLink, SECTIONS, LABELS } from "../GitHubIssueLink"; | ||
import { Modal } from "../Modal"; | ||
import IconGitHubSolid from "@apollo/icons/small/IconGitHubSolid.svg"; | ||
|
||
interface ErrorModalProps { | ||
open: boolean; | ||
} | ||
|
||
export function UnknownErrorModal({ open }: ErrorModalProps) { | ||
return ( | ||
<Modal open={open} onClose={() => false} size="xl"> | ||
<Modal.Header> | ||
<Modal.Title>Error</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<Modal.Description> | ||
An unknown error occured. <br /> | ||
If this error persists, please open an issue on GitHub. | ||
</Modal.Description> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Button | ||
asChild | ||
size="md" | ||
variant="secondary" | ||
icon={<IconGitHubSolid />} | ||
> | ||
<GitHubIssueLink | ||
className="no-underline" | ||
labels={[LABELS.bug]} | ||
body={` | ||
${SECTIONS.defaultDescription} | ||
${SECTIONS.apolloClientVersion} | ||
${SECTIONS.devtoolsVersion} | ||
`} | ||
> | ||
<span>Create an issue</span> | ||
</GitHubIssueLink> | ||
</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
); | ||
} |
Oops, something went wrong.