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

Sidebar enhancements for summary fields #4833

Merged
merged 18 commits into from
Sep 25, 2024
Merged

Conversation

benjaminpkane
Copy link
Contributor

@benjaminpkane benjaminpkane commented Sep 23, 2024

What changes are proposed in this pull request?

Adds improved sidebar support for Summary Fields #4765

import fiftyone as fo
import fiftyone.zoo as foz
from fiftyone import ViewField as F

dataset = foz.load_zoo_dataset("quickstart-video")
dataset.set_field("frames.detections.detections.confidence", F.rand()).save()

dataset.create_summary_field("frames.detections.detections.label")

dataset.create_summary_field("frames.detections.detections.confidence")

dataset.create_summary_field(
    "frames.detections.detections.label",
    field_name="frames_detections_label2",
    include_counts=True,
)

session = fo.launch_app(dataset)
  • Adds support for filtering lists of dynamic embedded documents, e.g. a summary field
  • Handles sidebar group configurations that prefer parent embedded doc fields (e.g. metadata) over individual flat filters (e.g. metadata.width)
  • Text bubble grouping for embedded document filters
Screen.Recording.2024-09-23.at.6.45.32.PM.mov

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

  • Server unit tests for embedded document filtering
  • App unit tests for text bubble rendering

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

    • Introduced a color prop across multiple components, enhancing customization options for visual elements.
    • Added functionality for handling embedded documents and improved data extraction methods in the new bubbles.ts file.
    • Implemented a new test suite for bubble generation and field retrieval, ensuring robustness against XSS vulnerabilities.
  • Bug Fixes

    • Streamlined sidebar functionality and visibility handling, improving user experience.
  • Documentation

    • Updated tests for date and datetime field visibility, focusing on core functionality.
  • Refactor

    • Enhanced filtering logic in fiftyone/server/view.py for better modularity and clarity.
    • Simplified layout behavior in CSS for the .lookerTags class.
  • Chores

    • Removed unused imports and functions across various components to clean up the codebase.

Copy link
Contributor

coderabbitai bot commented Sep 23, 2024

Walkthrough

The changes across multiple files primarily involve reorganization of import statements, modifications to component props, and enhancements to logic related to color handling and filtering. Notably, several components now accept a color prop, shifting from state-based retrieval to prop-based input. Additionally, improvements in type safety and code readability have been implemented, alongside the introduction of new utility functions for formatting and creating field representations.

Changes

File Path Change Summary
app/packages/core/src/components/Common/RangeSlider.tsx Reorganized import statements; no functional changes.
app/packages/core/src/components/Common/utils.tsx Reordered imports; added conditional formatting logic in getFormatter.
app/packages/core/src/components/Filters/FilterOption/FilterItem.tsx Modified import statements; changed ForwardedRef to type-only import; removed theme text styling from styled component.
app/packages/core/src/components/Filters/FilterOption/FilterOption.tsx Updated Props interface to include color: string; removed internal logic for color retrieval, now using prop directly.
app/packages/core/src/components/Filters/NumericFieldFilter/FilterOption.tsx Added color prop to FilterOption component; updated function signature.
app/packages/core/src/components/Filters/NumericFieldFilter/NumericFieldFilter.tsx Updated Props type to include color; modified logic for value formatting and state retrieval.
`app/packages/core/src/components/Filters/NumericFieldFilter/Reset.tsx Added color prop to Reset component; removed unused state retrieval.
`app/packages/core/src/components/Filters/StringFilter/Checkboxes.tsx Added color property to CheckboxesProps; modified handling of color within the component.
`app/packages/core/src/components/Filters/StringFilter/Reset.tsx Updated function signature to include color prop; removed unused state retrieval.
`app/packages/core/src/components/Filters/StringFilter/StringFilter.tsx Updated Props interface to include color; modified import statements.
`app/packages/core/src/components/Grid/Grid.tsx Consolidated parameters passed to useSpotlightPager hook; added clearRecords parameter.
app/packages/core/src/components/Grid/useFontSize.ts Updated MAX constant from 36 to 32.
app/packages/core/src/components/Grid/useSpotlightPager.ts Added clearRecords parameter; updated dependency array in useEffect.
app/packages/Sidebar/.../FilterablePathEntry/FilterItem.tsx Modified FilterItem interface; added color property and updated property order.
app/packages/Sidebar/.../FilterablePathEntry/FilterablePathEntries.tsx Added import for pathColor and utilized it in rendering logic.
app/packages/Sidebar/.../FilterablePathEntry/FilterablePathEntry.tsx Updated import for makePseudoField from local to external package.
`app/packages/Sidebar/.../FilterablePathEntry/Tune.tsx Changed RecoilState import to type-only import; reorganized import statements.
app/packages/Sidebar/.../FilterablePathEntry/state.ts Added color variable for path color retrieval; modified argument order in getFilterItemsProps.
app/packages/Sidebar/.../FilterablePathEntry/useFilterData.ts Updated getFilterItemsProps to accept color parameter; modified useFilterData hook to retrieve and pass color.
app/packages/Sidebar/.../PathValueEntry.tsx Removed unused format function; replaced with formatPrimitive; improved type safety.
app/packages/Sidebar/.../Entries/utils.tsx Removed makePseudoField function.
app/packages/looker/src/elements/common/bubbles.test.ts New test file for bubble-related functionalities.
app/packages/looker/src/elements/common/bubbles.ts Introduced functions for data extraction and manipulation related to embedded documents.
app/packages/utilities/src/index.ts Added formatPrimitive and makePseudoField functions.
fiftyone/server/view.py Restructured filter stage creation logic; split _make_filter_stages into multiple functions.
tests/unittests/server_tests.py Added new test method for filtering embedded documents.

Possibly related PRs

  • Add sidebar value text expansion #4487: This PR introduces a feature for text expansion in the modal sidebar, which may relate to UI changes in the RangeSlider.tsx file due to the focus on user interface enhancements.
  • visual tweaks for menu and views in menu #4562: This PR proposes visual tweaks for the menu and views, which could be relevant as it involves adjustments to the UI that may indirectly relate to the changes in import organization in RangeSlider.tsx.
  • Add date fields to primitives sidebar group #4815: This PR adds date fields to the primitives sidebar group, which could be related to the organization of imports in RangeSlider.tsx if date fields are involved in the slider functionality.

Suggested labels

bug

Suggested reviewers

  • brimoor
  • sashankaryal
  • imanjra

🐇 In the code, we hop and play,
With colors bright, we find our way.
Props and imports, all aligned,
A cleaner path, we’ve surely signed.
With tests to guard, our code is sound,
In every change, new joy is found! 🐇


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.

@benjaminpkane benjaminpkane marked this pull request as ready for review September 24, 2024 16:10
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: 19

Outside diff range and nitpick comments (32)
app/packages/core/src/components/Grid/useFontSize.ts (2)

Line range hint 15-17: Improve error handling with more context

The current error message "unexpected" doesn't provide much information about what went wrong. Consider improving the error message to include more context about the failure.

Suggested improvement:

- throw new Error("unexpected");
+ throw new Error(`Failed to get width for element with id: ${id}`);

6-6: Add a comment explaining the SCALE_FACTOR

The SCALE_FACTOR constant (0.09) is a magic number without any explanation. Consider adding a comment to explain its significance and how it was determined.

Suggested improvement:

+ // SCALE_FACTOR determines how quickly the font size grows relative to the element width.
+ // A lower value results in slower growth, while a higher value results in faster growth.
const SCALE_FACTOR = 0.09;
app/packages/looker/src/index.ts (1)

17-17: LGTM! Consider adding a brief comment for the new export.

The addition of KeypointSkeleton to the exported types is consistent with the file structure and TypeScript best practices. It's correctly placed in alphabetical order within the list.

To improve documentation, consider adding a brief comment explaining the purpose of the KeypointSkeleton type and how it relates to the sidebar enhancements for summary fields mentioned in the PR objectives.

export type {
  BaseState,
  Coloring,
  CustomizeColor,
  FrameConfig,
  FrameOptions,
  ImageConfig,
  ImageOptions,
+ /** Represents the structure of keypoint skeletons for summary fields */
  KeypointSkeleton,
  LabelData,
  Point,
  Sample,
  VideoConfig,
  VideoOptions,
} from "./state";
app/packages/core/src/components/Sidebar/Entries/FilterablePathEntry/FilterablePathEntries.tsx (2)

18-18: LGTM: Recoil state is correctly accessed for path color.

The useRecoilValue hook is appropriately used to retrieve the color associated with the given path. This aligns with the PR objective of enhancing sidebar functionality.

Consider adding a comment explaining the purpose of the pathColor function for better code readability:

// Retrieve the color associated with the current path from Recoil state
const color = useRecoilValue(pathColor(path));

21-22: LGTM: FilterItem now uses the color from Recoil state.

The changes correctly implement the use of the color retrieved from Recoil state, omitting any color that might have been in the data. This aligns with the PR objective of enhancing sidebar functionality.

For improved type safety, consider explicitly typing the props object:

{data.map(({ color: _, ...props }: { color: string; [key: string]: any }) => (
  <FilterItem key={props.path} color={color} {...events} {...props} />
))}

This change ensures that color is expected to be a string and allows for additional properties in props.

app/packages/core/src/components/Filters/NumericFieldFilter/FilterOption.tsx (1)

7-15: LGTM! Consider using a Props interface for better maintainability.

The addition of the color prop is well-implemented and properly typed. This change enhances the component's flexibility by allowing color customization.

For improved maintainability, consider defining a Props interface:

interface FilterOptionProps {
  color: string;
  modal: boolean;
  path: string;
}

function FilterOption({ color, modal, path }: FilterOptionProps) {
  // ... component logic
}

This approach centralizes prop definitions, making it easier to manage and document props as the component evolves.

app/packages/core/src/components/Sidebar/Entries/FilterablePathEntry/FilterItem.tsx (2)

6-11: Consider maintaining a consistent property order in the FilterItem interface.

The changes to the FilterItem interface are functionally correct:

  1. The new color: string property has been added as mentioned in the PR summary.
  2. The reordering of listField and path properties doesn't affect functionality.

However, to improve code readability and maintainability, consider ordering interface properties consistently, perhaps alphabetically or by importance. This makes it easier to locate specific properties, especially as the interface grows.

Here's a suggested ordering of properties:

interface FilterItem {
  color: string;
  ftype: string;
  listField: boolean;
  modal: boolean;
  named?: boolean;
  path: string;
  title?: string;
}

Line range hint 30-42: Ensure the FilterItem component utilizes the newly added color property.

The FilterItem interface has been updated to include a color property, but the component implementation doesn't reflect this change. This inconsistency may lead to unused props and potential bugs.

Consider updating the component to utilize the color prop:

  1. Destructure the color prop in the component parameters.
  2. Use the color prop within the component, possibly to style elements or pass it down to child components.

Here's a suggested update to the component signature:

const FilterItem = ({
  color,
  ftype,
  listField,
  path,
  title,
  ...rest
}: FilterItem & { onBlur?: () => void; onFocus?: () => void }) => {
  // Use the color prop here or pass it to child components
  // ...
};

If the color prop is not meant to be used in this component, consider removing it from the FilterItem interface to maintain consistency between the interface and its implementation.

app/packages/core/src/components/Filters/NumericFieldFilter/Reset.tsx (1)

23-31: Approved: Simplified component props and reduced Recoil dependencies

The changes to the Reset component's signature, particularly the addition of the color prop, are a positive improvement. This modification reduces the component's dependency on Recoil state and adheres to the React principle of "lifting state up".

Consider using TypeScript's type inference to simplify the prop type definition:

function Reset({ color, modal, path }: { color: string; modal: boolean; path: string })

Could be simplified to:

type ResetProps = { color: string; modal: boolean; path: string };
function Reset({ color, modal, path }: ResetProps)

This approach improves readability and allows for easier reuse of the prop type if needed elsewhere.

app/packages/core/src/components/Sidebar/Entries/FilterablePathEntry/Tune.tsx (1)

4-7: LGTM! Consider grouping related imports.

The changes to the import statements are good:

  1. Using import type for RecoilState is a best practice in TypeScript when the import is only used for type checking.
  2. Moving DisabledReason to a separate line improves readability.

Consider grouping related imports together for better organization. You could move the Recoil-related imports next to each other:

import type { RecoilState } from "recoil";
import { useSetRecoilState } from "recoil";
import { LIGHTNING_MODE } from "../../../../utils/links";
import DisabledReason from "./DisabledReason";
app/packages/core/src/components/Common/utils.tsx (2)

8-9: Consider reorganizing imports for better readability.

While the reordering of imports doesn't affect functionality, it's generally a good practice to group imports in a consistent manner. Consider organizing imports in the following order:

  1. React and other third-party libraries
  2. Local imports (starting with @fiftyone)
  3. Relative imports

This would improve code readability and maintainability.


74-76: Approve the additional precision for small ranges, but consider improving clarity.

The addition of more precise formatting for small ranges is a good improvement. It will provide better readability for users when dealing with data that has small differences.

However, to improve code clarity and maintainability, consider the following suggestions:

  1. Extract the magic number 0.1 into a named constant with a descriptive name, explaining its significance.
  2. Consider adding a comment explaining the rationale behind this condition, especially if it's addressing a specific use case or user feedback.

Example:

const SMALL_RANGE_THRESHOLD = 0.1;
// Use more precise formatting for small ranges to improve readability
const format = bounds[1] - bounds[0] < SMALL_RANGE_THRESHOLD ? "0.0000a" : "0.00a";

This change will make the code more self-documenting and easier to maintain in the future.

fiftyone/server/routes/frames.py (2)

Line range hint 12-12: Consider removing unused variable

The group_slice variable is defined but not used in the visible code. If it's no longer needed after the refactoring, consider removing it to improve code clarity.

- group_slice = data.get("slice", None)

Incomplete removal of group_slice in frames.py

The group_slice variable is still present in fiftyone/server/routes/frames.py at lines 40-48:

  • group_slice = data.get("slice", None)

Please ensure that all references to group_slice have been properly removed or updated as intended.

Analysis chain

Line range hint 1-67: Verify completeness of changes

The AI summary mentions the removal of a conditional check for view.media_type related to GROUP and group_slice, but this change is not visible in the provided code. Please ensure that all intended changes have been included in this PR.

To verify the completeness of the changes, please run the following script:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to view.media_type, GROUP, or group_slice in the file

