From 3215d3a4701bcb28ebf7b25f794cc83228b572a8 Mon Sep 17 00:00:00 2001 From: RINO-GAELICO Date: Wed, 9 Oct 2024 13:21:53 -0700 Subject: [PATCH 1/8] Added a filtering mechanism within list_connectors in connector.py --- app/api/v1/connector.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/api/v1/connector.py b/app/api/v1/connector.py index 78555cf5..286fbda3 100644 --- a/app/api/v1/connector.py +++ b/app/api/v1/connector.py @@ -1,3 +1,4 @@ +from typing import Optional from fastapi import APIRouter, Depends from sqlalchemy.orm import Session import app.schemas.connector as schemas @@ -24,10 +25,10 @@ actions = APIRouter() @router.get("/list", response_model=resp_schemas.CommonResponse) -def list_connectors(db: Session = Depends(get_db)): +def list_connectors(db: Session = Depends(get_db), provider_category_id: Optional[int] = None ): """ - Retrieves a list of all connectors from the database. + Retrieves a list of all connectors from the database. If a provider category ID is provided, only connectors from that category are returned. Args: db (Session): Database session dependency. @@ -38,6 +39,9 @@ def list_connectors(db: Session = Depends(get_db)): result, error = svc.list_connectors(db) + if provider_category_id: + result = list(filter(lambda x: x["provider_category_id"] == provider_category_id, result)) + if error: return commons.is_error_response("DB Error", result, {"connectors": []}) From 7c4c57336014b3736970e611113111a0e4c7d587 Mon Sep 17 00:00:00 2001 From: RINO-GAELICO Date: Thu, 10 Oct 2024 16:37:20 -0700 Subject: [PATCH 2/8] Added the ability to pass the parameter provider_category_id from frontend --- ui/src/services/Connectors.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui/src/services/Connectors.js b/ui/src/services/Connectors.js index 3885d2a9..9eaa5df5 100644 --- a/ui/src/services/Connectors.js +++ b/ui/src/services/Connectors.js @@ -3,7 +3,10 @@ import DeleteService from "src/utils/http/DeleteService"; import GetService from "src/utils/http/GetService"; import PostService from "src/utils/http/PostService"; -export const getConnectors = ()=>{ +export const getConnectors = (provider_category_id = null)=>{ + if (provider_category_id) { + return GetService(API_URL + `/connector/list?provider_category_id=${provider_category_id}`); + } return GetService(API_URL + "/connector/list") } From 755a0f95b95d9cf6fc0f423b2b1212aec35348de Mon Sep 17 00:00:00 2001 From: RINO-GAELICO Date: Fri, 11 Oct 2024 10:10:56 -0700 Subject: [PATCH 3/8] Added the parameter 2 to the getConnectors function in frontend --- ui/src/pages/Samples/SampleForm.jsx | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ui/src/pages/Samples/SampleForm.jsx b/ui/src/pages/Samples/SampleForm.jsx index 93d7cc10..68e5a613 100644 --- a/ui/src/pages/Samples/SampleForm.jsx +++ b/ui/src/pages/Samples/SampleForm.jsx @@ -20,7 +20,7 @@ const SampleForm = ({ sample = {}, afterCreate = ()=>{}, onCancel = ()=>{}})=>{ const getAllConnectors = ()=>{ - getConnectors().then(response=>{ + getConnectors(2).then(response=>{ let tempOptions = []; response.data?.data?.connectors?.map(item=>{ @@ -29,7 +29,7 @@ const SampleForm = ({ sample = {}, afterCreate = ()=>{}, onCancel = ()=>{}})=>{ setConnectors(tempOptions) }) } - + const saveSample = (data)=>{ saveSamples(sample.id, { @@ -66,23 +66,23 @@ const SampleForm = ({ sample = {}, afterCreate = ()=>{}, onCancel = ()=>{}})=>{ Question} hasError={errors["question"]?.message} errorMessage={errors["question"]?.message} {...register("question", {required: "This is required"})} />
- ( - Connector } value={connectors.find(c => c.value === value)} - options={connectors} + options={connectors} onChange={val=>onChange(val.value)} /> )} - + /> - +