Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

Adapter search results fix (#243)

Athul14e0f7fdcfe3
diff --git a/frontend/src/components/input-output/add-source-modal/AddSourceModal.jsx b/frontend/src/components/input-output/add-source-modal/AddSourceModal.jsx
index 7bf744e9f..e2c114025 100644
--- a/frontend/src/components/input-output/add-source-modal/AddSourceModal.jsx
+++ b/frontend/src/components/input-output/add-source-modal/AddSourceModal.jsx
@@ -9,6 +9,7 @@ import { useSessionStore } from "../../../store/session-store";
import { AddSource } from "../add-source/AddSource";
import { ListOfSources } from "../list-of-sources/ListOfSources";
import { useExceptionHandler } from "../../../hooks/useExceptionHandler";
+import { SpinnerLoader } from "../../widgets/spinner-loader/SpinnerLoader";
function AddSourceModal({
open,
@@ -25,6 +26,14 @@ function AddSourceModal({
const { setAlertDetails } = useAlertStore();
const axiosPrivate = useAxiosPrivate();
const handleException = useExceptionHandler();
+ const [isLoading, setIsLoading] = useState(false);
+ const [sourcesList, setSourcesList] = useState([]);
+
+ const disabledIdsByType = {
+ EMBEDDING: ["huggingface|90ec9ec2-1768-4d69-8fb1-c88b95de5e5a"],
+ LLM: ["replicate|2715ce84-05af-4ab4-b8e9-67ac3211b81e"],
+ VECTOR_DB: ["milvus|3f42f6f9-4b8e-4546-95f3-22ecc9aca442"],
+ };
useEffect(() => {
const addOrEdit = editItemId?.length ? "Edit" : "Add";
@@ -50,6 +59,10 @@ function AddSourceModal({
setEditItemId(null);
}, 500);
}
+
+ if (type && type !== null) {
+ getListOfSources();
+ }
}, [open]);
const getSourceDetails = () => {
@@ -88,6 +101,40 @@ function AddSourceModal({
});
};
+ const getListOfSources = () => {
+ let url = `/api/v1/unstract/${sessionDetails?.orgId}`;
+ if (type && sourceTypes.connectors.includes(type)) {
+ url += `/supported_connectors/?type=${type?.toUpperCase()}`;
+ } else {
+ url += `/supported_adapters/?adapter_type=${type?.toUpperCase()}`;
+ }
+ // API to get the list of adapters.
+ const requestOptions = {
+ method: "GET",
+ url,
+ };
+
+ setIsLoading(true);
+ setSourcesList([]);
+ axiosPrivate(requestOptions)
+ .then((res) => {
+ const sources = res?.data || [];
+ const updatedSources = sources?.map((source) => ({
+ ...source,
+ isDisabled: disabledIdsByType[source?.adapter_type]?.includes(
+ source?.id
+ ),
+ }));
+ setSourcesList(updatedSources || []);
+ })
+ .catch((err) => {
+ setAlertDetails(handleException(err));
+ })
+ .finally(() => {
+ setIsLoading(false);
+ });
+ };
+
return (
<Modal
open={open}
@@ -111,8 +158,14 @@ function AddSourceModal({
editItemId={editItemId}
metadata={metadata}
/>
+ ) : isLoading ? (
+ <SpinnerLoader />
) : (
- <ListOfSources setSelectedSourceId={setSelectedSourceId} type={type} />
+ <ListOfSources
+ setSelectedSourceId={setSelectedSourceId}
+ open={open}
+ sourcesList={sourcesList}
+ />
)}
</Modal>
);
@@ -121,7 +174,7 @@ function AddSourceModal({
AddSourceModal.propTypes = {
open: PropTypes.bool.isRequired,
setOpen: PropTypes.func.isRequired,
- type: PropTypes.string.isRequired,
+ type: PropTypes.any,
addNewItem: PropTypes.func.isRequired,
editItemId: PropTypes.string,
setEditItemId: PropTypes.func.isRequired,
diff --git a/frontend/src/components/input-output/list-of-sources/ListOfSources.jsx b/frontend/src/components/input-output/list-of-sources/ListOfSources.jsx
index b14176f33..b359c0574 100644
--- a/frontend/src/components/input-output/list-of-sources/ListOfSources.jsx
+++ b/frontend/src/components/input-output/list-of-sources/ListOfSources.jsx
@@ -1,107 +1,51 @@
import { SearchOutlined } from "@ant-design/icons";
import { Input, List } from "antd";
-import debounce from "lodash/debounce";
import PropTypes from "prop-types";
-import { useCallback, useEffect, useState } from "react";
+import { useEffect, useState } from "react";
+import debounce from "lodash/debounce";
-import { sourceTypes } from "../../../helpers/GetStaticData";
-import { useAxiosPrivate } from "../../../hooks/useAxiosPrivate";
-import { useAlertStore } from "../../../store/alert-store";
-import { useSessionStore } from "../../../store/session-store";
-import { SpinnerLoader } from "../../widgets/spinner-loader/SpinnerLoader";
import { DataSourceCard } from "../data-source-card/DataSourceCard";
import "./ListOfSources.css";
-import { useExceptionHandler } from "../../../hooks/useExceptionHandler";
-function ListOfSources({ setSelectedSourceId, type }) {
- const [sourcesList, setSourcesList] = useState([]);
+function ListOfSources({ setSelectedSourceId, open, sourcesList }) {
const [filteredSourcesList, setFilteredSourcesList] = useState([]);
const [searchText, setSearchText] = useState("");
- const [isLoading, setIsLoading] = useState(false);
- const { sessionDetails } = useSessionStore();
- const { setAlertDetails } = useAlertStore();
- const axiosPrivate = useAxiosPrivate();
- const handleException = useExceptionHandler();
- const disabledIdsByType = {
- EMBEDDING: ["huggingface|90ec9ec2-1768-4d69-8fb1-c88b95de5e5a"],
- LLM: ["replicate|2715ce84-05af-4ab4-b8e9-67ac3211b81e"],
- VECTOR_DB: ["milvus|3f42f6f9-4b8e-4546-95f3-22ecc9aca442"],
- };
+ useEffect(() => {
+ onSearch(searchText);
+ }, [sourcesList]);
useEffect(() => {
- if (searchText?.length === 0) {
- setFilteredSourcesList(sourcesList);
- }
const filteredList = [...sourcesList].filter((source) => {
const name = source?.name?.toUpperCase();
const searchUpperCase = searchText.toUpperCase();
return name.includes(searchUpperCase);
});
setFilteredSourcesList(filteredList);
- }, [sourcesList, searchText]);
+ }, [sourcesList]);
- useEffect(() => {
- if (!type) {
- setSourcesList([]);
- return;
- }
- getListOfSources();
- }, [type, open]);
-
- const getListOfSources = () => {
- let url = `/api/v1/unstract/${sessionDetails?.orgId}`;
- if (sourceTypes.connectors.includes(type)) {
- url += `/supported_connectors/?type=${type.toUpperCase()}`;
- } else {
- url += `/supported_adapters/?adapter_type=${type.toUpperCase()}`;
- }
- // API to get the list of adapters.
- const requestOptions = {
- method: "GET",
- url,
- };
+ const onSearch = debounce((searchText) => {
+ const searchUpperCase = searchText?.toUpperCase()?.trim();
+ const filteredList = sourcesList?.filter((source) => {
+ const name = source?.name?.toUpperCase();
+ return name.includes(searchUpperCase);
+ });
+ setFilteredSourcesList(filteredList);
+ setSearchText(searchText);
+ }, 600);
- setIsLoading(true);
- setSourcesList([]);
- axiosPrivate(requestOptions)
- .then((res) => {
- const sources = res?.data || [];
- const updatedSources = sources?.map((source) => ({
- ...source,
- isDisabled: disabledIdsByType[source?.adapter_type]?.includes(
- source?.id
- ),
- }));
- setSourcesList(updatedSources || []);
- })
- .catch((err) => {
- setAlertDetails(handleException(err));
- })
- .finally(() => {
- setIsLoading(false);
- });
+ const handleInputChange = (event) => {
+ const { value } = event.target;
+ onSearch(value);
};
- const onSearchDebounce = useCallback(
- debounce(({ target: { value } }) => {
- setSearchText(value);
- }, 600),
- []
- );
-
- if (isLoading) {
- return <SpinnerLoader />;
- }
-
return (
<div className="list-of-srcs">
<div className="searchbox">
<Input
placeholder="Search"
prefix={<SearchOutlined className="search-outlined" />}
- onChange={onSearchDebounce}
- value={searchText}
+ onChange={handleInputChange}
/>
</div>
<div className="list">
@@ -124,7 +68,8 @@ function ListOfSources({ setSelectedSourceId, type }) {
ListOfSources.propTypes = {
setSelectedSourceId: PropTypes.func.isRequired,
- type: PropTypes.string.isRequired,
+ open: PropTypes.bool,
+ sourcesList: PropTypes.array,
};
export { ListOfSources };