Use user-defined segment in a plugin

Feature(s) impacted

Using the FA API with segments inside a plugin.

Observed behavior

I have segments defined both in the backend and in the front-end.
However, only segments created on the backend via addSegment calls on CollectionCustomizer seem to work.

Sample code:

async function myPlugin(
  dataSourceCustomizer: DataSourceCustomizer,
  ...
) {
  const dataSource = await dataSourceCustomizer.getDataSource(someLogger)
  const results = await dataSource.getCollection(someCollectionName).list(
    someCaller,
    new PaginatedFilter({
      segment: 'My front-end defined segment',
    }),
    myProjection,
  )
  // ...
}

The above code will simply query the collection, without any use of the segment.

Expected behavior

I would like to be able to use both kinds of segments in calls to Collection.list.

Failure Logs

N/A, if the segment is not found then the API simply ignores it.

Context

  • Agent technology: nodejs
  • Agent (forest package) name & version: 1.50.1 with sequelize 6.37.4
  • Database type: MSSQL

Hello @kll,

Sadly this is not possible as segment defined in the frontend are only present and defined in the layout of the team in which they have been created. They are not propagated to the agent.

What would be the use case of your plugin ? We may be able to find another solution :slight_smile:

Happy to help,

Hi @dogan.ay,

That’s too bad. I wanted to use user-defined segments coupled with some light configuration to allow for notifications to be sent when entities enter some segments.

For example: when a customer enters the “newly upgraded” segment, send a notification to our Teams channel.

This would have allowed me to use user-defined segments as filters, offloading the task to Forest users.

Using Forest for notifications would be so much simpler than using my backend, for compliance and reliability reasons. I hoped to use segments as a way to kickstart the process.

I’m not sure I’ve fully grasped your needs, what is the “newly upgraded” segment (frontend defined or via code inside the agent) ?

Are you exposing the UI to customers and would like to monitor the usage of segments (both types) ?

I am also noting that you are interested in a way to notify your team via the agents, I’ll forward that to our product team :wink:

In any case, the frontend is sending the segmentName query param to the agent when the user is viewing the records via a segment (be it frontend defined or via code), the only limitation is that when the segment is defined on the frontend, the call will contain both filters defining the segment and any additional filter the user may apply, making it a bit blurry if you want to fetch the exact definition of the filters for a segment defined in the frontend.

Ah, it was just a random example. I could want to send notifications on recent new records, records that had a state flag changing (PendingReview becoming true for example), or other criteria. Ideally, these criteria would be defined on the front-end.

No this would be an internal plugin, unplanned for release, and without any UI.

Yep so there isn’t a right way to get these segment definitions… I can think of a couple wrong ways but I’d rather not. I might just have to give up on this topic for now.

I could want to send notifications on recent new records, records that had a state flag changing (PendingReview becoming true for example), or other criteria.

It was funny for us to see your topic about sending notifications because the tech team was working on something similar during our last on-site event, you can see the PR on our agent here. Not via the UI sadly as this is a quick project strapped together by the tech team in 1 or 2 days.

I can think of a couple wrong ways but I’d rather not. I might just have to give up on this topic for now.

Sorry that we couldn’t find a solution.

I mean, with your validation features and other workflows, it almost seems surprising that FA doesn’t already allow this kind of internal notification :smiley:
They would pair superbly with inboxes… right now inboxes are just segments, but in a new place. Slap in some notifications and it’s an essential.

It was a long shot anyway.

1 Like