# Test: Search for view.media_type, GROUP, and group_slice
rg --type python 'view\.media_type|GROUP|group_slice' fiftyone/server/routes/frames.py

Length of output: 119


Script:

#!/bin/bash
# Description: Check for any remaining references to view.media_type, GROUP, or group_slice in the file

# Test: Search for view.media_type, GROUP, and group_slice without specifying file type
rg 'view\.media_type|GROUP|group_slice' fiftyone/server/routes/frames.py

Length of output: 120

app/packages/core/src/components/Filters/FilterOption/FilterOption.tsx (2)

36-36: LGTM: New color prop added to Props interface

The addition of the color: string property to the Props interface is a good change that allows for more flexible color management in the component.

Consider adding a JSDoc comment to describe the purpose and expected format of the color prop. For example:

/** The color to be used for highlighting. Should be a valid CSS color string. */
color: string;

45-49: LGTM: FilterOption component updated to use color prop

The changes to the FilterOption component, including the addition of the color prop and the removal of the Recoil state for color, are good improvements that simplify the component's logic.

Consider maintaining a consistent order of props in the destructuring to improve readability. You might want to group related props together or follow an alphabetical order. For example:

const FilterOption: React.FC<Props> = ({
  color,
  excludeAtom,
  isMatchingAtom,
  valueName,
  modal,
  path,
}) => {
  // ...
};
e2e-pw/src/oss/specs/regression-tests/sidebar/sidebar-datetime.spec.ts (1)

74-76: LGTM with a minor suggestion.

The changes look good and improve the test's readability. The reordering of operations (clicking checkbox before dropdown) aligns better with expected user interaction.

Consider adding a comment explaining the reason for the specific order of operations (checkbox before dropdown) to improve code maintainability.

Also applies to: 80-80, 87-89

app/packages/core/src/components/Filters/NumericFieldFilter/NumericFieldFilter.tsx (2)

33-38: LGTM: Props type updated with color property

The addition of the color: string property to the Props type is appropriate for supporting customizable colors in the component. The reordering of properties doesn't affect functionality.

Consider alphabetizing the properties in the Props type for better consistency and easier maintenance. For example:

type Props = {
  color: string;
  modal: boolean;
  named?: boolean;
  onBlur?: () => void;
  onFocus?: () => void;
  path: string;
};

80-80: LGTM: Improved value formatting and color prop usage

The changes in the component's JSX improve value formatting and allow for consistent styling:

  1. Using formatPrimitive for the one value enhances support for different field types and time zones.
  2. Passing the color prop to FilterOption and Reset components enables consistent styling.

These changes follow React best practices for prop passing and component composition.

Consider extracting the formatPrimitive call into a separate variable for improved readability:

const formattedOne = formatPrimitive({ ftype, timeZone, value: one })?.toString();
// ...
{one !== null ? formattedOne : (
  // ... RangeSlider component
)}

Also applies to: 98-99

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

Line range hint 32-95: Suggestions for component optimization

While the FilterableEntry component is well-structured, consider the following improvements:

  1. Specify the type for the trigger prop instead of using any:
trigger?: (
  event: React.MouseEvent<HTMLDivElement>,
  key: string,
  cb: () => void
) => void;
  1. Use the useCallback hook for the onClick function to optimize performance:
const onClick = useCallback(
  (event: React.MouseEvent<HTMLButtonElement>) => {
    const checked = (event.target as HTMLInputElement).checked;
    set(fos.activeField({ modal, path }), checked);
  },
  [modal, path, set]
);

These changes will improve type safety and potentially enhance performance.

app/packages/core/src/components/Sidebar/Entries/FilterablePathEntry/useFilterData.ts (1)

28-31: LGTM: Updated function signature with color parameter

The addition of the color parameter to the getFilterItemsProps function aligns with the PR objectives of enhancing sidebar functionality. The parameter type is correctly specified as string.

Consider adding a JSDoc comment to describe the purpose of the color parameter for better code documentation.

app/packages/core/src/components/Filters/StringFilter/StringFilter.tsx (1)

37-37: Props interface update looks good, minor suggestion

The addition of the color prop enhances the component's styling capabilities. The reordering of props doesn't affect functionality.

Consider adding a comment explaining the purpose of the color prop for better code documentation:

interface Props {
+  // Color used for styling child components
  color: string;
  excludeAtom: RecoilState<boolean>; // toggles select or exclude
  isMatchingAtom: RecoilState<boolean>; // toggles match or filter
  modal: boolean;
  path: string;
  named?: boolean;
  resultsAtom: ResultsAtom;
  selectedAtom: RecoilState<(string | null)[]>;
}

Also applies to: 43-44

app/packages/core/src/components/Grid/useSpotlightPager.ts (1)

49-61: LGTM! Consider adding JSDoc comments for better documentation.

The updated function signature looks good. Grouping parameters into an object is a good practice, especially for functions with multiple parameters. The types are properly defined, adhering to TypeScript best practices.

Consider adding JSDoc comments to describe the purpose of the clearRecords parameter and how it affects the hook's behavior. This would improve the code's self-documentation and make it easier for other developers to understand and use the hook.

Example:

/**
 * A hook for managing spotlight paging.
 * @param {Object} params - The parameters for the hook.
 * @param {string} params.clearRecords - A string that triggers clearing of records when changed.
 * @param {RecoilValueReadOnly<...>} params.pageSelector - A selector for paginating samples.
 * @param {Records} params.records - The records to be managed.
 * @param {RecoilValueReadOnly<boolean>} params.zoomSelector - A selector for zoom state.
 */
const useSpotlightPager = ({
  clearRecords,
  pageSelector,
  records,
  zoomSelector,
}: {
  // ... (rest of the type definitions)
}) => {
  // ... (function body)
};
app/packages/core/src/components/Grid/Grid.tsx (1)

39-44: Improved hook usage, consider destructuring for consistency

The changes to the useSpotlightPager hook usage improve code readability by grouping related parameters into an object. This is a good practice in React and makes the code more maintainable.

Consider destructuring the object parameter for consistency with other hooks in the file:

const { page, store } = useSpotlightPager({
  clearRecords: pageReset,
  pageSelector: pageParameters,
  records,
  zoomSelector: gridCrop,
});

This minor change would align the usage with React best practices and improve consistency throughout the codebase.

app/packages/core/src/components/Filters/StringFilter/Checkboxes.tsx (1)

21-21: LGTM: Added color prop, minor suggestion on property order

The addition of the color property to CheckboxesProps is good, aligning with the PR objectives for enhanced styling flexibility.

Consider grouping related properties together for better readability. For example:

interface CheckboxesProps {
  color: string;
  path: string;
  modal: boolean;
  results: Result[] | null;
  selectedAtom: RecoilState<(string | null)[]>;
  excludeAtom: RecoilState<boolean>;
  isMatchingAtom: RecoilState<boolean>;
}

Also applies to: 26-27

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

242-242: Remove unnecessary Fragment

The Fragment on this line is redundant as it contains only one child. Consider removing it to simplify the code:

-      {values.length === 0 && <>No results</>}
+      {values.length === 0 && "No results"}

This change will maintain the same functionality while reducing unnecessary JSX nesting.

Tools
Biome

[error] 242-242: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)

app/packages/operators/src/built-in-operators.ts (3)

Line range hint 1024-1026: Security concern: Use of eval in createFunctionFromSource

