In this module, you will learn how to:
- Filter a view by
excludepattern - Filter a view by
includepattern - Disable filter
⌛ Estimated time to complete: 10 min
Most of the time, you want your view to contain everything that matters. You do this by specifying the include * field, where Structurizr does all the heavy lifting for you. You can also explicitly list what you want (not very sustainable in most cases), or use predicates. Those techniques are beyond this course but documented there. Another common way to achieve the same goal is to leverage the built-in filtered view. Let's see how it works.
Assuming you do have a view you would like to filter, just start typing filtered and let Cornifer guide you:
filtered "baseview_name" include|exclude "tags" "name" "description"
Start by specifying the view you would like to filter, the strategy include|exclude and the tag(s) which will serve to match the strategy against.
✏️ Create a filtered view from Container one, taking all but stuff tagged with #web.
📙 REVEAL THE ANSWER
views {
container mila "Container" "" {
include *
}
+ filtered "Container" exclude "#web" "Container-mobile-filter" ""
}✏️ Create a filtered view from Container one, taking all that is tagged with either Person, Relationship, #mobile or #web.
📙 REVEAL THE ANSWER
views {
container mila "Container" "" {
include *
}
+ filtered "Container" include "Person, Relationship, #mobile, #web" "Container-frontend-filter" ""
}As soon as you introduce a filtered view, the base one is no more part of the resulting views. If you want it back, simply get it back by introducing a matching filter eg exclude "":
✏️ Create a non filtered view from Container one.
📙 REVEAL THE ANSWER
views {
container mila "Container" "" {
include *
}
+ filtered "Container" exclude "" "Container-full" ""
}You may have noticed how layout is shared among views, which may seem strange, but prove to be very powerful for effective diff spoting.
📘 Completing this stage should lead to this final workspace.
Filtering complex software model is an easy task with built-in filtered views, and serve many purposes:
- Comparing option A and option B
- Tracing evolution between version 1 and version 2
- Focusing on a dedicated aspect like frontend or backend
- ...
Another great tool exists to vary viewpoints, and it is all about next stage is.