refinedev / refine

A React Framework for building internal tools, admin panels, dashboards & B2B apps with unmatched flexibility.
https://refine.dev
MIT License
27.72k stars 2.15k forks source link

[FEAT] Supabase Data Provider needs an array_overlap operator #6024

Open jim-knight opened 3 months ago

jim-knight commented 3 months ago

Is your feature request related to a problem? Please describe.

I would like to filter an array column with an array in Supabase, where any row is shown where a value in the column matches at least one selected.

Example: I have 4 rows of data under "Fruits".

I would like to filter with the following:

The returned result should be:

Describe alternatives you've considered

Issue #5922 is similar in that it added the ability to check if an array matches an array with the ina and nina operators but differs based on the ability to match if ANY value in the filtering array matches the column array.

Additional context

Here's a couple of examples of using the Supabse JS client to do the call:

let { data: orders } = await supabaseClient
    .from('orders')
    .select('*')
    .or('fruits.ov.{Apple,Kiwi}');

let { data: orders2 } = await supabaseClient
    .from('orders')
    .select('*')
    .overlaps('fruits', ['Apple', 'Kiwi']);

Describe the thing to improve

I believe we could follow a similar route and add ina_overlap and nina_overlap CrudFilter and map to query.overlaps in Supabase data provider.

jim-knight commented 3 months ago

If I could get assigned to this, I'll give it a shot at getting it included. Thanks in advance!

alicanerdurmaz commented 3 months ago

Hello @jim-knight,

I believe It's okay to add ina_overlap operator but I'm sorry I couldn't quite understand why ina doesn't work for you. It seems exactly what you looking for.

for example: test: https://github.com/refinedev/refine/pull/5922/files#diff-50bbe4ac8d69008dd5bca7c6b83650fcd59684616f14a9e50dbe9299fd79529eR316 mock: https://github.com/issa012/refine/blob/84bf034c7f6df12cfd0837160125cac9f340a19d/packages/supabase/test/getList/index.mock.ts#L1677

we sent this value: ["health", "travel"] with ina:

and we can get the following data

but we can't get this because "health" is not available in the array.

do you also want to get ["travel", "food"]?

jim-knight commented 3 months ago

@alicanerdurmaz Thanks Alican, that's correct. Ideally in my use case the query would include any post that has a tag that matches ANY in the filter vs requiring ALL to match.

Using your example, if we used value: ["health", "travel"] with ina_overlap, it should return the following examples:

Specifically in my use case, we have a table of businesses with categories tied to the industries that they're in. The categories column is an array of strings. Here's a short listing of some of the values: Aerospace, Automotive, Business Services, Consumer Products & Services, Distribution & Logistics, Education, Energy, Food and Beverage, Healthcare.

Let's say business A is in Education and Healthcare, while business B is in Automotive and Education, while business C is in Aerospace.

When filtering for ['Education', 'Healthcare'], businesses A and B should be included because they match at least one of the values in the filter. The user might be looking for businesses in specific industries but they don't necessarily need to be a perfect match.

I hope that helps with what I'm looking for.

alicanerdurmaz commented 3 months ago

@jim-knight Thanks for excellent explanation. I assigned issue to you. ๐Ÿ™

jim-knight commented 3 months ago

@alicanerdurmaz Perfect. Thanks, Alican! I'll get to work on it sometime this week.

jim-knight commented 3 months ago

@alicanerdurmaz Unfortunately I don't think I'll be able to continue working on this issue. I've been struggling to get the environment set up on my Windows based machine and seem to run into a number of install errors via git bash, or powershell. I've got the main 6 files updated but can't commit due to failing on the install and not being able to run lint-staged.

BatuhanW commented 3 months ago

@jim-knight sorry to hear about your issue. Could you provide more information on your errors? Would be nice to provide any error you encountered.

jim-knight commented 3 months ago

@BatuhanW

Sure thing, so running with Powershell didn't work just because it didn't like the syntax of the devPreinstall command from package.json, which was expected.

Next up, I tried Git Bash and running just the direct install command but got the following message:

