import React, { useState, useEffect, useContext, memo } from "react"; import { Context } from "../context/ContextApi.jsx"; import { getTheme } from "../theme.jsx"; import { GetIconInfo } from "../views/Workflows2.jsx"; import { toast } from 'react-toastify'; import { Dialog, DialogTitle, DialogContent, Typography, IconButton, Paper, LinearProgress, Grid, Button, Tooltip, Autocomplete, TextField, Box, } from '@mui/material'; import { Rocket as RocketIcon, FilterAlt as FilterAltIcon, Add as AddIcon, Check as CheckIcon, } from '@mui/icons-material'; import { green, red, } from '../views/AngularWorkflow.jsx' import algoliasearch from 'algoliasearch/lite'; const searchClient = algoliasearch("JNSS5CFDZZ", "c8f882473ff42d41158430be09ec2b4e") const CollectIngestModal = (props) => { const { globalUrl, open, setOpen, workflows, getWorkflows, apps, } = props; const { themeMode, brandColor } = useContext(Context); const theme = getTheme(themeMode, brandColor); if (open === undefined || open === null) { console.error("CollectIngestModal: 'open' prop is required."); return null } if (setOpen === undefined || setOpen === null) { console.error("CollectIngestModal: 'setOpen' prop is required."); return null } const startIngestion = (bundleName, appnames, category, index) => { var body = { "label": bundleName, "app_name": appnames, "category": "", } if (category !== undefined && category !== null) { body.category = category } const url = `${globalUrl}/api/v2/workflows/generate` fetch(url, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(body), credentials: "include", }) .then((response) => { if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response.json(); }) .then((data) => { if (getWorkflows !== undefined) { getWorkflows() } console.log("Ingestion started successfully:", data); toast.success(`Ingestion for ${bundleName} started successfully!`); }) .catch((error) => { console.error("Error starting ingestion:", error); toast.error(`Failed to start ingestion for ${bundleName}. Please try again or contact support@shuffler.io if this persists.`); }); } const IngestItem = (props) => { const { type, appCategory, index, webhook } = props const [hovering, setHovering] = useState(false); const [selectedApps, setSelectedApps] = useState([]); const [showAppsearch, setShowAppsearch] = useState(false); const [algoliaOptions, setAlgoliaOptions] = useState([]); const [generating, setGenerating] = useState(false); const appname = type const ingestedAmount = 20 const iconDetails = GetIconInfo({ "app_name": appname, "name": appname, }) var foundMatchingWorkflow = null if (!showAppsearch && workflows !== undefined && workflows !== null && workflows.length > 0) { const parsedName = type.toLowerCase().replaceAll(" ", "_"); const foundWorkflow = workflows.find((workflow) => { return workflow?.name?.toLowerCase().replaceAll(" ", "_") === parsedName }) if (foundWorkflow !== undefined && foundWorkflow !== null) { foundMatchingWorkflow = foundWorkflow // Find relevant apps and maps them if (apps.length > 0 && selectedApps.length === 0 && foundWorkflow?.actions !== undefined && foundWorkflow?.actions !== null && foundWorkflow?.actions.length > 0) { var newSelectedApps = [] for (var actionkey in foundWorkflow.actions) { const action = foundWorkflow.actions[actionkey] if (action?.app_name !== "Singul" && action?.app_id !== "integration") { continue } for (var paramkey in action.parameters) { const param = action.parameters[paramkey] if (!((param.name === "app_name" || param.name === "appName") && param.value !== undefined && param.value !== null && param.value.length > 0)) { continue } // Find the app in available apps const parsedname = param.value.replaceAll(" ", "_").toLowerCase() for (var appkey in apps) { const appname = apps[appkey].name.replaceAll(" ", "_").toLowerCase() if (appname === parsedname) { newSelectedApps.push(apps[appkey]) break } } break } } if (newSelectedApps.length > 0) { setSelectedApps(newSelectedApps) } } } } var matchingapps = [] if (appCategory !== undefined && appCategory !== null && appCategory.length > 0 && apps !== undefined && apps !== null && apps.length > 0) { for (var appkey in apps) { const app = apps[appkey] for (var categorykey in app.categories) { const category = app.categories[categorykey] if (category.toLowerCase() === appCategory.toLowerCase()) { matchingapps.push(app) } } } } const runIngestion = () => { setGenerating(true) setTimeout(() => { setGenerating(false) }, 5000) toast.info("Starting ingest for relevant apps") var newapps = "" for (var key in selectedApps) { const app = selectedApps[key] if (newapps.length > 0) { newapps += "," } newapps += app.name } startIngestion(appname, newapps, appCategory, index) if (webhook === true) { startIngestion(appname+"_webhook", newapps, appCategory, index) } } return ( // { //if (foundMatchingWorkflow !== null) { //} else { setHovering(true) //} }} onMouseLeave={() => setHovering(false)} >
{generating ? null : selectedApps.map((app, index) => { // Show image of each one return (
) })} {!generating && appCategory !== undefined && appCategory !== null && appCategory.length > 0 ? { if (showAppsearch === true) { runIngestion() } setShowAppsearch(!showAppsearch) }} > {showAppsearch ? : } : null}
{showAppsearch ? { console.log("New value: ", value) setSelectedApps(value) }} getOptionLabel={(option) => { const parsedname = option.name.replaceAll("_", " ") return parsedname //return ( //
// {option.name} // // {parsedname} // //
//) }} renderOption={(props, option, state, ownerState) => { const { key, ...optionProps } = props; return ( {option.name} {ownerState.getOptionLabel(option)} ); }} renderInput={(params) => { return ( ) }} /> : }
{iconDetails?.originalIcon && ( iconDetails?.originalIcon )} {appname}
{foundMatchingWorkflow !== null ? : null} {hovering ?
: null} {foundMatchingWorkflow !== null ?
{ingestedAmount} / X {/* */}
: null}
) } return ( { setOpen(false) }} > Collection and Ingestion ) } export default CollectIngestModal