merging modal refactor

This commit is contained in:
Cristhian Zanforlin Lousa 2023-07-24 16:18:45 -03:00
commit 2c32b13632
27 changed files with 1647 additions and 2641 deletions

View file

@ -134,6 +134,7 @@ async def stream_build(flow_id: str):
# to set the input_keys values
artifacts.update(vertex.artifacts)
except Exception as exc:
logger.exception(exc)
params = str(exc)
valid = False
flow_data_store[flow_id]["status"] = BuildStatus.FAILURE

View file

@ -176,6 +176,8 @@ class Vertex:
for node in nodes:
built = node.build()
if isinstance(built, list):
if key not in self.params:
self.params[key] = []
self.params[key].extend(built)
else:
self.params[key].append(built)

View file

@ -98,7 +98,7 @@ class DocumentLoaderVertex(Vertex):
self._built_object
)
return f"""{self.vertex_type}({len(self._built_object)} documents)
\nAvg. Document Length (characters): {avg_length}
\nAvg. Document Length (characters): {int(avg_length)}
Documents: {self._built_object[:3]}..."""
return f"{self.vertex_type}()"
@ -136,7 +136,7 @@ class TextSplitterVertex(Vertex):
self._built_object
)
return f"""{self.vertex_type}({len(self._built_object)} documents)
\nAvg. Document Length (characters): {avg_length}
\nAvg. Document Length (characters): {int(avg_length)}
\nDocuments: {self._built_object[:3]}..."""
return f"{self.vertex_type}()"

View file

@ -59,15 +59,20 @@ def setup_static_files(app: FastAPI, static_files_dir: Path):
return FileResponse(path)
# app = create_app()
# setup_static_files(app, static_files_dir)
def get_static_files_dir():
"""Get the static files directory relative to Langflow's main.py file."""
frontend_path = Path(__file__).parent
return frontend_path / "frontend"
def setup_app(static_files_dir: Optional[Path] = None) -> FastAPI:
"""Setup the FastAPI app."""
# get the directory of the current file
if not static_files_dir:
frontend_path = Path(__file__).parent
static_files_dir = frontend_path / "frontend"
static_files_dir = get_static_files_dir()
if not static_files_dir or not static_files_dir.exists():
raise RuntimeError(f"Static files directory {static_files_dir} does not exist.")
app = create_app()
setup_static_files(app, static_files_dir)
return app

View file

@ -15,6 +15,7 @@ class TextSplittersFrontendNode(FrontendNode):
required=True,
show=True,
name="documents",
is_list=True,
)
)
name = "separator"

View file

@ -259,7 +259,7 @@ class VectorStoreFrontendNode(FrontendNode):
field.required = False
field.show = True
field.advanced = False
field.is_list = True
elif "embedding" in field.name:
# for backwards compatibility
field.name = "embedding"

File diff suppressed because it is too large Load diff

View file