$ pnpm install
Scope: all 240 workspace projects
. pnpm:devPreinstall$ powershell -Command "New-Item -ItemType Directory -Force -Path 'packages/cli/dist','packages/devtoโ€ฆ
โ”‚     Directory: F:\Dev projects\Supabase testing\Refine-6024\packages\cli
โ”‚ Mode                 LastWriteTime         Length Name                                                                โ€ฆ
โ”‚ ----                 -------------         ------ ----                                                                โ€ฆ
โ”‚ d-----         6/15/2024  11:54 AM                dist                                                                โ€ฆ  
โ”‚     Directory: F:\Dev projects\Supabase testing\Refine-6024\packages\devtools-server
โ”‚ Mode                 LastWriteTime         Length Name                                                                โ€ฆ  
โ”‚ ----                 -------------         ------ ----                                                                โ€ฆ  
โ”‚ d-----         6/15/2024  11:54 AM                dist                                                                โ€ฆ  
โ””โ”€ Done in 345ms

   โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
   โ”‚                                                                 โ”‚
   โ”‚                Update available! 9.3.0 โ†’ 9.4.0.                 โ”‚
   โ”‚   Changelog: https://github.com/pnpm/pnpm/releases/tag/v9.4.0   โ”‚
   โ”‚         Run a script from: https://pnpm.io/installation         โ”‚
   โ”‚                                                                 โ”‚
   โ”‚        Follow @pnpmjs for updates: https://x.com/pnpmjs         โ”‚
   โ”‚                                                                 โ”‚
   โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Lockfile is up to date, resolution step is skipped
