Advanced Filters

From 3B Knowledge
Jump to navigation Jump to search

The V10 release adds advanced filters to the Scheduler filters panel. Unlike the existing checkbox filters, an advanced filter presents one or more input fields (text, dropdown, slider, date, time, address search…) and only applies when the user clicks Execute. Five ready-made filters are included.

What's new for users

  • Advanced filters appear in the filters panel (right drawer) alongside the existing checkbox filters.
  • Fill in the inputs, click Execute — the schedule filters immediately. A Clear button removes the filter again.
  • Active advanced filters get a number badge and participate in the Filter Logic expression (1 AND (2 OR 3)) and header summary pills exactly like checkbox filters.
  • Address inputs use Google address search — start typing and pick a suggestion from the dropdown.

One-time org setup (required for address search only)

Address inputs need a Google Maps API key (Places API enabled):

  1. Setup → Custom SettingsScheduler Settings (b3s__Scheduler__c) → Manage.
  2. Set Google Maps API Key (b3s__Google_Maps_API_Key__c) at org level.

Without the key, filters using address inputs show a warning and cannot be executed. All other input types work without any setup.

Included filters

All five ship as b3s__Scheduling_Filter__mdt records (in unpackaged/customMetadata). Deploy the ones you want; delete or don't deploy the rest.

Filter Record What it does
Workers by Distance Resource_Distance_Filter Enter an address, pick a radius (1/3/5/10/15 km). Shows only workers whose contact MailingLatitude/MailingLongitude falls within the radius.
Shifts by Distance Shift_Distance_Filter Enter an address, drag a distance slider. Shows only shifts whose work site location falls within the radius.
Available After Time Resource_Available_After Enter a time. Shows only workers with no shift and no "Unavailable" employee request overlapping the rest of that day after the entered time.
Available Before Time Resource_Available_Before Same, but for the part of the day before the entered time.
Worker Availability Resource_Availability Pick a day (Today / Tomorrow / the day after — labelled with real dates) and a period: Morning (before 12pm), Day (before 7pm), Night (after 7pm) or Full day. Shows only workers not booked in that window.

Cancelled shifts never count as bookings. The "Unassigned" swimlane is never hidden by resource filters.

Data prerequisites

  • Workers by Distance — the contacts loader must include MailingLatitude and MailingLongitude in fieldToLoad (the shipped contact loaders already do).
  • Shifts by Distance — the shift definition in your Scheduling Context Provider must list the site coordinates in additionalFields:
{ "field": "b3s__Work_Site__r.b3s__Location__Latitude__s" },
{ "field": "b3s__Work_Site__r.b3s__Location__Longitude__s" }

(already present in the shipped Global provider).

  • Availability filters — need shifts and employee requests loaded; a request counts as a booking when b3s__Type__c = "Unavailable".

Availability is evaluated against events currently loaded in the scheduler's date range, in the browser's local timezone.

Building your own advanced filter

Create a b3s__Scheduling_Filter__mdt record. The Javascript_Code__c field holds a JS object — same as checkbox filters, but with inputs instead of items:

{
    name: "my_filter",                 // unique
    label: "My Filter",                // panel heading
    type: 'resource',                  // 'resource' filters workers, 'shift' filters events
    inputs: [
        { name: "query", type: "text", label: "Contains", required: true },
        { name: "site",  type: "select", label: "Site", default: "a",
          options: [ { label: "Site A", value: "a" }, { label: "Site B", value: "b" } ] }
    ],
    matchesItems: function(object, items) {
        const values = items[0] ?? {};   // { query: "...", site: "a" }
        // return true to keep the object visible, false to hide it
        return true;
    }
}

When the user clicks Execute, all input values are collected into a single object and passed to matchesItems as items[0], keyed by input name.

Input types

type Renders Value in matchesItems
text text box string
select dropdown (options) option value (string) — use Number(...) if numeric
multiselect checkbox list (options) array of option values
range slider with options: the selected option's value; or numeric with min/max/step/unit
date native date picker "YYYY-MM-DD"
time native time picker "HH:MM"
address Google address search { label, lat, lng }

Common input properties: name, type, label, required, placeholder, default, options ([{ label, value }]).

Tips

  • Your snippet is evaluated with the same closure variables as checkbox filters: events, screenEvents, resources, screenReources, viewName.
  • required inputs are validated on Execute; an address input must be picked from the Google suggestions (typing alone carries no coordinates).
  • Dynamic options (e.g. date labels) can be computed with an IIFE — see the day input in Scheduling_Filter.Resource_Availability for an example.
  • Order__c controls panel position; the shipped filters use 6–10.