|
| 1 | +# feat: add string array support to solo object properties |
| 2 | + |
| 3 | +## Project Goals |
| 4 | + |
| 5 | +The goal of this feature is to enhance the filtering capabilities of the `ReactPivot` component by allowing the `solo` prop to accept arrays of strings. This enables multi-value filtering for a given dimension, providing more flexible and powerful data exploration for users. |
| 6 | + |
| 7 | +## Approaches |
| 8 | + |
| 9 | +### Approach 1 - Direct Implementation (Implemented Here) |
| 10 | + |
| 11 | +This approach involves modifying the core logic of the `ReactPivot` component to natively support array values in the `solo` prop. |
| 12 | + |
| 13 | +- **Core Logic Implementation:** |
| 14 | + - A new function, `getFilteredRows`, was introduced to filter the raw data based on the `solo` prop before any calculations are performed. This function iterates through the `solo` object and applies the following logic: |
| 15 | + - If a `solo` property value is an array, the function checks if the row's value for that dimension is present in the array (OR condition). |
| 16 | + - If a `solo` property value is a single string, it performs a direct comparison (existing AND condition). |
| 17 | + - The filtering combines multiple `solo` properties with AND logic. |
| 18 | + - The `setSolo` function was updated to handle array manipulation. When a value is selected: |
| 19 | + - If the existing `solo` value is an array, the new value is added or removed (toggled). |
| 20 | + - If the existing `solo` value is a single value, it's converted to an array when a second value is added. |
| 21 | + |
| 22 | +- **UI Control for Solo Filters:** |
| 23 | + - To make this new functionality user-friendly, a new component, `SoloControl`, was created. |
| 24 | + - This new component provides a user interface for managing the `solo` filters. It displays each active filter and allows users to: |
| 25 | + - **Add values:** A dropdown menu for each dimension shows the unique values from the dataset, allowing users to add them to the filter. |
| 26 | + - **Remove values:** Each selected value in a filter can be individually removed. |
| 27 | + - **Remove filters:** The entire filter for a dimension can be removed. |
| 28 | + - The `SoloControl` component is rendered in the main `ReactPivot` component, and it communicates changes back to the parent component through the `onChange` prop. |
| 29 | + |
| 30 | +- **Unique Value Extraction:** |
| 31 | + - To populate the dropdowns in the `SoloControl` component, a `getUniqueValues` function was added to `index.jsx`. |
| 32 | + - This function iterates through the dataset and extracts all unique values for each dimension, which are then passed to the `SoloControl` component. |
| 33 | + |
| 34 | +#### Pros |
| 35 | + |
| 36 | +- **Integrated Solution:** The feature is built directly into the component, providing a seamless experience for the user. |
| 37 | +- **High Performance:** Filtering is done in memory, and the `getFilteredRows` function is optimized for performance. |
| 38 | +- **Good User Experience:** The `SoloControl` component provides an intuitive way to manage complex filters. |
| 39 | + |
| 40 | +#### Cons |
| 41 | + |
| 42 | +- **Increased Complexity:** The core component's logic is now more complex, which could make future maintenance more challenging. |
| 43 | +- **Tightly Coupled:** The filtering logic is tightly coupled with the `ReactPivot` component, making it difficult to reuse in other contexts. |
| 44 | + |
| 45 | +### Approach 2 - Custom Patch Layer |
| 46 | + |
| 47 | +This approach involves creating a custom patch layer that intercepts the `rows` prop and applies the filtering logic before passing the data to the `ReactPivot` component. |
| 48 | + |
| 49 | +- **Patch Layer:** |
| 50 | + - A higher-order component (HOC) would be created to wrap the `ReactPivot` component. |
| 51 | + - This HOC would be responsible for managing the `solo` state and filtering the `rows` prop before passing it to the `ReactPivot` component. |
| 52 | + - The `solo` prop of the `ReactPivot` component would not be used directly. |
| 53 | + |
| 54 | +#### Pros |
| 55 | + |
| 56 | +- **Separation of Concerns:** The filtering logic is decoupled from the `ReactPivot` component, making the code easier to maintain and reason about. |
| 57 | +- **Reusability:** The patch layer could be reused with other components that need similar filtering capabilities. |
| 58 | +- **Less Intrusive:** This approach does not require any changes to the core `ReactPivot` component. |
| 59 | + |
| 60 | +#### Cons |
| 61 | + |
| 62 | +- **Potential for Bugs:** The patch layer could introduce subtle bugs if it's not carefully implemented and tested. |
| 63 | +- **Less Performant:** The patch layer would add an extra layer of processing, which could impact performance, especially with large datasets. |
| 64 | +- **More Complex to Use:** Users would need to understand how to use the patch layer in addition to the `ReactPivot` component. |
| 65 | + |
| 66 | +### Approach 3 - Wrapper Component |
| 67 | + |
| 68 | +This approach involves creating a new wrapper component that encapsulates the `ReactPivot` component and provides the desired filtering functionality. |
| 69 | + |
| 70 | +- **Wrapper Component:** |
| 71 | + - A new component, `FilterableReactPivot`, would be created. |
| 72 | + - This component would render the `ReactPivot` component and provide its own `solo` prop that supports arrays. |
| 73 | + - The `FilterableReactPivot` component would be responsible for managing the `solo` state and filtering the `rows` prop before passing it to the `ReactPivot` component. |
| 74 | + |
| 75 | +#### Pros |
| 76 | + |
| 77 | +- **Clear API:** The `FilterableReactPivot` component would provide a clear and concise API for users who need the filtering functionality. |
| 78 | +- **Good for a library:** This approach is well-suited for a library, as it provides a clean separation between the core component and the new functionality. |
| 79 | +- **Easy to maintain:** The filtering logic is contained within the `FilterableReactPivot` component, making it easy to maintain and update without affecting the core `ReactPivot` component. |
| 80 | + |
| 81 | +#### Cons |
| 82 | + |
| 83 | +- **Code Duplication:** The `FilterableReactPivot` component would duplicate some of the logic from the `ReactPivot` component, which could lead to maintenance issues. |
| 84 | +- **Less Flexible:** The `FilterableReactPivot` component would be less flexible than the patch layer approach, as it would be tightly coupled with the `ReactPivot` component. |
| 85 | +- **Increased Bundle Size:** The `FilterableReactPivot` component would add to the overall bundle size of the application. |
0 commit comments