feature: add edit option to global variables table (#3712)
* first attempt to edit variables on the data table * refactor: Rename AddNewVariableButton to GlobalVariableModal and update its usage The component AddNewVariableButton has been renamed to GlobalVariableModal to better reflect its purpose. The component is now used in multiple places, including the GlobalVariablesPage and InputGlobalComponent. This change improves code clarity and consistency. * fix: fix apply to fields on table edit option * refactor: Trim field names before checking for availability in GlobalVariableModal and GlobalVariablesPage Trim field names before checking for availability in GlobalVariableModal and GlobalVariablesPage to ensure consistent comparison and avoid any potential issues with leading or trailing spaces. * Refactor GlobalVariablesPage to remove unused cellRenderer in the "value" field * [autofix.ci] apply automated fixes * Add validation for 'value' field in VariableRead model and import CREDENTIAL_TYPE - Introduced a field validator for the 'value' field in the VariableRead model to handle cases where the variable type is CREDENTIAL_TYPE. - Added necessary import for CREDENTIAL_TYPE. - Removed an unnecessary blank line in the variable API. * Add constants for credential and generic types in variable service * Refactor import statements in `kubernetes.py` to improve module organization * Refactor imports in test_service.py for better organization * refactor: Update import statements in variable.py for better organization * Refactor import and reorder fields in VariableRead model - Changed import of `CREDENTIAL_TYPE` from `service` to `constants` module. - Reordered fields in `VariableRead` model to place `type` before `value`. * ✨ (userSettings.spec.ts): Add additional randomName variables for testing purposes 📝 (userSettings.spec.ts): Update test to interact with global variables and improve readability and maintainability of the code * test: fix test_create_variable --------- Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> Co-authored-by: cristhianzl <cristhian.lousa@gmail.com> Co-authored-by: italojohnny <italojohnnydosanjos@gmail.com>
This commit is contained in:
parent
19818db68b
commit
d3b8f6cd7e
15 changed files with 186 additions and 68 deletions
|
|
@ -9,7 +9,8 @@ from langflow.services.database.models.user.model import User
|
|||
from langflow.services.database.models.variable import VariableCreate, VariableRead, VariableUpdate
|
||||
from langflow.services.deps import get_session, get_settings_service, get_variable_service
|
||||
from langflow.services.variable.base import VariableService
|
||||
from langflow.services.variable.service import GENERIC_TYPE, DatabaseVariableService
|
||||
from langflow.services.variable.constants import GENERIC_TYPE
|
||||
from langflow.services.variable.service import DatabaseVariableService
|
||||
|
||||
router = APIRouter(prefix="/variables", tags=["Variables"])
|
||||
|
||||
|
|
@ -61,7 +62,6 @@ def read_variables(
|
|||
"""Read all variables."""
|
||||
try:
|
||||
return variable_service.get_all(user_id=current_user.id, session=session)
|
||||
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e)) from e
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@ from datetime import datetime, timezone
|
|||
from typing import TYPE_CHECKING, List, Optional
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from pydantic import ValidationInfo, field_validator
|
||||
from sqlmodel import JSON, Column, DateTime, Field, Relationship, SQLModel, func
|
||||
|
||||
from langflow.services.variable.constants import CREDENTIAL_TYPE
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langflow.services.database.models.user.model import User
|
||||
|
||||
|
|
@ -52,8 +55,16 @@ class VariableRead(SQLModel):
|
|||
id: UUID
|
||||
name: Optional[str] = Field(None, description="Name of the variable")
|
||||
type: Optional[str] = Field(None, description="Type of the variable")
|
||||
value: Optional[str] = Field(None, description="Encrypted value of the variable")
|
||||
default_fields: Optional[List[str]] = Field(None, description="Default fields for the variable")
|
||||
|
||||
@field_validator("value")
|
||||
@classmethod
|
||||
def validate_value(cls, value: str, info: ValidationInfo):
|
||||
if info.data.get("type") == CREDENTIAL_TYPE:
|
||||
return None
|
||||
return value
|
||||
|
||||
|
||||
class VariableUpdate(SQLModel):
|
||||
id: UUID # Include the ID for updating
|
||||
|
|
|
|||
2
src/backend/base/langflow/services/variable/constants.py
Normal file
2
src/backend/base/langflow/services/variable/constants.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
CREDENTIAL_TYPE = "Credential"
|
||||
GENERIC_TYPE = "Generic"
|
||||
|
|
@ -10,8 +10,8 @@ from langflow.services.base import Service
|
|||
from langflow.services.database.models.variable.model import Variable, VariableCreate
|
||||
from langflow.services.settings.service import SettingsService
|
||||
from langflow.services.variable.base import VariableService
|
||||
from langflow.services.variable.constants import CREDENTIAL_TYPE, GENERIC_TYPE
|
||||
from langflow.services.variable.kubernetes_secrets import KubernetesSecretManager, encode_user_id
|
||||
from langflow.services.variable.service import CREDENTIAL_TYPE, GENERIC_TYPE
|
||||
|
||||
|
||||
class KubernetesSecretService(VariableService, Service):
|
||||
|
|
|
|||
|
|
@ -12,13 +12,11 @@ from langflow.services.base import Service
|
|||
from langflow.services.database.models.variable.model import Variable, VariableCreate, VariableUpdate
|
||||
from langflow.services.deps import get_session
|
||||
from langflow.services.variable.base import VariableService
|
||||
from langflow.services.variable.constants import CREDENTIAL_TYPE, GENERIC_TYPE
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langflow.services.settings.service import SettingsService
|
||||
|
||||
CREDENTIAL_TYPE = "Credential"
|
||||
GENERIC_TYPE = "Generic"
|
||||
|
||||
|
||||
class DatabaseVariableService(VariableService, Service):
|
||||
def __init__(self, settings_service: "SettingsService"):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue