Skip to content

Commit

Permalink
Download Button [3/n]: Remove config param from onDownload() callba…
Browse files Browse the repository at this point in the history
…ck (#1067)

Download Button [3/n]: Remove config param from `onDownload()` callback


We decided to pass in the config directly inside of the callback itself
so that we use the server_side source of truth. Once this is packaged
we'll update this for Gradio callback

## Test Plan
No functional changes
  • Loading branch information
rossdanlm authored Jan 29, 2024
2 parents 13b1e76 + c420ef7 commit 2c60fb2
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 35 deletions.
35 changes: 16 additions & 19 deletions python/src/aiconfig/editor/client/src/components/AIConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export type AIConfigCallbacks = {
) => Promise<{ aiconfig: AIConfig }>;
clearOutputs: () => Promise<{ aiconfig: AIConfig }>;
deletePrompt: (promptName: string) => Promise<void>;
download?: (config: AIConfig) => Promise<void>;
download?: () => Promise<void>;
getModels: (search: string) => Promise<string[]>;
getServerStatus?: () => Promise<{ status: "OK" | "ERROR" }>;
logEventHandler?: (event: LogEvent, data?: LogEventData) => void;
Expand Down Expand Up @@ -161,24 +161,21 @@ export default function AIConfigEditor({
const logEventHandler = callbacks?.logEventHandler;

const downloadCallback = callbacks?.download;
const onDownload = useCallback(
async (config: AIConfig) => {
if (!downloadCallback) {
return;
}
try {
await downloadCallback(config);
} catch (err: unknown) {
const message = (err as RequestCallbackError).message ?? null;
showNotification({
title: "Error downloading AIConfig",
message,
color: "red",
});
}
},
[downloadCallback]
);
const onDownload = useCallback(async () => {
if (!downloadCallback) {
return;
}
try {
await downloadCallback();
} catch (err: unknown) {
const message = (err as RequestCallbackError).message ?? null;
showNotification({
title: "Error downloading AIConfig",
message,
color: "red",
});
}
}, [downloadCallback]);

const shareCallback = callbacks?.share;
const onShare = useCallback(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import { Button } from "@mantine/core";
import { AIConfig } from "aiconfig";
import { memo, useContext, useState } from "react";
import AIConfigContext from "../../contexts/AIConfigContext";
import { clientConfigToAIConfig } from "../../shared/types";
import { memo, useState } from "react";

type Props = {
onDownload: (config: AIConfig) => Promise<void>;
onDownload: () => Promise<void>;
};

export default memo(function DownloadButton({ onDownload }: Props) {
const { getState } = useContext(AIConfigContext);
const [isDownloading, setIsDownloading] = useState<boolean>(false);

const onClick = async () => {
if (isDownloading) {
return;
}
setIsDownloading(true);
const config: AIConfig = clientConfigToAIConfig(getState());
await onDownload(config);
await onDownload();
setIsDownloading(false);
};

Expand Down
6 changes: 3 additions & 3 deletions python/src/aiconfig/editor/server/static/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"files": {
"main.js": "/static/js/main.9eebadf6.js",
"main.js": "/static/js/main.7cef3223.js",
"index.html": "/index.html",
"main.9eebadf6.js.map": "/static/js/main.9eebadf6.js.map"
"main.7cef3223.js.map": "/static/js/main.7cef3223.js.map"
},
"entrypoints": [
"static/js/main.9eebadf6.js"
"static/js/main.7cef3223.js"
]
}
2 changes: 1 addition & 1 deletion python/src/aiconfig/editor/server/static/index.html
Original file line number Diff line number Diff line change
@@ -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.9eebadf6.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!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.7cef3223.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

This file was deleted.

0 comments on commit 2c60fb2

Please sign in to comment.