Merge feature/ui_table into feature/ui_table
This commit is contained in:
commit
0cad2e1978
25 changed files with 257 additions and 90 deletions
|
|
@ -22,7 +22,6 @@ depends_on: Union[str, Sequence[str], None] = None
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
conn = op.get_bind()
|
conn = op.get_bind()
|
||||||
inspector = Inspector.from_engine(conn) # type: ignore
|
inspector = Inspector.from_engine(conn) # type: ignore
|
||||||
table_names = inspector.get_table_names()
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
column_names = [column["name"] for column in inspector.get_columns("variable")]
|
column_names = [column["name"] for column in inspector.get_columns("variable")]
|
||||||
with op.batch_alter_table("variable", schema=None) as batch_op:
|
with op.batch_alter_table("variable", schema=None) as batch_op:
|
||||||
|
|
@ -35,7 +34,6 @@ def upgrade() -> None:
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
conn = op.get_bind()
|
conn = op.get_bind()
|
||||||
inspector = Inspector.from_engine(conn) # type: ignore
|
inspector = Inspector.from_engine(conn) # type: ignore
|
||||||
table_names = inspector.get_table_names()
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
column_names = [column["name"] for column in inspector.get_columns("variable")]
|
column_names = [column["name"] for column in inspector.get_columns("variable")]
|
||||||
with op.batch_alter_table("variable", schema=None) as batch_op:
|
with op.batch_alter_table("variable", schema=None) as batch_op:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
"""Set name and value to not nullable
|
||||||
|
|
||||||
|
Revision ID: c153816fd85f
|
||||||
|
Revises: 1f4d6df60295
|
||||||
|
Create Date: 2024-04-30 14:31:23.898995
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
|
from sqlalchemy.engine.reflection import Inspector
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = "c153816fd85f"
|
||||||
|
down_revision: Union[str, None] = "1f4d6df60295"
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
conn = op.get_bind()
|
||||||
|
inspector = Inspector.from_engine(conn) # type: ignore
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
columns = inspector.get_columns("variable")
|
||||||
|
with op.batch_alter_table("variable", schema=None) as batch_op:
|
||||||
|
name_column = [column for column in columns if column["name"] == "name"][0]
|
||||||
|
if name_column and name_column["nullable"]:
|
||||||
|
batch_op.alter_column("name", existing_type=sa.VARCHAR(), nullable=False)
|
||||||
|
value_column = [column for column in columns if column["name"] == "value"][0]
|
||||||
|
if value_column and value_column["nullable"]:
|
||||||
|
batch_op.alter_column("value", existing_type=sa.VARCHAR(), nullable=False)
|
||||||
|
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
conn = op.get_bind()
|
||||||
|
inspector = Inspector.from_engine(conn) # type: ignore
|
||||||
|
columns = inspector.get_columns("variable")
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table("variable", schema=None) as batch_op:
|
||||||
|
name_column = [column for column in columns if column["name"] == "name"][0]
|
||||||
|
if name_column and not name_column["nullable"]:
|
||||||
|
batch_op.alter_column("name", existing_type=sa.VARCHAR(), nullable=True)
|
||||||
|
value_column = [column for column in columns if column["name"] == "value"][0]
|
||||||
|
if value_column and not value_column["nullable"]:
|
||||||
|
batch_op.alter_column("name", existing_type=sa.VARCHAR(), nullable=True)
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
@ -37,7 +37,11 @@ def create_variable(
|
||||||
variable_dict["user_id"] = current_user.id
|
variable_dict["user_id"] = current_user.id
|
||||||
|
|
||||||
db_variable = Variable.model_validate(variable_dict)
|
db_variable = Variable.model_validate(variable_dict)
|
||||||
if not db_variable.value:
|
if not db_variable.name and not db_variable.value:
|
||||||
|
raise HTTPException(status_code=400, detail="Variable name and value cannot be empty")
|
||||||
|
elif not db_variable.name:
|
||||||
|
raise HTTPException(status_code=400, detail="Variable name cannot be empty")
|
||||||
|
elif not db_variable.value:
|
||||||
raise HTTPException(status_code=400, detail="Variable value cannot be empty")
|
raise HTTPException(status_code=400, detail="Variable value cannot be empty")
|
||||||
encrypted = auth_utils.encrypt_api_key(db_variable.value, settings_service=settings_service)
|
encrypted = auth_utils.encrypt_api_key(db_variable.value, settings_service=settings_service)
|
||||||
db_variable.value = encrypted
|
db_variable.value = encrypted
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from langchain.llms.base import BaseLanguageModel
|
|
||||||
from langchain_openai import AzureChatOpenAI
|
from langchain_openai import AzureChatOpenAI
|
||||||
from pydantic.v1 import SecretStr
|
from pydantic.v1 import SecretStr
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from langchain_community.chat_models.litellm import ChatLiteLLM, ChatLiteLLMExce
|
||||||
|
|
||||||
from langflow.base.constants import STREAM_INFO_TEXT
|
from langflow.base.constants import STREAM_INFO_TEXT
|
||||||
from langflow.base.models.model import LCModelComponent
|
from langflow.base.models.model import LCModelComponent
|
||||||
from langflow.field_typing import BaseLanguageModel, Text
|
from langflow.field_typing import Text
|
||||||
|
|
||||||
|
|
||||||
class ChatLiteLLMModelComponent(LCModelComponent):
|
class ChatLiteLLMModelComponent(LCModelComponent):
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from typing import Literal, Optional
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
from langchain_core.messages import BaseMessage
|
from langchain_core.messages import BaseMessage
|
||||||
from pydantic import BaseModel, model_validator
|
from pydantic import BaseModel, model_validator
|
||||||
from langchain_core.messages import HumanMessage, AIMessage, BaseMessage
|
from langchain_core.messages import HumanMessage, AIMessage
|
||||||
|
|
||||||
|
|
||||||
class Record(BaseModel):
|
class Record(BaseModel):
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ def utc_now():
|
||||||
|
|
||||||
|
|
||||||
class VariableBase(SQLModel):
|
class VariableBase(SQLModel):
|
||||||
name: Optional[str] = Field(None, description="Name of the variable")
|
name: str = Field(description="Name of the variable")
|
||||||
value: Optional[str] = Field(None, description="Encrypted value of the variable")
|
value: str = Field(description="Encrypted value of the variable")
|
||||||
default_fields: Optional[List[str]] = Field(sa_column=Column(JSON))
|
default_fields: Optional[List[str]] = Field(sa_column=Column(JSON))
|
||||||
type: Optional[str] = Field(None, description="Type of the variable")
|
type: Optional[str] = Field(None, description="Type of the variable")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ class DatabaseService(Service):
|
||||||
alembic_cfg = Config(stdout=buffer)
|
alembic_cfg = Config(stdout=buffer)
|
||||||
# alembic_cfg.attributes["connection"] = session
|
# alembic_cfg.attributes["connection"] = session
|
||||||
alembic_cfg.set_main_option("script_location", str(self.script_location))
|
alembic_cfg.set_main_option("script_location", str(self.script_location))
|
||||||
alembic_cfg.set_main_option("sqlalchemy.url", self.database_url.replace('%', '%%'))
|
alembic_cfg.set_main_option("sqlalchemy.url", self.database_url.replace("%", "%%"))
|
||||||
|
|
||||||
should_initialize_alembic = False
|
should_initialize_alembic = False
|
||||||
with Session(self.engine) as session:
|
with Session(self.engine) as session:
|
||||||
|
|
|
||||||
1
src/frontend/.prettierignore
Normal file
1
src/frontend/.prettierignore
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
build/*
|
||||||
|
|
@ -72,7 +72,7 @@
|
||||||
"start": "vite",
|
"start": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"serve": "vite preview",
|
"serve": "vite preview",
|
||||||
"format": "npx prettier --write \"./**/*.{js,jsx,ts,tsx,json,md}\"",
|
"format": "npx prettier --write \"./**/*.{js,jsx,ts,tsx,json,md}\" --ignore-path .prettierignore",
|
||||||
"type-check": "tsc --noEmit --pretty --project tsconfig.json && vite"
|
"type-check": "tsc --noEmit --pretty --project tsconfig.json && vite"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import useFlowsManagerStore from "./stores/flowsManagerStore";
|
||||||
import { useGlobalVariablesStore } from "./stores/globalVariables";
|
import { useGlobalVariablesStore } from "./stores/globalVariables";
|
||||||
import { useStoreStore } from "./stores/storeStore";
|
import { useStoreStore } from "./stores/storeStore";
|
||||||
import { useTypesStore } from "./stores/typesStore";
|
import { useTypesStore } from "./stores/typesStore";
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const removeFromTempNotificationList = useAlertStore(
|
const removeFromTempNotificationList = useAlertStore(
|
||||||
(state) => state.removeFromTempNotificationList
|
(state) => state.removeFromTempNotificationList
|
||||||
|
|
@ -48,6 +47,9 @@ export default function App() {
|
||||||
const setGlobalVariables = useGlobalVariablesStore(
|
const setGlobalVariables = useGlobalVariablesStore(
|
||||||
(state) => state.setGlobalVariables
|
(state) => state.setGlobalVariables
|
||||||
);
|
);
|
||||||
|
const setUnavailableFields = useGlobalVariablesStore(
|
||||||
|
(state) => state.setUnavaliableFields
|
||||||
|
);
|
||||||
const checkHasStore = useStoreStore((state) => state.checkHasStore);
|
const checkHasStore = useStoreStore((state) => state.checkHasStore);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const dark = useDarkStore((state) => state.dark);
|
const dark = useDarkStore((state) => state.dark);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { registerGlobalVariable } from "../../controllers/API";
|
||||||
import BaseModal from "../../modals/baseModal";
|
import BaseModal from "../../modals/baseModal";
|
||||||
import useAlertStore from "../../stores/alertStore";
|
import useAlertStore from "../../stores/alertStore";
|
||||||
import { useGlobalVariablesStore } from "../../stores/globalVariables";
|
import { useGlobalVariablesStore } from "../../stores/globalVariables";
|
||||||
|
import { useTypesStore } from "../../stores/typesStore";
|
||||||
import { ResponseErrorDetailAPI } from "../../types/api";
|
import { ResponseErrorDetailAPI } from "../../types/api";
|
||||||
import ForwardedIconComponent from "../genericIconComponent";
|
import ForwardedIconComponent from "../genericIconComponent";
|
||||||
import InputComponent from "../inputComponent";
|
import InputComponent from "../inputComponent";
|
||||||
|
|
@ -10,27 +11,39 @@ import { Button } from "../ui/button";
|
||||||
import { Input } from "../ui/input";
|
import { Input } from "../ui/input";
|
||||||
import { Label } from "../ui/label";
|
import { Label } from "../ui/label";
|
||||||
import { Textarea } from "../ui/textarea";
|
import { Textarea } from "../ui/textarea";
|
||||||
import { useTypesStore } from "../../stores/typesStore";
|
|
||||||
|
|
||||||
//TODO IMPLEMENT FORM LOGIC
|
//TODO IMPLEMENT FORM LOGIC
|
||||||
|
|
||||||
export default function AddNewVariableButton({ children }): JSX.Element {
|
export default function AddNewVariableButton({ children }): JSX.Element {
|
||||||
const [key, setKey] = useState("");
|
const [key, setKey] = useState("");
|
||||||
const [value, setValue] = useState("");
|
const [value, setValue] = useState("");
|
||||||
const [type, setType] = useState("");
|
const [type, setType] = useState("Generic");
|
||||||
const [fields, setFields] = useState<string[]>([]);
|
const [fields, setFields] = useState<string[]>([]);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
const componentFields = useTypesStore((state) => state.ComponentFields);
|
const componentFields = useTypesStore((state) => state.ComponentFields);
|
||||||
|
const unavaliableFields =new Set(Object.keys(useGlobalVariablesStore(
|
||||||
|
(state) => state.unavaliableFields
|
||||||
|
)));
|
||||||
|
|
||||||
|
const availableFields = Array.from(componentFields).filter(
|
||||||
|
(field) => !unavaliableFields.has(field)
|
||||||
|
);
|
||||||
const addGlobalVariable = useGlobalVariablesStore(
|
const addGlobalVariable = useGlobalVariablesStore(
|
||||||
(state) => state.addGlobalVariable
|
(state) => state.addGlobalVariable
|
||||||
);
|
);
|
||||||
|
|
||||||
function handleSaveVariable() {
|
function handleSaveVariable() {
|
||||||
let data: { name: string; value: string; type?: string; default_fields?: string[] } = {
|
let data: {
|
||||||
|
name: string;
|
||||||
|
value: string;
|
||||||
|
type?: string;
|
||||||
|
default_fields?: string[];
|
||||||
|
} = {
|
||||||
name: key,
|
name: key,
|
||||||
type,
|
type,
|
||||||
value,
|
value,
|
||||||
default_fields: fields
|
default_fields: fields,
|
||||||
};
|
};
|
||||||
registerGlobalVariable(data)
|
registerGlobalVariable(data)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
|
@ -39,6 +52,7 @@ export default function AddNewVariableButton({ children }): JSX.Element {
|
||||||
setKey("");
|
setKey("");
|
||||||
setValue("");
|
setValue("");
|
||||||
setType("");
|
setType("");
|
||||||
|
setFields([]);
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|
@ -98,8 +112,8 @@ export default function AddNewVariableButton({ children }): JSX.Element {
|
||||||
setSelectedOptions={(value) => setFields(value)}
|
setSelectedOptions={(value) => setFields(value)}
|
||||||
selectedOptions={fields}
|
selectedOptions={fields}
|
||||||
password={false}
|
password={false}
|
||||||
options={Array.from(componentFields)}
|
options={availableFields}
|
||||||
placeholder="Choose a type for the variable..."
|
placeholder="Choose a field for the variable..."
|
||||||
></InputComponent>
|
></InputComponent>
|
||||||
</div>
|
</div>
|
||||||
</BaseModal.Content>
|
</BaseModal.Content>
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,9 @@ export default function Dropdown({
|
||||||
|
|
||||||
const refButton = useRef<HTMLButtonElement>(null);
|
const refButton = useRef<HTMLButtonElement>(null);
|
||||||
|
|
||||||
const PopoverContentDropdown = children ? PopoverContent : PopoverContentWithoutPortal;
|
const PopoverContentDropdown = children
|
||||||
|
? PopoverContent
|
||||||
|
: PopoverContentWithoutPortal;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
@ -77,7 +79,11 @@ export default function Dropdown({
|
||||||
)}
|
)}
|
||||||
<PopoverContentDropdown
|
<PopoverContentDropdown
|
||||||
className="nocopy nowheel nopan nodelete nodrag noundo p-0"
|
className="nocopy nowheel nopan nodelete nodrag noundo p-0"
|
||||||
style={children ? {} : { minWidth: refButton?.current?.clientWidth ?? "200px" }}
|
style={
|
||||||
|
children
|
||||||
|
? {}
|
||||||
|
: { minWidth: refButton?.current?.clientWidth ?? "200px" }
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<Command>
|
<Command>
|
||||||
<CommandInput placeholder="Search options..." className="h-9" />
|
<CommandInput placeholder="Search options..." className="h-9" />
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import { deleteGlobalVariable } from "../../controllers/API";
|
||||||
import DeleteConfirmationModal from "../../modals/DeleteConfirmationModal";
|
import DeleteConfirmationModal from "../../modals/DeleteConfirmationModal";
|
||||||
import useAlertStore from "../../stores/alertStore";
|
import useAlertStore from "../../stores/alertStore";
|
||||||
import { useGlobalVariablesStore } from "../../stores/globalVariables";
|
import { useGlobalVariablesStore } from "../../stores/globalVariables";
|
||||||
import { ResponseErrorDetailAPI } from "../../types/api";
|
|
||||||
import { InputGlobalComponentType } from "../../types/components";
|
import { InputGlobalComponentType } from "../../types/components";
|
||||||
import { cn } from "../../utils/utils";
|
import { cn } from "../../utils/utils";
|
||||||
import AddNewVariableButton from "../addNewVariableButtonComponent/addNewVariableButton";
|
import AddNewVariableButton from "../addNewVariableButtonComponent/addNewVariableButton";
|
||||||
|
|
@ -24,6 +23,9 @@ export default function InputGlobalComponent({
|
||||||
);
|
);
|
||||||
|
|
||||||
const getVariableId = useGlobalVariablesStore((state) => state.getVariableId);
|
const getVariableId = useGlobalVariablesStore((state) => state.getVariableId);
|
||||||
|
const unavaliableFields = useGlobalVariablesStore(
|
||||||
|
(state) => state.unavaliableFields
|
||||||
|
);
|
||||||
const removeGlobalVariable = useGlobalVariablesStore(
|
const removeGlobalVariable = useGlobalVariablesStore(
|
||||||
(state) => state.removeGlobalVariable
|
(state) => state.removeGlobalVariable
|
||||||
);
|
);
|
||||||
|
|
@ -40,10 +42,24 @@ export default function InputGlobalComponent({
|
||||||
}
|
}
|
||||||
}, [globalVariablesEntries]);
|
}, [globalVariablesEntries]);
|
||||||
|
|
||||||
function handleDelete(key: string) {
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
!data.node?.template[name].value &&
|
||||||
|
data.node?.template[name].display_name
|
||||||
|
) {
|
||||||
|
if (unavaliableFields[data.node?.template[name].display_name!]) {
|
||||||
|
setDb(true);
|
||||||
|
onChange(unavaliableFields[data.node?.template[name].display_name!]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [unavaliableFields]);
|
||||||
|
|
||||||
|
async function handleDelete(key: string) {
|
||||||
const id = getVariableId(key);
|
const id = getVariableId(key);
|
||||||
if (id !== undefined) {
|
if (id !== undefined) {
|
||||||
removeGlobalVariable(key).then((_) => {
|
await deleteGlobalVariable(id)
|
||||||
|
.then(() => {
|
||||||
|
removeGlobalVariable(key);
|
||||||
if (
|
if (
|
||||||
data?.node?.template[name].value === key &&
|
data?.node?.template[name].value === key &&
|
||||||
data?.node?.template[name].load_from_db
|
data?.node?.template[name].load_from_db
|
||||||
|
|
@ -52,11 +68,10 @@ export default function InputGlobalComponent({
|
||||||
setDb(false);
|
setDb(false);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch(() => {
|
||||||
let responseError = error as ResponseErrorDetailAPI;
|
|
||||||
setErrorData({
|
setErrorData({
|
||||||
title: "Error deleting variable",
|
title: "Error deleting variable",
|
||||||
list: [responseError.response.data.detail ?? "Unknown error"],
|
list: [cn("ID not found for variable: ", key)],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -115,7 +130,8 @@ export default function InputGlobalComponent({
|
||||||
</DeleteConfirmationModal>
|
</DeleteConfirmationModal>
|
||||||
)}
|
)}
|
||||||
selectedOption={
|
selectedOption={
|
||||||
data?.node?.template[name].load_from_db ?? false
|
data?.node?.template[name].load_from_db &&
|
||||||
|
globalVariablesEntries.includes(data?.node?.template[name].value??"")
|
||||||
? data?.node?.template[name].value
|
? data?.node?.template[name].value
|
||||||
: ""
|
: ""
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -860,14 +860,14 @@ export async function requestLogout() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getGlobalVariables(): Promise<{
|
export async function getGlobalVariables(): Promise<{
|
||||||
[key: string]: { id: string; type: string,default_fields:string[] };
|
[key: string]: { id: string; type: string; default_fields: string[] };
|
||||||
}> {
|
}> {
|
||||||
const globalVariables = {};
|
const globalVariables = {};
|
||||||
(await api.get(`${BASE_URL_API}variables/`)).data.forEach((element) => {
|
(await api.get(`${BASE_URL_API}variables/`)).data.forEach((element) => {
|
||||||
globalVariables[element.name] = {
|
globalVariables[element.name] = {
|
||||||
id: element.id,
|
id: element.id,
|
||||||
type: element.type,
|
type: element.type,
|
||||||
default_fields:element.default_fields
|
default_fields: element.default_fields,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return globalVariables;
|
return globalVariables;
|
||||||
|
|
@ -884,16 +884,26 @@ export async function registerGlobalVariable({
|
||||||
type?: string;
|
type?: string;
|
||||||
default_fields?: string[];
|
default_fields?: string[];
|
||||||
}): Promise<AxiosResponse<{ name: string; id: string; type: string }>> {
|
}): Promise<AxiosResponse<{ name: string; id: string; type: string }>> {
|
||||||
return await api.post(`${BASE_URL_API}variables/`, {
|
try {
|
||||||
|
const response = await api.post(`${BASE_URL_API}variables/`, {
|
||||||
name,
|
name,
|
||||||
value,
|
value,
|
||||||
type,
|
type,
|
||||||
default_fields:default_fields
|
default_fields: default_fields,
|
||||||
});
|
});
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteGlobalVariable(id: string) {
|
export async function deleteGlobalVariable(id: string) {
|
||||||
api.delete(`${BASE_URL_API}variables/${id}`);
|
try {
|
||||||
|
const response = await api.delete(`${BASE_URL_API}variables/${id}`);
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateGlobalVariable(
|
export async function updateGlobalVariable(
|
||||||
|
|
@ -901,10 +911,16 @@ export async function updateGlobalVariable(
|
||||||
value: string,
|
value: string,
|
||||||
id: string
|
id: string
|
||||||
) {
|
) {
|
||||||
api.patch(`${BASE_URL_API}variables/${id}`, {
|
try {
|
||||||
|
const response = api.patch(`${BASE_URL_API}variables/${id}`, {
|
||||||
name,
|
name,
|
||||||
value,
|
value,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getVerticesOrder(
|
export async function getVerticesOrder(
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ import Dropdown from "../../../../components/dropdownComponent";
|
||||||
import ForwardedIconComponent from "../../../../components/genericIconComponent";
|
import ForwardedIconComponent from "../../../../components/genericIconComponent";
|
||||||
import TableComponent from "../../../../components/tableComponent";
|
import TableComponent from "../../../../components/tableComponent";
|
||||||
import { Badge } from "../../../../components/ui/badge";
|
import { Badge } from "../../../../components/ui/badge";
|
||||||
|
import { deleteGlobalVariable } from "../../../../controllers/API";
|
||||||
|
import useAlertStore from "../../../../stores/alertStore";
|
||||||
import { useGlobalVariablesStore } from "../../../../stores/globalVariables";
|
import { useGlobalVariablesStore } from "../../../../stores/globalVariables";
|
||||||
import { cn } from "../../../../utils/utils";
|
import { cn } from "../../../../utils/utils";
|
||||||
|
|
||||||
|
|
@ -21,6 +23,8 @@ export default function GlobalVariablesPage() {
|
||||||
const globalVariables = useGlobalVariablesStore(
|
const globalVariables = useGlobalVariablesStore(
|
||||||
(state) => state.globalVariables
|
(state) => state.globalVariables
|
||||||
);
|
);
|
||||||
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
|
const getVariableId = useGlobalVariablesStore((state) => state.getVariableId);
|
||||||
|
|
||||||
const BadgeRenderer = (props) => {
|
const BadgeRenderer = (props) => {
|
||||||
return props.value !== "" ? (
|
return props.value !== "" ? (
|
||||||
|
|
@ -34,17 +38,24 @@ export default function GlobalVariablesPage() {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [rowData, setRowData] = useState<
|
||||||
const [rowData, setRowData] = useState<{ type: string | undefined;
|
{
|
||||||
id: string; name: string; default_fields:string | undefined }[]>();
|
type: string | undefined;
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
default_fields: string | undefined;
|
||||||
|
}[]
|
||||||
|
>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const rows:Array<{type: string | undefined; id: string;
|
const rows: Array<{
|
||||||
name: string;default_fields:string | undefined}> = [];
|
type: string | undefined;
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
default_fields: string | undefined;
|
||||||
|
}> = [];
|
||||||
globalVariablesEntries.forEach((entrie) => {
|
globalVariablesEntries.forEach((entrie) => {
|
||||||
const globalVariableObj = globalVariables[entrie];
|
const globalVariableObj = globalVariables[entrie];
|
||||||
|
|
||||||
rows.push({
|
rows.push({
|
||||||
type: globalVariableObj.type,
|
type: globalVariableObj.type,
|
||||||
id: globalVariableObj.id,
|
id: globalVariableObj.id,
|
||||||
|
|
@ -52,7 +63,6 @@ export default function GlobalVariablesPage() {
|
||||||
name: entrie,
|
name: entrie,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
console.log(rows);
|
|
||||||
setRowData(rows);
|
setRowData(rows);
|
||||||
}, [globalVariables]);
|
}, [globalVariables]);
|
||||||
|
|
||||||
|
|
@ -95,15 +105,27 @@ export default function GlobalVariablesPage() {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
editable: false,
|
editable: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const [selectedRows, setSelectedRows] = useState<string[]>([]);
|
const [selectedRows, setSelectedRows] = useState<string[]>([]);
|
||||||
|
|
||||||
function removeVariables() {
|
async function removeVariables() {
|
||||||
|
const deleteGlobalVariablesPromise = selectedRows.map(async (row) => {
|
||||||
|
const id = getVariableId(row);
|
||||||
|
const deleteGlobalVariables = deleteGlobalVariable(id!);
|
||||||
|
await deleteGlobalVariables;
|
||||||
|
});
|
||||||
|
Promise.all(deleteGlobalVariablesPromise)
|
||||||
|
.then(() => {
|
||||||
selectedRows.forEach((row) => {
|
selectedRows.forEach((row) => {
|
||||||
removeGlobalVariable(row);
|
removeGlobalVariable(row);
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
setErrorData({
|
||||||
|
title: `Error deleting global variables.`,
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -124,9 +124,7 @@ export default function ShortcutsPage() {
|
||||||
<Card x-chunk="dashboard-04-chunk-2">
|
<Card x-chunk="dashboard-04-chunk-2">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Flow</CardTitle>
|
<CardTitle>Flow</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>Shortcuts relating to the flow.</CardDescription>
|
||||||
Shortcuts relating to the flow.
|
|
||||||
</CardDescription>
|
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<TableComponent
|
<TableComponent
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import ApiKeysPage from "./pages/ApiKeysPage";
|
||||||
import FlowPage from "./pages/FlowPage";
|
import FlowPage from "./pages/FlowPage";
|
||||||
import HomePage from "./pages/MainPage";
|
import HomePage from "./pages/MainPage";
|
||||||
import ComponentsComponent from "./pages/MainPage/components/components";
|
import ComponentsComponent from "./pages/MainPage/components/components";
|
||||||
import ProfileSettingsPage from "./pages/ProfileSettingsPage";
|
|
||||||
import SettingsPage from "./pages/SettingsPage";
|
import SettingsPage from "./pages/SettingsPage";
|
||||||
import GeneralPage from "./pages/SettingsPage/pages/GeneralPage";
|
import GeneralPage from "./pages/SettingsPage/pages/GeneralPage";
|
||||||
import GlobalVariablesPage from "./pages/SettingsPage/pages/GlobalVariablesPage";
|
import GlobalVariablesPage from "./pages/SettingsPage/pages/GlobalVariablesPage";
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,10 @@ const useFlowsManagerStore = create<FlowsManagerStoreType>((set, get) => ({
|
||||||
);
|
);
|
||||||
useTypesStore.setState((state) => ({
|
useTypesStore.setState((state) => ({
|
||||||
data: { ...state.data, ["saved_components"]: data },
|
data: { ...state.data, ["saved_components"]: data },
|
||||||
ComponentFields: extractFieldsFromComponenents({...state.data, ["saved_components"]: data }),
|
ComponentFields: extractFieldsFromComponenents({
|
||||||
|
...state.data,
|
||||||
|
["saved_components"]: data,
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
set({ isLoading: false });
|
set({ isLoading: false });
|
||||||
resolve();
|
resolve();
|
||||||
|
|
@ -199,7 +202,10 @@ const useFlowsManagerStore = create<FlowsManagerStoreType>((set, get) => ({
|
||||||
set({ isLoading: false });
|
set({ isLoading: false });
|
||||||
useTypesStore.setState((state) => ({
|
useTypesStore.setState((state) => ({
|
||||||
data: { ...state.data, ["saved_components"]: data },
|
data: { ...state.data, ["saved_components"]: data },
|
||||||
ComponentFields: extractFieldsFromComponenents({...state.data, ["saved_components"]: data }),
|
ComponentFields: extractFieldsFromComponenents({
|
||||||
|
...state.data,
|
||||||
|
["saved_components"]: data,
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
}, 200);
|
}, 200);
|
||||||
// addFlowToLocalState(newFlow);
|
// addFlowToLocalState(newFlow);
|
||||||
|
|
@ -222,7 +228,10 @@ const useFlowsManagerStore = create<FlowsManagerStoreType>((set, get) => ({
|
||||||
set({ isLoading: false });
|
set({ isLoading: false });
|
||||||
useTypesStore.setState((state) => ({
|
useTypesStore.setState((state) => ({
|
||||||
data: { ...state.data, ["saved_components"]: data },
|
data: { ...state.data, ["saved_components"]: data },
|
||||||
ComponentFields: extractFieldsFromComponenents({...state.data, ["saved_components"]: data }),
|
ComponentFields: extractFieldsFromComponenents({
|
||||||
|
...state.data,
|
||||||
|
["saved_components"]: data,
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Return the id
|
// Return the id
|
||||||
|
|
@ -252,7 +261,10 @@ const useFlowsManagerStore = create<FlowsManagerStoreType>((set, get) => ({
|
||||||
set({ isLoading: false });
|
set({ isLoading: false });
|
||||||
useTypesStore.setState((state) => ({
|
useTypesStore.setState((state) => ({
|
||||||
data: { ...state.data, ["saved_components"]: data },
|
data: { ...state.data, ["saved_components"]: data },
|
||||||
ComponentFields: extractFieldsFromComponenents({...state.data, ["saved_components"]: data }),
|
ComponentFields: extractFieldsFromComponenents({
|
||||||
|
...state.data,
|
||||||
|
["saved_components"]: data,
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,17 @@
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import { GlobalVariablesStore } from "../types/zustand/globalVariables";
|
import { GlobalVariablesStore } from "../types/zustand/globalVariables";
|
||||||
import { deleteGlobalVariable } from "../controllers/API";
|
import { getUnavailableFields } from "../utils/utils";
|
||||||
|
|
||||||
export const useGlobalVariablesStore = create<GlobalVariablesStore>(
|
export const useGlobalVariablesStore = create<GlobalVariablesStore>(
|
||||||
(set, get) => ({
|
(set, get) => ({
|
||||||
unavaliableFields: new Set(),
|
unavaliableFields: {},
|
||||||
setUnavaliableFields: (fields) => {
|
setUnavaliableFields: (fields) => {
|
||||||
set({ unavaliableFields: fields });
|
set({ unavaliableFields: fields });
|
||||||
},
|
},
|
||||||
addUnavaliableField: (field) => {
|
|
||||||
set({ unavaliableFields: get().unavaliableFields.add(field) });
|
|
||||||
},
|
|
||||||
removeUnavaliableField: (field) => {
|
removeUnavaliableField: (field) => {
|
||||||
get().unavaliableFields.delete(field);
|
const newFields = get().unavaliableFields;
|
||||||
|
delete newFields[field];
|
||||||
|
set({ unavaliableFields: newFields });
|
||||||
},
|
},
|
||||||
globalVariablesEntries: [],
|
globalVariablesEntries: [],
|
||||||
globalVariables: {},
|
globalVariables: {},
|
||||||
|
|
@ -20,6 +19,7 @@ export const useGlobalVariablesStore = create<GlobalVariablesStore>(
|
||||||
set({
|
set({
|
||||||
globalVariables: variables,
|
globalVariables: variables,
|
||||||
globalVariablesEntries: Object.keys(variables),
|
globalVariablesEntries: Object.keys(variables),
|
||||||
|
unavaliableFields: getUnavailableFields(variables),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
addGlobalVariable: (name, id, type, default_fields) => {
|
addGlobalVariable: (name, id, type, default_fields) => {
|
||||||
|
|
@ -28,17 +28,18 @@ export const useGlobalVariablesStore = create<GlobalVariablesStore>(
|
||||||
set({
|
set({
|
||||||
globalVariables: newVariables,
|
globalVariables: newVariables,
|
||||||
globalVariablesEntries: Object.keys(newVariables),
|
globalVariablesEntries: Object.keys(newVariables),
|
||||||
|
unavaliableFields: getUnavailableFields(newVariables),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
removeGlobalVariable: async (name) => {
|
removeGlobalVariable: async (name) => {
|
||||||
const id = get().globalVariables[name]?.id;
|
const id = get().globalVariables[name]?.id;
|
||||||
if (id === undefined) return;
|
if (id === undefined) return;
|
||||||
await deleteGlobalVariable(id)
|
|
||||||
const newVariables = { ...get().globalVariables };
|
const newVariables = { ...get().globalVariables };
|
||||||
delete newVariables[name];
|
delete newVariables[name];
|
||||||
set({
|
set({
|
||||||
globalVariables: newVariables,
|
globalVariables: newVariables,
|
||||||
globalVariablesEntries: Object.keys(newVariables),
|
globalVariablesEntries: Object.keys(newVariables),
|
||||||
|
unavaliableFields: getUnavailableFields(newVariables),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getVariableId: (name) => {
|
getVariableId: (name) => {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,11 @@ import { create } from "zustand";
|
||||||
import { getAll } from "../controllers/API";
|
import { getAll } from "../controllers/API";
|
||||||
import { APIDataType } from "../types/api";
|
import { APIDataType } from "../types/api";
|
||||||
import { TypesStoreType } from "../types/zustand/types";
|
import { TypesStoreType } from "../types/zustand/types";
|
||||||
import { extractFieldsFromComponenents, templatesGenerator, typesGenerator } from "../utils/reactflowUtils";
|
import {
|
||||||
|
extractFieldsFromComponenents,
|
||||||
|
templatesGenerator,
|
||||||
|
typesGenerator,
|
||||||
|
} from "../utils/reactflowUtils";
|
||||||
import useAlertStore from "./alertStore";
|
import useAlertStore from "./alertStore";
|
||||||
import useFlowsManagerStore from "./flowsManagerStore";
|
import useFlowsManagerStore from "./flowsManagerStore";
|
||||||
|
|
||||||
|
|
@ -28,7 +32,10 @@ export const useTypesStore = create<TypesStoreType>((set, get) => ({
|
||||||
set((old) => ({
|
set((old) => ({
|
||||||
types: typesGenerator(data),
|
types: typesGenerator(data),
|
||||||
data: { ...old.data, ...data },
|
data: { ...old.data, ...data },
|
||||||
ComponentFields: extractFieldsFromComponenents({ ...old.data, ...data }),
|
ComponentFields: extractFieldsFromComponenents({
|
||||||
|
...old.data,
|
||||||
|
...data,
|
||||||
|
}),
|
||||||
templates: templatesGenerator(data),
|
templates: templatesGenerator(data),
|
||||||
}));
|
}));
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,12 @@ export type GlobalVariablesStore = {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
setGlobalVariables: (variables: {
|
setGlobalVariables: (variables: {
|
||||||
[name: string]: { id: string; type?: string; default_fields?: string[],value?: string };
|
[name: string]: {
|
||||||
|
id: string;
|
||||||
|
type?: string;
|
||||||
|
default_fields?: string[];
|
||||||
|
value?: string;
|
||||||
|
};
|
||||||
}) => void;
|
}) => void;
|
||||||
addGlobalVariable: (
|
addGlobalVariable: (
|
||||||
name: string,
|
name: string,
|
||||||
|
|
@ -20,8 +25,7 @@ export type GlobalVariablesStore = {
|
||||||
) => void;
|
) => void;
|
||||||
removeGlobalVariable: (name: string) => Promise<void>;
|
removeGlobalVariable: (name: string) => Promise<void>;
|
||||||
getVariableId: (name: string) => string | undefined;
|
getVariableId: (name: string) => string | undefined;
|
||||||
unavaliableFields: Set<string>;
|
unavaliableFields: {[name: string]: string};
|
||||||
setUnavaliableFields: (fields: Set<string>) => void;
|
setUnavaliableFields: (fields: {[name: string]: string}) => void;
|
||||||
addUnavaliableField: (field: string) => void;
|
|
||||||
removeUnavaliableField: (field: string) => void;
|
removeUnavaliableField: (field: string) => void;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1239,12 +1239,14 @@ export function extractFieldsFromComponenents(data:APIObjectType ) {
|
||||||
Object.keys(data).forEach((key) => {
|
Object.keys(data).forEach((key) => {
|
||||||
Object.keys(data[key]).forEach((kind) => {
|
Object.keys(data[key]).forEach((kind) => {
|
||||||
Object.keys(data[key][kind].template).forEach((field) => {
|
Object.keys(data[key][kind].template).forEach((field) => {
|
||||||
if(data[key][kind].template[field].display_name && data[key][kind].template[field].show)
|
if (
|
||||||
|
data[key][kind].template[field].display_name &&
|
||||||
|
data[key][kind].template[field].show
|
||||||
|
)
|
||||||
fields.add(data[key][kind].template[field].display_name!);
|
fields.add(data[key][kind].template[field].display_name!);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
console.log(fields);
|
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,20 @@ export function toTitleCase(
|
||||||
.join(" ");
|
.join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getUnavailableFields(variables: {
|
||||||
|
[key: string]: { default_fields?: string[] };
|
||||||
|
}): {[name: string]: string} {
|
||||||
|
const unVariables:{[name: string]: string} = {};
|
||||||
|
Object.keys(variables).forEach((key) => {
|
||||||
|
if (variables[key].default_fields) {
|
||||||
|
variables[key].default_fields!.forEach((field) => {
|
||||||
|
unVariables[field] = key;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return unVariables;
|
||||||
|
}
|
||||||
|
|
||||||
export const upperCaseWords: string[] = ["llm", "uri"];
|
export const upperCaseWords: string[] = ["llm", "uri"];
|
||||||
export function checkUpperWords(str: string): string {
|
export function checkUpperWords(str: string): string {
|
||||||
const words = str.split(" ").map((word) => {
|
const words = str.split(" ").map((word) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue