@wix/auto-patterns 1.40.0 → 1.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/AutoPatternsApp/AutoPatternsApp.uni.driver.js +57 -0
- package/dist/cjs/components/AutoPatternsApp/AutoPatternsApp.uni.driver.js.map +1 -0
- package/dist/cjs/components/AutoPatternsCollectionPage/AutoPatternsCollectionPage.js +0 -1
- package/dist/cjs/components/AutoPatternsCollectionPage/AutoPatternsCollectionPage.js.map +1 -1
- package/dist/cjs/components/AutoPatternsEntityPage/ViewModeEntityPage.uni.driver.js +42 -0
- package/dist/cjs/components/AutoPatternsEntityPage/ViewModeEntityPage.uni.driver.js.map +1 -0
- package/dist/cjs/components/AutoPatternsGrid/AutoPatternsGrid.js +3 -1
- package/dist/cjs/components/AutoPatternsGrid/AutoPatternsGrid.js.map +1 -1
- package/dist/cjs/components/AutoPatternsTable/AutoPatternsTable.js +3 -1
- package/dist/cjs/components/AutoPatternsTable/AutoPatternsTable.js.map +1 -1
- package/dist/cjs/exports/testkit/enzyme.js +10 -0
- package/dist/cjs/exports/testkit/enzyme.js.map +1 -0
- package/dist/cjs/exports/testkit/jsdom.js +10 -0
- package/dist/cjs/exports/testkit/jsdom.js.map +1 -0
- package/dist/cjs/exports/testkit/playwright.js +10 -0
- package/dist/cjs/exports/testkit/playwright.js.map +1 -0
- package/dist/cjs/exports/testkit/puppeteer.js +10 -0
- package/dist/cjs/exports/testkit/puppeteer.js.map +1 -0
- package/dist/cjs/hooks/useCommonCollectionFeatures.js +12 -7
- package/dist/cjs/hooks/useCommonCollectionFeatures.js.map +1 -1
- package/dist/cjs/hooks/useDragAndDropBaseProps.js +7 -3
- package/dist/cjs/hooks/useDragAndDropBaseProps.js.map +1 -1
- package/dist/cjs/hooks/useTableFeatures.js.map +1 -1
- package/dist/cjs/hooks/useViews.js +107 -0
- package/dist/cjs/hooks/useViews.js.map +1 -0
- package/dist/cjs/providers/AutoPatternsOverridesContext.js +1 -1
- package/dist/cjs/providers/AutoPatternsOverridesContext.js.map +1 -1
- package/dist/cjs/testkit/enzyme.js +8 -0
- package/dist/cjs/testkit/enzyme.js.map +1 -0
- package/dist/cjs/testkit/jsdom.js +8 -0
- package/dist/cjs/testkit/jsdom.js.map +1 -0
- package/dist/cjs/testkit/playwright.js +8 -0
- package/dist/cjs/testkit/playwright.js.map +1 -0
- package/dist/cjs/testkit/puppeteer.js +8 -0
- package/dist/cjs/testkit/puppeteer.js.map +1 -0
- package/dist/cjs/types/CollectionPageConfig.js.map +1 -1
- package/dist/esm/components/AutoPatternsApp/AutoPatternsApp.uni.driver.js +50 -0
- package/dist/esm/components/AutoPatternsApp/AutoPatternsApp.uni.driver.js.map +1 -0
- package/dist/esm/components/AutoPatternsCollectionPage/AutoPatternsCollectionPage.js +0 -1
- package/dist/esm/components/AutoPatternsCollectionPage/AutoPatternsCollectionPage.js.map +1 -1
- package/dist/esm/components/AutoPatternsEntityPage/ViewModeEntityPage.uni.driver.js +37 -0
- package/dist/esm/components/AutoPatternsEntityPage/ViewModeEntityPage.uni.driver.js.map +1 -0
- package/dist/esm/components/AutoPatternsGrid/AutoPatternsGrid.js +2 -0
- package/dist/esm/components/AutoPatternsGrid/AutoPatternsGrid.js.map +1 -1
- package/dist/esm/components/AutoPatternsTable/AutoPatternsTable.js +2 -0
- package/dist/esm/components/AutoPatternsTable/AutoPatternsTable.js.map +1 -1
- package/dist/esm/exports/testkit/enzyme.js +2 -0
- package/dist/esm/exports/testkit/enzyme.js.map +1 -0
- package/dist/esm/exports/testkit/jsdom.js +2 -0
- package/dist/esm/exports/testkit/jsdom.js.map +1 -0
- package/dist/esm/exports/testkit/playwright.js +2 -0
- package/dist/esm/exports/testkit/playwright.js.map +1 -0
- package/dist/esm/exports/testkit/puppeteer.js +2 -0
- package/dist/esm/exports/testkit/puppeteer.js.map +1 -0
- package/dist/esm/hooks/useCommonCollectionFeatures.js +8 -3
- package/dist/esm/hooks/useCommonCollectionFeatures.js.map +1 -1
- package/dist/esm/hooks/useDragAndDropBaseProps.js +8 -4
- package/dist/esm/hooks/useDragAndDropBaseProps.js.map +1 -1
- package/dist/esm/hooks/useTableFeatures.js.map +1 -1
- package/dist/esm/hooks/useViews.js +106 -0
- package/dist/esm/hooks/useViews.js.map +1 -0
- package/dist/esm/providers/AutoPatternsOverridesContext.js.map +1 -1
- package/dist/esm/testkit/enzyme.js +4 -0
- package/dist/esm/testkit/enzyme.js.map +1 -0
- package/dist/esm/testkit/jsdom.js +4 -0
- package/dist/esm/testkit/jsdom.js.map +1 -0
- package/dist/esm/testkit/playwright.js +4 -0
- package/dist/esm/testkit/playwright.js.map +1 -0
- package/dist/esm/testkit/puppeteer.js +4 -0
- package/dist/esm/testkit/puppeteer.js.map +1 -0
- package/dist/esm/types/CollectionPageConfig.js.map +1 -1
- package/dist/types/components/AutoPatternsApp/AutoPatternsApp.uni.driver.d.ts +45 -0
- package/dist/types/components/AutoPatternsApp/AutoPatternsApp.uni.driver.d.ts.map +1 -0
- package/dist/types/components/AutoPatternsEntityPage/ViewModeEntityPage.uni.driver.d.ts +81 -0
- package/dist/types/components/AutoPatternsEntityPage/ViewModeEntityPage.uni.driver.d.ts.map +1 -0
- package/dist/types/components/AutoPatternsGrid/AutoPatternsGrid.d.ts.map +1 -1
- package/dist/types/components/AutoPatternsTable/AutoPatternsTable.d.ts.map +1 -1
- package/dist/types/exports/testkit/enzyme.d.ts +2 -0
- package/dist/types/exports/testkit/enzyme.d.ts.map +1 -0
- package/dist/types/exports/testkit/jsdom.d.ts +2 -0
- package/dist/types/exports/testkit/jsdom.d.ts.map +1 -0
- package/dist/types/exports/testkit/playwright.d.ts +2 -0
- package/dist/types/exports/testkit/playwright.d.ts.map +1 -0
- package/dist/types/exports/testkit/puppeteer.d.ts +2 -0
- package/dist/types/exports/testkit/puppeteer.d.ts.map +1 -0
- package/dist/types/hooks/useCommonCollectionFeatures.d.ts +3 -2
- package/dist/types/hooks/useCommonCollectionFeatures.d.ts.map +1 -1
- package/dist/types/hooks/useDragAndDropBaseProps.d.ts.map +1 -1
- package/dist/types/hooks/useGridFeatures.d.ts +1 -0
- package/dist/types/hooks/useGridFeatures.d.ts.map +1 -1
- package/dist/types/hooks/useTableFeatures.d.ts +1 -0
- package/dist/types/hooks/useTableFeatures.d.ts.map +1 -1
- package/dist/types/hooks/useTableGridSwitchFeatures.d.ts +1 -0
- package/dist/types/hooks/useTableGridSwitchFeatures.d.ts.map +1 -1
- package/dist/types/hooks/useViews.d.ts +4 -0
- package/dist/types/hooks/useViews.d.ts.map +1 -0
- package/dist/types/providers/AutoPatternsOverridesContext.d.ts +1 -0
- package/dist/types/providers/AutoPatternsOverridesContext.d.ts.map +1 -1
- package/dist/types/testkit/enzyme.d.ts +16 -0
- package/dist/types/testkit/enzyme.d.ts.map +1 -0
- package/dist/types/testkit/jsdom.d.ts +16 -0
- package/dist/types/testkit/jsdom.d.ts.map +1 -0
- package/dist/types/testkit/playwright.d.ts +20 -0
- package/dist/types/testkit/playwright.d.ts.map +1 -0
- package/dist/types/testkit/puppeteer.d.ts +20 -0
- package/dist/types/testkit/puppeteer.d.ts.map +1 -0
- package/dist/types/types/CollectionPageConfig.d.ts +193 -1
- package/dist/types/types/CollectionPageConfig.d.ts.map +1 -1
- package/mcp-docs/app_config_structure.md +95 -0
- package/mcp-docs/auto-patterns-guide.md +721 -15
- package/mcp-docs/custom_overrides.md +37 -0
- package/mcp-docs/error_handling.md +251 -15
- package/mcp-docs/index.md +4 -0
- package/mcp-docs/views.md +335 -0
- package/package.json +49 -15
|
@@ -179,6 +179,40 @@ function columnOverride(props: IColumnValue<string>) {
|
|
|
179
179
|
}
|
|
180
180
|
```
|
|
181
181
|
|
|
182
|
+
### Important Guidelines for Column Functions
|
|
183
|
+
|
|
184
|
+
**Column ID Naming**: Column IDs are always in camelCase, and your function names should match exactly:
|
|
185
|
+
- Column ID: `petName` → Function name: `petName`
|
|
186
|
+
- Column ID: `isVaccinated` → Function name: `isVaccinated`
|
|
187
|
+
- Column ID: `lastActivity` → Function name: `lastActivity`
|
|
188
|
+
|
|
189
|
+
**React Limitations**: Column override functions are **NOT React function components**, which means:
|
|
190
|
+
- ❌ **No React hooks allowed** (useState, useEffect, useContext, etc.)
|
|
191
|
+
- ❌ **No custom hook calls** inside the function
|
|
192
|
+
- ✅ **Only pure rendering logic** with JSX return
|
|
193
|
+
|
|
194
|
+
**Using Hooks in Column Overrides**: If you need React hooks, create a separate React component and return it from your column function:
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
// ❌ WRONG - Hooks directly in column function
|
|
198
|
+
export function myColumn({ value, row }: IColumnValue<string>) {
|
|
199
|
+
const [state, setState] = useState(value); // ERROR: Hooks not allowed!
|
|
200
|
+
return <span>{state}</span>;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ✅ CORRECT - Hooks in separate component
|
|
204
|
+
function MyColumnComponent({ value, row }: IColumnValue<string>) {
|
|
205
|
+
const [state, setState] = useState(value); // ✅ Hooks allowed in React components
|
|
206
|
+
const contextValue = useContext(MyContext); // ✅ Context hooks work here
|
|
207
|
+
|
|
208
|
+
return <span>{state} - {contextValue}</span>;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function myColumn(props: IColumnValue<string>) {
|
|
212
|
+
return <MyColumnComponent {...props} />; // ✅ Return React component
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
182
216
|
### Type-Specific Examples
|
|
183
217
|
|
|
184
218
|
The generic type `T` in `IColumnValue<T>` should match your field's data type:
|
|
@@ -440,6 +474,9 @@ AutoPatternsOverridesProvider
|
|
|
440
474
|
|
|
441
475
|
### Important Guidelines
|
|
442
476
|
|
|
477
|
+
- **Function Naming**: Column function names must be in camelCase and match the column ID exactly
|
|
478
|
+
- **No React Hooks**: Column functions are NOT React components - no useState, useEffect, useContext, etc.
|
|
479
|
+
- **Hook Workaround**: If you need hooks, create a separate React component and return it from your column function
|
|
443
480
|
- **TypeScript Usage**: Always use `IColumnValue<T>` and import it from `@wix/auto-patterns/types`
|
|
444
481
|
- **Type Matching**: Ensure the generic type `T` matches your field's actual data type (string, number, boolean, etc.)
|
|
445
482
|
- **Performance**: Remember that column functions are called for every row, so keep calculations lightweight
|
|
@@ -11,12 +11,53 @@
|
|
|
11
11
|
|
|
12
12
|
**⚠️ CRITICAL**: When implementing custom data sources that make HTTP requests, you **MUST** wrap specific HTTP calls with proper error handling. This ensures consistent error management, prevents unhandled promise rejections, and provides better user experience.
|
|
13
13
|
|
|
14
|
+
## 🚨 GOLDEN RULE: If it's a Wix Library, Wrap it with errorHandler!
|
|
15
|
+
|
|
16
|
+
**Simple Rule for AI Agents:**
|
|
17
|
+
- **ANY Wix SDK call** from libraries with `@wix/` prefix → **ALWAYS wrap with `errorHandler.withErrorHandler`**
|
|
18
|
+
- This includes: `@wix/data`, `@wix/stores`, `@wix/events`, `@wix/bookings`, `@wix/crm`, and ALL other `@wix/*` packages
|
|
19
|
+
- **NO exceptions** - all Wix SDK calls must use error handling
|
|
20
|
+
|
|
21
|
+
### ❌ DON'T DO THIS (Common Mistake)
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { items } from '@wix/data';
|
|
25
|
+
|
|
26
|
+
// ❌ WRONG - No errorHandler wrapping
|
|
27
|
+
async function getAllPets() {
|
|
28
|
+
try {
|
|
29
|
+
const result = await items.query('WixPets').find();
|
|
30
|
+
return result.items;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error(error);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### ✅ DO THIS (Correct Pattern)
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { items } from '@wix/data';
|
|
42
|
+
import { errorHandler } from '@wix/essentials';
|
|
43
|
+
|
|
44
|
+
// ✅ CORRECT - Wix SDK call wrapped with errorHandler
|
|
45
|
+
async function getAllPets() {
|
|
46
|
+
return errorHandler.withErrorHandler(
|
|
47
|
+
async () => {
|
|
48
|
+
const result = await items.query('WixPets').find();
|
|
49
|
+
return result.items;
|
|
50
|
+
},
|
|
51
|
+
{}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
14
55
|
## What Requires Error Handling
|
|
15
56
|
|
|
16
57
|
**ONLY the following HTTP requests** in your custom data source actions must be wrapped with `errorHandler.withErrorHandler`:
|
|
17
58
|
|
|
18
59
|
- **httpClient from @wix/essentials** (e.g., `httpClient.request(getDummyEntity(...))`)
|
|
19
|
-
- **Wix
|
|
60
|
+
- **Wix API calls from libraries with `wix/` prefix** (e.g., `@wix/data`, `@wix/stores`, `@wix/events`, `@wix/bookings`, `collections.getDataCollection()`, etc.)
|
|
20
61
|
- **httpClient.fetchWithAuth()** calls
|
|
21
62
|
|
|
22
63
|
**DO NOT use errorHandler.withErrorHandler with:**
|
|
@@ -154,12 +195,68 @@ return errorHandler.withErrorHandler(async () => {
|
|
|
154
195
|
}, {});
|
|
155
196
|
```
|
|
156
197
|
|
|
157
|
-
**Wix APIs (wix/data, wix/stores):**
|
|
198
|
+
**Wix APIs (@wix/data, @wix/stores, @wix/crm, etc.):**
|
|
158
199
|
|
|
159
200
|
```typescript
|
|
201
|
+
import { items } from '@wix/data';
|
|
202
|
+
import { errorHandler } from '@wix/essentials';
|
|
203
|
+
|
|
204
|
+
// ✅ CORRECT: Wix Data API calls wrapped with errorHandler
|
|
160
205
|
return errorHandler.withErrorHandler(async () => {
|
|
161
206
|
return await items.get(collectionId, entityId);
|
|
162
207
|
}, {});
|
|
208
|
+
|
|
209
|
+
// ✅ CORRECT: Query operations wrapped with errorHandler
|
|
210
|
+
return errorHandler.withErrorHandler(async () => {
|
|
211
|
+
return await items.query('WixPets').find();
|
|
212
|
+
}, {});
|
|
213
|
+
|
|
214
|
+
// ✅ CORRECT: Insert operations wrapped with errorHandler
|
|
215
|
+
return errorHandler.withErrorHandler(async () => {
|
|
216
|
+
return await items.insert(collectionId, dataItem);
|
|
217
|
+
}, {});
|
|
218
|
+
|
|
219
|
+
// ✅ CORRECT: Update operations wrapped with errorHandler
|
|
220
|
+
return errorHandler.withErrorHandler(async () => {
|
|
221
|
+
return await items.update(collectionId, dataItem);
|
|
222
|
+
}, {});
|
|
223
|
+
|
|
224
|
+
// ✅ CORRECT: Delete operations wrapped with errorHandler
|
|
225
|
+
return errorHandler.withErrorHandler(async () => {
|
|
226
|
+
return await items.remove(collectionId, itemId);
|
|
227
|
+
}, {});
|
|
228
|
+
|
|
229
|
+
// ✅ CORRECT: Bulk delete operations wrapped with errorHandler
|
|
230
|
+
return errorHandler.withErrorHandler(async () => {
|
|
231
|
+
return await items.bulkRemove(collectionId, itemIds);
|
|
232
|
+
}, {});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**All Other Wix API calls from libraries with `@wix/` prefix:**
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
import { stores } from '@wix/stores';
|
|
239
|
+
import { events } from '@wix/events';
|
|
240
|
+
import { bookings } from '@wix/bookings';
|
|
241
|
+
import { contacts } from '@wix/crm';
|
|
242
|
+
import { errorHandler } from '@wix/essentials';
|
|
243
|
+
|
|
244
|
+
// ✅ CORRECT: All Wix API calls from @wix/* libraries must be wrapped
|
|
245
|
+
return errorHandler.withErrorHandler(async () => {
|
|
246
|
+
return await stores.queryProducts().find();
|
|
247
|
+
}, {});
|
|
248
|
+
|
|
249
|
+
return errorHandler.withErrorHandler(async () => {
|
|
250
|
+
return await events.queryEvents().find();
|
|
251
|
+
}, {});
|
|
252
|
+
|
|
253
|
+
return errorHandler.withErrorHandler(async () => {
|
|
254
|
+
return await bookings.queryBookings().find();
|
|
255
|
+
}, {});
|
|
256
|
+
|
|
257
|
+
return errorHandler.withErrorHandler(async () => {
|
|
258
|
+
return await contacts.queryContacts().find();
|
|
259
|
+
}, {});
|
|
163
260
|
```
|
|
164
261
|
|
|
165
262
|
**httpClient.fetchWithAuth() calls:**
|
|
@@ -207,25 +304,120 @@ The error handling in your custom data source integrates seamlessly with AutoPat
|
|
|
207
304
|
**BEFORE implementing ANY custom action or data source, AI agents MUST verify:**
|
|
208
305
|
|
|
209
306
|
### ✅ Error Handling Requirements
|
|
210
|
-
- **
|
|
211
|
-
-
|
|
212
|
-
- **httpClient
|
|
213
|
-
- **
|
|
214
|
-
- **
|
|
215
|
-
-
|
|
307
|
+
- ✅ **ALL Wix API calls from `@wix/*` libraries** are wrapped with `errorHandler.withErrorHandler`
|
|
308
|
+
- Including: `@wix/data`, `@wix/stores`, `@wix/events`, `@wix/bookings`, `@wix/crm`, and ALL other `@wix/*` packages
|
|
309
|
+
- ✅ **httpClient from @wix/essentials** is wrapped with `errorHandler.withErrorHandler`
|
|
310
|
+
- ✅ **httpClient.fetchWithAuth()** calls are wrapped with `errorHandler.withErrorHandler`
|
|
311
|
+
- ✅ **External API calls are NOT wrapped** with errorHandler (e.g., fetch(), axios, third-party HTTP clients)
|
|
312
|
+
- ✅ **SDK actions are used directly** without error handling (e.g., `sdk.getOptimisticActions()`, `sdk.getSchema()`)
|
|
313
|
+
- ✅ **@wix/essentials** is installed as a dependency
|
|
314
|
+
|
|
315
|
+
### ✅ Correct API Signature Verification
|
|
316
|
+
- ✅ **Check TypeScript/linter errors FIRST** - they tell you when the API is used incorrectly
|
|
317
|
+
- ✅ **Verify imports are correct** - `import { items } from '@wix/data'` (not default imports)
|
|
318
|
+
- ✅ **Use correct method signatures** - refer to the API reference section
|
|
319
|
+
- ✅ **Pass correct parameters** - verify collectionId, itemId, and data structure
|
|
320
|
+
- ✅ **Handle return values correctly** - `.find()` returns `{ items, ... }`, not just items array
|
|
216
321
|
|
|
217
322
|
### ✅ Implementation Checklist
|
|
218
|
-
- **Read this error handling documentation** before implementing any custom action
|
|
219
|
-
- **Identify the type of HTTP request** being made (Wix vs External)
|
|
220
|
-
- **Apply the correct error handling pattern** based on the request type
|
|
221
|
-
- **Test error scenarios** to ensure proper error handling
|
|
222
|
-
- **Verify error messages** are user-friendly and actionable
|
|
323
|
+
- ✅ **Read this error handling documentation** before implementing any custom action
|
|
324
|
+
- ✅ **Identify the type of HTTP request** being made (Wix vs External)
|
|
325
|
+
- ✅ **Apply the correct error handling pattern** based on the request type
|
|
326
|
+
- ✅ **Test error scenarios** to ensure proper error handling
|
|
327
|
+
- ✅ **Verify error messages** are user-friendly and actionable
|
|
328
|
+
- ✅ **Run linter after implementation** to catch any API usage errors
|
|
223
329
|
|
|
224
330
|
### ✅ Common Mistakes to Avoid
|
|
225
331
|
- ❌ **NEVER** wrap external API calls (fetch, axios) with errorHandler
|
|
226
332
|
- ❌ **NEVER** wrap SDK methods (sdk.getOptimisticActions) with errorHandler
|
|
227
333
|
- ❌ **NEVER** forget to wrap Wix HTTP requests with errorHandler
|
|
228
334
|
- ❌ **NEVER** implement custom actions without reading this documentation first
|
|
335
|
+
- ❌ **NEVER** use incorrect API signatures (e.g., `items.queryDataItems()` instead of `items.query()`)
|
|
336
|
+
- ❌ **NEVER** ignore TypeScript/linter errors - they indicate incorrect API usage
|
|
337
|
+
- ❌ **NEVER** use try-catch blocks instead of errorHandler for Wix SDK calls
|
|
338
|
+
|
|
339
|
+
## 🎯 Common Wix SDK API Reference
|
|
340
|
+
|
|
341
|
+
### @wix/data - Data Items API
|
|
342
|
+
|
|
343
|
+
**ALWAYS use with errorHandler.withErrorHandler:**
|
|
344
|
+
|
|
345
|
+
```typescript
|
|
346
|
+
import { items } from '@wix/data';
|
|
347
|
+
import { errorHandler } from '@wix/essentials';
|
|
348
|
+
|
|
349
|
+
// Query all items
|
|
350
|
+
errorHandler.withErrorHandler(async () => {
|
|
351
|
+
const result = await items.query('WixPets').find();
|
|
352
|
+
return result.items;
|
|
353
|
+
}, {});
|
|
354
|
+
|
|
355
|
+
// Query with filters
|
|
356
|
+
errorHandler.withErrorHandler(async () => {
|
|
357
|
+
const result = await items.query('WixPets')
|
|
358
|
+
.contains('name', 'fluffy')
|
|
359
|
+
.eq('age', 5)
|
|
360
|
+
.find();
|
|
361
|
+
return result.items;
|
|
362
|
+
}, {});
|
|
363
|
+
|
|
364
|
+
// Get single item by ID
|
|
365
|
+
errorHandler.withErrorHandler(async () => {
|
|
366
|
+
const item = await items.get('WixPets', itemId);
|
|
367
|
+
return item;
|
|
368
|
+
}, {});
|
|
369
|
+
|
|
370
|
+
// Insert new item
|
|
371
|
+
errorHandler.withErrorHandler(async () => {
|
|
372
|
+
const newItem = await items.insert('WixPets', { name: 'Fluffy', age: 5 });
|
|
373
|
+
return newItem;
|
|
374
|
+
}, {});
|
|
375
|
+
|
|
376
|
+
// Update existing item
|
|
377
|
+
errorHandler.withErrorHandler(async () => {
|
|
378
|
+
const updatedItem = await items.update('WixPets', { _id: itemId, name: 'Updated Name' });
|
|
379
|
+
return updatedItem;
|
|
380
|
+
}, {});
|
|
381
|
+
|
|
382
|
+
// Delete single item
|
|
383
|
+
errorHandler.withErrorHandler(async () => {
|
|
384
|
+
await items.remove('WixPets', itemId);
|
|
385
|
+
}, {});
|
|
386
|
+
|
|
387
|
+
// Bulk delete items
|
|
388
|
+
errorHandler.withErrorHandler(async () => {
|
|
389
|
+
await items.bulkRemove('WixPets', [itemId1, itemId2, itemId3]);
|
|
390
|
+
}, {});
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
### @wix/essentials - Error Handler
|
|
394
|
+
|
|
395
|
+
```typescript
|
|
396
|
+
import { errorHandler } from '@wix/essentials';
|
|
397
|
+
|
|
398
|
+
// Basic pattern (recommended)
|
|
399
|
+
errorHandler.withErrorHandler(
|
|
400
|
+
async () => {
|
|
401
|
+
// Your Wix SDK call here
|
|
402
|
+
return await items.query('WixPets').find();
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
// Optional: Custom error handling
|
|
406
|
+
handleError: (error) => {
|
|
407
|
+
console.error('Custom error handling:', error);
|
|
408
|
+
throw error; // Re-throw to show error to user
|
|
409
|
+
},
|
|
410
|
+
}
|
|
411
|
+
);
|
|
412
|
+
|
|
413
|
+
// Simple pattern (empty options object)
|
|
414
|
+
errorHandler.withErrorHandler(
|
|
415
|
+
async () => {
|
|
416
|
+
return await items.query('WixPets').find();
|
|
417
|
+
},
|
|
418
|
+
{}
|
|
419
|
+
);
|
|
420
|
+
```
|
|
229
421
|
|
|
230
422
|
## Quick Decision Tree for AI Agents
|
|
231
423
|
|
|
@@ -236,7 +428,7 @@ The error handling in your custom data source integrates seamlessly with AutoPat
|
|
|
236
428
|
- **YES** → Go to step 2
|
|
237
429
|
|
|
238
430
|
2. **What type of HTTP request?**
|
|
239
|
-
- **Wix
|
|
431
|
+
- **Wix API libraries with `@wix/` prefix** (@wix/data, @wix/stores, @wix/events, @wix/bookings, @wix/crm) → **WRAP with errorHandler.withErrorHandler**
|
|
240
432
|
- **External APIs** (fetch, axios, third-party) → **NO errorHandler needed**
|
|
241
433
|
- **SDK methods** (sdk.getOptimisticActions, sdk.getSchema) → **NO errorHandler needed**
|
|
242
434
|
|
|
@@ -245,6 +437,15 @@ The error handling in your custom data source integrates seamlessly with AutoPat
|
|
|
245
437
|
- **External requests** are NOT wrapped
|
|
246
438
|
- **SDK methods** are used directly
|
|
247
439
|
|
|
440
|
+
## 🚨 TypeScript Error Detection
|
|
441
|
+
|
|
442
|
+
**CRITICAL**: If you see TypeScript/linter errors when using Wix SDK methods:
|
|
443
|
+
|
|
444
|
+
1. ✅ **Check the import** - Make sure you're importing from the correct package
|
|
445
|
+
2. ✅ **Check the method signature** - Verify you're using the correct API signature (refer to the API reference above)
|
|
446
|
+
3. ✅ **Check errorHandler wrapping** - Ensure the call is wrapped with `errorHandler.withErrorHandler`
|
|
447
|
+
4. ✅ **Run linter** - Read the linter error message carefully; it tells you what's wrong
|
|
448
|
+
|
|
248
449
|
## Complete Examples for All Custom Action Types
|
|
249
450
|
|
|
250
451
|
### ActionCell Custom Actions
|
|
@@ -437,9 +638,44 @@ export const myCustomDataSource = async (collectionId: string, context: any) =>
|
|
|
437
638
|
};
|
|
438
639
|
```
|
|
439
640
|
|
|
641
|
+
### Actions Using Wix API Libraries (REQUIRES errorHandler)
|
|
642
|
+
|
|
643
|
+
**Example 7: Action using Wix API libraries with `wix/` prefix (REQUIRES errorHandler)**
|
|
644
|
+
```typescript
|
|
645
|
+
import { errorHandler } from '@wix/essentials';
|
|
646
|
+
import { data } from '@wix/data';
|
|
647
|
+
import { stores } from '@wix/stores';
|
|
648
|
+
import { CustomActionCellActionResolver } from '@wix/auto-patterns';
|
|
649
|
+
|
|
650
|
+
export const syncWithWixData: CustomActionCellActionResolver = (params) => {
|
|
651
|
+
const { actionParams, sdk } = params;
|
|
652
|
+
const { item } = actionParams;
|
|
653
|
+
|
|
654
|
+
return {
|
|
655
|
+
label: 'Sync with Wix Data',
|
|
656
|
+
icon: <SyncIcon />,
|
|
657
|
+
onClick: () => {
|
|
658
|
+
// ✅ CORRECT: Wix API library calls wrapped with errorHandler
|
|
659
|
+
errorHandler.withErrorHandler(
|
|
660
|
+
async () => {
|
|
661
|
+
// Using @wix/data library
|
|
662
|
+
const dataResult = await data.query('MyCollection').eq('id', item.id).find();
|
|
663
|
+
|
|
664
|
+
// Using @wix/stores library
|
|
665
|
+
const productResult = await stores.queryProducts().eq('sku', item.sku).find();
|
|
666
|
+
|
|
667
|
+
return { dataResult, productResult };
|
|
668
|
+
},
|
|
669
|
+
{}
|
|
670
|
+
);
|
|
671
|
+
},
|
|
672
|
+
};
|
|
673
|
+
};
|
|
674
|
+
```
|
|
675
|
+
|
|
440
676
|
### Actions Using SDK Methods (NO errorHandler needed)
|
|
441
677
|
|
|
442
|
-
**Example
|
|
678
|
+
**Example 8: Action using SDK methods (NO errorHandler needed)**
|
|
443
679
|
```typescript
|
|
444
680
|
import { CustomActionCellActionResolver } from '@wix/auto-patterns';
|
|
445
681
|
|
package/mcp-docs/index.md
CHANGED
|
@@ -26,6 +26,10 @@ This index maps user requests to the appropriate section IDs for fetching releva
|
|
|
26
26
|
**Topics**: Collection page components, table/grid layouts, column configuration
|
|
27
27
|
**Keywords**: collection page, table/grid configuration, layout arrays, Table/Grid layouts, column setup, customColumns, view switching, displaying collections, list views
|
|
28
28
|
|
|
29
|
+
### ID: `views`
|
|
30
|
+
**Topics**: Views configuration, presets, categories, filters integration, column preferences, default view
|
|
31
|
+
**Keywords**: views, presets, categories, columnPreferences, filters, default view, All items, learnMore, placeholder, showTotal
|
|
32
|
+
|
|
29
33
|
### ID: `collection_page_actions`
|
|
30
34
|
**Topics**: Page-level actions, create actions, custom collection actions, action menus
|
|
31
35
|
**Keywords**: page-level actions, collection actions, create actions, adding new items, primaryActions, secondaryActions, action menus, custom actions, navigation
|