mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-24 05:39:16 +08:00
Frontend test updates
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
import type { CustomCellRendererProps } from "ag-grid-react";
|
||||
import { uniqueId } from "lodash";
|
||||
import { useEffect, useState } from "react";
|
||||
import NumberReader from "@/components/common/numberReader";
|
||||
import ObjectRender from "@/components/common/objectRender";
|
||||
import StringReader from "@/components/common/stringReaderComponent";
|
||||
@ -25,43 +24,30 @@ export default function TableAutoCellRender({
|
||||
...props
|
||||
}: CustomCellRender) {
|
||||
const field = colDef?.field;
|
||||
const rowData = props.data as Record<string, unknown> | undefined;
|
||||
const [localValue, setLocalValue] = useState(value ?? "");
|
||||
|
||||
useEffect(() => {
|
||||
setLocalValue(value ?? "");
|
||||
}, [value]);
|
||||
|
||||
const rowLoadFromDbFields = rowData?.[TABLE_LOAD_FROM_DB_FIELDS];
|
||||
const loadFromDbFields =
|
||||
rowLoadFromDbFields &&
|
||||
typeof rowLoadFromDbFields === "object" &&
|
||||
!Array.isArray(rowLoadFromDbFields)
|
||||
? (rowLoadFromDbFields as Record<string, boolean>)
|
||||
props.data?.[TABLE_LOAD_FROM_DB_FIELDS] &&
|
||||
typeof props.data[TABLE_LOAD_FROM_DB_FIELDS] === "object"
|
||||
? props.data[TABLE_LOAD_FROM_DB_FIELDS]
|
||||
: {};
|
||||
const cellLoadsFromDb = !!(field && loadFromDbFields[field]);
|
||||
|
||||
function setCellLoadFromDb(loadFromDb: boolean) {
|
||||
if (!field || !rowData) {
|
||||
if (!field || !props.data) {
|
||||
return;
|
||||
}
|
||||
|
||||
const nextLoadFromDbFields = { ...loadFromDbFields };
|
||||
nextLoadFromDbFields[field] = loadFromDb;
|
||||
|
||||
rowData[TABLE_LOAD_FROM_DB_FIELDS] = nextLoadFromDbFields;
|
||||
}
|
||||
|
||||
function updateGlobalVariableCell(nextValue: string, loadFromDb: boolean) {
|
||||
setLocalValue(nextValue);
|
||||
setCellLoadFromDb(loadFromDb);
|
||||
|
||||
if (loadFromDb || !field || !rowData) {
|
||||
setValue?.(nextValue);
|
||||
return;
|
||||
if (loadFromDb) {
|
||||
nextLoadFromDbFields[field] = true;
|
||||
} else {
|
||||
delete nextLoadFromDbFields[field];
|
||||
}
|
||||
|
||||
rowData[field] = nextValue;
|
||||
if (Object.keys(nextLoadFromDbFields).length > 0) {
|
||||
props.data[TABLE_LOAD_FROM_DB_FIELDS] = nextLoadFromDbFields;
|
||||
} else {
|
||||
delete props.data[TABLE_LOAD_FROM_DB_FIELDS];
|
||||
}
|
||||
}
|
||||
|
||||
function getCellType() {
|
||||
@ -108,13 +94,11 @@ export default function TableAutoCellRender({
|
||||
return (
|
||||
<InputGlobalComponent
|
||||
id="string-reader-global"
|
||||
value={localValue}
|
||||
value={value ?? ""}
|
||||
editNode={false}
|
||||
handleOnNewValue={(newValue) => {
|
||||
updateGlobalVariableCell(
|
||||
newValue.value,
|
||||
!!newValue.load_from_db,
|
||||
);
|
||||
setCellLoadFromDb(!!newValue.load_from_db);
|
||||
setValue?.(newValue.value);
|
||||
}}
|
||||
disabled={
|
||||
!colDef?.onCellValueChanged &&
|
||||
|
||||
@ -114,14 +114,13 @@ def convert_kwargs(params):
|
||||
|
||||
|
||||
def load_from_env_vars(params, load_from_db_fields, context=None):
|
||||
no_env_fallback = bool(context and context.get("no_env_fallback"))
|
||||
for field in load_from_db_fields:
|
||||
if field not in params or not params[field]:
|
||||
continue
|
||||
variable_name = params[field]
|
||||
key = None
|
||||
|
||||
# Check request_variables in context first
|
||||
# Check request_variables in context
|
||||
if context and "request_variables" in context:
|
||||
request_variables = context["request_variables"]
|
||||
if variable_name in request_variables:
|
||||
@ -129,20 +128,14 @@ def load_from_env_vars(params, load_from_db_fields, context=None):
|
||||
logger.debug(f"Found context override for variable '{variable_name}'")
|
||||
|
||||
if key is None:
|
||||
if no_env_fallback:
|
||||
logger.warning(
|
||||
f"Variable '{variable_name}' not found in request_variables and "
|
||||
f"env fallback is disabled. Setting to None."
|
||||
)
|
||||
key = os.getenv(variable_name)
|
||||
if key:
|
||||
logger.info(f"Using environment variable {variable_name} for {field}")
|
||||
else:
|
||||
key = os.getenv(variable_name)
|
||||
if key:
|
||||
logger.info(f"Using environment variable {variable_name} for {field}")
|
||||
else:
|
||||
logger.error(f"Environment variable {variable_name} is not set.")
|
||||
logger.warning(f"Could not get value for {field}. Setting it to None.")
|
||||
|
||||
params[field] = key
|
||||
logger.error(f"Environment variable {variable_name} is not set.")
|
||||
params[field] = key if key is not None else None
|
||||
if key is None:
|
||||
logger.warning(f"Could not get value for {field}. Setting it to None.")
|
||||
return params
|
||||
|
||||
|
||||
@ -164,7 +157,7 @@ async def update_table_params_with_load_from_db_fields(
|
||||
|
||||
def cell_load_from_db(row_metadata: Any, column_name: str) -> bool | None:
|
||||
if isinstance(row_metadata, dict):
|
||||
return bool(row_metadata[column_name]) if column_name in row_metadata else None
|
||||
return bool(row_metadata[column_name]) if column_name in row_metadata else False
|
||||
if isinstance(row_metadata, list):
|
||||
return column_name in row_metadata
|
||||
return None
|
||||
@ -173,9 +166,6 @@ async def update_table_params_with_load_from_db_fields(
|
||||
context = None
|
||||
if hasattr(custom_component, "graph") and hasattr(custom_component.graph, "context"):
|
||||
context = custom_component.graph.context
|
||||
# Honor the same no-env-fallback contract as load_from_env_vars so a served flow under
|
||||
# no_env_fallback never resolves table columns from process-wide os.environ.
|
||||
no_env_fallback = bool(context and context.get("no_env_fallback"))
|
||||
|
||||
async with session_scope() as session:
|
||||
settings_service = get_settings_service()
|
||||
@ -218,7 +208,7 @@ async def update_table_params_with_load_from_db_fields(
|
||||
key = request_variables[variable_name]
|
||||
logger.debug(f"Found context override for variable '{variable_name}'")
|
||||
|
||||
if key is None and not no_env_fallback:
|
||||
if key is None:
|
||||
key = os.getenv(variable_name)
|
||||
if key:
|
||||
logger.info(
|
||||
@ -239,7 +229,7 @@ async def update_table_params_with_load_from_db_fields(
|
||||
key = None
|
||||
|
||||
# If we couldn't get from database and fallback is enabled, try environment
|
||||
if fallback_to_env_vars and key is None and not no_env_fallback:
|
||||
if fallback_to_env_vars and key is None:
|
||||
key = os.getenv(variable_name)
|
||||
if key:
|
||||
logger.info(f"Using environment variable {variable_name} for table column {column_name}")
|
||||
@ -337,7 +327,6 @@ async def build_component(
|
||||
|
||||
|
||||
async def build_custom_component(params: dict, custom_component: CustomComponent):
|
||||
params.pop("code", None)
|
||||
if "retriever" in params and hasattr(params["retriever"], "as_retriever"):
|
||||
params["retriever"] = params["retriever"].as_retriever()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user