Skip to content

Commit 3088ae0

Browse files
author
Rossdan Craig rossdan@lastmileai.dev
committed
Download Button [1/n]: Setup UI on the editor client
If the download callback is defined (not for local editor or VSCode, but will be for Gradio), then we display it and use the loading state to disable you from clicking on the button ## Test Plan Rebase onto #1045 Go to `aiconfig/python/src/aiconfig/editor/client` and run this command: ``` rm -rf node_modules && yarn && yarn build ``` Then go to `aiconfig` dir and run this command: ``` aiconfig_path=./cookbooks/Gradio/huggingface.aiconfig.json parsers_path=./cookbooks/Gradio/hf_model_parsers.py aiconfig edit --aiconfig-path=$aiconfig_path --server-port=8080 --server-mode=debug_servers --parsers-module-path=$parsers_path ``` https://github.com/lastmile-ai/aiconfig/assets/151060367/123319cf-2e92-49e8-8f93-2d930a3b0ac7
1 parent c838856 commit 3088ae0

File tree

9 files changed

+61
-9
lines changed

9 files changed

+61
-9
lines changed

python/src/aiconfig/editor/client/src/components/AIConfigEditor.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
import { IconDeviceFloppy } from "@tabler/icons-react";
5757
import CopyButton from "./CopyButton";
5858
import AIConfigEditorThemeProvider from "../themes/AIConfigEditorThemeProvider";
59+
import DownloadButton from "./global/DownloadButton";
5960
import ShareButton from "./global/ShareButton";
6061
import PromptsContainer from "./prompt/PromptsContainer";
6162

@@ -103,6 +104,7 @@ export type AIConfigCallbacks = {
103104
) => Promise<{ aiconfig: AIConfig }>;
104105
clearOutputs: () => Promise<{ aiconfig: AIConfig }>;
105106
deletePrompt: (promptName: string) => Promise<void>;
107+
download?: () => Promise<void>;
106108
getModels: (search: string) => Promise<string[]>;
107109
getServerStatus?: () => Promise<{ status: "OK" | "ERROR" }>;
108110
logEventHandler?: (event: LogEvent, data?: LogEventData) => void;
@@ -150,6 +152,23 @@ export default function AIConfigEditor({
150152

151153
const logEventHandler = callbacks?.logEventHandler;
152154

155+
const downloadCallback = callbacks?.download;
156+
const onDownload = useCallback(async () => {
157+
if (!downloadCallback) {
158+
return;
159+
}
160+
try {
161+
await downloadCallback();
162+
} catch (err: unknown) {
163+
const message = (err as RequestCallbackError).message ?? null;
164+
showNotification({
165+
title: "Error downloading AIConfig",
166+
message,
167+
color: "red",
168+
});
169+
}
170+
}, [downloadCallback]);
171+
153172
const shareCallback = callbacks?.share;
154173
const onShare = useCallback(async () => {
155174
if (!shareCallback) {
@@ -962,6 +981,9 @@ export default function AIConfigEditor({
962981
<Flex justify="flex-end" mt="md" mb="xs">
963982
{!readOnly && (
964983
<Group>
984+
{downloadCallback && (
985+
<DownloadButton onDownload={onDownload} />
986+
)}
965987
{shareCallback && <ShareButton onShare={onShare} />}
966988
{onClearOutputs && (
967989
<Button
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Button } from "@mantine/core";
2+
import { memo, useState } from "react";
3+
4+
type Props = {
5+
onDownload: () => Promise<string | void>;
6+
};
7+
8+
export default memo(function ShareButton({ onDownload }: Props) {
9+
const [isDownloading, setIsDownloading] = useState<boolean>(false);
10+
11+
const onClick = async () => {
12+
if (isDownloading) {
13+
return;
14+
}
15+
setIsDownloading(true);
16+
await onDownload();
17+
setIsDownloading(false);
18+
};
19+
20+
return (
21+
<Button
22+
loaderPosition="center"
23+
loading={isDownloading}
24+
onClick={onClick}
25+
size="xs"
26+
variant="filled"
27+
>
28+
Download
29+
</Button>
30+
);
31+
});

python/src/aiconfig/editor/client/src/components/global/ShareButton.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export default memo(function ShareButton({ onShare }: Props) {
3838
loaderPosition="center"
3939
loading={isLoading}
4040
onClick={onClick}
41-
p="xs"
4241
size="xs"
4342
variant="filled"
4443
>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"files": {
3-
"main.js": "/static/js/main.175446b3.js",
3+
"main.js": "/static/js/main.6eacb377.js",
44
"index.html": "/index.html",
5-
"main.175446b3.js.map": "/static/js/main.175446b3.js.map"
5+
"main.6eacb377.js.map": "/static/js/main.6eacb377.js.map"
66
},
77
"entrypoints": [
8-
"static/js/main.175446b3.js"
8+
"static/js/main.6eacb377.js"
99
]
1010
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>AIConfig Editor</title><script defer="defer" src="/static/js/main.175446b3.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>AIConfig Editor</title><script defer="defer" src="/static/js/main.6eacb377.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

python/src/aiconfig/editor/server/static/static/js/main.175446b3.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

python/src/aiconfig/editor/server/static/static/js/main.175446b3.js renamed to python/src/aiconfig/editor/server/static/static/js/main.6eacb377.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/src/aiconfig/editor/server/static/static/js/main.175446b3.js.LICENSE.txt renamed to python/src/aiconfig/editor/server/static/static/js/main.6eacb377.js.LICENSE.txt

File renamed without changes.

python/src/aiconfig/editor/server/static/static/js/main.6eacb377.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)