diff --git a/src/CodexUrllSettings/CodexUrlSettings.tsx b/src/CodexUrllSettings/CodexUrlSettings.tsx index f616ab5..99f6766 100644 --- a/src/CodexUrllSettings/CodexUrlSettings.tsx +++ b/src/CodexUrllSettings/CodexUrlSettings.tsx @@ -1,7 +1,6 @@ import { useQueryClient } from "@tanstack/react-query"; import { useEffect, useState } from "react"; import { Button, Input, Toast } from "@codex/marketplace-ui-components"; -import { CircleCheck } from "lucide-react"; import { CodexSdk } from "../sdk/codex"; export function CodexUrlSettings() { @@ -27,13 +26,6 @@ export function CodexUrlSettings() { }); }; - const Check = () => ( - - ); - return ( <> - + ); } diff --git a/src/components/ErrorBoundary/ErrorBoundary.css b/src/components/ErrorBoundary/ErrorBoundary.css new file mode 100644 index 0000000..5f2d369 --- /dev/null +++ b/src/components/ErrorBoundary/ErrorBoundary.css @@ -0,0 +1,7 @@ +.errorBoundary { + border-radius: var(--codex-border-radius); + border: 1px solid var(--codex-border-color); + background-color: var(--codex-background-secondary); + margin: auto; + padding: 1.5rem; +} diff --git a/src/components/ErrorBoundary/ErrorBoundary.tsx b/src/components/ErrorBoundary/ErrorBoundary.tsx index eb9e398..0c26772 100644 --- a/src/components/ErrorBoundary/ErrorBoundary.tsx +++ b/src/components/ErrorBoundary/ErrorBoundary.tsx @@ -1,18 +1,14 @@ +import { Placeholder } from "@codex/marketplace-ui-components"; +import { CircleX } from "lucide-react"; import React, { ErrorInfo, ReactNode } from "react"; -import { ErrorBoundaryContext } from "../../contexts/ErrorBoundaryContext"; +import "./ErrorBoundary.css"; type State = { hasError: boolean; }; type Props = { - fallback: ({ - children, - error, - }: { - children: ReactNode; - error: string; - }) => ReactNode; + card: boolean; children: ReactNode; }; @@ -37,34 +33,21 @@ export class ErrorBoundary extends React.Component { console.error("Got error", error, info); } - private catch(error: Error) { - //logErrorToMyService(error); - console.error(error); - this.setState({ hasError: true }); - } - render() { if (this.state.hasError) { - const Fallback = this.props.fallback; - return ( - - - +
+ } + title="Something went wrong" + message="Something went wrong, please try to load the component again." + onRetry={() => this.setState({ hasError: false })}> +
); } - return ( - this.catch(error)}> - {this.props.children} - - ); + console.info("couc"); + + return this.props.children; } } diff --git a/src/components/LogLevel/LogLevel.tsx b/src/components/LogLevel/LogLevel.tsx index 97bdb6b..44422cf 100644 --- a/src/components/LogLevel/LogLevel.tsx +++ b/src/components/LogLevel/LogLevel.tsx @@ -1,35 +1,42 @@ import { CodexLogLevel } from "@codex/sdk-js"; import { useMutation, useQueryClient } from "@tanstack/react-query"; -import { useContext, useState } from "react"; -import { ErrorBoundaryContext } from "../../contexts/ErrorBoundaryContext"; +import { useState } from "react"; import { CodexSdk } from "../../sdk/codex"; import "./LogLevel.css"; import { Button, Select, Toast } from "@codex/marketplace-ui-components"; -import { CircleCheck } from "lucide-react"; +import { Promises } from "../../utils/promises"; export function LogLevel() { const queryClient = useQueryClient(); const [level, setLevel] = useState("DEBUG"); - const report = useContext(ErrorBoundaryContext); - const { mutateAsync, isPending, isError, error } = useMutation({ + const { mutateAsync, isPending } = useMutation({ mutationKey: ["debug"], mutationFn: (level: CodexLogLevel) => - CodexSdk.debug().then((debug) => debug.setLogLevel(level)), + CodexSdk.debug() + .then((debug) => debug.setLogLevel(level)) + .then((s) => Promises.rejectOnError(s)), onSuccess: () => { setToast({ message: "The log level has been updated successfully.", time: Date.now(), + variant: "success", }); queryClient.invalidateQueries({ queryKey: ["debug"] }); }, + onError: (error) => { + // TODO report to sentry + setToast({ + message: "Error when trying to update: " + error, + time: Date.now(), + variant: "error", + }); + }, + }); + const [toast, setToast] = useState({ + time: 0, + message: "", + variant: "success", }); - const [toast, setToast] = useState({ time: 0, message: "" }); - - if (isError) { - // TODO remove this - report(new Error(error.message)); - return ""; - } function onChange(e: React.FormEvent) { const value = e.currentTarget.value; @@ -52,13 +59,6 @@ export function LogLevel() { ["FATAL", "FATAL"], ] satisfies [string, string][]; - const Check = () => ( - - ); - return ( <> */} - ), }); diff --git a/src/utils/promises.ts b/src/utils/promises.ts index b07dcea..c0ad570 100644 --- a/src/utils/promises.ts +++ b/src/utils/promises.ts @@ -1,6 +1,8 @@ import { SafeValue } from "@codex/sdk-js"; export const Promises = { - rejectOnError: (safe: SafeValue) => - safe.error ? Promise.reject(safe.data) : Promise.resolve(safe.data), + rejectOnError: (safe: SafeValue) => { + // TODO Sentry + return safe.error ? Promise.reject(safe.data) : Promise.resolve(safe.data); + }, };