Packages: -145
-------------------------------------------------------------------------------------------------------------------------
โ€‰WARNโ€‰ Failed to create bin at F:\Dev projects\Supabase testing\Refine-6024\packages\devtools\node_modules\.bin\refine-devtools. ENOENT: no such file or directory, stat 'F:\Dev projects\Supabase testing\Refine-6024\packages\devtools\node_modules\@refinedev\devtools-server\dist\cli.cjs.EXE'
โ€‰WARNโ€‰ Failed to create bin at F:\Dev projects\Supabase testing\Refine-6024\packages\cli\node_modules\.bin\refine-devtools. ENOENT: no such file or directory, stat 'F:\Dev projects\Supabase testing\Refine-6024\packages\cli\node_modules\@refinedev\devtools-server\dist\cli.cjs.EXE'
Progress: resolved 0, reused 124, downloaded 0, added 0, done
โ€‰WARNโ€‰ Failed to create bin at F:\Dev projects\Supabase testing\Refine-6024\packages\devtools\node_modules\.bin\refine-devtools. ENOENT: no such file or directory, stat 'F:\Dev projects\Supabase testing\Refine-6024\packages\devtools\node_modules\@refinedev\devtools-server\dist\cli.cjs.EXE'
โ€‰WARNโ€‰ Failed to create bin at F:\Dev projects\Supabase testing\Refine-6024\packages\cli\node_modules\.bin\refine-devtools. ENOENT: no such file or directory, stat 'F:\Dev projects\Supabase testing\Refine-6024\packages\cli\node_modules\@refinedev\devtools-server\dist\cli.cjs.EXE'
packages/create-refine-app prepare$ pnpm -w build --scope create-refine-app
[86 lines collapsed]                                                                                                       
โ”‚ @refinedev/core: CJS dist\index.cjs.map 746.61 KB
โ”‚ @refinedev/core: CJS โšก๏ธ Build success in 2245ms
โ”‚ @refinedev/core: ESM dist\index.mjs     141.37 KB
โ”‚ @refinedev/core: ESM dist\index.mjs.map 738.88 KB
โ”‚ @refinedev/core: ESM โšก๏ธ Build success in 2248ms
โ”‚ @refinedev/core: Generating declarations...
โ”‚ @refinedev/core: Generating d.mts and d.cts files...
โ”‚ @refinedev/core: โœ“ Declarations are generated.
โ”‚  Lerna (powered by Nx)   Successfully ran target build for 2 projects and 2 tasks they depend on
โ”‚ Nx read the output from the cache instead of running the command for 1 out of 4 tasks.
โ””โ”€ Done in 2m 2.1s
packages/devtools-shared prepare$ pnpm -w build --scope @refinedev/devtools-shared
[65 lines collapsed]                                                                                                       
โ”‚ CJS dist\index.cjs.map 746.61 KB
โ”‚ CJS โšก๏ธ Build success in 2245ms
โ”‚ ESM dist\index.mjs     141.37 KB
โ”‚ ESM dist\index.mjs.map 738.88 KB
โ”‚ ESM โšก๏ธ Build success in 2248ms
โ”‚ Generating declarations...
โ”‚ Generating d.mts and d.cts files...
โ”‚ โœ“ Declarations are generated.
โ”‚  Lerna (powered by Nx)   Successfully ran target build for 2 projects and 1 task they depend on
โ”‚ Nx read the output from the cache instead of running the command for 3 out of 3 tasks.
โ””โ”€ Done in 1m 19.6s
. prepare$ husky install
โ”‚ husky - Git hooks installed
โ””โ”€ Done in 282ms
packages/devtools-internal prepare$ pnpm -w build --scope @refinedev/devtools-internal
[65 lines collapsed]                                                                                                       
โ”‚ CJS dist\index.cjs.map 746.61 KB
โ”‚ CJS โšก๏ธ Build success in 2245ms
โ”‚ ESM dist\index.mjs     141.37 KB
โ”‚ ESM dist\index.mjs.map 738.88 KB
โ”‚ ESM โšก๏ธ Build success in 2248ms
โ”‚ Generating declarations...
โ”‚ Generating d.mts and d.cts files...
โ”‚ โœ“ Declarations are generated.
โ”‚  Lerna (powered by Nx)   Successfully ran target build for 2 projects and 1 task they depend on
โ”‚ Nx read the output from the cache instead of running the command for 3 out of 3 tasks.
โ””โ”€ Done in 10.1s
packages/devtools-ui prepare$ pnpm -w build --scope @refinedev/devtools-ui
[89 lines collapsed]                                                                                                       
โ”‚ @refinedev/devtools-ui: CJS dist\index.cjs     130.36 KB
โ”‚ @refinedev/devtools-ui: CJS dist\style.css     46.49 KB
โ”‚ @refinedev/devtools-ui: CJS dist\index.cjs.map 328.98 KB
โ”‚ @refinedev/devtools-ui: CJS dist\style.css.map 74.58 KB
โ”‚ @refinedev/devtools-ui: CJS โšก๏ธ Build success in 8107ms
โ”‚ @refinedev/devtools-ui: Generating declarations...
โ”‚ @refinedev/devtools-ui: Generating d.mts and d.cts files...
โ”‚ @refinedev/devtools-ui: โœ“ Declarations are generated.
โ”‚  Lerna (powered by Nx)   Successfully ran target build for 2 projects and 2 tasks they depend on
โ”‚ Nx read the output from the cache instead of running the command for 3 out of 4 tasks.
โ””โ”€ Done in 42.5s
packages/devtools-server prepare$ pnpm -w build --scope @refinedev/devtools-server
โ”‚ > refinedev@0.0.0 build F:\Dev projects\Supabase testing\Refine-6024                                                     
โ”‚ > lerna run build --scope @refinedev/core "--scope" "@refinedev/devtools-server"
โ”‚ (node:22496) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instโ€ฆ
โ”‚ (Use node --trace-deprecation ... to show where the warning was created)
โ”‚ lerna notice cli v8.1.2
โ”‚ lerna notice filter including ["@refinedev/core","@refinedev/devtools-server"]
โ”‚ lerna notice filter excluding "{monorepo-*,with-nx,blog-react-aria,blog-sveltekit-crud}"
โ”‚ lerna info filter [
โ”‚ lerna info filter   '@refinedev/core',
โ”‚ lerna info filter   '@refinedev/devtools-server',
โ”‚ lerna info filter   '!{monorepo-*,with-nx,blog-react-aria,blog-sveltekit-crud}'
โ”‚ lerna info filter ]
โ”‚ lerna info run Using the "ignore" option when Nx targets are configured will exclude only tasks that are not determineโ€ฆ
โ”‚  Lerna (powered by Nx)   Running target build for 2 projects and 3 tasks they depend on:
โ”‚ - @refinedev/core
โ”‚ - @refinedev/devtools-server
โ”‚ > @refinedev/devtools-shared:build  [existing outputs match the cache, left as is]
โ”‚ > @refinedev/devtools-shared@1.1.9 build F:\Dev projects\Supabase testing\Refine-6024\packages\devtools-shared
โ”‚ > tsup && node ../shared/generate-declarations.js
โ”‚ CLI Building entry: src/index.ts
โ”‚ CLI Using tsconfig: tsconfig.json
โ”‚ CLI tsup v6.7.0
โ”‚ CLI Using tsup config: F:\Dev projects\Supabase testing\Refine-6024\packages\devtools-shared\tsup.config.ts
โ”‚ CLI Target: node14
โ”‚ CJS Build start
โ”‚ ESM Build start
โ”‚ ESM dist\index.mjs     2.60 KB
โ”‚ ESM dist\index.mjs.map 11.21 KB
โ”‚ ESM โšก๏ธ Build success in 252ms
โ”‚ CJS dist\index.cjs     3.23 KB
โ”‚ CJS dist\index.cjs.map 12.06 KB
โ”‚ CJS โšก๏ธ Build success in 254ms
โ”‚ Generating declarations...
โ”‚ Generating d.mts and d.cts files...
โ”‚ โœ“ Declarations are generated.
โ”‚ > @refinedev/devtools-internal:build  [existing outputs match the cache, left as is]
โ”‚ > @refinedev/devtools-internal@1.1.11 build F:\Dev projects\Supabase testing\Refine-6024\packages\devtools-internal      
โ”‚ > tsup && node ../shared/generate-declarations.js
โ”‚ CLI Building entry: src/index.ts
โ”‚ CLI Using tsconfig: tsconfig.json
โ”‚ CLI tsup v6.7.0
โ”‚ CLI Using tsup config: F:\Dev projects\Supabase testing\Refine-6024\packages\devtools-internal\tsup.config.ts
โ”‚ CLI Target: node14
โ”‚ CJS Build start
โ”‚ ESM Build start
โ”‚ CJS dist\index.cjs     3.95 KB
โ”‚ CJS dist\index.cjs.map 14.58 KB
โ”‚ CJS โšก๏ธ Build success in 76ms
โ”‚ ESM dist\index.mjs     3.30 KB
โ”‚ ESM dist\index.mjs.map 14.37 KB
โ”‚ ESM โšก๏ธ Build success in 77ms
โ”‚ Generating declarations...
โ”‚ Generating d.mts and d.cts files...
โ”‚ โœ“ Declarations are generated.
โ”‚ > @refinedev/devtools-ui:build  [existing outputs match the cache, left as is]
โ”‚ > @refinedev/devtools-ui@1.1.24 build F:\Dev projects\Supabase testing\Refine-6024\packages\devtools-ui
โ”‚ > tsup && node ../shared/generate-declarations.js
โ”‚ CLI Building entry: src/index.ts, src/style.css
โ”‚ CLI Using tsconfig: tsconfig.json
โ”‚ CLI tsup v6.7.0
โ”‚ CLI Using tsup config: F:\Dev projects\Supabase testing\Refine-6024\packages\devtools-ui\tsup.config.ts
โ”‚ CLI Target: node14
โ”‚ CJS Build start
โ”‚ ESM Build start
โ”‚ ESM dist\style.css     46.49 KB
โ”‚ ESM dist\index.mjs     119.92 KB
โ”‚ ESM dist\style.css.map 74.58 KB
โ”‚ ESM dist\index.mjs.map 324.36 KB
โ”‚ ESM โšก๏ธ Build success in 8105ms
โ”‚ CJS dist\index.cjs     130.36 KB
โ”‚ CJS dist\style.css     46.49 KB
โ”‚ CJS dist\index.cjs.map 328.98 KB
โ”‚ CJS dist\style.css.map 74.58 KB
โ”‚ CJS โšก๏ธ Build success in 8107ms
โ”‚ Generating declarations...
โ”‚ Generating d.mts and d.cts files...
โ”‚ โœ“ Declarations are generated.
โ”‚ > @refinedev/devtools-server:build
โ”‚ (node:22496) [DEP0060] DeprecationWarning: The util._extend API is deprecated. Please use Object.assign() instead.     
โ”‚ > @refinedev/core:build  [existing outputs match the cache, left as is]
โ”‚ > @refinedev/core@4.51.0 build F:\Dev projects\Supabase testing\Refine-6024\packages\core
โ”‚ > tsup && node ../shared/generate-declarations.js
โ”‚ CLI Building entry: src/index.tsx
โ”‚ CLI Using tsconfig: tsconfig.json
โ”‚ CLI tsup v6.7.0
โ”‚ CLI Using tsup config: F:\Dev projects\Supabase testing\Refine-6024\packages\core\tsup.config.ts
โ”‚ CLI Target: node14
โ”‚ CJS Build start
โ”‚ ESM Build start
โ”‚ CJS dist\index.cjs     146.36 KB
โ”‚ CJS dist\index.cjs.map 746.61 KB
โ”‚ CJS โšก๏ธ Build success in 2245ms
โ”‚ ESM dist\index.mjs     141.37 KB
โ”‚ ESM dist\index.mjs.map 738.88 KB
โ”‚ ESM โšก๏ธ Build success in 2248ms
โ”‚ Generating declarations...
โ”‚ Generating d.mts and d.cts files...
โ”‚ โœ“ Declarations are generated.
โ”‚ @refinedev/devtools-server: > @refinedev/devtools-server@1.1.31 build F:\Dev projects\Supabase testing\Refine-6024\pacโ€ฆ  
โ”‚ @refinedev/devtools-server: > pnpm build:client && tsup && node ../shared/generate-declarations.js
โ”‚ @refinedev/devtools-server: > @refinedev/devtools-server@1.1.31 build:client F:\Dev projects\Supabase testing\Refine-6โ€ฆ  
โ”‚ @refinedev/devtools-server: > NODE_ENV=production tsc && vite build --config src/client/vite.config.ts
โ”‚ @refinedev/devtools-server: 'NODE_ENV' is not recognized as an internal or external command,
โ”‚ @refinedev/devtools-server: operable program or batch file.
โ”‚ @refinedev/devtools-server: โ€‰ELIFECYCLEโ€‰ Command failed with exit code 1.
โ”‚ @refinedev/devtools-server: โ€‰ELIFECYCLEโ€‰ Command failed with exit code 1.
โ”‚  Lerna (powered by Nx)   Running target build for 2 projects and 3 tasks they depend on failed
โ”‚ Failed tasks:
โ”‚ - @refinedev/devtools-server:build
โ”‚ โ€‰ELIFECYCLEโ€‰ Command failed with exit code 1.
โ””โ”€ Failed in 10.6s at F:\Dev projects\Supabase testing\Refine-6024\packages\devtools-server
โ€‰ELIFECYCLEโ€‰ Command failed with exit code 1.
packages/core prepare$ pnpm -w build --scope @refinedev/core
โ””โ”€ Running...

I then tried running it while ignoring scripts, and got the following message:

$ pnpm install --ignore-scripts
Scope: all 240 workspace projects
Lockfile is up to date, resolution step is skipped
Packages: -145
-------------------------------------------------------------------------------------------------------------------------
โ€‰WARNโ€‰ Failed to create bin at F:\Dev projects\Supabase testing\Refine-6024\packages\devtools\node_modules\.bin\refine-devtools. ENOENT: no such file or directory, stat 'F:\Dev projects\Supabase testing\Refine-6024\packages\devtools\node_modules\@refinedev\devtools-server\dist\cli.cjs.EXE'
โ€‰WARNโ€‰ Failed to create bin at F:\Dev projects\Supabase testing\Refine-6024\packages\cli\node_modules\.bin\refine-devtools. ENOENT: no such file or directory, stat 'F:\Dev projects\Supabase testing\Refine-6024\packages\cli\node_modules\@refinedev\devtools-server\dist\cli.cjs.EXE'
Progress: resolved 0, reused 124, downloaded 0, added 0, done
โ€‰WARNโ€‰ Failed to create bin at F:\Dev projects\Supabase testing\Refine-6024\packages\devtools\node_modules\.bin\refine-devtools. ENOENT: no such file or directory, stat 'F:\Dev projects\Supabase testing\Refine-6024\packages\devtools\node_modules\@refinedev\devtools-server\dist\cli.cjs.EXE'
โ€‰WARNโ€‰ Failed to create bin at F:\Dev projects\Supabase testing\Refine-6024\packages\cli\node_modules\.bin\refine-devtools. ENOENT: no such file or directory, stat 'F:\Dev projects\Supabase testing\Refine-6024\packages\cli\node_modules\@refinedev\devtools-server\dist\cli.cjs.EXE'
Done in 1m 16s

