OverviewEngine preset filters - apply filter on mount

Hi,

I am implementing a preset filter on OverviewEngine, just like described here, but to apply it, it is always necessary to click on it and click “apply”.

Is it possible to “apply” the filter directly, on mount?

I already tried to reproduce the default behavior of the OverviewEngine by triggering OverviewEngineActions.documentMultiSelectionClear and OverviewEngineActions.queryParametersChanged on mount, to apply the filter, but it doesn’t seem to work.

The code looks like this (simplified):

const presetFilter: OverviewEngineApi.FilterMap = {
  "root.manufacturer": {
    filterType: "String",
    criteria: {
      value: "blabla",
    },
    nonRemovable: false,
  },
};

export const CustomOverview = (props: View) => {
  const [activeFilters, setActiveFilters] = useState<OverviewEngineApi.FilterMap>(presetFilter);

  return (
    <ViewViews.OverviewEngineView
      {...props}
      fieldBasedFiltering={{ activeFilters }}
      ...
    />
  );
}

You could try to set the respective filter state in the activity when it is first created.
The data loading should then pick it up and apply the filter setting already on the first load.

Thanks for the answer.

Could you describe this a bit more specifically?
I don’t completely get where I would do that in the code. Is it in the appmodel.json file or somewhere in a middleware or similar?

The activity is either created on menu item click, i.e. by the client library itself, or via your own custom code.
In the first case you have to decide whether you want to keep that creation logic in the client code or not. If so, you would have to add a middleware that intercepts the ActivityActions.push action and modifies the activity within its payload.
Otherwise, if you move the activity creation to your custom code, you can adapt the activity data structure there.

The filter, sorting & paging settings for the overview engine are kept in a slice of the default data holder of the activity. The name of that slice is “list”.
The list slice looks as follows: OverviewEngineState

You can directly put this list slice into your activity in the way that you need, i.e. with the preset filters specified, upon activity creation or intercept & adapt it accordingly in a middleware. This modified activity can then be created using the push action.

However:
Unfortunately, this “list” key for the slice is not public. In other words, it could be changed in the future without resulting in a breaking change notice.

You can now either just accept it or instead of specifying/coding the list slice directly, you could apply the [overview engine state data reducers] on the default data holder of the activity with actions that would set the filters according to your needs (you mentioned those action yourself already).
This second option would be more robust since you would only use public API.