Skip to content

Commit

Permalink
check
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnnsrs committed Sep 10, 2023
1 parent 23f1e5b commit 11bd7bc
Show file tree
Hide file tree
Showing 27 changed files with 1,227 additions and 492 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
"@headlessui/react": "^1.7.10",
"@hookform/resolvers": "^3.3.1",
"@jhnnsrs/fakts": "^0.1.1",
"@radix-ui/react-dialog": "^1.0.4",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-menubar": "^1.0.3",
"@radix-ui/react-popover": "^1.0.6",
"@radix-ui/react-scroll-area": "^1.0.4",
"@radix-ui/react-select": "^1.2.2",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tooltip": "^1.0.6",
"@tailwindcss/container-queries": "^0.1.0",
Expand All @@ -31,6 +33,7 @@
"framer-motion": "^10.16.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.11",
"react-hook-form": "^7.46.1",
"react-icons": "^4.8.0",
"react-router-dom": "^6.8.1",
Expand Down
52 changes: 52 additions & 0 deletions repo/channels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"repo": "default",
"channels":
[
{
"name": "paper",
"title": "Paper",
"experimental": false,
"logo": "https://python.doctor/images/django-python.png",
"long": "The paper deployment to reproduce the paper. Comes with a preconfigured set of apps and services to reproduce the paper",
"description": "The original paper deployment",
"features": [
{
"name": "Easy",
"description": "Easy to use",
"long": "This deployment is easy to use"
}
],
"builder": "jhnnsrs/arkitekt_paper_builder",
"forms": ["admin_user", "users", "groups"],
"defaults": {
"name": "mydeployment",
"admin_username": "",
"admin_password": "",
"admin_email": ""
}
},
{
"name": "next",
"title": "next",
"experimental": true,
"logo": "https://python.doctor/images/django-python.png",
"long": "The next deployment contains breaking changes and is not yet stable. It does however give an impression of the future of Arkitekt",
"description": "The next deployment",
"features": [
{
"name": "Easy",
"description": "Easy to use",
"long": "This deployment is easy to use"
}
],
"builder": "jhnnsrs/arkitekt_paper_builder",
"forms": ["admin_user", "users", "groups"],
"defaults": {
"name": "mydeployment",
"admin_username": "",
"admin_password": "",
"admin_email": ""
}
}
]
}
28 changes: 16 additions & 12 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@ import { SettingsProvider } from "./settings/settings-provider";
import { StorageProvider } from "./storage/storage-provider";
import { AppMenu } from "./components/AppMenu";
import { AnimatePresence } from "framer-motion";
import { TooltipProvider } from "./components/ui/tooltip";
import { AlerterProvider } from "./alerter/alert-provider";
import { AlerterContext } from "./alerter/alerter-context";
import { AlerterDialog } from "./alerter/AlerterDialog";