I thought that running the command through Git Bash would help to resolve any issue relating to NODE_ENV not being recognized in Windows. I then switched to using WSL with Ubuntu to install and again ran up against issues:

jknight@DESKTOP-PCBKQJF:~$ npm install -g pnpm
npm notice
npm notice New minor version of npm available! 10.7.0 -> 10.8.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.1
npm notice To update run: npm install -g npm@10.8.1
npm notice
npm error code EACCES
npm error syscall mkdir
npm error path /usr/lib/node_modules/pnpm
npm error errno -13
npm error [Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/pnpm'] {
npm error   errno: -13,
npm error   code: 'EACCES',
npm error   syscall: 'mkdir',
npm error   path: '/usr/lib/node_modules/pnpm'
npm error }
npm error
npm error The operation was rejected by your operating system.
npm error It is likely you do not have the permissions to access this file as the current user
npm error
npm error If you believe this might be a permissions issue, please double-check the
npm error permissions of the file and its containing directories, or try running
npm error the command again as root/Administrator.

npm error A complete log of this run can be found in: /home/jknight/.npm/_logs/2024-06-17T20_57_50_919Z-debug-0.log

At that point I called it quits as I just ran out of time and thought it might be better for someone else to step in.

aliemir commented 2 months ago

Hey @jim-knight, we've implemented the fix about the Windows environment. Can you check if you can continue working on this one? Please let us know if you encounter any other issues ๐Ÿ™

jim-knight commented 2 months ago

Hey @jim-knight, we've implemented the fix about the Windows environment. Can you check if you can continue working on this one? Please let us know if you encounter any other issues ๐Ÿ™

Thanks for the update @aliemir. I'll give it a shot as soon as I have some free time and will report back.