Skip to content

Root: ui|v2.5|src|components|Galleries: GallerySelect.tsx

Serechops edited this page Apr 9, 2024 · 1 revision

GallerySelect.tsx

Contains React components for selecting galleries using React Select.

  1. Imports: The file imports various modules and components from React, react-select, classnames, and other custom modules within the project.

  2. Type Definitions:

    • Gallery: This type defines the structure of a gallery object, including its id, title, files, and folder.
    • Option: This type defines the structure of an option for the select component, which includes the value and object properties.
  3. Component Props:

    • ExtraGalleryProps: This interface defines additional props that can be passed to the gallery select components, such as hoverPlacement, excludeIds, and extraCriteria.
  4. _GallerySelect:

    • This component is responsible for rendering a select component for galleries. It includes functionality to load galleries based on user input, display options with their titles and paths, and handle multi-value selection.
    • It uses FilterSelectComponent from ../Shared/FilterSelect to render the select component.
    • Inside this component, there are three nested components: GalleryOption, GalleryMultiValueLabel, and GalleryValueLabel, responsible for rendering options, multi-value labels, and single value labels respectively.
  5. _GalleryIDSelect:

    • This component extends _GallerySelect and adds functionality to load galleries by their IDs.
    • It maintains the selected galleries' state and updates it when the IDs change.
  6. getExcludeFilebaseGalleriesFilter:

    • This function creates a criterion for excluding file-based galleries. It returns a PathCriterion with the modifier set to IsNull.
  7. excludeFileBasedGalleries:

    • This is an array containing a single criterion returned by getExcludeFilebaseGalleriesFilter. It's used to exclude file-based galleries when filtering.

Example usage:

import { GallerySelect } from "./GallerySelect";

// Inside a React component
<GallerySelect 
  isMulti={true} 
  excludeIds={["gallery1", "gallery2"]} 
  extraCriteria={[...]}
  onSelect={(selectedGalleries) => console.log(selectedGalleries)}
/>

Explanation:

This example renders a multi-select gallery component, excluding galleries with IDs "gallery1" and "gallery2", and applying additional criteria specified in extraCriteria. When galleries are selected, their details will be logged to the console.

Clone this wiki locally