Skip to content

Commit fbfb09c

Browse files
author
Rossdan Craig rossdan@lastmileai.dev
committed
Share Button [7/n]: Display loading UI
Created a separate component for the shareButton to manage the `isLoading` state and show that in the UI ## Test Plan Rebase on then do: #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 ``` No Error Testing https://github.com/lastmile-ai/aiconfig/assets/151060367/1e9f4b90-a9e9-4c60-a813-afa2a46a1b5a Error Testing https://github.com/lastmile-ai/aiconfig/assets/151060367/1abcce37-8ba4-4513-b826-ea0f9d7bb720
1 parent a9c75aa commit fbfb09c

File tree

2 files changed

+51
-16
lines changed

2 files changed

+51
-16
lines changed

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

Lines changed: 3 additions & 16 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 ShareButton from "./global/ShareButton";
5960
import PromptsContainer from "./prompt/PromptsContainer";
6061

6162
type Props = {
@@ -155,10 +156,8 @@ export default function AIConfigEditor({
155156
return;
156157
}
157158
try {
158-
// TODO: While uploading, show a loader state for share button
159159
const { share_url: shareUrl } = await shareCallback();
160-
// TODO: display the shareUrl in a dialog
161-
// console.log("Share URL: ", shareUrl);
160+
return shareUrl;
162161
} catch (err: unknown) {
163162
const message = (err as RequestCallbackError).message ?? null;
164163
showNotification({
@@ -962,19 +961,7 @@ export default function AIConfigEditor({
962961
<Flex justify="flex-end" mt="md" mb="xs">
963962
{!readOnly && (
964963
<Group>
965-
{shareCallback && (
966-
<Tooltip label={"Create a link to share your AIConfig!"}>
967-
<Button
968-
loading={undefined}
969-
onClick={onShare}
970-
size="xs"
971-
variant="filled"
972-
>
973-
Share
974-
</Button>
975-
</Tooltip>
976-
)}
977-
964+
{shareCallback && <ShareButton onShare={onShare} />}
978965
{onClearOutputs && (
979966
<Button
980967
loading={undefined}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Button, Tooltip } from "@mantine/core";
2+
import { memo, useState } from "react";
3+
4+
type Props = {
5+
onShare: () => Promise<string | void>;
6+
};
7+
8+
export default memo(function ShareButton({ onShare }: Props) {
9+
const [isLoading, setIsLoading] = useState<boolean>(false);
10+
11+
const onClick = async () => {
12+
if (isLoading) {
13+
return;
14+
}
15+
16+
setIsLoading(true);
17+
const shareUrl: string | void = await onShare();
18+
setIsLoading(false);
19+
20+
if (!shareUrl) {
21+
return;
22+
}
23+
24+
console.log("Share URL: ", shareUrl);
25+
};
26+
27+
const button = (
28+
<Button
29+
loaderPosition="center"
30+
loading={isLoading}
31+
onClick={onClick}
32+
p="xs"
33+
size="xs"
34+
variant="filled"
35+
>
36+
Share
37+
</Button>
38+
);
39+
40+
const tooltipMessage: string = isLoading
41+
? "Generating share link..."
42+
: "Create a link to share your AIConfig!";
43+
return (
44+
<Tooltip label={tooltipMessage} withArrow>
45+
<div>{button}</div>
46+
</Tooltip>
47+
);
48+
});

0 commit comments

Comments
 (0)