refactor: decouple zustand from filter store#4625
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
|
Claude finished @devinat1's task —— View job PR Review: Decouple Zustand from Filter StoreTodo List:
SummaryThis PR successfully refactors the filter store to decouple it from Zustand, making it testable and more modular. However, there is one critical type safety issue that should be addressed before merging.
|
There was a problem hiding this comment.
Greptile Summary
This pull request refactors the filter store architecture to improve testability by decoupling it from Zustand's state management. The main change extracts the core store logic into a reusable buildFilterStore function that accepts generic set and get functions, enabling the same logic to work with different store implementations.
The refactor introduces a new createFilterStore function that provides a standalone, in-memory store implementation with subscribe/unsubscribe capabilities. This allows the filter store logic to be tested in isolation without requiring React or Zustand dependencies. The existing useFilterStore is updated to use the new buildFilterStore function while maintaining backward compatibility and the same Zustand persistence configuration.
Additionally, the PR adds comprehensive unit tests covering initialization, filter manipulation (adding, removing, updating expressions), state management scenarios, and edge cases. The testing infrastructure is supported by new Jest configuration and dependencies added to package.json.
The filter store manages complex filter expressions used throughout the Helicone application for data filtering. This refactor follows dependency injection patterns, making the codebase more modular and maintainable while enabling better test coverage for the critical filtering functionality.
Confidence score: 3/5
- This PR requires careful review due to a potential type safety issue in the recursive function call
- Score lowered due to unsafe type assertion
(get() as any)inremoveFilterExpressionthat could cause runtime errors - Pay close attention to the type assertion in
web/filterAST/store/filterStore.tsat line 259
4 files reviewed, 3 comments
| moduleNameMapper: { | ||
| "^@/(.*)$": "<rootDir>/$1", | ||
| }, | ||
| testMatch: ["**/__tests__/**/*.test.(ts|tsx|js)"], |
There was a problem hiding this comment.
style: Test pattern excludes .jsx files but includes them in moduleFileExtensions - consider adding **/__tests__/**/*.test.jsx if JSX tests are needed
|
|
||
| // If parent has no children, remove it too (unless it's the root) | ||
| if (current.expressions.length === 0 && parentPath.length > 0) { | ||
| (get() as any).removeFilterExpression(parentPath); |
There was a problem hiding this comment.
logic: Using (get() as any) bypasses TypeScript's type checking and could cause runtime errors. The recursive call should be typed properly or restructured to avoid the type assertion.
| (get() as any).removeFilterExpression(parentPath); | |
| removeFilterExpression(parentPath); |
|
peak " |
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
This pull request introduces unit tests for the
filterStorelogic, refactors the store to support both Zustand and standalone usage.Refactored
filterStore.tsto extract store logic into a reusablebuildFilterStorefunction, allowing both Zustand and standalone in-memory store creation viacreateFilterStore. This enables easier testing and future extensibility. [1] [2]Improved type safety and code clarity by adding explicit types to store actions and internal variables, and cleaning up navigation logic for filter expression manipulation. [1] [2] [3] [4] [5] [6]
Introduced unit tests for the filter store in
web/filterAST/store/__tests__/filterStore.test.ts, covering initialization, filter manipulation, and state management scenarios.