AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
import { isNil } from '@activepieces/core-utils';
import { FlowVersionState, PopulatedFlow } from '@activepieces/shared';
import { useQuery } from '@tanstack/react-query';
import { ReactFlowProvider } from '@xyflow/react';
import { t } from 'i18next';
import { FileX } from 'lucide-react';
import { Link, useParams, useSearchParams } from 'react-router-dom';
import { BuilderPage } from '@/app/builder';
import { BuilderStateProvider } from '@/app/builder/state/builder-state-provider';
import { LoadingSpinner } from '@/components/custom/spinner';
import { buttonVariants } from '@/components/ui/button';
import { flowHooks, flowsApi, sampleDataHooks } from '@/features/flows';
import { authenticationSession } from '@/lib/authentication-session';
import { cn } from '@/lib/utils';
const FlowBuilderPage = () => {
const { flowId } = useParams();
const [searchParams] = useSearchParams();
const versionId = searchParams.get('versionId') ?? undefined;
const {
data: flow,
isLoading,
isError,
} = useQuery<PopulatedFlow, Error>({
queryKey: [
...flowHooks.createFlowQueryKeys({ flowId: flowId!, versionId }),
authenticationSession.getProjectId(),
],
queryFn: () => flowsApi.get(flowId!, versionId ? { versionId } : undefined),
gcTime: 0,
retry: false,
refetchOnWindowFocus: false,
});
const { data: sampleData, isLoading: isSampleDataLoading } =
sampleDataHooks.useSampleDataForFlow(flow?.version, flow?.projectId);
const { data: sampleDataInput, isLoading: isSampleDataInputLoading } =
sampleDataHooks.useSampleDataInputForFlow(flow?.version, flow?.projectId);
if (isLoading || isSampleDataLoading || isSampleDataInputLoading) {
return (
<div className="bg-gray-1 flex h-full w-full items-center justify-center ">
<LoadingSpinner isLarge={true}></LoadingSpinner>
</div>
);
}
if (isNil(flow) || isError) {
return (
<div className="flex flex-col items-center justify-center h-full text-center space-y-4">
<div className="rounded-full bg-gray-3 p-4">
<FileX className="size-9 text-gray-11" />
</div>
<div>
<h2 className="text-lg font-semibold">{t('Flow not found')}</h2>
<p className="text-sm text-gray-11">
{t("The flow you are looking for doesn't exist or was removed.")}
</p>
</div>
<Link
className={cn(buttonVariants({ variant: 'outline' }))}
to="/dashboard"
>
{t('Go to Dashboard')}
</Link>
</div>
);
}
return (
<ReactFlowProvider>
<BuilderStateProvider
flow={flow}
flowVersion={flow!.version}
readonly={flow!.version.state === FlowVersionState.LOCKED}
hideTestWidget={false}
run={null}
outputSampleData={sampleData ?? {}}
inputSampleData={sampleDataInput ?? {}}
>
<BuilderPage />
</BuilderStateProvider>
</ReactFlowProvider>
);
};
export { FlowBuilderPage };