codeledge / ra-tools

React Admin Tools, namely the Prisma Data Adapter
67 stars 19 forks source link

Update extractWhere.ts #50

Closed linsua01 closed 1 year ago

linsua01 commented 2 years ago

Hi, I started working with ra-data-simple-prisma a time ago, it's very cool solution, thank you a lot!

I found an issue with the filter (where), as I been saw, It's is no posible to search for more than 1 column on each text input,

I find a solution, I would love to shere with you, would be great to know what do you think :)

passing a string with separate ',' for each column and ':' for the related fields

const profileFilters = [
  <TextInput key="1" label="Smart Search" source="firstName,lastName,idNumber,user:email" alwaysOn resettable={true}/>
];
const userFilters = [
  <TextInput key="1" label="Smart Search" source="name,email,companies:some:name" alwaysOn />,
];

in the extractWhere.ts

 if (colName.includes(",") || colName.includes(":")) {
        const colsName = colName.split(",");
        auxWhere = colsName.map((colName, i) => {
          const aux = {}
          setObjectProp(aux, colName.replaceAll(':','.'), {
            contains: value,
            mode: options?.filterMode ? options?.filterMode : "insensitive",
          });
          return {...aux}
        });
        setObjectProp(where, 'OR', auxWhere)
        return;
      }
ogroppo commented 2 years ago

Hi Luciano, it's a creative idea indeed, but it would have the following problems:

What I suggest is just to use a private field i.e. <TextInput source="_smart_search" /> the underscore will be ignored, but you can still catch it (with the relevant handler) and do what you want on the server!