Skip to content

DataView: don't offer select/multiselect filters with empty filterOptions #849

Description

@ravisuhag

Summary

DataView offers select / multiselect filters in the "add filter" menu even when the field's filterOptions is empty. Picking one seeds a chip that has no value and nothing to choose from — a dead control the user can't complete or use.

This is common when filter options are loaded async (e.g. a "Status" or "Owner" facet whose options arrive from the server after first paint): for a moment the field is filterable: true but has zero options, and the menu still lists it.

Where it happens

components/data-view-beta/components/filters.tsx

  • filterableFields only checks filterable (line ~105):
    const filterableFields = fields?.filter(f => f.filterable) ?? [];
  • availableFilters only removes already-applied fields (line ~40):
    const availableFilters = fieldList?.filter(
      f => !appliedFiltersSet.has(f.accessorKey)
    );

Neither step checks whether a select / multiselect field actually has options.

components/data-view-beta/hooks/useFilters.tsxonAddFilter then seeds the value from the (empty) options (line ~22):

const options = field.filterOptions || [];
...
: filterType === FilterType.select
  ? options[0]?.value        // undefined when filterOptions is empty

So the resulting filter is { _type: 'select', value: undefined, ... } — an unpickable chip.

Request

Exclude select / multiselect fields with no filterOptions from the available-filters list, so an unusable filter is never offered. Roughly:

const isSelect =
  field.filterType === 'select' || field.filterType === 'multiselect';
const hasOptions = Boolean(field.filterOptions?.length);
// keep the field only if it's not a select, or it's a select WITH options
return !isSelect || hasOptions;

Non-select filter types (string, number, date) are unaffected — they don't depend on filterOptions.

Workaround

We currently re-implement the add-filter menu (also needed for the align gap in #848) and apply this same guard client-side before offering a field. Folding the options check into Apsara's own available-filters logic would let consumers drop the guard.

Willing to contribute

Happy to open a PR if the approach looks right.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions