diff --git a/packages/ui/lib/integration/Data.jsx b/packages/ui/lib/integration/Data.jsx index 75596cecd..894e2ffe3 100644 --- a/packages/ui/lib/integration/Data.jsx +++ b/packages/ui/lib/integration/Data.jsx @@ -19,8 +19,8 @@ const Data = ({ friggBaseUrl, authToken, integrationId }) => { const fetchData = async () => { if (authToken) { const api = new API(friggBaseUrl, authToken); - // let sampleData = await api.getSampleData(integrationId); - let sampleData = getFakeData(); // Uncomment if you need fake data + let sampleData = await api.getSampleData(integrationId); + // let sampleData = getFakeData(); // Uncomment if you need fake data if (sampleData && sampleData.error) { toast({ diff --git a/packages/ui/lib/integration/IntegrationList.jsx b/packages/ui/lib/integration/IntegrationList.jsx index 14a1473d2..babbed967 100644 --- a/packages/ui/lib/integration/IntegrationList.jsx +++ b/packages/ui/lib/integration/IntegrationList.jsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from "react"; +import { useEffect, useState, useCallback } from "react"; import IntegrationSkeleton from "./IntegrationSkeleton"; import { getActiveAndPossibleIntegrationsCombined } from "../utils/IntegrationUtils"; import API from "../api/api"; @@ -10,6 +10,7 @@ import { IntegrationHorizontal, IntegrationVertical } from "../integration"; * @param props.friggBaseUrl - Base URL for Frigg backend * @param props.componentLayout - Layout for displaying integrations - either 'default-horizontal' or 'default-vertical' * @param props.authToken - JWT token for authenticated user in Frigg + * @param {string} props.sampleDataRoute - A route to display sample data for the integration * @returns {JSX.Element} The rendered component * @constructor */ @@ -18,11 +19,7 @@ const IntegrationList = (props) => { const [integrations, setIntegrations] = useState([]); const [isloading, setIsLoading] = useState(true); - const loadIntegrations = async () => { - if (!props.authToken) { - console.log("Authentication token is required to fetch integrations."); - } - + const loadIntegrations = useCallback(async () => { const api = new API(props.friggBaseUrl, props.authToken); const integrationsData = await api.listIntegrations(); @@ -37,11 +34,16 @@ const IntegrationList = (props) => { getActiveAndPossibleIntegrationsCombined(integrationsData); setIntegrations(activeAndPossibleIntegrations); } - }; + }, [props.authToken, props.friggBaseUrl]); useEffect(() => { + if (!props.authToken) { + console.log("Authentication token is required to fetch integrations."); + return; + } + loadIntegrations().then(() => setIsLoading(false)); - }, []); + }, [loadIntegrations, props.authToken]); const setInstalled = (data) => { const items = [data, ...installedIntegrations]; @@ -58,6 +60,7 @@ const IntegrationList = (props) => { refreshIntegrations={loadIntegrations} friggBaseUrl={props.friggBaseUrl} authToken={props.authToken} + sampleDataRoute={props.sampleDataRoute} /> ); } diff --git a/packages/ui/lib/integration/QuickActionsMenu.jsx b/packages/ui/lib/integration/QuickActionsMenu.jsx index 654a68e13..3d91e136b 100644 --- a/packages/ui/lib/integration/QuickActionsMenu.jsx +++ b/packages/ui/lib/integration/QuickActionsMenu.jsx @@ -43,7 +43,7 @@ function QuickActionsMenu({ const getSampleData = async () => { if (sampleDataRoute) { - window.location.href = sampleDataRoute; + window.location.href = `${sampleDataRoute}/${integrationId}`; return; }