refine icon indicating copy to clipboard operation
refine copied to clipboard

[BUG] Strapi v4 data provider does not working with nested filters $or and $and operator

Open htdangkhoa opened this issue 1 year ago • 4 comments

Describe the bug

image image

Steps To Reproduce

import { generateFilter } from "@refinedev/strapi-v4";

const filters = [
  {
    operator: "or",
    value: [
      {
        field: "affect_global",
        operator: "eq",
        value: true,
      },
      {
        operator: "and",
        value: [
          {
            field: "studio.id",
            operator: "eq",
            value: 2,
          },
          {
            field: "is_primary",
            operator: "eq",
            value: true,
          },
        ],
      },
    ],
  },
];

const query = generateFilter(filters);

Expected behavior

filters[$or][0][affect_global][$eq]=true&filters[$or][1][$and][0][studio][id][$eq]=2&filters[$or][1][$and][1][is_primary][$eq]=true

Screenshot

No response

Desktop

No response

Mobile

No response

Additional Context

No response

htdangkhoa avatar Jan 04 '24 14:01 htdangkhoa

Hello @htdangkhoa thanks for the report. It could be an issue, can you confirm that expected filter example works with Strapi v4?

We are open to contributions for this one.

BatuhanW avatar Jan 10 '24 08:01 BatuhanW

Hi @BatuhanW, I confirm that the expected filter example I gave above is working properly on Strapi v4 Screenshot 2024-01-10 at 21 54 29

htdangkhoa avatar Jan 10 '24 14:01 htdangkhoa

Hey @BatuhanW, I have been working on this. I found out that other contributor had not handled the case when the value of conditional filter could be another conditional filter. So the only way I could think of solving was recursively parsing the filters. However I am having trouble with parse and stringify from "qs" library.

My recursive approach yields expected result of @htdangkhoa, but those functions from "qs" seem to add multiple square braces where not needed.

Here is the screenshot of a new test I added in jest that handles the issue that @htdangkhoa had.

Screenshot 2024-01-14 at 11 56 29 PM

vidurkhanal avatar Jan 15 '24 05:01 vidurkhanal

Hey @vidurkhanal could you try with query-string import? If you create a PR, we can also continue the discussion there, thanks!

BatuhanW avatar Jan 15 '24 11:01 BatuhanW