Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model evaluation panel permission ux tweaks #5253

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

imanjra
Copy link
Contributor

@imanjra imanjra commented Dec 10, 2024

What changes are proposed in this pull request?

Disable actions with appropriate messages instead of hiding when permission is not sufficient to perform an action

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

Using model evaluation panel with several action disabled due to permission

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

See above

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

    • Enhanced permission handling for evaluation actions in the Evaluate component.
    • Added tooltips and conditional disabling for evaluation notes editing based on user permissions.
    • Introduced a read-only mode for the Status component to prevent unauthorized edits.
  • Bug Fixes

    • Refined user feedback for evaluation actions to prevent interactions when permissions are insufficient.
  • Style

    • Minor adjustments to layout and styling for consistency with the application's design language.

@imanjra imanjra requested a review from a team December 10, 2024 17:02
Copy link
Contributor

coderabbitai bot commented Dec 10, 2024

Walkthrough

The changes in this pull request involve modifications to several components within the Native Model Evaluation View. Key updates include the addition of permission handling in the Evaluate component, enhancements to the Evaluation component for editing evaluation notes, and the introduction of a read-only mode in the Status component. The Overview component also reflects changes in how the Status component is rendered. These updates focus on improving user feedback and interaction based on permission states across the evaluation components.

Changes

File Change Summary
app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Evaluate.tsx Updated EvaluateProps to include a permissions property. Added permission checks for evaluation actions and modified rendering logic for user feedback.
app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Evaluation.tsx Enhanced evaluation notes handling with permission checks. Added tooltip for edit button to indicate permission status and conditionally disable it.
app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Overview.tsx Modified EvaluationCard to include a readOnly prop for the Status component, affecting its behavior.
app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Status.tsx Added readOnly prop to StatusProps, replacing canEdit checks. Updated Select component behavior based on permissions and added tooltip for feedback.

Possibly related PRs

Suggested reviewers

  • ritch
  • Br2850

🐇 In the meadow, I hop and play,
With changes brightening the day.
Permissions checked, feedback clear,
Evaluation fun, bring on the cheer!
Buttons and boxes, all in line,
A joyful code, oh how it shines! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 1

🧹 Outside diff range and nitpick comments (7)
app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Evaluate.tsx (1)

10-22: Consider accessibility improvements for disabled state.

While the implementation is good, consider enhancing accessibility:

 <Box
   title={canEvaluate ? "" : "You do not have permission to evaluate model"}
   sx={{ cursor: canEvaluate ? "pointer" : "not-allowed" }}
+  role="presentation"
+  aria-disabled={!canEvaluate}
 >
   <MuiButton
     onClick={onEvaluate}
     startIcon={<Add />}
     variant="contained"
     disabled={!canEvaluate}
+    aria-label="Evaluate Model"
   >
     Evaluate Model
   </MuiButton>
 </Box>
app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Status.tsx (1)

72-73: Consider improving type safety.

The props interface could be more type-safe:

 type StatusProps = {
   status?: string;
   canEdit?: boolean;
-  readOnly?: boolean;
-  setStatusEvent: string;
+  readOnly: boolean;  // Make required to prevent undefined behavior
+  setStatusEvent: string;
+  status: keyof typeof STATUS_LABELS;  // Restrict to valid status values
 };
app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Overview.tsx (2)

100-100: Consider adding error boundary and memoization.

While the Status component integration is good, consider these improvements:

  1. Wrap the Status component with error boundary
  2. Memoize the Status component to prevent unnecessary re-renders
-          {status && <Status status={status} readOnly />}
+          {status && (
+            <ErrorBoundary fallback={<StatusErrorFallback />}>
+              <MemoizedStatus status={status} readOnly />
+            </ErrorBoundary>
+          )}

Line range hint 115-122: Improve type safety for evaluation objects.

Consider making the types more specific:

 type EvaluationType = {
   key: string;
   id: string;
   description: string;
-  status: string;
+  status: keyof typeof STATUS_LABELS;
 };
app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Evaluation.tsx (3)

Line range hint 1019-1030: Enhance type safety and documentation for component props.

The EvaluationProps type could be improved for better type safety and maintainability.

Consider applying these improvements:

 type EvaluationProps = {
   name: string;
   id: string;
   navigateBack: () => void;
   loadEvaluation: (key?: string) => void;
   onChangeCompareKey: (compareKey: string) => void;
   compareKey?: string;
-  data: any;
+  data: {
+    permissions?: {
+      can_edit_note?: boolean;
+      can_edit_status?: boolean;
+    };
+    evaluations?: Array<{ key: string }>;
+    [key: `evaluation_${string}`]: EvaluationData;
+  };
   setStatusEvent: string;
   statuses: Record<string, string>;
   setNoteEvent: string;
   notes: Record<string, string>;
-  loadView: (type: string, params: any) => void;
+  loadView: (type: 'field' | 'class' | 'matrix' | 'clear', params: Record<string, unknown>) => void;
 };

Line range hint 40-54: Consider consolidating dialog state management.

The component uses separate state for different dialogs with similar structures. This could be consolidated for better maintainability.

Consider using a single dialog state manager:

-  const [editNoteState, setEditNoteState] = useState({ open: false, note: "" });
-  const [classPerformanceDialogConfig, setClassPerformanceDialogConfig] =
-    useState<PLOT_CONFIG_DIALOG_TYPE>(DEFAULT_BAR_CONFIG);
-  const [confusionMatrixDialogConfig, setConfusionMatrixDialogConfig] =
-    useState<PLOT_CONFIG_DIALOG_TYPE>(DEFAULT_BAR_CONFIG);

+  const [dialogState, setDialogState] = useState<{
+    type: 'note' | 'classPerformance' | 'confusionMatrix' | null;
+    config: {
+      open: boolean;
+      note?: string;
+      sortBy?: string;
+      limit?: number;
+      log?: boolean;
+    };
+  }>({ type: null, config: { open: false } });

Line range hint 183-191: Consider splitting large render tree into smaller components.

The component has a complex render tree that could benefit from being split into smaller, focused components for better maintainability and performance.

Consider extracting the summary section into a separate component:

+const EvaluationSummary = memo(({ summaryRows, name, compareKey, loadView }: EvaluationSummaryProps) => {
+  return (
     <EvaluationTable>
       <TableHead>
         {/* ... header content ... */}
       </TableHead>
       <TableBody>
         {/* ... summary rows mapping ... */}
       </TableBody>
     </EvaluationTable>
+  );
+});
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ea8b36f and 0c1c7db.

📒 Files selected for processing (4)
  • app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Evaluate.tsx (1 hunks)
  • app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Evaluation.tsx (1 hunks)
  • app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Overview.tsx (1 hunks)
  • app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Status.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Overview.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Evaluate.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Evaluation.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Status.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (3)
app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Evaluate.tsx (1)

7-8: LGTM! Clean permission handling implementation.

The permission check is clear and well-typed. The canEvaluate boolean provides a single source of truth for permission state.

app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Status.tsx (1)

25-30: LGTM! Clear permission feedback.

Good implementation of permission feedback with tooltip and disabled state.

app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Evaluation.tsx (1)

563-582: Well-implemented permission handling for evaluation notes editing.

The permission controls are properly implemented with:

  • Clear user feedback through tooltips
  • Appropriate cursor styling
  • Proper button disabling
  • Consistent React patterns

@@ -4,10 +4,10 @@ import React from "react";
import { useTriggerEvent } from "./utils";

export default function Status(props: StatusProps) {
const { status, canEdit, setStatusEvent } = props;
const { status, canEdit, readOnly, setStatusEvent } = props;
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider simplifying permission logic.

The component uses both canEdit and readOnly props for permission handling, which could lead to confusing states. Consider consolidating these into a single permission control.

-  const { status, canEdit, readOnly, setStatusEvent } = props;
+  const { status, canEdit: maybeCanEdit, setStatusEvent } = props;
+  const canEdit = maybeCanEdit && !props.readOnly;

-  if (!readOnly) {
+  if (canEdit) {

Also applies to: 10-10

import React from "react";

export default function Evaluate(props: EvaluateProps) {
const { onEvaluate } = props;
const { onEvaluate, permissions } = props;
const canEvaluate = permissions.can_evaluate;
Copy link
Contributor

Choose a reason for hiding this comment

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

How where is this permission set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Permissions are initialized on loading the panel in file fiftyone/operators/builtins/panels/model_evaluation/__init__.py

@imanjra imanjra force-pushed the bugfix/model-eval-perm branch from 0c1c7db to edb53e5 Compare December 19, 2024 17:59
@imanjra imanjra changed the base branch from develop to release/v1.2.0 December 19, 2024 17:59
@imanjra imanjra requested a review from a team December 19, 2024 17:59
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: 0

🧹 Nitpick comments (2)
app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Evaluation.tsx (2)

614-633: LGTM! Permission handling implementation looks good.

The permission-based UI implementation effectively handles the edit button state with proper user feedback through tooltips and cursor styles. This aligns well with the PR objectives for improving permission UX.

Consider adding aria-label to improve accessibility:

 <Box
   title={
     can_edit_note
       ? ""
       : "You do not have permission to edit evaluation notes"
   }
+  aria-label={
+    can_edit_note
+      ? "Edit evaluation notes"
+      : "You do not have permission to edit evaluation notes"
+  }
   sx={{ cursor: can_edit_note ? "pointer" : "not-allowed" }}
 >

Line range hint 1001-1013: Consider improving TypeScript type definitions.

The data prop is currently typed as any, which bypasses TypeScript's type checking benefits. Consider creating proper interfaces for the data structure, especially for permissions.

+ interface Permissions {
+   can_edit_note: boolean;
+   can_edit_status: boolean;
+ }
+
+ interface EvaluationData {
+   permissions?: Permissions;
+   evaluations?: Array<{ key: string }>;
+   // ... other data properties
+ }
+
 type EvaluationProps = {
   name: string;
   id: string;
   navigateBack: () => void;
   loadEvaluation: (key?: string) => void;
   onChangeCompareKey: (compareKey: string) => void;
   compareKey?: string;
-  data: any;
+  data: EvaluationData;
   setStatusEvent: string;
   statuses: Record<string, string>;
   setNoteEvent: string;
   notes: Record<string, string>;
   loadView: (type: string, params: any) => void;
 };
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c1c7db and edb53e5.

📒 Files selected for processing (4)
  • app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Evaluate.tsx (1 hunks)
  • app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Evaluation.tsx (1 hunks)
  • app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Overview.tsx (1 hunks)
  • app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Status.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Overview.tsx
  • app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Evaluate.tsx
  • app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Status.tsx
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Evaluation.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (2)
app/packages/core/src/plugins/SchemaIO/components/NativeModelEvaluationView/Evaluation.tsx (2)

Line range hint 37-67: Well-structured state management implementation.

The component demonstrates good state management practices:

  • Effective use of useMemo for derived states
  • Clear separation of local and global state
  • Consistent state updates through proper event handlers

Line range hint 68-613: Clean and consistent UI/UX implementation.

The UI implementation demonstrates good practices:

  • Consistent use of Material-UI components
  • Clear user feedback for different states
  • Proper handling of loading and error states
  • Responsive layout with appropriate spacing

Also applies to: 634-1000

Copy link
Contributor

@manivoxel51 manivoxel51 left a comment

Choose a reason for hiding this comment

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

🍨

<MuiButton onClick={onEvaluate} startIcon={<Add />} variant="contained">
Evaluate Model
</MuiButton>
<Box
Copy link
Contributor

Choose a reason for hiding this comment

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

curious: is it better to use TooltipProvider

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh, is that a new component? Yah, it might be better. Sorry, I saw the comment after merging. I'll follow-up

@imanjra imanjra merged commit 79349af into release/v1.2.0 Dec 19, 2024
10 of 12 checks passed
@imanjra imanjra deleted the bugfix/model-eval-perm branch December 19, 2024 18:49
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.

3 participants