Skip to content

refactor: consolidate shared types and extract constants#3

Open
ashkanrdn wants to merge 1 commit intofix/dead-code-and-bugsfrom
refactor/type-consolidation
Open

refactor: consolidate shared types and extract constants#3
ashkanrdn wants to merge 1 commit intofix/dead-code-and-bugsfrom
refactor/type-consolidation

Conversation

@ashkanrdn
Copy link
Owner

@ashkanrdn ashkanrdn commented Feb 21, 2026

Summary

  • Add app/types/map.ts with canonical EnhancedFeature interface (was duplicated in 3 files)
  • Add lib/constants/mapConfig.ts with named constants (LOAD_DELAY_MS, FLY_TO_ZOOM, TRANSITION_DURATION_MS, UNSELECTED_COUNTY_COLOR, MAP_BOUNDS, MIN_ZOOM)
  • Add lib/constants/dataDescriptions.ts — moved from 34 inline lines in MapStory.tsx
  • Update MapStory.tsx, dataProcessor.worker.ts, MapTooltip.tsx to import from canonical locations

Test plan

  • npm run build passes with no TypeScript errors
  • Load /map — map renders counties with colors
  • Hover tooltips appear
  • Metric buttons switch displayed data

🤖 Generated with Claude Code

Summary by Sourcery

Consolidate shared map-related types and configuration into reusable modules and update consumers to import from these canonical sources.

Enhancements:

  • Introduce a shared EnhancedFeature GeoJSON interface under app/types for reuse across map components and workers.
  • Extract map configuration values such as zoom levels, delays, transition durations, unselected county color, and bounds into lib/constants/mapConfig.
  • Move static data source and metric descriptions from MapStory into lib/constants/dataDescriptions for centralized reuse.

- Add app/types/map.ts with canonical EnhancedFeature interface
- Add lib/constants/mapConfig.ts (LOAD_DELAY_MS, FLY_TO_ZOOM, TRANSITION_DURATION_MS, UNSELECTED_COUNTY_COLOR, MAP_BOUNDS, MIN_ZOOM)
- Add lib/constants/dataDescriptions.ts with data source descriptions
- Remove duplicate EnhancedFeature definitions from MapStory, worker, MapTooltip
- Replace inline magic numbers in MapStory with named constants
- Move inline dataDescriptions from MapStory to lib/constants

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Feb 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
casi-2 Error Error Feb 21, 2026 7:01pm

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 21, 2026

Reviewer's Guide

Refactors map-related code by introducing shared types and configuration constants, moving previously duplicated interfaces and inline literals into dedicated modules, and updating map components to import from these canonical sources.

Class diagram for shared map types and configuration constants

classDiagram
    class Feature {
    }

    class EnhancedFeature {
        +properties name string
        +properties metricKey any
        +properties rawValue number
        +properties perCapitaValue number
        +properties rowCount number
        +properties totalCostValue number
        +properties avgCostPerPrisonerValue number
    }

    Feature <|-- EnhancedFeature

    class mapConfig {
        <<module>>
        +LOAD_DELAY_MS number
        +FLY_TO_ZOOM number
        +TRANSITION_DURATION_MS number
        +UNSELECTED_COUNTY_COLOR number[4]
        +MAP_BOUNDS number[2][2]
        +MIN_ZOOM number
    }

    class dataDescriptionsModule {
        <<module>>
        +dataDescriptions arrest
        +dataDescriptions county_prison
        +dataDescriptions jail
    }

    class dataDescriptions_arrest {
        +name string
        +description string
        +metrics_Arrest_rate string
        +metrics_Total_Arrests string
    }

    class dataDescriptions_county_prison {
        +name string
        +description string
        +metrics_Imprisonments string
        +metrics_Cost_per_prisoner string
        +metrics_Total_Cost string
    }

    class dataDescriptions_jail {
        +name string
        +description string
        +metrics_ADPtotrate string
        +metrics_ADPtotal string
        +metrics_Felony string
        +metrics_Misd string
        +metrics_Postdisp string
        +metrics_Predisp string
    }

    dataDescriptionsModule --> dataDescriptions_arrest
    dataDescriptionsModule --> dataDescriptions_county_prison
    dataDescriptionsModule --> dataDescriptions_jail
Loading

File-Level Changes

Change Details Files
Introduce a canonical EnhancedFeature type for map-related GeoJSON features and use it across components.
  • Create app/types/map.ts exporting the EnhancedFeature interface extending GeoJSON Feature with typed properties for map metrics.
  • Remove locally-declared EnhancedFeature interfaces from MapStory and MapTooltip.
  • Update MapStory and MapTooltip to import EnhancedFeature from the shared types module.
app/types/map.ts
app/components/widgets/MapStory.tsx
app/components/widgets/map/MapTooltip.tsx
Extract map configuration values into a reusable constants module and wire it into MapStory.
  • Create lib/constants/mapConfig.ts containing shared map configuration constants such as load delay, fly-to zoom level, transition duration, unselected county color, map bounds, and minimum zoom.
  • Remove inline MAP_BOUNDS and MIN_ZOOM declarations from MapStory in favor of imports.
  • Replace hard-coded numeric values for loading delay, fly-to zoom, transition duration, and unselected county color in MapStory with the corresponding imported constants.
lib/constants/mapConfig.ts
app/components/widgets/MapStory.tsx
Move static data source descriptions into a dedicated constants file and import them into MapStory.
  • Create lib/constants/dataDescriptions.ts exporting the dataDescriptions object that documents data sources and metric descriptions.
  • Remove the inline dataDescriptions object from MapStory and import it from the new constants module instead.
lib/constants/dataDescriptions.ts
app/components/widgets/MapStory.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The MAP_BOUNDS values in mapConfig look reversed (minLongitude is -117.59 and maxLongitude is -120.99); consider swapping or renaming to avoid incorrect bounding behavior and confusion.
  • EnhancedFeature.properties uses an index signature with any; consider tightening this to unknown or a more specific union and/or splitting computed properties into a separate typed sub-object to catch more type issues at compile time.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The MAP_BOUNDS values in mapConfig look reversed (minLongitude is -117.59 and maxLongitude is -120.99); consider swapping or renaming to avoid incorrect bounding behavior and confusion.
- EnhancedFeature.properties uses an index signature with `any`; consider tightening this to `unknown` or a more specific union and/or splitting computed properties into a separate typed sub-object to catch more type issues at compile time.

## Individual Comments

### Comment 1
<location> `lib/constants/mapConfig.ts:17-19` </location>
<code_context>
+ * Geographic bounds constraining map panning (roughly California).
+ * [ [minLongitude, minLatitude], [maxLongitude, maxLatitude] ]
+ */
+export const MAP_BOUNDS: [[number, number], [number, number]] = [
+    [-117.595944, 33.386416], // Southwest corner
+    [-120.999866, 42.183974], // Northeast corner
+];
+
</code_context>

<issue_to_address>
**issue (bug_risk):** MAP_BOUNDS longitudes appear reversed (west > east), which may break consumers expecting [west, south], [east, north].

These bounds are `[-117.595944, 33.386416]` to `[-120.999866, 42.183974]`. Since -120.999866 < -117.595944, this encodes `[east, south]``[west, north]` instead of `[west, south]``[east, north]`. Many mapping APIs (Mapbox, deck.gl) assume west < east and may fail or behave oddly with reversed longitudes, especially now that this constant is shared. If this isn’t intentional, please swap the longitudes and align the comments with the correct convention.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +17 to +19
export const MAP_BOUNDS: [[number, number], [number, number]] = [
[-117.595944, 33.386416], // Southwest corner
[-120.999866, 42.183974], // Northeast corner
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): MAP_BOUNDS longitudes appear reversed (west > east), which may break consumers expecting [west, south], [east, north].

These bounds are [-117.595944, 33.386416] to [-120.999866, 42.183974]. Since -120.999866 < -117.595944, this encodes [east, south][west, north] instead of [west, south][east, north]. Many mapping APIs (Mapbox, deck.gl) assume west < east and may fail or behave oddly with reversed longitudes, especially now that this constant is shared. If this isn’t intentional, please swap the longitudes and align the comments with the correct convention.

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.

1 participant