Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions frontend/ui-core/src/screens/ImageIngestFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import {
type JSX,
} from "react";

import { BATCH_ACTION, declares } from "../data/capabilities";
import { refusalProse } from "../data/refusals";
import { Alert, AlertDescription, AlertTitle, Badge, Button, Card, CardContent, Progress, Input, Label, FieldDescription, FieldError, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@robomous/ui-core";
import { formatBytes, formatCount } from "../lib/format";
Expand Down Expand Up @@ -208,9 +209,12 @@ export function ImageIngestFlow({
void queries.invalidateQueries({ queryKey: ["projects", projectId] });
}, [settled, projectId, queries]);

// Only a draft batch may take an ingest. Anything else is refused at the launch
// with 409 `BATCH_NOT_EDITABLE`, so offering one would be offering a refusal.
const draftBatches = (batches.data?.items ?? []).filter((batch) => batch.state === "draft");
// Only a batch declaring `edit_membership` may take an ingest. Anything else is
// refused at the launch with 409 `BATCH_NOT_EDITABLE`, so offering one would be
// offering a refusal.
const editableBatches = (batches.data?.items ?? []).filter((batch) =>
declares(batch, BATCH_ACTION.editMembership),
);

// What the source is called unless the user types otherwise.
// Without a stated name the server calls the source by its staged directory,
Expand Down Expand Up @@ -305,7 +309,7 @@ export function ImageIngestFlow({
? batchName.trim() === ""
? (source?.name ?? "")
: batchName.trim()
: (draftBatches.find((batch) => batch.id === batchChoice)?.name ?? "the batch");
: (editableBatches.find((batch) => batch.id === batchChoice)?.name ?? "the batch");

return (
<ol className="flex flex-col">
Expand Down Expand Up @@ -385,7 +389,7 @@ export function ImageIngestFlow({
</SelectTrigger>
<SelectContent>
<SelectItem value={NEW_BATCH}>New batch</SelectItem>
{draftBatches.map((batch) => (
{editableBatches.map((batch) => (
<SelectItem key={batch.id} value={batch.id}>
{batch.name} ({batch.asset_count})
</SelectItem>
Expand Down
23 changes: 23 additions & 0 deletions frontend/ui-core/src/screens/ingest.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,29 @@ describe("launching a run", () => {
expect(screen.queryByRole("option", { name: /frozen/ })).toBeNull();
});

it("reads the offer off `edit_membership`, not off the batch's state", async () => {
on("GET", /\/batches$/, {
status: 200,
body: {
items: [
{ id: "b1", project_id: PROJECT, name: "declared", state: "in_annotation", schema_version: 1, asset_count: 4, progress: NO_PROGRESS, allowed_actions: ["edit_membership"], promoted_asset_count: 0, parent_batch_id: null, pre_label_run: null },
{ id: "b2", project_id: PROJECT, name: "withheld", state: "draft", schema_version: null, asset_count: 9, progress: NO_PROGRESS, allowed_actions: [], promoted_asset_count: 0, parent_batch_id: null, pre_label_run: null },
],
total: 2,
},
});
on("POST", /\/sources\/images$/, { status: 201, body: IMAGE_SOURCE });

renderWithData(<IngestScreen projectId={PROJECT} />);
await choose([pick("a.png", "image/png")]);
await userEvent.click(screen.getByTestId("register-source"));
await screen.findByTestId("source-card");

await userEvent.click(screen.getByTestId("target-batch"));
expect(screen.queryByRole("option", { name: /declared/ })).not.toBeNull();
expect(screen.queryByRole("option", { name: /withheld/ })).toBeNull();
});

it("names a new batch after the source when nobody typed one", async () => {
on("GET", /\/batches$/, { status: 200, body: { items: [], total: 0 } });
on("POST", /\/sources\/images$/, { status: 201, body: IMAGE_SOURCE });
Expand Down
Loading