Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

2.1 KB
Raw Blame
'use client';

import { createStaticStyles, Flexbox } from '@lobehub/ui';
import { memo } from 'react';
import { useParams } from 'react-router';

import AsyncError from '@/components/AsyncError';
import { RouteLoading } from '@/components/Skeleton/RouteSegment';
import { experimentSelectors, useEvalStore } from '@/store/eval';

import BenchmarksSection from './BenchmarksSection';
import ExperimentHeader from './ExperimentHeader';
import ExperimentStats from './ExperimentStats';
import RunsSection from './RunsSection';
import ScopedDatasetsSection from './ScopedDatasetsSection';
import { useExperimentActions } from './useExperimentActions';

const styles = createStaticStyles(({ css }) => ({
  container: css`
    overflow-y: auto;
    padding-block: 24px;
    padding-inline: 32px;
  `,
}));

/**
 * Experiment workspace page. Thin orchestrator: one fetch populates the single
 * experiment-detail payload (benchmarks + datasets + runs); every section is a
 * focused component fed by the shared useExperimentActions.
 */
const ExperimentDetailPage = memo(() => {
  const { experimentId } = useParams<{ experimentId: string }>();
  const useFetchExperimentDetail = useEvalStore((s) => s.useFetchExperimentDetail);
  const experiment = useEvalStore(experimentSelectors.getExperimentDetailById(experimentId || ''));

  const { error, isLoading, mutate } = useFetchExperimentDetail(experimentId);

  const actions = useExperimentActions(experiment);

  if (!experiment) {
    if (isLoading || !error) return <RouteLoading />;
    return <AsyncError error={error} variant={'page'} onRetry={() => void mutate()} />;
  }

  return (
    <Flexbox className={styles.container} gap={24} height="100%" width="100%">
      <ExperimentHeader experiment={experiment} />
      <ExperimentStats datasetCount={experiment.datasets.length} experiment={experiment} />
      <BenchmarksSection actions={actions} experiment={experiment} />
      <ScopedDatasetsSection actions={actions} />
      <RunsSection actions={actions} experiment={experiment} />
    </Flexbox>
  );
});

export default ExperimentDetailPage;