A Segment is a subset of a collection gathering filtered records.
Segments are designed for those who want to systematically visualize data according to specific sets of filters. It allows you to save your filters configuration so you don’t have to compute the same actions every day (e.g. signup this week, pending transactions).
Forest Admin provides a straightforward UI to configure the segments you want step-by-step. The only information Forest Admin needs to create a segment within a collection is a name and some filters.
To create a new segment, activate the Layout Editor mode (1) on the top right part of your screen and click on the cog just next to the collection you want to edit (2) and select the Segments tab (3).
At this point there are 2 possibilities:
If you have never created any segment for this collection, click the "Create your first segment" (4).
Otherwise, click the "+ New segment" link (5).
To create your segment, give it a name (6) and add 1 or more filter(s) (7). You can also adjust your sorting field and order like you would for a collection.
Forest Admin gives you a second option to create segment: SQL queries.
SQL queries allow you to create advanced filters and connect your data through a few lines of code if you know how SQL queries work.
Simply switch to Query mode (1), type in your SQL query (2) and save.
QUERYSELECT t.id FROM transactions tJOIN companies beneficiary ON t.beneficiary_company_id = beneficiary.idJOIN companies emitter ON t.emitter_company_id = emitter.idWHERE beneficiary.headquarter ILIKE '%United States%' AND emitter.headquarter ILIKE '%United States%'
In the above example, we display the transactions whose beneficiaries and emitters are in the United States.
Usually, you want the organization of your segments to match the sequencing of your business workflows. To do so, you can reorder your segments using the Layout Editor mode just like you would for collections.