Skip to content

Conversation

benjaminpkane
Copy link
Contributor

@benjaminpkane benjaminpkane commented Oct 15, 2025

What changes are proposed in this pull request?

Sidebar cleanup

How is this patch tested? If it is not, please explain why.

Locally

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features

    • Annotation and schema management now respect user permissions, disabling controls and showing informative alerts when access is restricted.
    • Read-only users are prevented from entering annotation mode; Explore is shown instead.
  • Improvements

    • Clearer option labels in editors (e.g., True/False/None) and more robust number handling when fields are empty.
    • Broader handling of polyline fields in list-type logic.
  • Bug Fixes

    • Prevented potential errors during schema loading when annotation types are unavailable.
    • More accurate initial state usage for position data.

@benjaminpkane benjaminpkane requested a review from a team as a code owner October 15, 2025 15:00
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Walkthrough

Introduces permission-aware annotation and schema management via new hooks, updates Sidebar to conditionally load/render annotation features, refines annotation editing and parsing logic, adjusts overlay creation/label handling, broadens list-type field handling, and updates public exports. Minor refactors and cleanup are included.

Changes

Cohort / File(s) Summary
Permissions & gating
app/packages/core/src/components/Modal/Sidebar/Annotate/Actions.tsx, .../Annotate/Edit/AddSchema.tsx, .../Annotate/ImportSchema.tsx, .../Annotate/useCanManageSchema.ts, .../Annotate/useCanAnnotate.ts, app/packages/core/src/components/Modal/Sidebar/Sidebar.tsx
Added hooks for permissions (manage schema, annotate). Gated Schema UI and Annotate mode based on permissions. Sidebar loads schemas only when annotation enabled; hides Annotate UI otherwise. Buttons and alerts reflect manage-schema authorization.
Annotation editing internals
.../Annotate/Edit/AnnotationSchema.tsx, .../Annotate/Edit/Field.tsx, .../Annotate/Edit/Id.tsx, .../Annotate/Edit/Position.tsx, .../Annotate/Edit/state.ts, .../Annotate/useLoadSchemas.ts
Normalized option labels, refined numeric parsing (empty → null), adjusted label retrieval, updated error text. Minor refactors (local consts, removed label from id view, simplified state usage). Added POLYLINES to list-type set. Safe optional chaining in schema loading.
Creation & labeling logic
.../Annotate/useCreate.ts, .../Annotate/useAddAnnotationLabel.ts
Consolidated lighter imports; rely on useLighter for overlayFactory/addOverlay and export InteractiveDetectionHandler usage for DETECTION interactive flow. Updated DETECTION label mapping and bounds derivation; added POLYLINE case placeholder; improved error messages.
Public exports
app/packages/lighter/src/index.ts, app/packages/looker/src/index.ts
Exposed InteractiveDetectionHandler publicly; added type export DetectionLabel.
Misc cleanup
app/packages/core/src/plugins/SchemaIO/components/AutocompleteView.tsx
Removed unused React import and a console log.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Sidebar
  participant Hooks as useCanAnnotate / useCanManageSchema
  participant Loader as loadSchemas
  participant UI as Annotate UI

  User->>Sidebar: Open sidebar
  Sidebar->>Hooks: useCanAnnotate()
  alt canAnnotate = true
    Sidebar->>Loader: loadSchemas()
    Sidebar->>UI: Render Annotate mode
    UI->>Hooks: useCanManageSchema()
    alt canManageSchema = true
      UI-->>User: Show schema controls
    else
      UI-->>User: Hide/disable schema controls + info alert
    end
  else
    Sidebar-->>User: Render Explore only (Annotate hidden)
  end
Loading
sequenceDiagram
  autonumber
  actor User
  participant Annotate as Annotate/Create
  participant useCreate as useCreate()
  participant Lighter as useLighter()
  participant Scene
  participant Handler as InteractiveDetectionHandler

  User->>Annotate: Add DETECTION
  Annotate->>useCreate: createOverlay(Detection)
  useCreate->>Lighter: overlayFactory / addOverlay
  useCreate->>Scene: enter interactive mode
  useCreate->>Handler: new InteractiveDetectionHandler(scene)
  Note right of Handler: Manages user interaction\nfor detection drawing
  Handler-->>Scene: Interactive bbox creation
  Scene-->>useCreate: Overlay finalized
  useCreate-->>Annotate: Overlay instance
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

A rabbit taps code with a gentle thump-thump,
Gates swing for schemas with a hop and a jump.
If read-only winds blow, we sniff and we wait—
Else we draw boxes, a bounding-fate.
POLYLINES pending, whiskers astir—
Ship it, burrowed build, with a happy purr. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The description includes the sections for proposed changes, testing, and affected areas but omits the required “Release Notes” section specified in the template, so it does not fully adhere to the repository’s standard pull request description format. Please add the “Release Notes” section with the appropriate checkbox indicating whether this is a user-facing change and, if so, include a brief description to complete the template.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly identifies the primary change as a cleanup of the Human Annotation sidebar, is concise, and avoids unnecessary detail or noise, making it easy for teammates to understand the main intent at a glance.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ha-sidebar-linting

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/AnnotationSchema.tsx (1)

