diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index 92006340d..b7acd60d8 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -4,6 +4,7 @@ import { BASE_URL_API } from "../../constants/constants"; import { api } from "../../controllers/API/api"; import { APIObjectType, + Component, LoginType, Users, changeUser, @@ -579,3 +580,84 @@ export async function saveFlowStore(newFlow: { export async function getFlowsStore(): Promise> { return await api.get(`${BASE_URL_API}store/`); } + +export async function getStoreComponents(page: number = 1, limit: number = 10) { + try { + const res = await api.get( + `${BASE_URL_API}store/components/?page=${page}&limit=${limit}` + ); + if (res.status === 200) { + return res.data; + } + } catch (error) { + console.log("Error:", error); + throw error; + } +} + +export async function postStoreComponents(component: Component) { + try { + const res = await api.post(`${BASE_URL_API}store/components/`, component); + if (res.status === 200) { + return res.data; + } + } catch (error) { + console.log("Error:", error); + throw error; + } +} + +export async function getComponent(component_id: string) { + try { + const res = await api.get( + `${BASE_URL_API}store/components/${component_id}` + ); + if (res.status === 200) { + return res.data; + } + } catch (error) { + console.log("Error:", error); + throw error; + } +} + +export async function searchComponent( + query: string, + page?: number, + limit?: number, + status?: string, + tags?: [string] +) { + try { + debugger; + let url = `${BASE_URL_API}store/search/`; + const queryParams: any = []; + if (query !== undefined) { + queryParams.push(`query=${query}`); + } + if (page !== undefined) { + queryParams.push(`page=${page}`); + } + if (limit !== undefined) { + queryParams.push(`limit=${limit}`); + } + if (status !== undefined) { + queryParams.push(`status=${status}`); + } + if (tags !== undefined) { + queryParams.push(`tags=${tags}`); + } + if (queryParams.length > 0) { + url += `?${queryParams.join("&")}`; + } + + const res = await api.get(url); + + if (res.status === 200) { + return res.data; + } + } catch (error) { + console.log("Error:", error); + throw error; + } +} diff --git a/src/frontend/src/pages/AdminPage/index.tsx b/src/frontend/src/pages/AdminPage/index.tsx index f6e17a32a..b81d7a962 100644 --- a/src/frontend/src/pages/AdminPage/index.tsx +++ b/src/frontend/src/pages/AdminPage/index.tsx @@ -43,7 +43,6 @@ export default function AdminPage() { const { setErrorData, setSuccessData } = useContext(alertContext); const { userData } = useContext(AuthContext); const [totalRowsCount, setTotalRowsCount] = useState(0); - const { setTabId } = useContext(TabsContext); // set null id diff --git a/src/frontend/src/pages/StorePage/index.tsx b/src/frontend/src/pages/StorePage/index.tsx index 460258ada..25162272e 100644 --- a/src/frontend/src/pages/StorePage/index.tsx +++ b/src/frontend/src/pages/StorePage/index.tsx @@ -14,7 +14,9 @@ import { SelectValue, } from "../../components/ui/select"; import { Switch } from "../../components/ui/switch"; +import { alertContext } from "../../contexts/alertContext"; import { TabsContext } from "../../contexts/tabsContext"; +import { getStoreComponents, searchComponent } from "../../controllers/API"; import StoreApiKeyModal from "../../modals/StoreApiKeyModal"; import { FlowComponent } from "../../types/store"; import { cn } from "../../utils/utils"; @@ -33,20 +35,36 @@ export default function StorePage(): JSX.Element { const [filteredCategories, setFilteredCategories] = useState(new Set()); const [inputText, setInputText] = useState(""); const [searchData, setSearchData] = useState(data); + const { setErrorData } = useContext(alertContext); useEffect(() => { - setLoading(false); - /* getComponents() + handleGetComponents(); + }, []); + + const handleGetComponents = () => { + setLoading(true); + getStoreComponents(1, 10) .then((res) => { - setData(res); - setSearchData(res); - setDataSelect(res); + console.log(res); setLoading(false); }) .catch((err) => { setLoading(false); - }); */ - }, []); + setErrorData({ + title: "Error on delete user", + list: [err["response"]["data"]["detail"]], + }); + }); + }; + + const handleSearch = (inputText: string) => { + searchComponent(inputText).then( + (res) => { + console.log(res); + }, + (error) => {} + ); + }; return ( <> @@ -59,7 +77,11 @@ export default function StorePage(): JSX.Element { Langflow Store
- {}}> + { + handleGetComponents(); + }} + >