Skip to content

Commit

Permalink
Merge pull request sirocco-ventures#107 from RINO-GAELICO/Filter-Plugins
Browse files Browse the repository at this point in the history
Added a filtering mechanism within list_connectors in connector.py
  • Loading branch information
ashmilhussain authored Oct 31, 2024
2 parents f9be01b + 2e99e8b commit 0b8c77a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 20 deletions.
10 changes: 7 additions & 3 deletions app/api/v1/connector.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Optional
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
import app.schemas.connector as schemas
Expand Down Expand Up @@ -26,10 +27,10 @@
actions = APIRouter()

@router.get("/list", response_model=resp_schemas.CommonResponse, dependencies=[Depends(verify_token)])
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.
Expand All @@ -38,7 +39,10 @@ def list_connectors(db: Session = Depends(get_db)):
CommonResponse: A response containing either the list of connectors or an error message.
"""

result, error = svc.list_connectors(db)
if provider_category_id:
result, error = svc.list_connectors_by_provider_category(provider_category_id, db)
else:
result, error = svc.list_connectors(db)

if error:
return commons.is_error_response("DB Error", result, {"connectors": []})
Expand Down
1 change: 1 addition & 0 deletions app/schemas/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ConnectorResponse(ConnectorBase):
connector_id:int
connector_key :Optional[str]=None
icon:Optional[str]=None
provider_id: Optional[int] = None

class ConnectorUpdate(BaseModel):
connector_type: Optional[int] = None
Expand Down
25 changes: 24 additions & 1 deletion app/services/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,34 @@ def list_connectors(db: Session):
connector_docs=connector.connector_docs,
connector_key=connector.provider.key,
enable=connector.enable,
icon=connector.provider.icon
icon=connector.provider.icon,
provider_id=connector.provider.category_id
) for connector in connectors]

return connectors_response, None

def list_connectors_by_provider_category(category_id: int, db: Session):
"""
Retrieves all connector records from the database filtered by provider category.
Args:
category_id (int): The ID of the provider category.
db (Session): Database session object.
Returns:
Tuple: List of connector responses and error message (if any).
"""
connectors, error = list_connectors(db)

if error:
return [], error

filtered_connectors = [connector for connector in connectors if connector.provider_id == category_id]

return filtered_connectors, None



def get_connector(connector_id: int, db: Session):

"""
Expand Down
2 changes: 0 additions & 2 deletions ui/.env.example

This file was deleted.

26 changes: 13 additions & 13 deletions ui/src/pages/Samples/SampleForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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=>{
Expand All @@ -29,7 +29,7 @@ const SampleForm = ({ sample = {}, afterCreate = ()=>{}, onCancel = ()=>{}})=>{
setConnectors(tempOptions)
})
}


const saveSample = (data)=>{
saveSamples(sample.id, {
Expand Down Expand Up @@ -66,23 +66,23 @@ const SampleForm = ({ sample = {}, afterCreate = ()=>{}, onCancel = ()=>{}})=>{
<Input label={<span className="span-important">Question</span>} hasError={errors["question"]?.message} errorMessage={errors["question"]?.message} {...register("question", {required: "This is required"})} />
</div>
<div>
<Controller
<Controller
control={control}
name="connector"
rules={{
required: "This field is required"
}}
render={({ field: { onChange, value, ref } })=>(
<Select
inputRef={ref}
label={ <span className="span-important">Connector</span> }
<Select
inputRef={ref}
label={ <span className="span-important">Connector</span> }
value={connectors.find(c => c.value === value)}
options={connectors}
options={connectors}
onChange={val=>onChange(val.value)} />
)}

/>

</div>
<div>
<Textarea label={<span className="span-important">Query</span>} rows={6} style={{resize: "vertical"}} hasError={errors["query"]?.message} errorMessage={errors["query"]?.message} {...register("query", {required: "This is required"})} />
Expand All @@ -91,11 +91,11 @@ const SampleForm = ({ sample = {}, afterCreate = ()=>{}, onCancel = ()=>{}})=>{
<Textarea label="Metadata" rows={6} style={{resize: "vertical"}} hasError={errors["metadata"]?.message} errorMessage={errors["metadata"]?.message} {...register("metadata")} />
</div>
<div className="flex flex-gap-10 justify-content-end">
<div>
<Button variant="secondary-danger" onClick={onCancel}>Cancel <FiXCircle/></Button>
<div>
<Button variant="secondary-danger" onClick={onCancel}>Cancel <FiXCircle/></Button>
</div>
<div>
<Button buttonType="submit" disabled={isFormValid ? false: true} onClick={onCancel}>Save <FiCheckCircle/></Button>
<div>
<Button buttonType="submit" disabled={isFormValid ? false: true} onClick={onCancel}>Save <FiCheckCircle/></Button>
</div>
</div>
</form>
Expand Down
5 changes: 4 additions & 1 deletion ui/src/services/Connectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit 0b8c77a

Please sign in to comment.