@ -40,10 +40,10 @@ export const EditFlowSettings: React.FC<InputProps> = ({
const [desc, setDesc] = useState(
flows.find((f) => f.id === tabId).description
);
const handleDescriptionChange = (event: ChangeEvent<HTMLTextAreaElement>) => {
flows.find((f) => f.id === tabId).description = event.target.value;
setDesc(flows.find((f) => f.id === tabId).description)
setDesc(flows.find((f) => f.id === tabId).description);
setDescription(event.target.value);
};

View file

@ -254,8 +254,7 @@ export default function CodeTabsComponent({
n
].value
}
onChange={(k) => {}}
onAddInput={(k) => {
onChange={(k) => {
tweaks.buildTweakObject(
t["data"]["id"],
k,

View file

@ -1,4 +1,4 @@
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { FloatComponentType } from "../../types/components";
import { Input } from "../ui/input";
@ -12,6 +12,12 @@ export default function FloatComponent({
const min = 0;
const max = 1;
const [myValue, setMyValue] = useState(value);
useEffect(() => {
setMyValue(value);
}, [value]);
// Clear component state
useEffect(() => {
if (disabled) {
@ -42,6 +48,7 @@ export default function FloatComponent({
}
onChange={(e) => {
onChange(e.target.value);
setMyValue(e.target.value);
}}
/>
</div>

View file

@ -11,6 +11,11 @@ export default function InputComponent({
editNode = false,
}: InputComponentType) {
const [pwdVisible, setPwdVisible] = useState(false);
const [myValue, setMyValue] = useState(value);
useEffect(() => {
setMyValue(value);
}, [value]);
// Clear component state
useEffect(() => {
@ -33,6 +38,7 @@ export default function InputComponent({
placeholder={password && editNode ? "Key" : "Type something..."}
onChange={(e) => {
onChange(e.target.value);
setMyValue(e.target.value);
}}
/>
{password && (

View file

@ -1,18 +1,17 @@
import { useEffect, useState, useContext } from "react";
import { useContext, useEffect, useState } from "react";
import { InputListComponentType } from "../../types/components";
import _, { set } from "lodash";
import IconComponent from "../genericIconComponent";
import { Input } from "../ui/input";
import { classNames } from "../../utils/utils";
import _ from "lodash";
import { PopUpContext } from "../../contexts/popUpContext";
import IconComponent from "../genericIconComponent";
export default function InputListComponent({
value,
onChange,
disabled,
editNode = false,
onAddInput,
}: InputListComponentType) {
const [inputList, setInputList] = useState(value ?? [""]);
const { closeEdit } = useContext(PopUpContext);

View file

@ -1,4 +1,4 @@
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { FloatComponentType } from "../../types/components";
import { Input } from "../ui/input";
@ -10,6 +10,12 @@ export default function IntComponent({
}: FloatComponentType) {
const min = 0;
const [myValue, setMyValue] = useState(value);
useEffect(() => {
setMyValue(value);
}, [value]);
// Clear component state
useEffect(() => {
if (disabled) {
@ -52,6 +58,7 @@ export default function IntComponent({
placeholder={editNode ? "Integer number" : "Type an integer number"}
onChange={(e) => {
onChange(e.target.value);
setMyValue(e.target.value);
}}
/>
</div>

View file

@ -1,3 +1,4 @@
import { useEffect, useState } from "react";
import { ToggleComponentType } from "../../types/components";
import { Switch } from "../ui/switch";
@ -25,6 +26,13 @@ export default function ToggleShadComponent({
scaleX = 1;
scaleY = 1;
}
const [myValue, setMyValue] = useState(enabled);
useEffect(() => {
setMyValue(enabled);
}, [enabled]);
return (
<div className={disabled ? "pointer-events-none cursor-not-allowed " : ""}>
<Switch
@ -33,9 +41,10 @@ export default function ToggleShadComponent({
}}
disabled={disabled}
className=""
checked={enabled}
checked={myValue}
onCheckedChange={(x: boolean) => {
setEnabled(x);
setMyValue(x);
}}
></Switch>
</div>

View file

@ -76,7 +76,7 @@ export async function postValidatePrompt(
*/
export async function getExamples(): Promise<FlowType[]> {
const url =
"https://api.github.com/repos/logspace-ai/langflow_examples/contents/examples?ref=fix_examples";
"https://api.github.com/repos/logspace-ai/langflow_examples/contents/examples?ref=main";
const response = await axios.get(url);
const jsonFiles = response.data.filter((file: any) => {

View file

@ -22,12 +22,12 @@ import {
TableRow,
} from "../../components/ui/table";
import { limitScrollFieldsModal } from "../../constants/constants";
import { PopUpContext } from "../../contexts/popUpContext";
import { TabsContext } from "../../contexts/tabsContext";
import { typesContext } from "../../contexts/typesContext";
import { NodeDataType } from "../../types/flow";
import { classNames, getRandomKeyByssmm } from "../../utils/utils";
import BaseModal from "../baseModal";
import { PopUpContext } from "../../contexts/popUpContext";
const EditNodeModal = forwardRef(
(
@ -75,7 +75,6 @@ const EditNodeModal = forwardRef(
setCloseEdit(getRandomKeyByssmm().toString());
}, [modalOpen]);
return (
<BaseModal size="large-h-full" open={modalOpen} setOpen={setModalOpen}>
<BaseModal.Trigger>{children}</BaseModal.Trigger>

View file

@ -97,10 +97,8 @@ export default function GenericModal({
}, [inputValue, type]);
useEffect(() => {
setInputValue(value)
}, [value])
setInputValue(value);
}, [value]);
const coloredContent = (inputValue || "")
.replace(/</g, "&lt;")

View file

@ -94,24 +94,23 @@ export default function NodeToolbarComponent({ data, setData, deleteNode }) {
<ShadTooltip content="Edit" side="top">
<div>
<EditNodeModal
data={data}
setData={setData}
nodeLength={nodeLength}
>
<div
className={classNames(
"relative -ml-px inline-flex items-center rounded-r-md bg-background px-2 py-2 text-foreground shadow-md ring-1 ring-inset ring-ring transition-all duration-500 ease-in-out hover:bg-muted focus:z-10" +
(nodeLength == 0
? " text-muted-foreground"
: " text-foreground")
)}
<EditNodeModal
data={data}
setData={setData}
nodeLength={nodeLength}
>
<IconComponent name="Settings2" className="h-4 w-4 " />
</div>
</EditNodeModal>
<div
className={classNames(
"relative -ml-px inline-flex items-center rounded-r-md bg-background px-2 py-2 text-foreground shadow-md ring-1 ring-inset ring-ring transition-all duration-500 ease-in-out hover:bg-muted focus:z-10" +
(nodeLength == 0
? " text-muted-foreground"
: " text-foreground")
)}
>
<IconComponent name="Settings2" className="h-4 w-4 " />
</div>
</EditNodeModal>
</div>
</ShadTooltip>
</span>
</div>

View file

@ -45,7 +45,6 @@ export type InputListComponentType = {
onChange: (value: string[]) => void;
disabled: boolean;
editNode?: boolean;
onAddInput?: (value?: string[]) => void;
};
export type TextAreaComponentType = {

View file

@ -275,7 +275,7 @@ export function buildTweakObject(tweak) {
});
});
const tweakString = JSON.stringify(tweak, null, 2);
const tweakString = JSON.stringify(tweak.at(-1), null, 2);
return tweakString;
}