|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { useQuery, useSuspenseQuery } from '@tanstack/react-query'; |
| 4 | +import { notFound } from 'next/navigation'; |
| 5 | +import { use } from 'react'; |
| 6 | + |
| 7 | +import { getCircuit } from '@/api/entitycore/queries/model/circuit'; |
| 8 | +import { resolveSimulationByCampaignId } from '@/entity-configuration/domain/simulation/small-microcircuit-simulation'; |
| 9 | +import SimulationConfig from '@/features/small-microcircuit'; |
| 10 | +import { keyBuilder } from '@/ui/use-query-keys/data'; |
| 11 | + |
| 12 | +import type { ServerSideComponentProp, WorkspaceContext } from '@/types/common'; |
| 13 | +import type { WorkflowSimulatePanelKeys } from '@/ui/segments/workflows/simulate/single-neuron/shared/constant'; |
| 14 | +import type { ExperimentStepKeys } from '@/ui/segments/workflows/simulate/single-neuron/shared/elements/menu'; |
| 15 | + |
| 16 | +export default function Page({ |
| 17 | + searchParams, |
| 18 | + params: pathParams, |
| 19 | +}: ServerSideComponentProp< |
| 20 | + WorkspaceContext & { id: string }, |
| 21 | + { |
| 22 | + step: ExperimentStepKeys; |
| 23 | + sessionId: string; |
| 24 | + panel: WorkflowSimulatePanelKeys; |
| 25 | + initialCampaignId: string; |
| 26 | + } |
| 27 | +>) { |
| 28 | + const queryParams = use(searchParams); |
| 29 | + const { initialCampaignId } = queryParams; |
| 30 | + const { virtualLabId, projectId, id: modelId } = use(pathParams); |
| 31 | + |
| 32 | + let sessionId = queryParams?.sessionId; |
| 33 | + if (!sessionId) sessionId = crypto.randomUUID(); |
| 34 | + |
| 35 | + const { data: entity } = useSuspenseQuery({ |
| 36 | + queryKey: [modelId], |
| 37 | + queryFn: () => |
| 38 | + modelId ? getCircuit({ id: "cbeba583-c905-47c6-96b7-b7923d4fcefd", context: { virtualLabId, projectId } }) : null, |
| 39 | + }); |
| 40 | + |
| 41 | + const { |
| 42 | + data: campaignData, |
| 43 | + error, |
| 44 | + isLoading, |
| 45 | + } = useQuery({ |
| 46 | + queryKey: keyBuilder.simCampaign({ entityId: initialCampaignId }), |
| 47 | + queryFn: async () => { |
| 48 | + if (!initialCampaignId) return null; |
| 49 | + return await resolveSimulationByCampaignId({ |
| 50 | + id: initialCampaignId, |
| 51 | + context: { virtualLabId, projectId }, |
| 52 | + }); |
| 53 | + }, |
| 54 | + }); |
| 55 | + |
| 56 | + if (error || !entity) { |
| 57 | + return notFound(); |
| 58 | + } |
| 59 | + |
| 60 | + if ( |
| 61 | + !initialCampaignId || |
| 62 | + (initialCampaignId && !isLoading && campaignData && campaignData.config.form) |
| 63 | + ) { |
| 64 | + return ( |
| 65 | + <div className="border-neutral-2 ml-2 h-full rounded-2xl border pt-3"> |
| 66 | + <SimulationConfig |
| 67 | + modelId={entity.id} |
| 68 | + virtualLabId={virtualLabId} |
| 69 | + projectId={projectId} |
| 70 | + initialConfig={campaignData?.config.form} |
| 71 | + className="px-10 pt-2" |
| 72 | + /> |
| 73 | + </div> |
| 74 | + ); |
| 75 | + } |
| 76 | +} |
0 commit comments