Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { isDefined } from "@humansignal/core/lib/utils/helpers";
import { API } from "apps/labelstudio/src/providers/ApiProvider";
import { projectAtom } from "apps/labelstudio/src/providers/ProjectProvider";
import { atomWithQuery } from "jotai-tanstack-query";
 
export const sampleDatasetAtom = atomWithQuery((get) => {
  const project = get(projectAtom);
  const labelConfig = project?.label_config;
  return {
    queryKey: [labelConfig, project, "sample-data"],
    enabled: isDefined(labelConfig) && labelConfig !== "<View></View>",
    async queryFn() {
      const response = await API.invoke(
        "createSampleTask",
        { pk: project.id },
        {
          body: {
            label_config: project?.label_config ?? "<View></View>",
            include_annotation_and_prediction: true,
          },
        },
      );
 
      if (!response?.$meta?.ok) {
        return JSON.stringify({ error: "Can't prepare sample data." }, null, "  ");
      }
 
      if (!response?.sample_task) {
        return JSON.stringify({ error: "No sample task data available." }, null, "  ");
      }
 
      return JSON.stringify(response.sample_task, null, "  ");
    },
  };
});