118-118: Throw Error instance instead of raw string.

Throwing a raw string is not idiomatic in JavaScript/TypeScript. Prefer throwing an Error instance for better stack traces and consistency.

Apply this diff:

-        throw "text";
+        throw new Error("text attribute type not yet implemented");
🧹 Nitpick comments (4)
app/packages/looker/src/index.ts (1)

10-10: LGTM! Export is type-safe and correct.

The type-only export of DetectionLabel is syntactically correct and follows TypeScript best practices. Note that this imports directly from ./overlays/detection while line 9 imports from the ./overlays barrel export. This pattern difference might be intentional (e.g., keeping detection-specific types separate), but you may want to verify consistency across your export strategy for future maintainability.

app/packages/core/src/components/Modal/Sidebar/Sidebar.tsx (1)

35-38: Consider using JSX comment syntax for inline comments.

The inline comment uses a less idiomatic format for JSX. Consider using standard JSX comment syntax for better consistency.

Apply this diff for more idiomatic JSX comments:

-      {
-        // Hide Annotation for read only users
-        !disableAnnotation && <Mode />
-      }
+      {/* Hide Annotation for read only users */}
+      {!disableAnnotation && <Mode />}
app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/AnnotationSchema.tsx (1)

19-29: Add explicit return type annotation.

The getLabel utility function lacks an explicit return type annotation, which could reduce type safety.

Apply this diff to add a return type:

-const getLabel = (value) => {
+const getLabel = (value: unknown): string => {
   if (typeof value === "boolean") {
     return value ? "True" : "False";
   }
 
   if (value === null || value === undefined) {
     return "None";
   }
 
-  return value;
+  return String(value);
 };
app/packages/core/src/components/Modal/Sidebar/Annotate/useAddAnnotationLabel.ts (1)

61-61: Prefer exhaustive type checking over generic default error

Use a switch on type with an assertNever default to catch new LabelType variants at compile time.

Example:

function assertNever(x: never): never {
  throw new Error(`Unhandled label type: ${String(x)}`);
}

// ...
switch (type) {
  case CLASSIFICATION:
    // ...
    break;
  case DETECTION:
    // ...
    break;
  case POLYLINE:
    // ...
    break;
  default:
    assertNever(type);
}
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 115036c and daa1a74.

📒 Files selected for processing (17)
  • app/packages/core/src/components/Modal/Sidebar/Annotate/Actions.tsx (3 hunks)
  • app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/AddSchema.tsx (2 hunks)
  • app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/AnnotationSchema.tsx (7 hunks)
  • app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/Field.tsx (1 hunks)
  • app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/Id.tsx (0 hunks)
  • app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/Position.tsx (2 hunks)
  • app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/state.ts (1 hunks)
  • app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/useCreate.ts (2 hunks)
  • app/packages/core/src/components/Modal/Sidebar/Annotate/ImportSchema.tsx (2 hunks)
  • app/packages/core/src/components/Modal/Sidebar/Annotate/useAddAnnotationLabel.ts (3 hunks)
  • app/packages/core/src/components/Modal/Sidebar/Annotate/useCanAnnotate.ts (1 hunks)
  • app/packages/core/src/components/Modal/Sidebar/Annotate/useCanManageSchema.ts (1 hunks)
  • app/packages/core/src/components/Modal/Sidebar/Annotate/useLoadSchemas.ts (1 hunks)
  • app/packages/core/src/components/Modal/Sidebar/Sidebar.tsx (2 hunks)
  • app/packages/core/src/plugins/SchemaIO/components/AutocompleteView.tsx (0 hunks)
  • app/packages/lighter/src/index.ts (1 hunks)
  • app/packages/looker/src/index.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/Id.tsx
  • app/packages/core/src/plugins/SchemaIO/components/AutocompleteView.tsx
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

⚙️ CodeRabbit configuration file

Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Files:

  • app/packages/core/src/components/Modal/Sidebar/Annotate/ImportSchema.tsx
  • app/packages/core/src/components/Modal/Sidebar/Annotate/useLoadSchemas.ts
  • app/packages/core/src/components/Modal/Sidebar/Annotate/useCanManageSchema.ts
  • app/packages/lighter/src/index.ts
  • app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/state.ts
  • app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/Field.tsx
  • app/packages/core/src/components/Modal/Sidebar/Annotate/useCanAnnotate.ts
  • app/packages/core/src/components/Modal/Sidebar/Annotate/Actions.tsx
  • app/packages/core/src/components/Modal/Sidebar/Sidebar.tsx
  • app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/useCreate.ts
  • app/packages/looker/src/index.ts
  • app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/AddSchema.tsx
  • app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/AnnotationSchema.tsx
  • app/packages/core/src/components/Modal/Sidebar/Annotate/useAddAnnotationLabel.ts
  • app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/Position.tsx
🔇 Additional comments (16)
app/packages/core/src/components/Modal/Sidebar/Annotate/useLoadSchemas.ts (1)

54-54: LGTM: Defensive null handling.

The nullish coalescing operator (?? "") provides a safe fallback when type is null or undefined, preventing potential runtime errors during schema loading. This aligns with the broader permission-driven UI changes in the Annotate workflow.

app/packages/lighter/src/index.ts (1)

45-45: LGTM: Public API expansion.

The export of InteractiveDetectionHandler is straightforward and supports the interactive annotation flow for DETECTION overlays.

app/packages/core/src/components/Modal/Sidebar/Annotate/useCanManageSchema.ts (1)

1-6: LGTM: Clean permission check abstraction.

The hook provides a clear, reusable abstraction for schema management permissions. While thin, it centralizes the permission logic and makes consuming components more readable.

app/packages/core/src/components/Modal/Sidebar/Annotate/Actions.tsx (1)

10-10: LGTM: Consistent permission-based rendering.

The hook import and conditional rendering of <Schema /> correctly implements permission-based UI gating, ensuring schema management features are only available to authorized users.

Also applies to: 235-235, 255-255

app/packages/core/src/components/Modal/Sidebar/Annotate/ImportSchema.tsx (1)

6-6: LGTM: User-friendly permission handling.

The replacement of hardcoded permission with runtime check properly gates the "Add schema" functionality. The informational alert provides clear feedback to users without manage permissions, enhancing the user experience.

Also applies to: 20-20, 42-42, 47-63

app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/Field.tsx (1)

48-52: LGTM: Improved readability.

Extracting the isCreating variable improves code readability without changing functionality. The descriptive name makes the intent clearer than the inline atom reference.

app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/Position.tsx (1)

49-59: LGTM: Simplified state initialization.

The removal of the initial fallback simplifies the code. The useEffect initialization runs immediately when overlay changes, and the schema fields are defined as optional, so SchemaIOComponent should handle the initial empty state correctly.

Also applies to: 108-108

app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/state.ts (1)

23-23: LGTM: Consistent list-type field handling.

Adding POLYLINES to IS_LIST ensures consistent treatment of plural annotation types. This allows fields with POLYLINES type to support multiple labels, matching the behavior of CLASSIFICATIONS and DETECTIONS.

app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/AddSchema.tsx (1)

13-13: LGTM! Permission-aware UI implementation.

The dynamic permission check using useCanManageSchema() correctly replaces the hardcoded value, and the informational Alert provides clear guidance to users without manage permissions.

Also applies to: 35-35, 60-60, 69-85

app/packages/core/src/components/Modal/Sidebar/Annotate/useCanAnnotate.ts (1)

1-6: LGTM! Clean permission hook implementation.

The hook correctly derives annotation permission from the readOnly state using Recoil's useRecoilValue.

app/packages/core/src/components/Modal/Sidebar/Sidebar.tsx (1)

7-7: LGTM! Permission-based conditional rendering.

The integration of useCanAnnotate() correctly guards annotation features for read-only users, and the effect dependencies are properly configured.

Also applies to: 26-26, 30-31, 39-39

app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/useCreate.ts (1)

1-7: LGTM! Clean import consolidation and type safety.

The use of import type for type-only imports and the consolidated import from @fiftyone/lighter improve type safety and align with TypeScript best practices. The InteractiveDetectionHandler integration is correct.

Also applies to: 21-21, 54-55

app/packages/core/src/components/Modal/Sidebar/Annotate/Edit/AnnotationSchema.tsx (3)

139-147: LGTM! Proper null handling for empty numeric inputs.

The logic correctly returns null for empty strings in numeric fields rather than attempting to parse them, which prevents NaN values.


165-166: LGTM! Safe optional chaining.

The optional chaining for overlay?.getLabel() provides appropriate defensive coding against undefined overlay references.


176-176: Verify error message accuracy.

The error message was changed from "no overlay" to "no field", but this check occurs when !field is true. Ensure this message accurately reflects the condition being checked, especially since there's a separate check for !overlay on Line 179.

Run the following script to understand the context of these error checks:

app/packages/core/src/components/Modal/Sidebar/Annotate/useAddAnnotationLabel.ts (1)

9-9: Import looks good

Importing POLYLINE aligns with the added type branch below.

@benjaminpkane benjaminpkane merged commit e96c227 into feat/human-annotation Oct 16, 2025
2 checks passed
@benjaminpkane benjaminpkane deleted the ha-sidebar-linting branch October 16, 2025 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant