Before extracting insights, we need to define what data we want to query. A Query Maker allows users to filter data dynamically - like a barista checking orders by status to see which drinks to make next. Let's enhance our Slice to support flexible queries with search parameters.
First, let's update the Slice to accept status filters. The .search() method defines query parameters that users can set from the frontend:
Let's understand the key components of this Slice definition:
🔍.search()
Defines a searchable parameter that can be set from the frontend. Here, "statuses" accepts an array of IcecreamOrderStatus values to filter orders.
⚡inWaiting / inPickup
Pre-defined slices with fixed status filters. inWaiting shows active and processing orders, while inPickup shows orders ready for customer pickup.
Add dictionary entries for the slice and its search parameter to enable localization:
Now let's create a UI component that allows users to select which statuses to filter by. This Query Maker component uses the auto-generated store hooks:
Key features of the Query Maker component:
🎣st.use.queryArgsOfIcecreamOrderInPublic(): Auto-generated hook that reads the current query arguments from the store. Returns the statuses array.
📝st.do.setQueryArgsOfIcecreamOrderInPublic(): Updates the query arguments in the store, which automatically triggers a re-fetch of the filtered data.
Finally, add the Query Maker to your page so users can filter orders dynamically: