Skip to content

Simplify years dropdown to static range instead of dynamic query #94

@davidharting

Description

@davidharting

Problem

The years dropdown on the media index page is populated by LogbookQuery->years(), which returns years where items have "finished" events. This creates issues:

  1. Incorrect years for backlog list - The backlog filters by media.created_at, but the dropdown shows years from finished events. If you added something to your backlog in 2015 but never finished anything that year, you can't filter to see it.

  2. No year support for in-progress - Filters are disabled entirely for in-progress items.

  3. Not responsive to type filter - If filtering by "book", the years dropdown still shows all years, not just years with books.

Current behavior

// MediaIndexController.php
private function years(): array
{
    return (new LogbookQuery)->years();
}

This queries:

SELECT DISTINCT EXTRACT(year FROM media_events.occurred_at) 
FROM media_event_types 
JOIN media_events ON ...
WHERE media_event_types.name = 'finished'

Proposed solution

Replace the dynamic query with a static year range:

  1. Determine a start year (either hardcoded like 2018 or MIN(created_at) from media table)
  2. Generate range from start year to current year
  3. Use this same list for all lists (finished, backlog, in-progress)

Benefits

  • Simpler code - remove years() method from LogbookQuery
  • Consistent behavior across all list types
  • No per-request database query for years
  • Works correctly regardless of which list or type filter is active

Trade-off

  • Users might select a year with no results (shows "No items" - acceptable UX)

Files involved

  • app/Http/Controllers/MediaIndexController.php - years() method
  • app/Queries/Media/LogbookQuery.php - can remove years() method after

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions