Skip to content

Commit 51fb8fd

Browse files
authored
Share Button [7/n]: Display loading UI (#1044)
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 --- Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/lastmile-ai/aiconfig/pull/1044). * #1045 * #1049 * __->__ #1044
2 parents 15c61ea + fbfb09c commit 51fb8fd

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({
@@ -963,19 +962,7 @@ export default function AIConfigEditor({
963962
<Flex justify="flex-end" mt="md" mb="xs">
964963
{!readOnly && (
965964
<Group>
966-
{shareCallback && (
967-
<Tooltip label={"Create a link to share your AIConfig!"}>
968-
<Button
969-
loading={undefined}
970-
onClick={onShare}
971-
size="xs"
972-
variant="filled"
973-
>
974-
Share
975-
</Button>
976-
</Tooltip>
977-
)}
978-
965+
{shareCallback && <ShareButton onShare={onShare} />}
979966
{onClearOutputs && (
980967
<Button
981968
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)