Skip to content

Commit 6b172f2

Browse files
authored
Merge pull request #47 from marmelab/update-ra-data-postgrest
Update to latest ra-data-postgrest
2 parents dc88752 + 1e1df8c commit 6b172f2

File tree

7 files changed

+111
-21
lines changed

7 files changed

+111
-21
lines changed

cypress/e2e/lists.cy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('Lists', () => {
1717
getPaginationText().then(el => {
1818
const count = parseInt(el.text().split('of')[1].trim());
1919

20-
cy.findByText('Before last month').click();
20+
cy.findByText('Earlier').click();
2121
// Use should here to allow built-in retry as it may take a few ms for the list to update
2222
getPaginationText().should(el => {
2323
const countFiltered = parseInt(el.text().split('of')[1].trim());

packages/demo/src/contacts/ContactListFilter.tsx

+25-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ import AccessTimeIcon from '@mui/icons-material/AccessTime';
1212
import TrendingUpIcon from '@mui/icons-material/TrendingUp';
1313
import LocalOfferIcon from '@mui/icons-material/LocalOffer';
1414
import SupervisorAccountIcon from '@mui/icons-material/SupervisorAccount';
15-
import { endOfYesterday, startOfWeek, startOfMonth, subMonths } from 'date-fns';
15+
import {
16+
endOfYesterday,
17+
startOfWeek,
18+
startOfMonth,
19+
subMonths,
20+
subWeeks,
21+
} from 'date-fns';
1622

1723
import { Status } from '../misc/Status';
1824

@@ -47,21 +53,34 @@ export const ContactListFilter = () => {
4753
}}
4854
/>
4955
<FilterListItem
50-
label="Before this week"
56+
label="Last week"
5157
value={{
52-
'last_seen@gte': undefined,
58+
'last_seen@gte': subWeeks(
59+
startOfWeek(new Date()),
60+
1
61+
).toISOString(),
5362
'last_seen@lte': startOfWeek(new Date()).toISOString(),
5463
}}
5564
/>
5665
<FilterListItem
57-
label="Before this month"
66+
label="This month"
5867
value={{
59-
'last_seen@gte': undefined,
68+
'last_seen@gte': startOfMonth(new Date()).toISOString(),
69+
'last_seen@lte': undefined,
70+
}}
71+
/>
72+
<FilterListItem
73+
label="Last month"
74+
value={{
75+
'last_seen@gte': subMonths(
76+
startOfMonth(new Date()),
77+
1
78+
).toISOString(),
6079
'last_seen@lte': startOfMonth(new Date()).toISOString(),
6180
}}
6281
/>
6382
<FilterListItem
64-
label="Before last month"
83+
label="Earlier"
6584
value={{
6685
'last_seen@gte': undefined,
6786
'last_seen@lte': subMonths(

packages/ra-supabase-core/README.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const MyAdmin = () => (
6868

6969
### DataProvider
7070

71-
`ra-supabase` is built on [`ra-data-postgrest`](https://github.com/raphiniert-com/ra-data-postgrest/tree/v2.0.0-alpha.0) that leverages [PostgREST](https://postgrest.org/en/stable/). As such, you have access the following features:
71+
`ra-supabase` is built on [`ra-data-postgrest`](https://github.com/raphiniert-com/ra-data-postgrest/tree/v2.0.0) that leverages [PostgREST](https://postgrest.org/en/stable/). As such, you have access the following features:
7272

7373
#### Filters operators
7474

@@ -93,6 +93,29 @@ See the [PostgREST documentation](https://postgrest.org/en/stable/api.html#opera
9393

9494
As users authenticate through supabase, you can leverage [Row Level Security](https://supabase.com/docs/guides/auth/row-level-security). Users identity will be propagated through the dataProvider if you provided the public API (anon) key. Keep in mind that passing the `service_role` key will bypass Row Level Security. This is not recommended.
9595

96+
#### Customizing the dataProvider
97+
98+
`supabaseDataProvider` also accepts the same options as the `ra-data-postgrest` dataProvider (except `apiUrl`), like [`primaryKeys`](https://github.com/raphiniert-com/ra-data-postgrest/blob/master/README.md#compound-primary-keys) or [`schema`](https://github.com/raphiniert-com/ra-data-postgrest/blob/master/README.md#custom-schema).
99+
100+
```jsx
101+
// in dataProvider.js
102+
import { supabaseDataProvider } from 'ra-supabase-core';
103+
import { supabaseClient } from './supabase';
104+
105+
export const dataProvider = supabaseDataProvider({
106+
instanceUrl: 'YOUR_SUPABASE_URL',
107+
apiKey: 'YOUR_SUPABASE_ANON_KEY',
108+
supabaseClient,
109+
primaryKeys: new Map([
110+
['some_table', ['custom_id']],
111+
['another_table', ['first_column', 'second_column']],
112+
]),
113+
schema: () => localStorage.getItem("schema") || "api",
114+
});
115+
```
116+
117+
See the [`ra-data-postgrest`` documentation](https://github.com/raphiniert-com/ra-data-postgrest/blob/master/README.md) for more details.
118+
96119
### Authentication
97120

98121
`ra-supabase` supports email/password and OAuth authentication.

packages/ra-supabase-core/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
"types": "esm/index.d.ts",
1616
"sideEffects": false,
1717
"peerDependencies": {
18-
"@raphiniert/ra-data-postgrest": "2.0.0-alpha.0",
18+
"@raphiniert/ra-data-postgrest": "^2.0.0",
1919
"@supabase/supabase-js": "^2.0.0",
2020
"ra-core": "^4.7.0"
2121
},
2222
"devDependencies": {
23-
"@raphiniert/ra-data-postgrest": "2.0.0-alpha.0",
23+
"@raphiniert/ra-data-postgrest": "^2.0.0",
2424
"@supabase/supabase-js": "^2.4.1",
2525
"@testing-library/jest-dom": "^5.16.5",
2626
"@testing-library/react": "^13.4.0",

packages/ra-supabase-core/src/dataProvider.ts

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,43 @@
11
import { DataProvider, fetchUtils } from 'ra-core';
2-
import postgrestRestProvider from '@raphiniert/ra-data-postgrest';
2+
import postgrestRestProvider, {
3+
IDataProviderConfig,
4+
defaultPrimaryKeys,
5+
defaultSchema,
6+
} from '@raphiniert/ra-data-postgrest';
37
import { SupabaseClient } from '@supabase/supabase-js';
48

59
/**
610
* A function that returns a dataProvider for Supabase.
711
* @param instanceUrl The URL of the Supabase instance
812
* @param apiKey The API key of the Supabase instance. Prefer the anonymous key.
913
* @param supabaseClient The Supabase client
14+
* @param defaultListOp Optional - The default list filter operator. Defaults to 'eq'.
15+
* @param primaryKeys Optional - The primary keys of the tables. Defaults to 'id'.
16+
* @param schema Optional - The custom schema to use. Defaults to none.
1017
* @returns A dataProvider for Supabase
1118
*/
1219
export const supabaseDataProvider = ({
1320
instanceUrl,
1421
apiKey,
1522
supabaseClient,
23+
httpClient = supabaseHttpClient({ apiKey, supabaseClient }),
24+
defaultListOp = 'eq',
25+
primaryKeys = defaultPrimaryKeys,
26+
schema = defaultSchema,
1627
}: {
1728
instanceUrl: string;
1829
apiKey: string;
1930
supabaseClient: SupabaseClient;
20-
}): DataProvider =>
21-
postgrestRestProvider(
22-
`${instanceUrl}/rest/v1`,
23-
supabaseHttpClient({ apiKey, supabaseClient })
24-
);
31+
} & Partial<Omit<IDataProviderConfig, 'apiUrl'>>): DataProvider => {
32+
const config: IDataProviderConfig = {
33+
apiUrl: `${instanceUrl}/rest/v1`,
34+
httpClient,
35+
defaultListOp,
36+
primaryKeys,
37+
schema,
38+
};
39+
return postgrestRestProvider(config);
40+
};
2541

2642
/**
2743
* A function that returns a httpClient for Supabase. It handles the authentication.

packages/ra-supabase/README.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ You must wrap your `<Admin>` inside a `<BrowserRouter>` as supabase use hash par
9090

9191
### DataProvider
9292

93-
`ra-supabase` is built on [`ra-data-postgrest`](https://github.com/raphiniert-com/ra-data-postgrest/tree/v2.0.0-alpha.0) that leverages [PostgREST](https://postgrest.org/en/stable/). As such, you have access the following features:
93+
`ra-supabase` is built on [`ra-data-postgrest`](https://github.com/raphiniert-com/ra-data-postgrest/tree/v2.0.0) that leverages [PostgREST](https://postgrest.org/en/stable/). As such, you have access the following features:
9494

9595
#### Filters operators
9696

@@ -115,6 +115,29 @@ See the [PostgREST documentation](https://postgrest.org/en/stable/api.html#opera
115115

116116
As users authenticate through supabase, you can leverage [Row Level Security](https://supabase.com/docs/guides/auth/row-level-security). Users identity will be propagated through the dataProvider if you provided the public API (anon) key. Keep in mind that passing the `service_role` key will bypass Row Level Security. This is not recommended.
117117

118+
#### Customizing the dataProvider
119+
120+
`supabaseDataProvider` also accepts the same options as the `ra-data-postgrest` dataProvider (except `apiUrl`), like [`primaryKeys`](https://github.com/raphiniert-com/ra-data-postgrest/blob/master/README.md#compound-primary-keys) or [`schema`](https://github.com/raphiniert-com/ra-data-postgrest/blob/master/README.md#custom-schema).
121+
122+
```jsx
123+
// in dataProvider.js
124+
import { supabaseDataProvider } from 'ra-supabase-core';
125+
import { supabaseClient } from './supabase';
126+
127+
export const dataProvider = supabaseDataProvider({
128+
instanceUrl: 'YOUR_SUPABASE_URL',
129+
apiKey: 'YOUR_SUPABASE_ANON_KEY',
130+
supabaseClient,
131+
primaryKeys: new Map([
132+
['some_table', ['custom_id']],
133+
['another_table', ['first_column', 'second_column']],
134+
]),
135+
schema: () => localStorage.getItem("schema") || "api",
136+
});
137+
```
138+
139+
See the [`ra-data-postgrest`` documentation](https://github.com/raphiniert-com/ra-data-postgrest/blob/master/README.md) for more details.
140+
118141
### Authentication
119142

120143
`ra-supabase` supports email/password and OAuth authentication.

yarn.lock

+13-4
Original file line numberDiff line numberDiff line change
@@ -2344,10 +2344,12 @@
23442344
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.6.tgz#cee20bd55e68a1720bdab363ecf0c821ded4cd45"
23452345
integrity sha512-50/17A98tWUfQ176raKiOGXuYpLyyVMkxxG6oylzL3BPOlA6ADGdK7EYunSa4I064xerltq9TGXs8HmOk5E+vw==
23462346

2347-
"@raphiniert/ra-data-postgrest@2.0.0-alpha.0":
2348-
version "2.0.0-alpha.0"
2349-
resolved "https://registry.yarnpkg.com/@raphiniert/ra-data-postgrest/-/ra-data-postgrest-2.0.0-alpha.0.tgz#12bc23ba9e25388b9b630e5400d290c4b23fe1a3"
2350-
integrity sha512-9bwWARORJX6ivdCkTyt/9hQ1we4hz0pW6MiPLqK7DWLSlqWyuC7A+/U0Iix5Qd52qoiB4ppA9Xov+btrDWgLWw==
2347+
"@raphiniert/ra-data-postgrest@^2.0.0":
2348+
version "2.0.0"
2349+
resolved "https://registry.yarnpkg.com/@raphiniert/ra-data-postgrest/-/ra-data-postgrest-2.0.0.tgz#4038621b4fe156095dde066353e29396e33cbb39"
2350+
integrity sha512-1Ss+/xAxL62aGmCBSSJnlFMMSl0T2/bNSfeV0lplm7N9AtsOxSfySDKnCQs53ngbSBK1rPbk4ypc/mDVm4y4xQ==
2351+
dependencies:
2352+
qs "^6.11.1"
23512353

23522354
"@react-spring/animated@~9.4.5":
23532355
version "9.4.5"
@@ -9503,6 +9505,13 @@ q@^1.5.1:
95039505
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
95049506
integrity sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw==
95059507

9508+
qs@^6.11.1:
9509+
version "6.11.2"
9510+
resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.2.tgz#64bea51f12c1f5da1bc01496f48ffcff7c69d7d9"
9511+
integrity sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==
9512+
dependencies:
9513+
side-channel "^1.0.4"
9514+
95069515
qs@~6.10.3:
95079516
version "6.10.5"
95089517
resolved "https://registry.yarnpkg.com/qs/-/qs-6.10.5.tgz#974715920a80ff6a262264acd2c7e6c2a53282b4"

0 commit comments

Comments
 (0)