The createFunctionFromSource function uses eval, which can be a security risk if the input is not properly sanitized. Consider using a safer alternative, such as the Function constructor, or implement strict input validation to mitigate potential security vulnerabilities.


Line range hint 1092-1094: Suggestion: Use constants for operator names

In the SetSpaces class, the LOAD_WORKSPACE_OPERATOR is used as a string literal. Consider defining constants for operator names to prevent typos and improve maintainability. This approach could be applied consistently throughout the file for all operator names.


Line range hint 1-1431: Enhance error handling throughout the file

While reviewing the file, I noticed that error handling could be improved in several areas. Consider implementing more comprehensive error handling and providing informative error messages to improve debugging and user experience. This is especially important in methods that interact with external state or perform complex operations.

app/packages/looker/src/elements/common/bubbles.test.ts (1)

174-198: Suggestion: Simplify Test Setup for Readability

The setup for listField and field in the "getBubble gets values for path" test is quite verbose and may affect readability. To enhance clarity, consider extracting common properties or simplifying the field definitions.

For example, you can create helper functions or constants to reduce repetition:

const createField = (overrides = {}) => ({
  ...FIELD_DATA,
  ...overrides,
});

Then use it in your tests:

const listField = createField({
  dbField: "my",
  ftype: LIST_FIELD,
  embeddedDocType: DYNAMIC_EMBEDDED_DOCUMENT_PATH,
  subfield: EMBEDDED_DOCUMENT_FIELD,
  fields: {
    list: createField(),
  },
});
app/packages/utilities/src/index.ts (1)

643-645: Add break statement after the last case in switch

Including a break; statement after the last case in a switch statement is a good practice. It prevents accidental fall-through if new cases are added later.

Proposed addition:

case DATE_TIME_FIELD:
  value = formatDateTime(value.datetime as number, timeZone);
+  break;
fiftyone/server/view.py (1)

195-197: Simplify stages initialization

You can streamline the initialization of stages by directly assigning it based on the existence of match_stage.

Apply this diff to simplify the code:

        match_stage = _make_match_stage(view, filters)
-        stages = []
-        if match_stage:
-            stages = [match_stage]
+        stages = [match_stage] if match_stage else []
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bfd758a and cb4c614.

Files ignored due to path filters (10)
  • e2e-pw/src/oss/specs/grid-tagging.spec.ts-snapshots/grid-tagged-chromium-darwin.png is excluded by !**/*.png, !**/*.png
  • e2e-pw/src/oss/specs/grid-tagging.spec.ts-snapshots/grid-tagged-chromium-linux.png is excluded by !**/*.png, !**/*.png
  • e2e-pw/src/oss/specs/grid-tagging.spec.ts-snapshots/grid-untagged-chromium-darwin.png is excluded by !**/*.png, !**/*.png
  • e2e-pw/src/oss/specs/grid-tagging.spec.ts-snapshots/grid-untagged-chromium-linux.png is excluded by !**/*.png, !**/*.png
  • e2e-pw/src/oss/specs/sidebar/sidebar-cifar.spec.ts-snapshots/hide-ship-chromium-linux.png is excluded by !**/*.png, !**/*.png
  • e2e-pw/src/oss/specs/sidebar/sidebar-cifar.spec.ts-snapshots/not-visible-cat-chromium-darwin.png is excluded by !**/*.png, !**/*.png
  • e2e-pw/src/oss/specs/sidebar/sidebar-cifar.spec.ts-snapshots/not-visible-cat-chromium-linux.png is excluded by !**/*.png, !**/*.png
  • e2e-pw/src/oss/specs/sidebar/sidebar-cifar.spec.ts-snapshots/show-frog-chromium-darwin.png is excluded by !**/*.png, !**/*.png
  • e2e-pw/src/oss/specs/sidebar/sidebar-cifar.spec.ts-snapshots/show-frog-chromium-linux.png is excluded by !**/*.png, !**/*.png
  • e2e-pw/src/oss/specs/sidebar/sidebar-cifar.spec.ts-snapshots/show-frog-ship-invisible-frog-chromium-darwin.png is excluded by !**/*.png, !**/*.png
Files selected for processing (35)
  • app/packages/core/src/components/Common/RangeSlider.tsx (1 hunks)
  • app/packages/core/src/components/Common/utils.tsx (2 hunks)
  • app/packages/core/src/components/Filters/FilterOption/FilterItem.tsx (1 hunks)
  • app/packages/core/src/components/Filters/FilterOption/FilterOption.tsx (3 hunks)
  • app/packages/core/src/components/Filters/NumericFieldFilter/FilterOption.tsx (2 hunks)
  • app/packages/core/src/components/Filters/NumericFieldFilter/NumericFieldFilter.tsx (5 hunks)
  • app/packages/core/src/components/Filters/NumericFieldFilter/Reset.tsx (1 hunks)
  • app/packages/core/src/components/Filters/StringFilter/Checkboxes.tsx (5 hunks)
  • app/packages/core/src/components/Filters/StringFilter/Reset.tsx (2 hunks)
  • app/packages/core/src/components/Filters/StringFilter/StringFilter.tsx (4 hunks)
  • app/packages/core/src/components/Grid/Grid.tsx (1 hunks)
  • app/packages/core/src/components/Grid/useFontSize.ts (1 hunks)
  • app/packages/core/src/components/Grid/useSpotlightPager.ts (3 hunks)
  • app/packages/core/src/components/Sidebar/Entries/FilterablePathEntry/FilterItem.tsx (1 hunks)
  • app/packages/core/src/components/Sidebar/Entries/FilterablePathEntry/FilterablePathEntries.tsx (2 hunks)
  • app/packages/core/src/components/Sidebar/Entries/FilterablePathEntry/FilterablePathEntry.tsx (1 hunks)
  • app/packages/core/src/components/Sidebar/Entries/FilterablePathEntry/Tune.tsx (1 hunks)
  • app/packages/core/src/components/Sidebar/Entries/FilterablePathEntry/state.ts (3 hunks)
  • app/packages/core/src/components/Sidebar/Entries/FilterablePathEntry/useFilterData.ts (9 hunks)
  • app/packages/core/src/components/Sidebar/Entries/PathValueEntry.tsx (6 hunks)
  • app/packages/core/src/components/Sidebar/Entries/utils.tsx (0 hunks)
  • app/packages/looker/src/elements/common/bubbles.test.ts (1 hunks)
  • app/packages/looker/src/elements/common/bubbles.ts (1 hunks)
  • app/packages/looker/src/elements/common/tags.module.css (0 hunks)
  • app/packages/looker/src/elements/common/tags.test.ts (0 hunks)
  • app/packages/looker/src/elements/common/tags.ts (18 hunks)
  • app/packages/looker/src/index.ts (1 hunks)
  • app/packages/operators/src/built-in-operators.ts (1 hunks)
  • app/packages/state/src/recoil/lightning.ts (2 hunks)
  • app/packages/state/src/recoil/sidebar.ts (18 hunks)
  • app/packages/utilities/src/index.ts (1 hunks)
  • e2e-pw/src/oss/specs/regression-tests/sidebar/sidebar-datetime.spec.ts (2 hunks)
  • fiftyone/server/routes/frames.py (1 hunks)
  • fiftyone/server/view.py (8 hunks)
  • tests/unittests/server_tests.py (2 hunks)
