SoftwareBrothers / adminjs-mongoose

Mongoose adapter for AdminJS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

List action returns both records with status Active and Inactive when search only for Active

geekyayush opened this issue · comments

I have a number of records in my collection; some have "Active" in status property and others have "Inactive".

In AdminJS frontend, when I filter status field to show me only "Active" status records, it returns both Active and Inactive. For Inactive status filter, it works fine.

I believe the reason could be in file "src/utils/convert-filter.ts", line number 19.
Link; https://github.com/SoftwareBrothers/adminjs-mongoose/blob/master/src/utils/convert-filter.ts#L19

It's searching a property using regex, which returns both Active and Inactive since both values contain "Active".

Is there any workaround we can do to make sure only either Active or Inactive records get returned by the list action?

You can use symbols such as ^ and $ while regex matching.

^ asserts position at start of a line
$ asserts position at the end of a line

so the final pattern becomes: ^Active$

Here is the playground: https://regex101.com/r/QUhCxQ/1