I’m not sure if this is a bug or a feature request. Please advise.
Feature(s) impacted
This affects Segments/Smart Segments.
Observed behavior
When inputting data into a Segment or a Smart Segment, the sorting is lost when creating the segment.
Expected behavior
What I assumed would be happening is that the Id’s being passed through to the segment would retain their sorting. (I see from the Forest Admin dashboard you are only allowed to select columns from the table to sort by default.) Using the code below we get an array of Ids that we would like to stay in the same order. The same should apply using a normal Segment through the Forest Dashboard.
const segments: SmartSegmentOptions[] = [
{
name: 'NTUs.',
where: juristicEntity => {
const result = await juristicEntityRepository.Query<JuristicEntity>(`
SELECT "Applications"."JuristicEntityId" as "Id"
FROM "Applications"
WHERE "Applications"."Approved" = TRUE
AND NOT "Applications"."JuristicEntityId" IN (SELECT DISTINCT "FinanceAgreements"."JuristicEntityId"
FROM "FinanceAgreements" WHERE "FinanceAgreements"."Status" IN ('Complete', 'InRepayment'))
group by "Applications"."JuristicEntityId"
order by min("Applications"."ApprovedOn") desc;
`);
const ids = result.map(je => je.Id);
return { Id: { [Op.in]: ids } };
}
}
];
Liana.collection('DbJuristicEntity', {
segments
});
Is it currently possible to have sorting using a custom query for a segment or have I done something incorrectly?
Context
- Project name: Bridgement.1
- Team name: Operations and Software Dev
- Environment name: Production
- Agent type & version: “forest-express-sequelize”: “^8.4.10”,
- Recent changes made on your end if any: N/A