Files not reviewed due to no reviewable changes (3)
  • app/packages/core/src/components/Sidebar/Entries/utils.tsx
  • app/packages/looker/src/elements/common/tags.module.css
  • app/packages/looker/src/elements/common/tags.test.ts
Additional context used
Path-based instructions (29)
app/packages/core/src/components/Common/RangeSlider.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/components/Common/utils.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/components/Filters/FilterOption/FilterItem.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/components/Filters/FilterOption/FilterOption.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/components/Filters/NumericFieldFilter/FilterOption.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/components/Filters/NumericFieldFilter/NumericFieldFilter.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/components/Filters/NumericFieldFilter/Reset.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/components/Filters/StringFilter/Checkboxes.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/components/Filters/StringFilter/Reset.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/components/Filters/StringFilter/StringFilter.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/components/Grid/Grid.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/components/Grid/useFontSize.ts (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/components/Grid/useSpotlightPager.ts (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/components/Sidebar/Entries/FilterablePathEntry/FilterItem.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/components/Sidebar/Entries/FilterablePathEntry/FilterablePathEntries.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/components/Sidebar/Entries/FilterablePathEntry/FilterablePathEntry.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/components/Sidebar/Entries/FilterablePathEntry/Tune.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/components/Sidebar/Entries/FilterablePathEntry/state.ts (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/components/Sidebar/Entries/FilterablePathEntry/useFilterData.ts (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/components/Sidebar/Entries/PathValueEntry.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/looker/src/elements/common/bubbles.test.ts (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/looker/src/elements/common/bubbles.ts (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/looker/src/elements/common/tags.ts (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/looker/src/index.ts (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/operators/src/built-in-operators.ts (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/state/src/recoil/lightning.ts (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/state/src/recoil/sidebar.ts (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/utilities/src/index.ts (1)

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

e2e-pw/src/oss/specs/regression-tests/sidebar/sidebar-datetime.spec.ts (1)

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

Biome
app/packages/core/src/components/Sidebar/Entries/PathValueEntry.tsx

[error] 242-242: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)

Ruff
fiftyone/server/view.py

479-483: Combine if branches using logical or operator

Combine if branches

(SIM114)

Additional comments not posted (57)
app/packages/core/src/components/Grid/useFontSize.ts (1)

4-4: Approve the MAX constant change, but verify its impact.

The reduction of the MAX constant from 36 to 32 is a reasonable adjustment that could improve readability and consistency in the UI, especially for summary fields in the sidebar. This change aligns with the PR objectives for sidebar enhancements.

To ensure this change doesn't negatively impact other parts of the application, please run the following verification:

Verification successful

MAX constant change has been verified with no adverse impacts.

The change to the MAX constant has been successfully verified and only affects app/packages/core/src/components/Grid/Grid.tsx. This ensures that the font size adjustment is appropriate and maintains readability and consistency within the component.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all usages of the useFontSize hook to verify the impact of the MAX constant change.

# Search for imports of useFontSize
echo "Searching for imports of useFontSize:"
rg --type typescript --type typescriptreact 'import.*useFontSize' app/packages

# Search for direct uses of useFontSize
echo "\nSearching for direct uses of useFontSize:"
rg --type typescript --type typescriptreact 'useFontSize\(' app/packages

# Note: Review the output to ensure that the font size change is appropriate for all use cases.

Length of output: 407


Script:

#!/bin/bash
# Description: Find all usages of the useFontSize hook to verify the impact of the MAX constant change.

# Search for imports of useFontSize in .ts and .tsx files
echo "Searching for imports of useFontSize in .ts and .tsx files:"
rg --glob '*.ts' --glob '*.tsx' 'import.*useFontSize' app/packages

# Search for direct uses of useFontSize in .ts and .tsx files
echo -e "\nSearching for direct uses of useFontSize in .ts and .tsx files:"
rg --glob '*.ts' --glob '*.tsx' 'useFontSize\(' app/packages

# Note: Review the output to ensure that the font size change is appropriate for all use cases.

Length of output: 577

app/packages/core/src/components/Sidebar/Entries/FilterablePathEntry/FilterablePathEntries.tsx (1)

1-3: LGTM: Import statements are correctly updated.

The new imports for pathColor and useRecoilValue are appropriately added to support the changes in the component. This follows best practices for React and Recoil usage.

app/packages/core/src/components/Filters/StringFilter/Reset.tsx (3)

2-4: Import statements updated correctly

The changes in the import statements are consistent with the modifications in the component's logic. The addition of isSidebarFilterMode and the removal of unused imports improve code cleanliness.


7-11: Function signature updated to improve flexibility

The addition of the color parameter to the function signature enhances the component's flexibility and reusability. This change reduces coupling with global state and allows for more direct control over the button's appearance.


25-25: Button color prop updated correctly

The color prop of the Button component is now correctly set to params.color, which is consistent with the updated function signature. This change simplifies the component's implementation while maintaining its functionality.

app/packages/core/src/components/Filters/NumericFieldFilter/FilterOption.tsx (1)

26-26: LGTM! Verify color handling in the Option component.

The color prop is correctly passed to the Option component, which is consistent with the updated function signature.

To ensure proper implementation, please verify that the Option component correctly handles and applies the color prop. Run the following script to check the Option component's implementation:

If the Option component doesn't handle the color prop, consider updating its implementation to utilize this new property.

app/packages/core/src/components/Sidebar/Entries/FilterablePathEntry/state.ts (3)

8-8: LGTM: Import statement updated correctly.

The addition of pathColor to the import statement is consistent with its usage in the file and follows the existing import pattern.


24-24: LGTM: Color variable added correctly.

The color variable is properly declared using the pathColor selector from Recoil state. Its placement and usage are consistent with Recoil best practices.


33-40: Verify getFilterItemsProps function implementation.

The color parameter has been added as the first argument to getFilterItemsProps, and the order of other arguments has been adjusted. While this change appears intentional, please ensure that:

  1. The getFilterItemsProps function implementation has been updated to accept color as its first parameter.
  2. The function correctly handles the new parameter order.

This will help prevent potential bugs related to argument mismatch.

To verify the getFilterItemsProps function implementation, please run the following script:

app/packages/core/src/components/Filters/NumericFieldFilter/Reset.tsx (1)

23-31: 🛠️ Refactor suggestion

Verify component usage and update documentation

The addition of the color prop simplifies the component's rendering logic. However, this change may require updates to all instances where the Reset component is used throughout the codebase.

Please run the following script to identify all usages of the Reset component and ensure they provide the new color prop:

If not already present, consider adding or updating the component's documentation (e.g., JSDoc comments) to reflect the new color prop and its usage. This will help maintain clear communication about the component's API for other developers.

Example:

/**
 * Reset component for numeric field filters.
 * @param {Object} props - The component props.
 * @param {string} props.color - The color of the reset button.
 * @param {boolean} props.modal - Indicates if the component is used in a modal context.
 * @param {string} props.path - The path of the field being filtered.
 */
function Reset({ color, modal, path }: ResetProps)

Also applies to: 48-48

Verification successful

All Reset component usages include the color prop

Verified that both instances of the Reset component in Checkboxes.tsx and NumericFieldFilter.tsx correctly pass the color prop. No further updates are necessary for component usage.

  • app/packages/core/src/components/Filters/StringFilter/Checkboxes.tsx
  • app/packages/core/src/components/Filters/NumericFieldFilter/NumericFieldFilter.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all usages of the Reset component and verify the color prop

# Search for Reset component usage
echo "Searching for Reset component usage:"
rg --type typescript --type typescriptreact 'Reset\s*\{' -C 3

# Search for imports of Reset component
echo "\nSearching for Reset component imports:"
rg --type typescript --type typescriptreact 'import.*Reset.*from'

Length of output: 375


Script:

#!/bin/bash
# Description: Find all usages of the Reset component and verify the color prop

# Search for Reset component usage in .ts and .tsx files
echo "Searching for Reset component usage in TypeScript files:"
rg --glob "*.ts" --glob "*.tsx" 'Reset\s*\{' -A 3

# Search for imports of Reset component in .ts and .tsx files
echo -e "\nSearching for Reset component imports in TypeScript files:"
rg --glob "*.ts" --glob "*.tsx" 'import.*Reset.*from'

Length of output: 2163


Script:

#!/bin/bash
# Description: Find all JSX usages of the Reset component and verify the presence of the color prop

# Search for Reset component usages in .ts and .tsx files
echo "Searching for Reset component usages in TypeScript files:"
rg --glob "*.ts" --glob "*.tsx" '<Reset\b[^>]*>' -C 2

Length of output: 1340

app/packages/core/src/components/Sidebar/Entries/FilterablePathEntry/Tune.tsx (1)

Line range hint 1-68: Overall implementation looks good!

The Tune component is well-implemented:

  1. Proper use of TypeScript for type safety.
  2. Correct usage of React hooks and Recoil state management.
  3. Good handling of disabled state and conditional rendering of tooltip.
  4. Proper event handling and propagation management.

The code is clean, well-structured, and follows React and TypeScript best practices.

fiftyone/server/routes/frames.py (1)

43-45: LGTM: Improved handling of embedded documents

The addition of flatten=True to the make_optimized_select_view function call aligns with the PR objectives. This change enhances support for filtering lists of dynamic embedded documents, which includes summary fields.

app/packages/core/src/components/Filters/FilterOption/FilterItem.tsx (2)

9-10: Improved import statements

The changes to the import statements are beneficial:

  1. Using a type-only import for ForwardedRef is a good TypeScript practice. It clearly separates type imports from value imports, which can help with tree-shaking and code clarity.
  2. Retaining the React import is necessary for JSX syntax and potential use of React hooks.

These changes align well with modern React and TypeScript best practices.


Line range hint 32-35: Verify the removal of theme text styling

The theme.text.primary style has been removed from the Text styled component. While this might be intentional, it's important to confirm that this change doesn't negatively impact the UI.

Please verify:

  1. Was this removal intentional?
  2. Does the text color still appear correctly without this style?
  3. Is the text color being set elsewhere, or is the default color appropriate for all use cases of this component?

To help verify the impact, you can run the following command to check for other occurrences of theme.text.primary in the codebase:

This will help determine if the text color is being set consistently across the application.

Verification successful

To accurately search for occurrences of theme.text.primary within .ts and .tsx files, please run the following script:


Removal of theme.text.primary Verified as Safe

The theme.text.primary style has been removed from the Text styled component in FilterItem.tsx. Given that theme.text.primary is still used across multiple other components, this removal appears intentional and isolated. Please ensure that the text color within FilterItem.tsx is appropriately managed through default styles or alternative theming to maintain UI consistency.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other occurrences of theme.text.primary
rg --type typescript --type typescriptreact 'theme\.text\.primary'

Length of output: 103


Script:

#!/bin/bash
# Search for other occurrences of theme.text.primary in .ts and .tsx files
rg 'theme\.text\.primary' --glob '*.ts' --glob '*.tsx'

Length of output: 8248

app/packages/core/src/components/Filters/FilterOption/FilterOption.tsx (2)

5-5: LGTM: Import of RecoilState added

The addition of the RecoilState import from Recoil is appropriate and aligns with the project's use of Recoil for state management.


Line range hint 1-114: Summary: FilterOption component successfully updated

The changes made to the FilterOption component and its Props interface successfully implement the required modifications for the sidebar enhancements. The addition of the color prop and the simplification of color management align well with the PR objectives.

Key points:

  1. The RecoilState import has been added correctly.
  2. The Props interface has been updated with the new color property.
  3. The FilterOption component now uses the color prop directly, simplifying its logic.

These changes improve the flexibility and maintainability of the component while adhering to the project's coding guidelines for React and Recoil usage.

e2e-pw/src/oss/specs/regression-tests/sidebar/sidebar-datetime.spec.ts (3)

106-106: LGTM: Consistent change in operation order.

The change in the order of operations (clicking checkbox before dropdown) is consistent with the modification made in the date field visibility test. This likely reflects a more accurate representation of the expected user interaction.


Line range hint 1-110: LGTM: Well-structured and consistent tests.

The overall structure and consistency of the tests are commendable. Both tests follow a similar pattern, use entryExpandPromise to handle UI animations, and focus on the core functionality of toggling visibility for date and datetime fields in the sidebar.

The tests effectively cover the intended functionality while maintaining a clean and readable structure.


Line range hint 1-110: Verify the impact of removing gridRefreshedEventPromise.

The removal of gridRefreshedEventPromise setup and related assertions might affect the test's ability to ensure that the grid has been updated after changing field visibility. While the remaining assertions still check for the presence of tags, which indirectly verifies the grid update, it's important to ensure this doesn't introduce any race conditions or timing issues.

Please run the following script to check for any remaining uses of gridRefreshedEventPromise in the test files:

If there are no results, it might indicate that this event is no longer used across tests. In that case, consider updating the test documentation to reflect this change in testing strategy.

Verification successful

Verified
The removal of gridRefreshedEventPromise from sidebar-datetime.spec.ts does not affect other tests, as it is still utilized in multiple test files. Ensure that the specific test maintains its functionality without introducing any timing or synchronization issues.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for remaining uses of gridRefreshedEventPromise in test files

# Test: Search for gridRefreshedEventPromise in test files
rg --type typescript 'gridRefreshedEventPromise' 'e2e-pw/src/oss/specs'

Length of output: 104


Script:

#!/bin/bash
# Description: Check for remaining uses of gridRefreshedEventPromise in TypeScript test files

# Search for gridRefreshedEventPromise in .ts and .tsx files within the specified directory
rg 'gridRefreshedEventPromise' --glob '*.ts' --glob '*.tsx' 'e2e-pw/src/oss/specs'

Length of output: 1568

app/packages/core/src/components/Filters/NumericFieldFilter/NumericFieldFilter.tsx (3)

2-2: LGTM: New import for formatting functionality

The addition of the formatPrimitive import from "@fiftyone/utilities" is appropriate for the new formatting requirements in the component.


41-41: LGTM: Component signature updated with color prop

The function signature has been correctly updated to include the color prop, and the prop order now matches the Props type definition. This change aligns with React best practices for functional components.


52-52: LGTM: Added timeZone state

The addition of the timeZone constant using useRecoilValue(fos.timeZone) is appropriate for handling time zone information in the component. This change aligns with the use of formatPrimitive and follows Recoil best practices.

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

3-3: Approved: Import source updated for better code organization.

The change to import makePseudoField from @fiftyone/utilities instead of a local utility file is a good practice for better code organization and reusability.

To ensure this change doesn't introduce any inconsistencies, please run the following script to check for any remaining imports of makePseudoField from the old source:

Verification successful

Verification Successful: No remaining imports from '../utils' found for makePseudoField.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining imports of makePseudoField from the old source

# Test: Search for imports of makePseudoField from ../utils
# Expect: No results, as all imports should now be from @fiftyone/utilities
rg --type typescript 'import.*makePseudoField.*from.*\.\.\/utils'

Length of output: 211


Script:

#!/bin/bash
# Description: Check for any remaining imports of makePseudoField from the old source

# Test: Search for imports of makePseudoField from ../utils
# Expect: No results, as all imports should now be from @fiftyone/utilities
rg --type typescript 'import.*makePseudoField.*from.*\.\./utils'

Length of output: 101


Script:

#!/bin/bash
# Description: Check for any remaining imports of makePseudoField from the old source

# Test: Search for imports of makePseudoField from ../utils
# Expect: No results, as all imports should now be from @fiftyone/utilities
rg --type ts 'import.*makePseudoField.*from.*\.\./utils'

Length of output: 58

app/packages/core/src/components/Sidebar/Entries/FilterablePathEntry/useFilterData.ts (4)

1-1: LGTM: Improved type imports

The changes to import statements, using type imports for KeypointSkeleton, Field, and FilterItem, align with TypeScript best practices. This can lead to better performance and clearer code intentions.

Also applies to: 4-4, 20-20


38-38: LGTM: Consistent usage of color parameter

The color parameter is correctly included in the returned objects for various conditions within the getFilterItemsProps function. This implementation is consistent with the function signature change and appears to be correctly applied across different scenarios.

Also applies to: 60-60, 83-83


129-129: LGTM: Proper integration of color in useFilterData hook

The changes in the useFilterData hook correctly retrieve the color using Recoil state management and pass it to the getFilterItemsProps function. This implementation is consistent with the overall changes and maintains the expected data flow.

Also applies to: 141-141


154-154: LGTM: Updated useMemo dependencies

The addition of color to the dependency array of useMemo is correct and necessary. This ensures that the memoized value is recalculated when the color changes, maintaining consistency with the new functionality.

app/packages/core/src/components/Filters/StringFilter/StringFilter.tsx (4)

4-5: Import statements look good

The changes to the import statements improve type safety and specificity. Explicitly importing types (RecoilState and ResultsAtom) enhances the overall type checking in the component.

Also applies to: 12-13


59-66: StringFilter function parameters updated correctly

The changes in the function parameters align well with the updates made to the Props interface. The addition of the color parameter and the reordering of other parameters maintain consistency with the interface definition.


Line range hint 93-101: FieldLabelAndInfo component usage updated correctly

The addition of the color prop to the FieldLabelAndInfo component is consistent with the changes made to the StringFilter component. This update allows for custom coloring of the field label, enhancing the component's flexibility.


127-130: Checkboxes component usage updated correctly

The changes to the Checkboxes component usage are consistent with the overall updates in the file. The addition of the color prop and the reordering of other props improve the component's customization capabilities and maintain code consistency.

app/packages/core/src/components/Grid/useSpotlightPager.ts (1)

Line range hint 122-141: Clarify the purpose of clearRecords and consider refactoring.

The addition of clearRecords to the dependency array is correct, ensuring the effect runs when it changes. However, the current implementation doesn't make use of this new parameter effectively.

  1. The line clearRecords; is a no-op statement and doesn't affect the behavior of the function. Consider removing it if it's not needed.

  2. The purpose of including clearRecords in the effect is not clear from the current implementation. If it's intended to trigger the clearing of records, consider refactoring the code to make this explicit.

Here's a potential refactoring to make better use of clearRecords:

useEffect(() => {
  const clear = () => {
    commitLocalUpdate(fos.getCurrentEnvironment(), (store) => {
      for (const id of keys.current) {
        store.get(id)?.invalidateRecord();
      }
    });
    keys.current.clear();
  };

  // Call clear when clearRecords changes
  if (clearRecords) {
    clear();
  }

  const unsubscribe = foq.subscribe(
    ({ event }) => event === "fieldVisibility" && clear()
  );

  return () => {
    unsubscribe();
  };
}, [clearRecords, refresher]);

This refactoring assumes that clearRecords is meant to trigger the clearing of records. If this is not the intended behavior, please clarify the purpose of clearRecords so we can suggest a more appropriate implementation.

To ensure that clearRecords is being used correctly throughout the codebase, let's verify its usage:

This will help us understand how clearRecords is being used and potentially set in other parts of the codebase, which could inform how it should be handled in this hook.

app/packages/core/src/components/Common/RangeSlider.tsx (1)

3-8: Improved import organization and TypeScript usage.

The changes to the import statements are beneficial:

  1. Reordering imports improves readability.
  2. Using the type keyword for type imports (ChangeEvent, RecoilState, RecoilValueReadOnly) is a TypeScript best practice, as it clearly separates type imports from value imports.

These changes align well with TypeScript and React best practices.

app/packages/core/src/components/Filters/StringFilter/Checkboxes.tsx (4)

4-4: LGTM: Improved type imports

The changes to use type-only imports for RecoilState and Result are good practices in TypeScript. This approach ensures that only type information is imported, keeping the type system separate from runtime code.

Also applies to: 16-16


76-86: LGTM: Improved loop in useCounts function

The change from forEach to a for...of loop in the useCounts function is a good improvement. It enhances readability and provides more flexibility for future modifications (e.g., adding break or continue statements if needed).


170-176: LGTM: Updated Checkboxes component props

The addition of the color prop to the Checkboxes component and the reordering of props are consistent with the CheckboxesProps interface changes. This update aligns well with the PR objectives for enhanced styling flexibility.


235-242: LGTM: Consistent color prop usage

The color prop is now correctly passed to the FilterOption and Reset components. This change ensures consistent color theming throughout the component hierarchy, aligning well with the PR objectives for enhanced styling flexibility.

app/packages/core/src/components/Sidebar/Entries/PathValueEntry.tsx (6)

3-3: Improved import organization

The changes to the import statements are appropriate. Adding formatPrimitive and makePseudoField while removing unused imports enhances code clarity and maintainability.


218-218: Improved type safety in SlicesLengthLoadable

Changing the type parameter from any[] to unknown[] enhances type safety. This modification forces more explicit type checking when working with the data, reducing the risk of runtime errors.


224-224: Consistent type safety improvement in LengthLoadable

The change from any[] to unknown[] in LengthLoadable is consistent with the previous modification. This maintains code consistency and improves overall type safety throughout the component.


229-229: Type safety and strict equality improvements in ListLoadable

  1. Changing the type parameter from any[] to unknown[] continues the trend of improving type safety.
  2. Using strict equality (===) instead of loose equality (==) is a best practice in JavaScript/TypeScript. It avoids unexpected type coercion and makes the code's intent clearer.

Both changes contribute to more robust and maintainable code.

Also applies to: 242-242


344-351: Improved iteration in useSlicesData

The change from a forEach loop to a for...of loop is a good improvement. for...of loops are generally more readable and can be slightly more performant, especially when dealing with large arrays. This change maintains the same functionality while enhancing code quality.


362-362: Simplified formatting in Loadable component

The replacement of the custom format function with formatPrimitive is consistent with the earlier changes mentioned in the summary. This modification simplifies the code and promotes the use of shared utility functions, which can lead to better maintainability and consistency across the codebase.

app/packages/operators/src/built-in-operators.ts (1)

59-63: LGTM: Improved dataset reloading mechanism

The changes to the ReloadDataset class are well-implemented. The new useHooks method and the updated execute method provide a more flexible and controlled way to refresh the dataset. This approach aligns better with React best practices and likely offers a less disruptive user experience compared to the previous implementation.

app/packages/looker/src/elements/common/bubbles.ts (1)

122-124: Check for Consistency in ID Field Handling

In the unwind function, there is a special case handling for _id fields by checking value.id. Ensure that throughout the codebase, the ID fields are consistently named and accessed to prevent any discrepancies between _id and id.

Run the following script to confirm the usage of ID fields:

#!/bin/bash
# Description: Search for instances where 'id' and '_id' are accessed.

# Test: Find all occurrences of 'value.id' and 'value._id'. Expect: Consistent usage of ID fields.
rg --type ts 'value\.(id|_id)'
app/packages/state/src/recoil/lightning.ts (2)

4-4: LGTM

The import of DYNAMIC_EMBEDDED_DOCUMENT_PATH is appropriate and necessary for the new functionality.


162-166: LGTM

The updated condition correctly includes fields with DYNAMIC_EMBEDDED_DOCUMENT_PATH, enhancing support for dynamic embedded documents as intended in the PR objectives.

app/packages/looker/src/elements/common/bubbles.test.ts (2)

254-257: Approved: XSS Prevention Test is Properly Implemented

The test case correctly checks that applyTagValue handles potentially harmful input without executing it, thereby preventing XSS attacks. This is essential for maintaining application security.


238-240: Verify Handling of Non-Existent Paths in getBubbles Function

In the test where getBubbles("test.predictions", TEST_SAMPLE, TEST_SCHEMA) is called, the resultField is expected to be null. Please verify that this is the intended behavior when the path does not exist in the schema and that the function handles such cases gracefully.

Run the following script to confirm that there are no schema entries for the path "test.predictions":

Ensure that $TEST_SCHEMA_JSON contains the serialized TEST_SCHEMA object.

Verification successful

Handling of Non-Existent Paths in getBubbles Function Verified

The path "test.predictions" does not exist in TEST_SCHEMA, confirming that getBubbles("test.predictions", TEST_SAMPLE, TEST_SCHEMA) correctly returns null as intended.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that "test.predictions" does not exist in TEST_SCHEMA

# Test: Search for the path in the schema. Expect: No matches.
echo "$TEST_SCHEMA_JSON" | jq 'paths | select(.[-1]=="predictions")' | grep 'test'

Length of output: 65


Script:

#!/bin/bash
# Description: Verify that the exact path ["test", "predictions"] does not exist in TEST_SCHEMA

# Test: Check for the exact path in TEST_SCHEMA_JSON. Expect no output if the path does not exist.
echo "$TEST_SCHEMA_JSON" | jq 'paths | select(. == ["test", "predictions"])'

Length of output: 61

app/packages/looker/src/elements/common/tags.ts (1)

646-653: ⚠️ Potential issue

Verify usage of updated 'shouldShowLabel' function parameters

The shouldShowLabel function's visibility parameter has been updated to an object with values and exclude properties. Please ensure that all calls to this function have been updated accordingly to prevent potential runtime errors.

Run the following script to verify all calls to shouldShowLabel use the new parameter structure:

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

650-652: Verify the name extraction logic in makePseudoField

The name is constructed by removing the first segment of the path. Ensure that this logic aligns with the expected behavior, especially for path values with varying depths.

If the intention is to exclude the root segment, this approach is correct. Otherwise, consider adjusting the indices used in slice.

app/packages/state/src/recoil/sidebar.ts (6)

1-6: Type-only imports enhance type safety and reduce runtime overhead

Using import type in lines 1-6 improves type safety and ensures that these imports are erased during compilation, preventing any unintended runtime impact. This adheres to TypeScript best practices.


241-241: Good use of flatMap for improved readability

The use of flatMap on line 241 enhances readability by combining mapping and flattening into a single operation, making the code more concise and easier to understand.


267-274: Efficient filtering and mapping of fields

In lines 267-274 and 276-287, the refactored loops use chained filter methods and for...of loops effectively. This enhances the clarity of the filtering conditions and improves maintainability.

Also applies to: 276-287


979-986: Parameter renaming improves code clarity

Renaming parameters in the pullSidebarValue function (lines 979-986) from field to inputField and data to input clarifies their purposes, enhancing the overall readability of the function.


Line range hint 680-734: Consistent handling of disabled paths

The code between lines 680-734 consistently identifies disabled paths for checkboxes and filters based on field types, ensuring unsupported field types are properly managed. This maintains robustness in the sidebar functionality.


770-791: Properly collecting paths for nested fields

Lines 770-791 correctly collect paths for fields with specific types, such as DICT_FIELD and LIST_FIELD, within embedded documents. This ensures that all relevant paths are included for processing.

tests/unittests/server_tests.py Outdated Show resolved Hide resolved
tests/unittests/server_tests.py Show resolved Hide resolved
app/packages/looker/src/elements/common/bubbles.ts Outdated Show resolved Hide resolved
app/packages/looker/src/elements/common/bubbles.ts Outdated Show resolved Hide resolved
app/packages/utilities/src/index.ts Outdated Show resolved Hide resolved
app/packages/utilities/src/index.ts Outdated Show resolved Hide resolved
app/packages/utilities/src/index.ts Show resolved Hide resolved
fiftyone/server/view.py Outdated Show resolved Hide resolved
app/packages/state/src/recoil/sidebar.ts Show resolved Hide resolved
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: 2

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cb4c614 and cf088ad.

Files selected for processing (5)
  • app/packages/looker/src/elements/common/bubbles.test.ts (1 hunks)
  • app/packages/looker/src/elements/common/bubbles.ts (1 hunks)
  • app/packages/utilities/src/index.ts (1 hunks)
  • fiftyone/server/view.py (8 hunks)
  • tests/unittests/server_tests.py (2 hunks)
Files skipped from review as they are similar to previous changes (4)
  • app/packages/looker/src/elements/common/bubbles.test.ts
  • app/packages/looker/src/elements/common/bubbles.ts
  • fiftyone/server/view.py
  • tests/unittests/server_tests.py
Additional context used
Path-based instructions (1)
app/packages/utilities/src/index.ts (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/utilities/src/index.ts Show resolved Hide resolved
app/packages/utilities/src/index.ts Show resolved Hide resolved
Copy link
Contributor

@minhtuev minhtuev left a comment

Choose a reason for hiding this comment

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

Awesome work, thanks Ben!

Copy link
Contributor

@brimoor brimoor left a comment

Choose a reason for hiding this comment

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

LGTM from a functional standpoint (tested it with summary fields as per the PR description) 🚀

@benjaminpkane benjaminpkane merged commit 1b14d08 into develop Sep 25, 2024
13 checks passed
@benjaminpkane benjaminpkane deleted the sidebar-enhancements branch September 25, 2024 13:55
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