function App() {

const location = useLocation();

return (
<CommunicationProvider>
<BindingsProvider>
<BeaconProvider>
<SettingsProvider>
<StorageProvider>
<div className="h-screen w-screen bg-back-900 text-white w-screen flex h-full overflow-y-hidden flex flex-col">
<AppMenu/>
<Routes location={location} key={location.pathname}>
<AlerterProvider>
<AlerterDialog />
<BeaconProvider>
<TooltipProvider>
<SettingsProvider>
<StorageProvider>
<Routes location={location} key={location.pathname}>
<Route path="/" element={<Home />} />
<Route path="/settings" element={<Settings />} />
<Route path="/setup" element={<Setup />} />
Expand All @@ -40,10 +43,11 @@ function App() {
element={<LogScreen />}
/>
</Routes>
</div>
</StorageProvider>
</SettingsProvider>
</BeaconProvider>
</StorageProvider>
</SettingsProvider>
</TooltipProvider>
</BeaconProvider>
</AlerterProvider>
</BindingsProvider>
</CommunicationProvider>
);
Expand Down
87 changes: 53 additions & 34 deletions src/CommandButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { CommandParams, useCommand } from "./hooks/useCommand";
import { callbackify } from "util";
import { useState } from "react";
import { Button } from "./components/ui/button";
import { useAlerter } from "./alerter/alerter-context";
import { Popover, PopoverContent } from "./components/ui/popover";
import { PopoverClose, PopoverTrigger } from "@radix-ui/react-popover";

export const CommandButton = (props: {
params: CommandParams;
Expand All @@ -11,6 +14,7 @@ export const CommandButton = (props: {
runningTitle?: string;
}) => {
const { run, logs, error, finished, running } = useCommand(props.params);
const { alert } = useAlerter();

return (
<>
Expand All @@ -22,7 +26,11 @@ export const CommandButton = (props: {
if (x.code == 0) {
props.callback && props.callback(x);
} else {
alert(x.stderr);
alert({
error: `Error while running ${props.title}`,
message: x.stderr,
subtitle: x.stdout,
});
}
});
}}
Expand All @@ -32,7 +40,6 @@ export const CommandButton = (props: {
}`}
>
{running && props.runningTitle ? props.runningTitle : props.title}
{finished?.code == 1 && <div className="text-red-400">Error</div>}
</Button>
</>
);
Expand All @@ -42,43 +49,55 @@ export const DangerousCommandButton = (props: {
params: CommandParams;
title: string;
callback?: (x: ChildProcess) => void;
confirmTitle?: string;
confirmDescription?: string;
runningTitle?: string;
to?: number;
}) => {
const { run, logs, error, finished, running } = useCommand(props.params);
const [countDown, setCountDown] = useState<number>(1);
const { alert } = useAlerter();
const to = props.to || 10;
return (
<>
<Button
onClick={() => {
console.log("run");
if (countDown == to) {
setCountDown(1);
run().then((x) => {
console.log(x);
if (x.code == 0) {
props.callback && props.callback(x);
} else {
alert(x.stderr);
}
});
} else {
setCountDown(countDown + 1);
}
}}
disabled={running}
className={`border cursor-pointer shadow-md shadow bg-red-200 hover:bg-red-400 ${
countDown > 1 && "bg-red-400"
} border-1 border-gray-300 rounded p-2 bg-white text-black ${
running ? "animate-pulse" : ""
}`}
>
{running && props.runningTitle ? props.runningTitle : props.title}
{countDown > 1 &&
countDown < 11 &&
` ( ${to - countDown} more clicks to confirm)`}
</Button>
</>
<Popover>
<PopoverTrigger asChild>
<Button>
{running && props.runningTitle ? props.runningTitle : props.title}
</Button>
</PopoverTrigger>
<PopoverContent>
<div className="flex flex-col gap-1">
<div className="text-md">{props.confirmTitle || "Are you sure?"}</div>
<div className="text-xs text-muted-foreground">
{props.confirmDescription || "This might cause unexpected results"}
</div>
<div className="flex flex-row gap-2 w-full mt-2">
<Button
className="w-full"
onClick={() => {
console.log("run");
run().then((x) => {
console.log(x);
if (x.code == 0) {
props.callback && props.callback(x);
} else {
alert({
error: `Error while running ${props.title}`,
message: x.stderr,
subtitle: x.stdout,
});
}
});
}}
>
Yes
</Button>

<PopoverClose asChild>
<Button className="w-full">No</Button>
</PopoverClose>
</div>
</div>
</PopoverContent>
</Popover>
);
};
31 changes: 31 additions & 0 deletions src/alerter/AlerterDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { DialogTitle } from "@radix-ui/react-dialog";
import {
Dialog,
DialogContent,
DialogDescription,
} from "../components/ui/dialog";
import { useAlerter } from "./alerter-context";
import { useEffect } from "react";
import React from "react";

export const AlerterDialog = () => {
const { activeError, ack } = useAlerter();

const [open, setOpen] = React.useState(false);

useEffect(() => {
setOpen(activeError != null);
}, [activeError]);

return (
<>
<Dialog open={open} onOpenChange={ack}>
<DialogContent>
<DialogTitle>{activeError?.error}</DialogTitle>
<DialogDescription>{activeError?.message}</DialogDescription>
<DialogDescription>{activeError?.subtitle}</DialogDescription>
</DialogContent>
</Dialog>
</>
);
};
56 changes: 56 additions & 0 deletions src/alerter/alert-provider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { forage } from "@tauri-apps/tauri-forage";
import React, { useCallback, useEffect, useState } from "react";
import { InstalledApp } from "../screens/wizard/types";
import { AlerterContext, AlertingError } from "./alerter-context";
import { ErrorBoundary } from "react-error-boundary";

export const AlerterProvider: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
const [activeError, setActiveError] = useState<AlertingError | null>(null);

const catchAlert = useCallback(
(e: Error | unknown) => {
if (e instanceof Error) {
setActiveError({
error: e.name,
message: e.message,
subtitle: e.stack || "",
causedBy: e,
});
return;
} else {
setActiveError({
error: "Unknown Error",
message: "An unknown error occurred",
subtitle: JSON.stringify(e),
});
}
},
[setActiveError]
);

const alert = useCallback(
(e: AlertingError) => {
setActiveError(e);
},
[setActiveError]
);

const ack = useCallback(() => {
setActiveError(null);
}, [setActiveError]);

return (
<AlerterContext.Provider
value={{
catchAlert: catchAlert,
alert: alert,
activeError: activeError,
ack: ack,
}}
>
{children}
</AlerterContext.Provider>
);
};
29 changes: 29 additions & 0 deletions src/alerter/alerter-context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { useContext } from "react";
import { SetupValues } from "../screens/wizard/Setup";

export type AlertingError = {
error: string;
message: string;
subtitle: string;
causedBy?: Error;
};

export type AlerterContext = {
catchAlert: (e: Error) => void;
alert: (e: AlertingError) => void;
activeError: AlertingError | null;
ack: () => void;
};

export const AlerterContext = React.createContext<AlerterContext>({
catchAlert(e: Error) {
alert(e.message);
},
alert(e: AlertingError) {
alert(e.message);
},
activeError: null,
ack() {},
});

export const useAlerter = () => useContext(AlerterContext);
Loading

0 comments on commit 11bd7bc

Please sign in to comment.