Put component and flow export into share modal
This commit is contained in:
parent
2fe6ea23db
commit
68a777b230
3 changed files with 82 additions and 69 deletions
|
|
@ -17,6 +17,7 @@ import {
|
||||||
} from "../../controllers/API";
|
} from "../../controllers/API";
|
||||||
import { FlowType } from "../../types/flow";
|
import { FlowType } from "../../types/flow";
|
||||||
import {
|
import {
|
||||||
|
downloadNode,
|
||||||
removeApiKeys,
|
removeApiKeys,
|
||||||
removeFileNameFromComponents,
|
removeFileNameFromComponents,
|
||||||
} from "../../utils/reactflowUtils";
|
} from "../../utils/reactflowUtils";
|
||||||
|
|
@ -39,7 +40,7 @@ export default function ShareModal({
|
||||||
setOpen?: (open: boolean) => void;
|
setOpen?: (open: boolean) => void;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
const { version, addFlow } = useContext(FlowsContext);
|
const { version, addFlow, downloadFlow } = useContext(FlowsContext);
|
||||||
const { hasApiKey, hasStore } = useContext(StoreContext);
|
const { hasApiKey, hasStore } = useContext(StoreContext);
|
||||||
const { setSuccessData, setErrorData } = useContext(alertContext);
|
const { setSuccessData, setErrorData } = useContext(alertContext);
|
||||||
const { reactFlowInstance } = useContext(typesContext);
|
const { reactFlowInstance } = useContext(typesContext);
|
||||||
|
|
@ -155,6 +156,13 @@ export default function ShareModal({
|
||||||
else internalSetOpen(false);
|
else internalSetOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleExportComponent = () => {
|
||||||
|
if (!checked) {
|
||||||
|
component = removeApiKeys(component);
|
||||||
|
}
|
||||||
|
downloadNode(component);
|
||||||
|
};
|
||||||
|
|
||||||
let modalConfirmation = useMemo(() => {
|
let modalConfirmation = useMemo(() => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
@ -205,7 +213,9 @@ export default function ShareModal({
|
||||||
open={(!disabled && open) ?? internalOpen}
|
open={(!disabled && open) ?? internalOpen}
|
||||||
setOpen={setOpen ?? internalSetOpen}
|
setOpen={setOpen ?? internalSetOpen}
|
||||||
>
|
>
|
||||||
<BaseModal.Trigger>{children ? children : <></>}</BaseModal.Trigger>
|
<BaseModal.Trigger asChild>
|
||||||
|
{children ? children : <></>}
|
||||||
|
</BaseModal.Trigger>
|
||||||
<BaseModal.Header
|
<BaseModal.Header
|
||||||
description={`Share your ${nameComponent} to the Langflow Store.`}
|
description={`Share your ${nameComponent} to the Langflow Store.`}
|
||||||
>
|
>
|
||||||
|
|
@ -262,10 +272,23 @@ export default function ShareModal({
|
||||||
</BaseModal.Content>
|
</BaseModal.Content>
|
||||||
|
|
||||||
<BaseModal.Footer>
|
<BaseModal.Footer>
|
||||||
<div className="text-right">
|
<div className="flex w-full justify-between gap-2">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
className="gap-2"
|
||||||
|
onClick={() => {
|
||||||
|
handleExportComponent();
|
||||||
|
(setOpen || internalSetOpen)(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IconComponent name="Download" className="h-4 w-4" />
|
||||||
|
Export
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
disabled={loadingNames}
|
disabled={loadingNames}
|
||||||
type="button"
|
type="button"
|
||||||
|
className={is_component ? "w-40" : "w-28"}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const isNameAvailable = !unavaliableNames.some(
|
const isNameAvailable = !unavaliableNames.some(
|
||||||
(element) => element.name === name
|
(element) => element.name === name
|
||||||
|
|
@ -281,7 +304,7 @@ export default function ShareModal({
|
||||||
>
|
>
|
||||||
{loadingNames ? (
|
{loadingNames ? (
|
||||||
<>
|
<>
|
||||||
<div className="center w-16">
|
<div className="center">
|
||||||
<Loader2 className="m-auto h-4 w-4 animate-spin"></Loader2>
|
<Loader2 className="m-auto h-4 w-4 animate-spin"></Loader2>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
|
|
@ -184,14 +184,18 @@ export default function ExtraSidebar(): JSX.Element {
|
||||||
}, [getFilterEdge, data]);
|
}, [getFilterEdge, data]);
|
||||||
|
|
||||||
const ModalMemo = useMemo(
|
const ModalMemo = useMemo(
|
||||||
() =>
|
() => (
|
||||||
!hasApiKey || !validApiKey ? (
|
<ShareModal
|
||||||
|
is_component={false}
|
||||||
|
component={flow!}
|
||||||
|
disabled={!hasApiKey || !validApiKey || !hasStore}
|
||||||
|
>
|
||||||
<button
|
<button
|
||||||
disabled={!hasApiKey || !validApiKey || !hasStore}
|
disabled={!hasApiKey || !validApiKey || !hasStore}
|
||||||
className={classNames(
|
className={classNames(
|
||||||
"extra-side-bar-buttons",
|
"extra-side-bar-buttons gap-2 text-sm",
|
||||||
!hasApiKey || !validApiKey || !hasStore
|
!hasApiKey || !validApiKey || !hasStore
|
||||||
? "button-disable cursor-default"
|
? "button-disable cursor-default text-muted-foreground"
|
||||||
: ""
|
: ""
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
|
@ -204,34 +208,10 @@ export default function ExtraSidebar(): JSX.Element {
|
||||||
: ""
|
: ""
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
Share
|
||||||
</button>
|
</button>
|
||||||
) : (
|
</ShareModal>
|
||||||
<ShareModal
|
),
|
||||||
is_component={false}
|
|
||||||
component={flow!}
|
|
||||||
disabled={!hasApiKey || !validApiKey || !hasStore}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
disabled={!hasApiKey || !validApiKey || !hasStore}
|
|
||||||
className={classNames(
|
|
||||||
"extra-side-bar-buttons",
|
|
||||||
!hasApiKey || !validApiKey || !hasStore
|
|
||||||
? "button-disable cursor-default"
|
|
||||||
: ""
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<IconComponent
|
|
||||||
name="Share2"
|
|
||||||
className={classNames(
|
|
||||||
"side-bar-button-size",
|
|
||||||
!hasApiKey || !validApiKey || !hasStore
|
|
||||||
? "extra-side-bar-save-disable"
|
|
||||||
: ""
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</ShareModal>
|
|
||||||
),
|
|
||||||
[hasApiKey, validApiKey, flow, hasStore]
|
[hasApiKey, validApiKey, flow, hasStore]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -270,7 +250,7 @@ export default function ExtraSidebar(): JSX.Element {
|
||||||
</button>
|
</button>
|
||||||
</ShadTooltip>
|
</ShadTooltip>
|
||||||
</div>
|
</div>
|
||||||
<div className="side-bar-button">{ExportMemo}</div>
|
{!hasStore && ExportMemo}
|
||||||
<ShadTooltip content={"Code"} side="top">
|
<ShadTooltip content={"Code"} side="top">
|
||||||
<div className="side-bar-button">
|
<div className="side-bar-button">
|
||||||
{flow && flow.data && (
|
{flow && flow.data && (
|
||||||
|
|
@ -295,36 +275,44 @@ export default function ExtraSidebar(): JSX.Element {
|
||||||
<div className="side-bar-button">
|
<div className="side-bar-button">
|
||||||
{flow && flow.data && (
|
{flow && flow.data && (
|
||||||
<ShadTooltip content="Save" side="top">
|
<ShadTooltip content="Save" side="top">
|
||||||
<div>
|
<button
|
||||||
<button
|
disabled={flow?.data?.nodes.length === 0}
|
||||||
disabled={flow?.data?.nodes.length === 0}
|
className={
|
||||||
|
"extra-side-bar-buttons " +
|
||||||
|
(isPending && flow!.data!.nodes?.length > 0
|
||||||
|
? ""
|
||||||
|
: "button-disable")
|
||||||
|
}
|
||||||
|
onClick={(event) => {
|
||||||
|
saveFlow(flow!);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IconComponent
|
||||||
|
name="Save"
|
||||||
className={
|
className={
|
||||||
"extra-side-bar-buttons " +
|
"side-bar-button-size" +
|
||||||
(isPending && flow!.data!.nodes?.length > 0
|
(isPending && flow!.data!.nodes?.length > 0
|
||||||
? ""
|
? " "
|
||||||
: "button-disable")
|
: " extra-side-bar-save-disable")
|
||||||
}
|
}
|
||||||
onClick={(event) => {
|
/>
|
||||||
saveFlow(flow!);
|
</button>
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IconComponent
|
|
||||||
name="Save"
|
|
||||||
className={
|
|
||||||
"side-bar-button-size" +
|
|
||||||
(isPending && flow!.data!.nodes?.length > 0
|
|
||||||
? " "
|
|
||||||
: " extra-side-bar-save-disable")
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</ShadTooltip>
|
</ShadTooltip>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<ShadTooltip content="Share" side="top" styleClasses="cursor-default">
|
{hasStore && (
|
||||||
<div className="side-bar-button">{ModalMemo}</div>
|
<ShadTooltip
|
||||||
</ShadTooltip>
|
content={
|
||||||
|
!hasApiKey || !validApiKey
|
||||||
|
? "Please review your API key."
|
||||||
|
: "Share"
|
||||||
|
}
|
||||||
|
side="top"
|
||||||
|
styleClasses="cursor-default"
|
||||||
|
>
|
||||||
|
<div className="side-bar-button">{ModalMemo}</div>
|
||||||
|
</ShadTooltip>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<Separator />
|
<Separator />
|
||||||
<div className="side-bar-search-div-placement">
|
<div className="side-bar-search-div-placement">
|
||||||
|
|
|
||||||
|
|
@ -257,15 +257,17 @@ export default function NodeToolbarComponent({
|
||||||
</div>{" "}
|
</div>{" "}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
)}
|
)}
|
||||||
<SelectItem value={"Download"}>
|
{!hasStore && (
|
||||||
<div className="flex">
|
<SelectItem value={"Download"}>
|
||||||
<IconComponent
|
<div className="flex">
|
||||||
name="Download"
|
<IconComponent
|
||||||
className="relative top-0.5 mr-2 h-4 w-4"
|
name="Download"
|
||||||
/>{" "}
|
className="relative top-0.5 mr-2 h-4 w-4"
|
||||||
Download{" "}
|
/>{" "}
|
||||||
</div>{" "}
|
Download{" "}
|
||||||
</SelectItem>
|
</div>{" "}
|
||||||
|
</SelectItem>
|
||||||
|
)}
|
||||||
{isMinimal && (
|
{isMinimal && (
|
||||||
<SelectItem value={"show"}>
|
<SelectItem value={"show"}>
|
||||||
<div className="flex">
|
<div className="flex">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue