@wix/auto-patterns 1.26.0 → 1.28.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.js +16 -7
- package/dist/cjs/components/AutoPatternsApp/AutoPatternsApp.js.map +1 -1
- package/dist/cjs/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.js +2 -2
- package/dist/cjs/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.js.map +1 -1
- package/dist/cjs/components/AutoPatternsCollectionPage/AutoPatternsCollectionPage.js +58 -4
- package/dist/cjs/components/AutoPatternsCollectionPage/AutoPatternsCollectionPage.js.map +1 -1
- package/dist/cjs/components/AutoPatternsRoute/AutoPatternsRoutes.js +19 -5
- package/dist/cjs/components/AutoPatternsRoute/AutoPatternsRoutes.js.map +1 -1
- package/dist/cjs/dataSourceAdapters/cms/cmsAdapter.js +1 -1
- package/dist/cjs/dataSourceAdapters/cms/cmsAdapter.js.map +1 -1
- package/dist/cjs/dataSourceAdapters/cms/fetchCmsData.js +1 -1
- package/dist/cjs/dataSourceAdapters/cms/fetchCmsData.js.map +1 -1
- package/dist/cjs/hooks/index.js +19 -0
- package/dist/cjs/hooks/index.js.map +1 -1
- package/dist/cjs/hooks/useAutoPatternsOptimisticActions.js +13 -6
- package/dist/cjs/hooks/useAutoPatternsOptimisticActions.js.map +1 -1
- package/dist/cjs/hooks/useBaseCollectionParams.js +38 -0
- package/dist/cjs/hooks/useBaseCollectionParams.js.map +1 -0
- package/dist/cjs/hooks/useCommonCollectionFeatures.js +13 -6
- package/dist/cjs/hooks/useCommonCollectionFeatures.js.map +1 -1
- package/dist/cjs/hooks/useFetchData.js +4 -5
- package/dist/cjs/hooks/useFetchData.js.map +1 -1
- package/dist/cjs/hooks/useGridFeatures.js +9 -26
- package/dist/cjs/hooks/useGridFeatures.js.map +1 -1
- package/dist/cjs/hooks/useNavigationUtils.js +21 -6
- package/dist/cjs/hooks/useNavigationUtils.js.map +1 -1
- package/dist/cjs/hooks/useTableFeatures.js +9 -26
- package/dist/cjs/hooks/useTableFeatures.js.map +1 -1
- package/dist/cjs/hooks/useTableGridSwitchFeatures.js +11 -28
- package/dist/cjs/hooks/useTableGridSwitchFeatures.js.map +1 -1
- package/dist/cjs/hooks/useUpdateAppContextItems.js +18 -0
- package/dist/cjs/hooks/useUpdateAppContextItems.js.map +1 -0
- package/dist/cjs/providers/AppContext.js +58 -0
- package/dist/cjs/providers/AppContext.js.map +1 -0
- package/dist/cjs/providers/ItemsContext.js +37 -0
- package/dist/cjs/providers/ItemsContext.js.map +1 -0
- package/dist/cjs/providers/PatternsWizardOverridesContext.js +1 -1
- package/dist/cjs/providers/PatternsWizardOverridesContext.js.map +1 -1
- package/dist/cjs/providers/index.js +12 -0
- package/dist/cjs/providers/index.js.map +1 -1
- package/dist/cjs/types/CollectionPageConfig.js.map +1 -1
- package/dist/cjs/types/fetchData.js +4 -0
- package/dist/cjs/types/fetchData.js.map +1 -0
- package/dist/cjs/types/index.js +6 -0
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/types.js.map +1 -1
- package/dist/docs/app_config_structure.md +1 -0
- package/dist/docs/auto-patterns-guide.md +270 -40
- package/dist/docs/bulk_actions.md +2 -5
- package/dist/docs/collection_page_actions.md +3 -12
- package/dist/docs/custom_overrides.md +1 -15
- package/dist/docs/entity_page_actions.md +3 -3
- package/dist/docs/entity_page_view_actions.md +2 -2
- package/dist/docs/error_handling.md +135 -0
- package/dist/docs/index.md +8 -0
- package/dist/docs/resolved_action.md +106 -0
- package/dist/docs/schema_config.md +11 -3
- package/dist/docs/wix_fqdn_custom_data_source.md +49 -7
- package/dist/esm/components/AutoPatternsApp/AutoPatternsApp.js +5 -3
- package/dist/esm/components/AutoPatternsApp/AutoPatternsApp.js.map +1 -1
- package/dist/esm/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.js +2 -2
- package/dist/esm/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.js.map +1 -1
- package/dist/esm/components/AutoPatternsCollectionPage/AutoPatternsCollectionPage.js +24 -0
- package/dist/esm/components/AutoPatternsCollectionPage/AutoPatternsCollectionPage.js.map +1 -1
- package/dist/esm/components/AutoPatternsRoute/AutoPatternsRoutes.js +8 -0
- package/dist/esm/components/AutoPatternsRoute/AutoPatternsRoutes.js.map +1 -1
- package/dist/esm/dataSourceAdapters/cms/cmsAdapter.js +1 -1
- package/dist/esm/dataSourceAdapters/cms/cmsAdapter.js.map +1 -1
- package/dist/esm/dataSourceAdapters/cms/fetchCmsData.js +1 -1
- package/dist/esm/dataSourceAdapters/cms/fetchCmsData.js.map +1 -1
- package/dist/esm/hooks/index.js +2 -0
- package/dist/esm/hooks/index.js.map +1 -1
- package/dist/esm/hooks/useAutoPatternsOptimisticActions.js +14 -9
- package/dist/esm/hooks/useAutoPatternsOptimisticActions.js.map +1 -1
- package/dist/esm/hooks/useBaseCollectionParams.js +37 -0
- package/dist/esm/hooks/useBaseCollectionParams.js.map +1 -0
- package/dist/esm/hooks/useCommonCollectionFeatures.js +9 -2
- package/dist/esm/hooks/useCommonCollectionFeatures.js.map +1 -1
- package/dist/esm/hooks/useFetchData.js +2 -2
- package/dist/esm/hooks/useFetchData.js.map +1 -1
- package/dist/esm/hooks/useGridFeatures.js +10 -30
- package/dist/esm/hooks/useGridFeatures.js.map +1 -1
- package/dist/esm/hooks/useNavigationUtils.js +21 -6
- package/dist/esm/hooks/useNavigationUtils.js.map +1 -1
- package/dist/esm/hooks/useTableFeatures.js +10 -30
- package/dist/esm/hooks/useTableFeatures.js.map +1 -1
- package/dist/esm/hooks/useTableGridSwitchFeatures.js +12 -32
- package/dist/esm/hooks/useTableGridSwitchFeatures.js.map +1 -1
- package/dist/esm/hooks/useUpdateAppContextItems.js +13 -0
- package/dist/esm/hooks/useUpdateAppContextItems.js.map +1 -0
- package/dist/esm/providers/AppContext.js +31 -0
- package/dist/esm/providers/AppContext.js.map +1 -0
- package/dist/esm/providers/ItemsContext.js +23 -0
- package/dist/esm/providers/ItemsContext.js.map +1 -0
- package/dist/esm/providers/PatternsWizardOverridesContext.js.map +1 -1
- package/dist/esm/providers/index.js +1 -0
- package/dist/esm/providers/index.js.map +1 -1
- package/dist/esm/types/CollectionPageConfig.js.map +1 -1
- package/dist/esm/types/fetchData.js +2 -0
- package/dist/esm/types/fetchData.js.map +1 -0
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/types.js.map +1 -1
- package/dist/types/components/AutoPatternsApp/AutoPatternsApp.d.ts +1 -0
- package/dist/types/components/AutoPatternsApp/AutoPatternsApp.d.ts.map +1 -1
- package/dist/types/components/AutoPatternsCollectionPage/AutoPatternsCollectionPage.d.ts.map +1 -1
- package/dist/types/components/AutoPatternsRoute/AutoPatternsRoutes.d.ts.map +1 -1
- package/dist/types/hooks/index.d.ts +2 -0
- package/dist/types/hooks/index.d.ts.map +1 -1
- package/dist/types/hooks/useAutoPatternsOptimisticActions.d.ts +7 -1
- package/dist/types/hooks/useAutoPatternsOptimisticActions.d.ts.map +1 -1
- package/dist/types/hooks/useBaseCollectionParams.d.ts +27 -0
- package/dist/types/hooks/useBaseCollectionParams.d.ts.map +1 -0
- package/dist/types/hooks/useCommonCollectionFeatures.d.ts +4 -3
- package/dist/types/hooks/useCommonCollectionFeatures.d.ts.map +1 -1
- package/dist/types/hooks/useFetchData.d.ts +3 -13
- package/dist/types/hooks/useFetchData.d.ts.map +1 -1
- package/dist/types/hooks/useGridFeatures.d.ts +1 -1
- package/dist/types/hooks/useGridFeatures.d.ts.map +1 -1
- package/dist/types/hooks/useNavigationUtils.d.ts +5 -1
- package/dist/types/hooks/useNavigationUtils.d.ts.map +1 -1
- package/dist/types/hooks/useTableFeatures.d.ts +1 -1
- package/dist/types/hooks/useTableFeatures.d.ts.map +1 -1
- package/dist/types/hooks/useTableGridSwitchFeatures.d.ts +1 -1
- package/dist/types/hooks/useTableGridSwitchFeatures.d.ts.map +1 -1
- package/dist/types/hooks/useUpdateAppContextItems.d.ts +2 -0
- package/dist/types/hooks/useUpdateAppContextItems.d.ts.map +1 -0
- package/dist/types/providers/AppContext.d.ts +11 -0
- package/dist/types/providers/AppContext.d.ts.map +1 -0
- package/dist/types/providers/ItemsContext.d.ts +11 -0
- package/dist/types/providers/ItemsContext.d.ts.map +1 -0
- package/dist/types/providers/PatternsWizardOverridesContext.d.ts +2 -1
- package/dist/types/providers/PatternsWizardOverridesContext.d.ts.map +1 -1
- package/dist/types/providers/index.d.ts +1 -0
- package/dist/types/providers/index.d.ts.map +1 -1
- package/dist/types/types/CollectionPageConfig.d.ts +4 -0
- package/dist/types/types/CollectionPageConfig.d.ts.map +1 -1
- package/dist/types/types/fetchData.d.ts +21 -0
- package/dist/types/types/fetchData.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/types/types.d.ts +6 -5
- package/dist/types/types/types.d.ts.map +1 -1
- package/package.json +14 -14
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Error Handling for HTTP Requests
|
|
2
|
+
|
|
3
|
+
**⚠️ 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.
|
|
4
|
+
|
|
5
|
+
## What Requires Error Handling
|
|
6
|
+
|
|
7
|
+
**ONLY the following HTTP requests** in your custom data source actions must be wrapped with `errorHandler`:
|
|
8
|
+
|
|
9
|
+
- **httpClient from @wix/essentials** (e.g., `httpClient.request(getDummyEntity(...))`)
|
|
10
|
+
- **Wix APIs** (e.g., `wix/data`, `wix/stores`, `items.get()`, `items.insert()`, `collections.getDataCollection()`)
|
|
11
|
+
- **httpClient.fetchWithAuth()** calls
|
|
12
|
+
|
|
13
|
+
**DO NOT use errorHandler with:**
|
|
14
|
+
|
|
15
|
+
- **External API calls** using `fetch()`, `axios.get()`, or other HTTP libraries
|
|
16
|
+
- **Custom HTTP clients** (e.g., any non-Wix HTTP request library)
|
|
17
|
+
- **Third-party API calls** using non-Wix HTTP methods
|
|
18
|
+
|
|
19
|
+
**EXCEPTION**: SDK actions that you get from the AutoPatterns SDK (e.g., `sdk.getOptimisticActions()`, `sdk.getSchema()`) do NOT need error handling as they are already handled internally.
|
|
20
|
+
|
|
21
|
+
## Why Error Handling is Required
|
|
22
|
+
|
|
23
|
+
Custom data sources often make HTTP requests to Wix APIs and services. Without proper error handling:
|
|
24
|
+
|
|
25
|
+
- **Unhandled Promise Rejections**: HTTP failures can crash your application
|
|
26
|
+
- **Poor User Experience**: Users don't get meaningful error messages
|
|
27
|
+
- **Inconsistent Error Management**: Different parts of your app handle errors differently
|
|
28
|
+
- **Debugging Difficulties**: Hard to trace and diagnose API failures
|
|
29
|
+
|
|
30
|
+
## Using @wix/essentials errorHandler
|
|
31
|
+
|
|
32
|
+
The recommended approach is to use the `errorHandler` from `@wix/essentials` package, which provides consistent error handling patterns across Wix applications.
|
|
33
|
+
|
|
34
|
+
### Installation
|
|
35
|
+
|
|
36
|
+
First, ensure `@wix/essentials` is installed in your project:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install @wix/essentials
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Basic Error Handling Pattern
|
|
43
|
+
|
|
44
|
+
Wrap Wix HTTP requests in your custom data source actions with `errorHandler.withErrorHandler`:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { errorHandler } from '@wix/essentials';
|
|
48
|
+
|
|
49
|
+
// In your custom data source actions
|
|
50
|
+
actions: {
|
|
51
|
+
get: async (entityId: string) => {
|
|
52
|
+
return errorHandler.withErrorHandler(
|
|
53
|
+
async () => {
|
|
54
|
+
const response = await httpClient.request(
|
|
55
|
+
getDummyEntity({ dummyEntityId: entityId })
|
|
56
|
+
);
|
|
57
|
+
return response.data.dummyEntity;
|
|
58
|
+
},
|
|
59
|
+
{}
|
|
60
|
+
);
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Examples of HTTP Requests That Need Error Handling
|
|
66
|
+
|
|
67
|
+
**httpClient from @wix/essentials:**
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
return errorHandler.withErrorHandler(async () => {
|
|
71
|
+
const response = await httpClient.request(
|
|
72
|
+
getDummyEntity({ dummyEntityId: entityId })
|
|
73
|
+
);
|
|
74
|
+
return response.data.dummyEntity;
|
|
75
|
+
}, {});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Wix APIs (wix/data, wix/stores):**
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
return errorHandler.withErrorHandler(async () => {
|
|
82
|
+
return await items.get(collectionId, entityId);
|
|
83
|
+
}, {});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**httpClient.fetchWithAuth() calls:**
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
return errorHandler.withErrorHandler(async () => {
|
|
90
|
+
const response = await httpClient.fetchWithAuth("/api/data");
|
|
91
|
+
return await response.json();
|
|
92
|
+
}, {});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Examples of HTTP Requests That Do NOT Need Error Handling
|
|
96
|
+
|
|
97
|
+
**External API calls (using fetch, axios, etc.):**
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
// ✅ CORRECT - No error handling needed for external APIs
|
|
101
|
+
const response = await fetch("https://api.example.com/data");
|
|
102
|
+
return await response.json();
|
|
103
|
+
|
|
104
|
+
// ✅ CORRECT - No error handling needed for axios
|
|
105
|
+
const response = await axios.get("https://api.example.com/data");
|
|
106
|
+
return response.data;
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Third-party HTTP libraries:**
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
// ✅ CORRECT - No error handling needed for third-party HTTP clients
|
|
113
|
+
const response = await someThirdPartyHttpClient.get("/data");
|
|
114
|
+
return response.data;
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Integration with AutoPatterns Error Handling
|
|
118
|
+
|
|
119
|
+
The error handling in your custom data source integrates seamlessly with AutoPatterns' built-in error handling:
|
|
120
|
+
|
|
121
|
+
1. **User-Friendly Messages**: Errors are displayed to users in a consistent format
|
|
122
|
+
2. **Retry Mechanisms**: Users can retry failed operations
|
|
123
|
+
3. **Loading States**: Proper loading states during HTTP requests
|
|
124
|
+
4. **Error Boundaries**: Errors are caught and handled gracefully
|
|
125
|
+
|
|
126
|
+
## Validation Checklist
|
|
127
|
+
|
|
128
|
+
Before deploying your custom data source, ensure:
|
|
129
|
+
|
|
130
|
+
✅ **httpClient from @wix/essentials** is wrapped with `errorHandler.withErrorHandler`
|
|
131
|
+
✅ **Wix APIs (wix/data, wix/stores, etc)** are wrapped with `errorHandler.withErrorHandler`
|
|
132
|
+
✅ **httpClient.fetchWithAuth()** calls are wrapped with `errorHandler.withErrorHandler`
|
|
133
|
+
✅ **External API calls are NOT wrapped** with errorHandler (e.g., fetch(), axios, third-party HTTP clients)
|
|
134
|
+
✅ **SDK actions are used directly** without error handling (e.g., `sdk.getOptimisticActions()`, `sdk.getSchema()`)
|
|
135
|
+
✅ **@wix/essentials** is installed as a dependency
|
package/dist/docs/index.md
CHANGED
|
@@ -58,6 +58,10 @@ This index maps user requests to the appropriate section IDs for fetching releva
|
|
|
58
58
|
**Topics**: Entity page view mode actions, primaryActions, secondaryActions, collection-style actions
|
|
59
59
|
**Keywords**: view mode actions, primaryActions, secondaryActions, read-only entity actions, entity page view operations, collection-style entity actions, navigation actions
|
|
60
60
|
|
|
61
|
+
### ID: `resolved_action`
|
|
62
|
+
**Topics**: ResolvedAction interface, common return type for custom actions, field documentation
|
|
63
|
+
**Keywords**: ResolvedAction, action return type, custom action interface, action fields, label, icon, onClick, disabled, hidden, tooltip, skin
|
|
64
|
+
|
|
61
65
|
### ID: `installation`
|
|
62
66
|
**Topics**: Package installation, setup process, component integration, provider setup
|
|
63
67
|
**Keywords**: installation, setup, getting started, initial setup, package installation, dependencies, component integration, provider setup
|
|
@@ -70,6 +74,10 @@ This index maps user requests to the appropriate section IDs for fetching releva
|
|
|
70
74
|
**Topics**: FQDN-based custom data sources, Wix Business API integration, schema mapping, custom data source implementation
|
|
71
75
|
**Keywords**: FQDN, Wix Business API, custom data source, schema mapping, client library, field type mapping, custom implementation, entityTypeSource custom, Business API integration, schema extraction
|
|
72
76
|
|
|
77
|
+
### ID: `error_handling`
|
|
78
|
+
**Topics**: HTTP request error handling, errorHandler usage, custom data source error management, API error handling
|
|
79
|
+
**Keywords**: error handling, HTTP errors, API errors, errorHandler, @wix/essentials, custom data source errors, error management, promise rejections, user experience, error messages
|
|
80
|
+
|
|
73
81
|
---
|
|
74
82
|
|
|
75
83
|
## Recipe Section IDs (Step-by-Step Guides)
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# ResolvedAction: Common Return Type for Custom Actions
|
|
2
|
+
|
|
3
|
+
All custom action resolvers in Auto Patterns must return a `ResolvedAction`. This applies to:
|
|
4
|
+
- Collection page actions (primary, secondary, menus) and `onRowClick`
|
|
5
|
+
- Entity page actions (view mode: primary/secondary/more; edit mode: moreActions)
|
|
6
|
+
- Bulk action toolbar actions
|
|
7
|
+
- Action Cell actions
|
|
8
|
+
|
|
9
|
+
## Type Definition
|
|
10
|
+
|
|
11
|
+
From `@wix/auto-patterns`:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
export interface ResolvedAction {
|
|
15
|
+
label: string;
|
|
16
|
+
icon: IconElement;
|
|
17
|
+
onClick: () => void;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
hidden?: boolean;
|
|
20
|
+
tooltip?: string;
|
|
21
|
+
skin?: string;
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Field Reference
|
|
26
|
+
|
|
27
|
+
### Required Fields
|
|
28
|
+
|
|
29
|
+
- **`label`** (string): Text displayed in the button or menu item.
|
|
30
|
+
- **`icon`** (IconElement): An icon component, typically from `@wix/wix-ui-icons-common`. Example: `icon: <Delete />`.
|
|
31
|
+
- **`onClick`** (function): Handler function invoked when the user triggers the action. Can be async.
|
|
32
|
+
|
|
33
|
+
### Optional Fields
|
|
34
|
+
|
|
35
|
+
- **`disabled`** (boolean): When `true`, renders the action as disabled. Pair with `tooltip` to explain why the action is unavailable.
|
|
36
|
+
- **`hidden`** (boolean): When `true`, the action is completely omitted from the UI. Useful for permission-based or state-based visibility control.
|
|
37
|
+
- **`tooltip`** (string): Tooltip text displayed on hover. Especially useful when the action is disabled.
|
|
38
|
+
- **`skin`** (string): Visual style of the action button. Availability may vary by placement context. Recommended values:
|
|
39
|
+
- Primary actions: `"standard"`, `"inverted"`, `"premium"`
|
|
40
|
+
- Secondary/more/menu items: `"dark"`, `"destructive"`, `"premium"`
|
|
41
|
+
- If unsure, omit `skin` or use `"standard"` for primary actions and `"dark"` for secondary actions.
|
|
42
|
+
|
|
43
|
+
## Examples
|
|
44
|
+
|
|
45
|
+
### Minimal Example
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { Add } from '@wix/wix-ui-icons-common';
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
label: 'Create',
|
|
52
|
+
icon: <Add />,
|
|
53
|
+
onClick: () => {
|
|
54
|
+
// Your action logic here
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Complete Example with State Control
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { Download } from '@wix/wix-ui-icons-common';
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
label: 'Export',
|
|
66
|
+
icon: <Download />,
|
|
67
|
+
onClick: async () => {
|
|
68
|
+
try {
|
|
69
|
+
// Perform export logic using SDK
|
|
70
|
+
await performExport();
|
|
71
|
+
} catch (error) {
|
|
72
|
+
// Handle errors, show toast, etc.
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
disabled: total === 0,
|
|
76
|
+
tooltip: total === 0 ? 'Select at least one item to export' : undefined,
|
|
77
|
+
hidden: !userHasExportPermission,
|
|
78
|
+
skin: 'premium'
|
|
79
|
+
};
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Context-Specific Notes
|
|
83
|
+
|
|
84
|
+
### Collection Page Actions
|
|
85
|
+
- **onRowClick**: Access clicked item data via `actionParams.item`
|
|
86
|
+
- **Collection-level actions**: Access collection context via `actionParams.collectionId`
|
|
87
|
+
|
|
88
|
+
### Entity Page Actions
|
|
89
|
+
- **View/Edit mode**: Access entity data via `actionParams.entity`
|
|
90
|
+
- **Edit mode only**: Access form instance via `actionParams.form`
|
|
91
|
+
|
|
92
|
+
### Bulk Actions
|
|
93
|
+
- **Selection data**: Use `actionParams.selectedValues` and `actionParams.total`
|
|
94
|
+
- **State control**: Commonly use `disabled: selectedValues.length === 0`
|
|
95
|
+
|
|
96
|
+
### Action Cell Actions
|
|
97
|
+
- **Row context**: Access item and position via `actionParams.item` and `actionParams.index`
|
|
98
|
+
|
|
99
|
+
## See Also
|
|
100
|
+
|
|
101
|
+
- [Collection Page Actions](./collection_page_actions.md)
|
|
102
|
+
- [Entity Page Actions](./entity_page_actions.md) (edit mode)
|
|
103
|
+
- [Entity Page View Actions](./entity_page_view_actions.md)
|
|
104
|
+
- [Bulk Actions Toolbar](./bulk_actions.md)
|
|
105
|
+
- [Action Cell](./action_cell.md)
|
|
106
|
+
- [App Config Structure](./app_config_structure.md) (action item `skin` property)
|
|
@@ -16,19 +16,25 @@ export interface SchemaConfig {
|
|
|
16
16
|
update: (updatedEntity: any) => Promise<any>;
|
|
17
17
|
delete: (entityId: string) => Promise<any>;
|
|
18
18
|
bulkDelete: (entityIds: string[]) => Promise<any>;
|
|
19
|
+
// The return shape depends on pagination mode (see AppConfig.collection.paginationMode)
|
|
20
|
+
// - Cursor mode: { items, cursor, total? }
|
|
21
|
+
// - Offset mode (default): { items, hasNext, total? }
|
|
19
22
|
find: (
|
|
20
23
|
query: Query,
|
|
21
24
|
options?: {
|
|
22
25
|
searchableFieldIds?: string[];
|
|
23
26
|
filterFieldMapping?: Record<string, { fieldId: string }>;
|
|
24
27
|
},
|
|
25
|
-
) => Promise<
|
|
28
|
+
) => Promise<
|
|
29
|
+
| { items: any[]; cursor?: string | null; total?: number | null }
|
|
30
|
+
| { items: any[]; hasNext?: boolean; total?: number | null }
|
|
31
|
+
>;
|
|
26
32
|
};
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
export interface Query {
|
|
30
36
|
limit: number; // Maximum number of items to return per request (controls page size)
|
|
31
|
-
offset
|
|
37
|
+
offset?: number; // Number of items to skip from the beginning (for pagination)
|
|
32
38
|
page: number; // Current page number (1-based, works with limit for pagination)
|
|
33
39
|
search?: string; // Text search query applied to searchable fields
|
|
34
40
|
cursor?: string | null; // Cursor-based pagination token (alternative to offset-based pagination)
|
|
@@ -127,7 +133,9 @@ export type Field = ReferenceField | NonReferenceField;
|
|
|
127
133
|
- `query`: Query object with pagination, filtering, sorting, and search criteria (see Query Interface section)
|
|
128
134
|
- `options.searchableFieldIds`: Array of field IDs that support text search
|
|
129
135
|
- `options.filterFieldMapping`: Maps filter IDs to actual field IDs for complex filtering
|
|
130
|
-
- Returns
|
|
136
|
+
- Returns (depends on pagination mode):
|
|
137
|
+
- Cursor mode: `{ items: any[]; cursor?: string | null; total?: number | null }`
|
|
138
|
+
- Offset mode (default): `{ items: any[]; hasNext?: boolean; total?: number | null }`
|
|
131
139
|
|
|
132
140
|
### Field Type Information
|
|
133
141
|
|
|
@@ -114,6 +114,7 @@ Follow the complete custom data source implementation guide in the "Custom Overr
|
|
|
114
114
|
1. **Import the client library** identified in Step 2
|
|
115
115
|
2. **Use the field mappings** from Step 3 in your SchemaConfig
|
|
116
116
|
3. **⚠️ CRITICAL: DO NOT IMPLEMENT THE ACTIONS** - Instead, add guidance comments explaining how to use the imported client library for each CRUD operation, then throw an "unimplemented exception" error
|
|
117
|
+
4. **⚠️ CRITICAL: Add Error Handling** - When implementing the actions, you MUST wrap all HTTP requests with proper error handling using `errorHandler` from `@wix/essentials` (see "Error Handling for HTTP Requests" section)
|
|
117
118
|
|
|
118
119
|
**Important**: The schema actions should contain helpful comments but NOT actual implementations. Each action should throw an error indicating it's unimplemented and needs to be implemented by the user.
|
|
119
120
|
|
|
@@ -123,6 +124,8 @@ Create your custom data source with the hook pattern:
|
|
|
123
124
|
|
|
124
125
|
In `components/customDataSources/myCustomDataSource.ts`:
|
|
125
126
|
```typescript
|
|
127
|
+
import { errorHandler } from '@wix/essentials';
|
|
128
|
+
|
|
126
129
|
export const myCustomDataSource = async (collectionId: string, context: any) => {
|
|
127
130
|
return {
|
|
128
131
|
id: 'myCustomCollection',
|
|
@@ -134,37 +137,76 @@ export const myCustomDataSource = async (collectionId: string, context: any) =>
|
|
|
134
137
|
actions: {
|
|
135
138
|
get: async (entityId: string) => {
|
|
136
139
|
// TODO: Implement using your FQDN client library
|
|
137
|
-
// Example:
|
|
140
|
+
// Example:
|
|
141
|
+
// return errorHandler.withErrorHandler(
|
|
142
|
+
// async () => {
|
|
143
|
+
// return yourFQDNClient.getEntity(entityId);
|
|
144
|
+
// },
|
|
145
|
+
// {}
|
|
146
|
+
// );
|
|
138
147
|
// Remember to map the response fields from snake_case to camelCase
|
|
139
148
|
throw new Error('get action not implemented - user must implement this method');
|
|
140
149
|
},
|
|
141
150
|
create: async (newEntity: any) => {
|
|
142
151
|
// TODO: Implement using your FQDN client library
|
|
143
|
-
// Example:
|
|
152
|
+
// Example:
|
|
153
|
+
// return errorHandler.withErrorHandler(
|
|
154
|
+
// async () => {
|
|
155
|
+
// return yourFQDNClient.createEntity(newEntity);
|
|
156
|
+
// },
|
|
157
|
+
// {}
|
|
158
|
+
// );
|
|
144
159
|
// Remember to map the request fields from camelCase to snake_case
|
|
145
160
|
throw new Error('create action not implemented - user must implement this method');
|
|
146
161
|
},
|
|
147
162
|
update: async (updatedEntity: any) => {
|
|
148
163
|
// TODO: Implement using your FQDN client library
|
|
149
|
-
// Example:
|
|
164
|
+
// Example:
|
|
165
|
+
// return errorHandler.withErrorHandler(
|
|
166
|
+
// async () => {
|
|
167
|
+
// return yourFQDNClient.updateEntity(updatedEntity);
|
|
168
|
+
// },
|
|
169
|
+
// {}
|
|
170
|
+
// );
|
|
150
171
|
// Remember to map the request fields from camelCase to snake_case
|
|
151
172
|
throw new Error('update action not implemented - user must implement this method');
|
|
152
173
|
},
|
|
153
174
|
delete: async (entityId: string) => {
|
|
154
175
|
// TODO: Implement using your FQDN client library
|
|
155
|
-
// Example:
|
|
176
|
+
// Example:
|
|
177
|
+
// return errorHandler.withErrorHandler(
|
|
178
|
+
// async () => {
|
|
179
|
+
// return yourFQDNClient.deleteEntity(entityId);
|
|
180
|
+
// },
|
|
181
|
+
// {}
|
|
182
|
+
// );
|
|
156
183
|
throw new Error('delete action not implemented - user must implement this method');
|
|
157
184
|
},
|
|
158
185
|
bulkDelete: async (entityIds: string[]) => {
|
|
159
186
|
// TODO: Implement using your FQDN client library
|
|
160
|
-
// Example:
|
|
187
|
+
// Example:
|
|
188
|
+
// return errorHandler.withErrorHandler(
|
|
189
|
+
// async () => {
|
|
190
|
+
// return yourFQDNClient.bulkDeleteEntities(entityIds);
|
|
191
|
+
// },
|
|
192
|
+
// {}
|
|
193
|
+
// );
|
|
161
194
|
throw new Error('bulkDelete action not implemented - user must implement this method');
|
|
162
195
|
},
|
|
163
196
|
find: async (query: Query, options?: any) => {
|
|
164
197
|
// TODO: Implement using your FQDN client library
|
|
165
|
-
// Example:
|
|
198
|
+
// Example:
|
|
199
|
+
// return errorHandler.withErrorHandler(
|
|
200
|
+
// async () => {
|
|
201
|
+
// return yourFQDNClient.queryEntities(query, options);
|
|
202
|
+
// },
|
|
203
|
+
// {}
|
|
204
|
+
// );
|
|
166
205
|
// Remember to map the response fields from snake_case to camelCase
|
|
167
|
-
//
|
|
206
|
+
// IMPORTANT: Return shape depends on pagination mode.
|
|
207
|
+
// Detect by presence of query.cursor (cursor mode) vs. query.offset/page (offset mode):
|
|
208
|
+
// - Cursor mode: return { items, cursor, total? }
|
|
209
|
+
// - Offset mode (default): return { items, hasNext, total? }
|
|
168
210
|
throw new Error('find action not implemented - user must implement this method');
|
|
169
211
|
}
|
|
170
212
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { RootAppProvider } from '../../providers/RootAppProvider';
|
|
3
|
+
import { AppContextProvider } from '../../providers/AppContext';
|
|
3
4
|
import { AutoPatternsRoutes } from '../AutoPatternsRoute/AutoPatternsRoutes';
|
|
4
5
|
export const AutoPatternsApp = _ref => {
|
|
5
6
|
let {
|
|
6
|
-
configuration
|
|
7
|
+
configuration,
|
|
8
|
+
children
|
|
7
9
|
} = _ref;
|
|
8
|
-
return /*#__PURE__*/React.createElement(RootAppProvider, {
|
|
10
|
+
return /*#__PURE__*/React.createElement(AppContextProvider, null, /*#__PURE__*/React.createElement(RootAppProvider, {
|
|
9
11
|
appConfig: configuration
|
|
10
12
|
}, /*#__PURE__*/React.createElement(AutoPatternsRoutes, {
|
|
11
13
|
config: configuration
|
|
12
|
-
}));
|
|
14
|
+
})), children);
|
|
13
15
|
};
|
|
14
16
|
//# sourceMappingURL=AutoPatternsApp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","RootAppProvider","AutoPatternsRoutes","AutoPatternsApp","_ref","configuration","createElement","appConfig","config"],"sources":["../../../../src/components/AutoPatternsApp/AutoPatternsApp.tsx"],"sourcesContent":["import React from 'react';\nimport { AppConfig } from '../../types';\nimport { RootAppProvider } from '../../providers/RootAppProvider';\nimport { AutoPatternsRoutes } from '../AutoPatternsRoute/AutoPatternsRoutes';\n\nexport interface AutoPatternsAppProps {\n configuration: AppConfig;\n}\n\nexport const AutoPatternsApp: React.FC<AutoPatternsAppProps> = ({\n configuration,\n}) => {\n return (\n <RootAppProvider appConfig={configuration}>\n
|
|
1
|
+
{"version":3,"names":["React","RootAppProvider","AppContextProvider","AutoPatternsRoutes","AutoPatternsApp","_ref","configuration","children","createElement","appConfig","config"],"sources":["../../../../src/components/AutoPatternsApp/AutoPatternsApp.tsx"],"sourcesContent":["import React from 'react';\nimport { AppConfig } from '../../types';\nimport { RootAppProvider } from '../../providers/RootAppProvider';\nimport { AppContextProvider } from '../../providers/AppContext';\nimport { AutoPatternsRoutes } from '../AutoPatternsRoute/AutoPatternsRoutes';\n\nexport interface AutoPatternsAppProps {\n configuration: AppConfig;\n children?: React.ReactNode;\n}\n\nexport const AutoPatternsApp: React.FC<AutoPatternsAppProps> = ({\n configuration,\n children,\n}) => {\n return (\n <AppContextProvider>\n <RootAppProvider appConfig={configuration}>\n <AutoPatternsRoutes config={configuration} />\n </RootAppProvider>\n {children}\n </AppContextProvider>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,eAAe,QAAQ,iCAAiC;AACjE,SAASC,kBAAkB,QAAQ,4BAA4B;AAC/D,SAASC,kBAAkB,QAAQ,yCAAyC;AAO5E,OAAO,MAAMC,eAA+C,GAAGC,IAAA,IAGzD;EAAA,IAH0D;IAC9DC,aAAa;IACbC;EACF,CAAC,GAAAF,IAAA;EACC,oBACEL,KAAA,CAAAQ,aAAA,CAACN,kBAAkB,qBACjBF,KAAA,CAAAQ,aAAA,CAACP,eAAe;IAACQ,SAAS,EAAEH;EAAc,gBACxCN,KAAA,CAAAQ,aAAA,CAACL,kBAAkB;IAACO,MAAM,EAAEJ;EAAc,CAAE,CAC7B,CAAC,EACjBC,QACiB,CAAC;AAEzB,CAAC","ignoreList":[]}
|
package/dist/esm/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AutoPatternsTableGridSwitch } from '../AutoPatternsTableGridSwitch/AutoPatternsTableGridSwitch';
|
|
2
|
-
import { AutoPatternsTable } from '../AutoPatternsTable';
|
|
3
|
-
import { AutoPatternsGrid } from '../AutoPatternsGrid';
|
|
2
|
+
import { AutoPatternsTable } from '../AutoPatternsTable/AutoPatternsTable';
|
|
3
|
+
import { AutoPatternsGrid } from '../AutoPatternsGrid/AutoPatternsGrid';
|
|
4
4
|
import { SchemaProvider } from '../../providers';
|
|
5
5
|
import { SkeletonCollection } from '../AutoPatternsCollectionPageContent/SkeletonCollection';
|
|
6
6
|
import React, { useMemo } from 'react';
|
package/dist/esm/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AutoPatternsTableGridSwitch","AutoPatternsTable","AutoPatternsGrid","SchemaProvider","SkeletonCollection","React","useMemo","AutoPatternsCollectionComponent","_ref","component","index","layout","sharedConfig","memoized","_layout$find","_layout$find2","length","componentToRender","componentType","tableConfig","find","item","type","table","gridConfig","grid","config","createElement","configuration","Fragment","key","collection","collectionId","skeleton"],"sources":["../../../../src/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.tsx"],"sourcesContent":["import { CollectionComponentConfig } from '../../types';\nimport { AutoPatternsTableGridSwitch } from '../AutoPatternsTableGridSwitch/AutoPatternsTableGridSwitch';\nimport { AutoPatternsTable } from '../AutoPatternsTable';\nimport { AutoPatternsGrid } from '../AutoPatternsGrid';\nimport { SchemaProvider } from '../../providers';\nimport { SkeletonCollection } from '../AutoPatternsCollectionPageContent/SkeletonCollection';\nimport React, { useMemo } from 'react';\n\nexport const AutoPatternsCollectionComponent = ({\n component,\n index,\n}: {\n component: CollectionComponentConfig;\n index: number;\n}) => {\n const { layout, ...sharedConfig } = component;\n\n const memoized = useMemo(() => {\n if (!layout?.length) {\n return {\n componentToRender: null,\n componentType: 'Table' as 'Table' | 'Grid',\n };\n }\n\n const tableConfig = layout.find((item) => item.type === 'Table')?.table;\n const gridConfig = layout.find((item) => item.type === 'Grid')?.grid;\n\n let componentType: 'Table' | 'Grid' = 'Table';\n let componentToRender: React.ReactNode = null;\n\n if (tableConfig && gridConfig) {\n const config = {\n ...sharedConfig,\n ...tableConfig,\n ...gridConfig,\n };\n componentToRender = (\n <AutoPatternsTableGridSwitch configuration={config} />\n );\n } else if (tableConfig) {\n const config = { ...sharedConfig, ...tableConfig };\n componentToRender = <AutoPatternsTable configuration={config} />;\n } else if (gridConfig) {\n componentType = 'Grid';\n const config = { ...sharedConfig, ...gridConfig };\n componentToRender = <AutoPatternsGrid configuration={config} />;\n }\n\n return { componentToRender, componentType };\n }, [layout, sharedConfig]);\n\n const { componentToRender, componentType } = memoized;\n\n return (\n <>\n {componentToRender ? (\n <SchemaProvider\n key={`${sharedConfig.collection.collectionId}-${index}`}\n collection={sharedConfig.collection}\n skeleton={<SkeletonCollection componentType={componentType} />}\n >\n {componentToRender}\n </SchemaProvider>\n ) : null}\n </>\n );\n};\n"],"mappings":"AACA,SAASA,2BAA2B,QAAQ,4DAA4D;AACxG,SAASC,iBAAiB,QAAQ,
|
|
1
|
+
{"version":3,"names":["AutoPatternsTableGridSwitch","AutoPatternsTable","AutoPatternsGrid","SchemaProvider","SkeletonCollection","React","useMemo","AutoPatternsCollectionComponent","_ref","component","index","layout","sharedConfig","memoized","_layout$find","_layout$find2","length","componentToRender","componentType","tableConfig","find","item","type","table","gridConfig","grid","config","createElement","configuration","Fragment","key","collection","collectionId","skeleton"],"sources":["../../../../src/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.tsx"],"sourcesContent":["import { CollectionComponentConfig } from '../../types';\nimport { AutoPatternsTableGridSwitch } from '../AutoPatternsTableGridSwitch/AutoPatternsTableGridSwitch';\nimport { AutoPatternsTable } from '../AutoPatternsTable/AutoPatternsTable';\nimport { AutoPatternsGrid } from '../AutoPatternsGrid/AutoPatternsGrid';\nimport { SchemaProvider } from '../../providers';\nimport { SkeletonCollection } from '../AutoPatternsCollectionPageContent/SkeletonCollection';\nimport React, { useMemo } from 'react';\n\nexport const AutoPatternsCollectionComponent = ({\n component,\n index,\n}: {\n component: CollectionComponentConfig;\n index: number;\n}) => {\n const { layout, ...sharedConfig } = component;\n\n const memoized = useMemo(() => {\n if (!layout?.length) {\n return {\n componentToRender: null,\n componentType: 'Table' as 'Table' | 'Grid',\n };\n }\n\n const tableConfig = layout.find((item) => item.type === 'Table')?.table;\n const gridConfig = layout.find((item) => item.type === 'Grid')?.grid;\n\n let componentType: 'Table' | 'Grid' = 'Table';\n let componentToRender: React.ReactNode = null;\n\n if (tableConfig && gridConfig) {\n const config = {\n ...sharedConfig,\n ...tableConfig,\n ...gridConfig,\n };\n componentToRender = (\n <AutoPatternsTableGridSwitch configuration={config} />\n );\n } else if (tableConfig) {\n const config = { ...sharedConfig, ...tableConfig };\n componentToRender = <AutoPatternsTable configuration={config} />;\n } else if (gridConfig) {\n componentType = 'Grid';\n const config = { ...sharedConfig, ...gridConfig };\n componentToRender = <AutoPatternsGrid configuration={config} />;\n }\n\n return { componentToRender, componentType };\n }, [layout, sharedConfig]);\n\n const { componentToRender, componentType } = memoized;\n\n return (\n <>\n {componentToRender ? (\n <SchemaProvider\n key={`${sharedConfig.collection.collectionId}-${index}`}\n collection={sharedConfig.collection}\n skeleton={<SkeletonCollection componentType={componentType} />}\n >\n {componentToRender}\n </SchemaProvider>\n ) : null}\n </>\n );\n};\n"],"mappings":"AACA,SAASA,2BAA2B,QAAQ,4DAA4D;AACxG,SAASC,iBAAiB,QAAQ,wCAAwC;AAC1E,SAASC,gBAAgB,QAAQ,sCAAsC;AACvE,SAASC,cAAc,QAAQ,iBAAiB;AAChD,SAASC,kBAAkB,QAAQ,yDAAyD;AAC5F,OAAOC,KAAK,IAAIC,OAAO,QAAQ,OAAO;AAEtC,OAAO,MAAMC,+BAA+B,GAAGC,IAAA,IAMzC;EAAA,IAN0C;IAC9CC,SAAS;IACTC;EAIF,CAAC,GAAAF,IAAA;EACC,MAAM;IAAEG,MAAM;IAAE,GAAGC;EAAa,CAAC,GAAGH,SAAS;EAE7C,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jE;IAEA,OAAO;MAAET,iBAAiB;MAAEC;IAAc,CAAC;EAC7C,CAAC,EAAE,CAACP,MAAM,EAAEC,YAAY,CAAC,CAAC;EAE1B,MAAM;IAAEK,iBAAiB;IAAEC;EAAc,CAAC,GAAGL,QAAQ;EAErD,oBACER,KAAA,CAAAsB,aAAA,CAAAtB,KAAA,CAAAwB,QAAA,QACGZ,iBAAiB,gBAChBZ,KAAA,CAAAsB,aAAA,CAACxB,cAAc;IACb2B,GAAG,EAAE,GAAGlB,YAAY,CAACmB,UAAU,CAACC,YAAY,IAAItB,KAAK,EAAG;IACxDqB,UAAU,EAAEnB,YAAY,CAACmB,UAAW;IACpCE,QAAQ,eAAE5B,KAAA,CAAAsB,aAAA,CAACvB,kBAAkB;MAACc,aAAa,EAAEA;IAAc,CAAE;EAAE,GAE9DD,iBACa,CAAC,GACf,IACJ,CAAC;AAEP,CAAC","ignoreList":[]}
|
|
@@ -2,6 +2,8 @@ import React from 'react';
|
|
|
2
2
|
import { CollectionPage } from '@wix/patterns/page';
|
|
3
3
|
import { AutoPatternsCollectionPageContent } from '../AutoPatternsCollectionPageContent';
|
|
4
4
|
import { useCollectionPageActions } from '../../hooks/useCollectionPageActions';
|
|
5
|
+
import { SidePanel, Box } from '@wix/design-system';
|
|
6
|
+
import { useAppConfigContext } from '../../providers';
|
|
5
7
|
export const AutoPatternsCollectionPage = _ref => {
|
|
6
8
|
let {
|
|
7
9
|
configuration
|
|
@@ -10,9 +12,31 @@ export const AutoPatternsCollectionPage = _ref => {
|
|
|
10
12
|
title,
|
|
11
13
|
subtitle
|
|
12
14
|
} = configuration;
|
|
15
|
+
const {
|
|
16
|
+
layout
|
|
17
|
+
} = useAppConfigContext();
|
|
13
18
|
const actions = useCollectionPageActions({
|
|
14
19
|
collectionPageActions: configuration.actions
|
|
15
20
|
});
|
|
21
|
+
|
|
22
|
+
// This is temporary until we have support on it on CollectionPage component of WixPatterns
|
|
23
|
+
if (layout === 'panel') {
|
|
24
|
+
return /*#__PURE__*/React.createElement(SidePanel, {
|
|
25
|
+
skin: "floating",
|
|
26
|
+
width: "360px"
|
|
27
|
+
}, /*#__PURE__*/React.createElement(SidePanel.Header, {
|
|
28
|
+
title: "Manage Content"
|
|
29
|
+
}), /*#__PURE__*/React.createElement(SidePanel.Content, {
|
|
30
|
+
noPadding: true,
|
|
31
|
+
stretchVertically: true
|
|
32
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
33
|
+
direction: "vertical",
|
|
34
|
+
width: "100%",
|
|
35
|
+
height: "490px"
|
|
36
|
+
}, /*#__PURE__*/React.createElement(AutoPatternsCollectionPageContent, {
|
|
37
|
+
configuration: configuration
|
|
38
|
+
}))));
|
|
39
|
+
}
|
|
16
40
|
return /*#__PURE__*/React.createElement(CollectionPage, {
|
|
17
41
|
height: "100vh",
|
|
18
42
|
dataHook: "auto-patterns-page"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","CollectionPage","AutoPatternsCollectionPageContent","useCollectionPageActions","AutoPatternsCollectionPage","_ref","configuration","title","subtitle","actions","collectionPageActions","createElement","
|
|
1
|
+
{"version":3,"names":["React","CollectionPage","AutoPatternsCollectionPageContent","useCollectionPageActions","SidePanel","Box","useAppConfigContext","AutoPatternsCollectionPage","_ref","configuration","title","subtitle","layout","actions","collectionPageActions","createElement","skin","width","Header","Content","noPadding","stretchVertically","direction","height","dataHook","primaryAction","primaryActions","secondaryActions"],"sources":["../../../../src/components/AutoPatternsCollectionPage/AutoPatternsCollectionPage.tsx"],"sourcesContent":["import React from 'react';\nimport { CollectionPage } from '@wix/patterns/page';\nimport { AutoPatternsCollectionPageContent } from '../AutoPatternsCollectionPageContent';\nimport { CollectionPageConfig } from '../../types/CollectionPageConfig';\nimport { useCollectionPageActions } from '../../hooks/useCollectionPageActions';\nimport { SidePanel, Box } from '@wix/design-system';\nimport { useAppConfigContext } from '../../providers';\n\nexport interface AutoPatternsCollectionPageProps {\n configuration: CollectionPageConfig;\n}\n\nexport const AutoPatternsCollectionPage: React.FC<\n AutoPatternsCollectionPageProps\n> = ({ configuration }) => {\n const { title, subtitle } = configuration;\n const { layout } = useAppConfigContext();\n\n const actions = useCollectionPageActions({\n collectionPageActions: configuration.actions,\n });\n\n // This is temporary until we have support on it on CollectionPage component of WixPatterns\n if (layout === 'panel') {\n return (\n <SidePanel skin=\"floating\" width=\"360px\">\n <SidePanel.Header title=\"Manage Content\" />\n <SidePanel.Content noPadding stretchVertically>\n <Box direction=\"vertical\" width=\"100%\" height=\"490px\">\n <AutoPatternsCollectionPageContent configuration={configuration} />\n </Box>\n </SidePanel.Content>\n </SidePanel>\n );\n }\n\n return (\n <CollectionPage height=\"100vh\" dataHook=\"auto-patterns-page\">\n <CollectionPage.Header\n title={title}\n subtitle={subtitle}\n primaryAction={actions.primaryActions}\n secondaryActions={actions.secondaryActions}\n />\n <CollectionPage.Content>\n <AutoPatternsCollectionPageContent configuration={configuration} />\n </CollectionPage.Content>\n </CollectionPage>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,iCAAiC,QAAQ,sCAAsC;AAExF,SAASC,wBAAwB,QAAQ,sCAAsC;AAC/E,SAASC,SAAS,EAAEC,GAAG,QAAQ,oBAAoB;AACnD,SAASC,mBAAmB,QAAQ,iBAAiB;AAMrD,OAAO,MAAMC,0BAEZ,GAAGC,IAAA,IAAuB;EAAA,IAAtB;IAAEC;EAAc,CAAC,GAAAD,IAAA;EACpB,MAAM;IAAEE,KAAK;IAAEC;EAAS,CAAC,GAAGF,aAAa;EACzC,MAAM;IAAEG;EAAO,CAAC,GAAGN,mBAAmB,CAAC,CAAC;EAExC,MAAMO,OAAO,GAAGV,wBAAwB,CAAC;IACvCW,qBAAqB,EAAEL,aAAa,CAACI;EACvC,CAAC,CAAC;;EAEF;EACA,IAAID,MAAM,KAAK,OAAO,EAAE;IACtB,oBACEZ,KAAA,CAAAe,aAAA,CAACX,SAAS;MAACY,IAAI,EAAC,UAAU;MAACC,KAAK,EAAC;IAAO,gBACtCjB,KAAA,CAAAe,aAAA,CAACX,SAAS,CAACc,MAAM;MAACR,KAAK,EAAC;IAAgB,CAAE,CAAC,eAC3CV,KAAA,CAAAe,aAAA,CAACX,SAAS,CAACe,OAAO;MAACC,SAAS;MAACC,iBAAiB;IAAA,gBAC5CrB,KAAA,CAAAe,aAAA,CAACV,GAAG;MAACiB,SAAS,EAAC,UAAU;MAACL,KAAK,EAAC,MAAM;MAACM,MAAM,EAAC;IAAO,gBACnDvB,KAAA,CAAAe,aAAA,CAACb,iCAAiC;MAACO,aAAa,EAAEA;IAAc,CAAE,CAC/D,CACY,CACV,CAAC;EAEhB;EAEA,oBACET,KAAA,CAAAe,aAAA,CAACd,cAAc;IAACsB,MAAM,EAAC,OAAO;IAACC,QAAQ,EAAC;EAAoB,gBAC1DxB,KAAA,CAAAe,aAAA,CAACd,cAAc,CAACiB,MAAM;IACpBR,KAAK,EAAEA,KAAM;IACbC,QAAQ,EAAEA,QAAS;IACnBc,aAAa,EAAEZ,OAAO,CAACa,cAAe;IACtCC,gBAAgB,EAAEd,OAAO,CAACc;EAAiB,CAC5C,CAAC,eACF3B,KAAA,CAAAe,aAAA,CAACd,cAAc,CAACkB,OAAO,qBACrBnB,KAAA,CAAAe,aAAA,CAACb,iCAAiC;IAACO,aAAa,EAAEA;EAAc,CAAE,CAC5C,CACV,CAAC;AAErB,CAAC","ignoreList":[]}
|
|
@@ -14,6 +14,14 @@ export const AutoPatternsRoutes = _ref => {
|
|
|
14
14
|
const {
|
|
15
15
|
getPagePath
|
|
16
16
|
} = usePagePath(config);
|
|
17
|
+
if (config.layout === 'panel') {
|
|
18
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, config.pages.map(page => {
|
|
19
|
+
return /*#__PURE__*/React.createElement(AutoPatternsPage, {
|
|
20
|
+
key: page.id,
|
|
21
|
+
pageConfig: page
|
|
22
|
+
});
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
17
25
|
const mainPage = config.pages.find(page => page.appMainPage);
|
|
18
26
|
const routes = config.pages.map(page => {
|
|
19
27
|
const routePath = getPagePath(page.id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","usePagePath","PatternsReactRoute","PatternsReactRouter","AutoPatternsPage","Navigate","pageTypeToRouteType","collectionPage","entityPage","AutoPatternsRoutes","_ref","config","getPagePath","
|
|
1
|
+
{"version":3,"names":["React","usePagePath","PatternsReactRoute","PatternsReactRouter","AutoPatternsPage","Navigate","pageTypeToRouteType","collectionPage","entityPage","AutoPatternsRoutes","_ref","config","getPagePath","layout","createElement","Fragment","pages","map","page","key","id","pageConfig","mainPage","find","appMainPage","routes","routePath","type","path","element","filter","Boolean","mainPagePath","push","to"],"sources":["../../../../src/components/AutoPatternsRoute/AutoPatternsRoutes.tsx"],"sourcesContent":["import React from 'react';\nimport { usePagePath } from '../../hooks';\nimport { PatternsReactRoute, PatternsReactRouter } from '@wix/patterns/router';\nimport { AutoPatternsPage } from './AutoPatternsPage';\nimport type { RouteType } from '@wix/patterns/dist/types/components/Router/types';\nimport { Navigate } from 'react-router-dom';\nimport { AppConfig } from '../../types';\n\nconst pageTypeToRouteType: Record<string, RouteType> = {\n collectionPage: 'collection',\n entityPage: 'editEntity',\n};\n\nexport const AutoPatternsRoutes = ({ config }: { config: AppConfig }) => {\n const { getPagePath } = usePagePath(config);\n\n if (config.layout === 'panel') {\n return (\n <>\n {config.pages.map((page) => {\n return <AutoPatternsPage key={page.id} pageConfig={page} />;\n })}\n </>\n );\n }\n\n const mainPage = config.pages.find((page) => page.appMainPage);\n\n const routes = config.pages\n .map((page) => {\n const routePath = getPagePath(page.id);\n\n if (!routePath) {\n return null;\n }\n\n return (\n <PatternsReactRoute\n key={page.id}\n type={pageTypeToRouteType[page.type] ?? 'other'}\n path={routePath}\n element={<AutoPatternsPage pageConfig={page} />}\n />\n );\n })\n .filter(Boolean);\n\n if (mainPage) {\n const mainPagePath = getPagePath(mainPage.id);\n\n if (mainPagePath) {\n routes.push(\n <PatternsReactRoute\n key=\"main-redirect\"\n type=\"other\"\n path=\"/\"\n element={<Navigate to={mainPagePath} />}\n />,\n );\n }\n }\n\n return <PatternsReactRouter>{routes}</PatternsReactRouter>;\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,WAAW,QAAQ,aAAa;AACzC,SAASC,kBAAkB,EAAEC,mBAAmB,QAAQ,sBAAsB;AAC9E,SAASC,gBAAgB,QAAQ,oBAAoB;AAErD,SAASC,QAAQ,QAAQ,kBAAkB;AAG3C,MAAMC,mBAA8C,GAAG;EACrDC,cAAc,EAAE,YAAY;EAC5BC,UAAU,EAAE;AACd,CAAC;AAED,OAAO,MAAMC,kBAAkB,GAAGC,IAAA,IAAuC;EAAA,IAAtC;IAAEC;EAA8B,CAAC,GAAAD,IAAA;EAClE,MAAM;IAAEE;EAAY,CAAC,GAAGX,WAAW,CAACU,MAAM,CAAC;EAE3C,IAAIA,MAAM,CAACE,MAAM,KAAK,OAAO,EAAE;IAC7B,oBACEb,KAAA,CAAAc,aAAA,CAAAd,KAAA,CAAAe,QAAA,QACGJ,MAAM,CAACK,KAAK,CAACC,GAAG,CAAEC,IAAI,IAAK;MAC1B,oBAAOlB,KAAA,CAAAc,aAAA,CAACV,gBAAgB;QAACe,GAAG,EAAED,IAAI,CAACE,EAAG;QAACC,UAAU,EAAEH;MAAK,CAAE,CAAC;IAC7D,CAAC,CACD,CAAC;EAEP;EAEA,MAAMI,QAAQ,GAAGX,MAAM,CAACK,KAAK,CAACO,IAAI,CAAEL,IAAI,IAAKA,IAAI,CAACM,WAAW,CAAC;EAE9D,MAAMC,MAAM,GAAGd,MAAM,CAACK,KAAK,CACxBC,GAAG,CAAEC,IAAI,IAAK;IACb,MAAMQ,SAAS,GAAGd,WAAW,CAACM,IAAI,CAACE,EAAE,CAAC;IAEtC,IAAI,CAACM,SAAS,EAAE;MACd,OAAO,IAAI;IACb;IAEA,oBACE1B,KAAA,CAAAc,aAAA,CAACZ,kBAAkB;MACjBiB,GAAG,EAAED,IAAI,CAACE,EAAG;MACbO,IAAI,EAAErB,mBAAmB,CAACY,IAAI,CAACS,IAAI,CAAC,IAAI,OAAQ;MAChDC,IAAI,EAAEF,SAAU;MAChBG,OAAO,eAAE7B,KAAA,CAAAc,aAAA,CAACV,gBAAgB;QAACiB,UAAU,EAAEH;MAAK,CAAE;IAAE,CACjD,CAAC;EAEN,CAAC,CAAC,CACDY,MAAM,CAACC,OAAO,CAAC;EAElB,IAAIT,QAAQ,EAAE;IACZ,MAAMU,YAAY,GAAGpB,WAAW,CAACU,QAAQ,CAACF,EAAE,CAAC;IAE7C,IAAIY,YAAY,EAAE;MAChBP,MAAM,CAACQ,IAAI,cACTjC,KAAA,CAAAc,aAAA,CAACZ,kBAAkB;QACjBiB,GAAG,EAAC,eAAe;QACnBQ,IAAI,EAAC,OAAO;QACZC,IAAI,EAAC,GAAG;QACRC,OAAO,eAAE7B,KAAA,CAAAc,aAAA,CAACT,QAAQ;UAAC6B,EAAE,EAAEF;QAAa,CAAE;MAAE,CACzC,CACH,CAAC;IACH;EACF;EAEA,oBAAOhC,KAAA,CAAAc,aAAA,CAACX,mBAAmB,QAAEsB,MAA4B,CAAC;AAC5D,CAAC","ignoreList":[]}
|
|
@@ -19,7 +19,7 @@ export const CmsFieldTypeToPatternsFieldType = {
|
|
|
19
19
|
};
|
|
20
20
|
export async function fetchCmsSchema(collectionId) {
|
|
21
21
|
const schema = await errorHandler.withErrorHandler(async () => collections.getDataCollection(collectionId), {});
|
|
22
|
-
const transformedFields = schema.fields.reduce((acc, field) => {
|
|
22
|
+
const transformedFields = (schema.fields || []).reduce((acc, field) => {
|
|
23
23
|
var _field$capabilities, _field$capabilities2, _field$typeMetadata;
|
|
24
24
|
if (!field.key) {
|
|
25
25
|
return acc;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["collections","items","fetchCmsData","errorHandler","CmsFieldTypeToPatternsFieldType","Type","TEXT","DATE","DATETIME","NUMBER","BOOLEAN","URL","ADDRESS","OBJECT","RICH_TEXT","RICH_CONTENT","ARRAY","ARRAY_STRING","REFERENCE","IMAGE","fetchCmsSchema","collectionId","schema","withErrorHandler","getDataCollection","transformedFields","fields","reduce","acc","field","_field$capabilities","_field$capabilities2","_field$typeMetadata","key","fieldType","type","baseField","id","displayName","validation","numberRange","min","undefined","max","stringLengthRange","minLength","maxLength","required","capabilities","supportedQueryOperators","queryOperators","sortable","typeMetadata","reference","referencedCollectionId","referenceField","referenceMetadata","nonReferenceType","nonReferenceField","schemaConfig","displayField","idField","actions","get","entityId","create","entity","insert","update","delete","remove","bulkDelete","entityIds","bulkRemove","find","query","options"],"sources":["../../../../src/dataSourceAdapters/cms/cmsAdapter.ts"],"sourcesContent":["import { Field, SchemaConfig, PatternsFieldType } from '../../types';\nimport { collections, items } from '@wix/data';\nimport { fetchCmsData } from './fetchCmsData';\nimport { errorHandler } from '@wix/essentials';\n\nexport const CmsFieldTypeToPatternsFieldType: Partial<\n Record<collections.Type, PatternsFieldType>\n> = {\n [collections.Type.TEXT]: 'SHORT_TEXT',\n [collections.Type.DATE]: 'DATE',\n [collections.Type.DATETIME]: 'DATETIME',\n [collections.Type.NUMBER]: 'NUMBER',\n [collections.Type.BOOLEAN]: 'BOOLEAN',\n [collections.Type.URL]: 'URL',\n [collections.Type.ADDRESS]: 'SHORT_TEXT',\n [collections.Type.OBJECT]: 'LONG_TEXT',\n [collections.Type.RICH_TEXT]: 'LONG_TEXT',\n [collections.Type.RICH_CONTENT]: 'SHORT_TEXT',\n [collections.Type.ARRAY]: 'ARRAY',\n [collections.Type.ARRAY_STRING]: 'ARRAY',\n [collections.Type.REFERENCE]: 'REFERENCE',\n [collections.Type.IMAGE]: 'IMAGE',\n};\n\nexport async function fetchCmsSchema(\n collectionId: string,\n): Promise<SchemaConfig> {\n const schema = await errorHandler.withErrorHandler(\n async () => collections.getDataCollection(collectionId),\n {},\n );\n const transformedFields = schema.fields.reduce<Record<string, Field>>(\n (acc, field) => {\n if (!field.key) {\n return acc;\n }\n\n const fieldType = field.type\n ? CmsFieldTypeToPatternsFieldType[field.type] || 'SHORT_TEXT'\n : 'SHORT_TEXT';\n const baseField = {\n id: field.key,\n displayName: field.displayName || '',\n validation: {\n numberRange: field.numberRange\n ? {\n min: field.numberRange.min ?? undefined,\n max: field.numberRange.max ?? undefined,\n }\n : undefined,\n stringLengthRange: field.stringLengthRange\n ? {\n minLength: field.stringLengthRange.minLength ?? undefined,\n maxLength: field.stringLengthRange.maxLength ?? undefined,\n }\n : undefined,\n required: field.required ?? false,\n },\n capabilities: {\n supportedQueryOperators: field.capabilities?.queryOperators || [],\n sortable: field.capabilities?.sortable || false,\n },\n };\n\n if (\n fieldType === 'REFERENCE' &&\n field.typeMetadata?.reference?.referencedCollectionId\n ) {\n const referenceField: Field = {\n ...baseField,\n type: 'REFERENCE',\n referenceMetadata: {\n referencedCollectionId:\n field.typeMetadata.reference.referencedCollectionId,\n },\n };\n acc[field.key] = referenceField;\n } else {\n const nonReferenceType =\n fieldType === 'REFERENCE' ? 'SHORT_TEXT' : fieldType;\n const nonReferenceField: Field = {\n ...baseField,\n type: nonReferenceType,\n };\n acc[field.key] = nonReferenceField;\n }\n\n return acc;\n },\n {},\n );\n\n const schemaConfig: SchemaConfig = {\n id: collectionId,\n displayField: schema.displayField ?? '_id',\n idField: '_id',\n fields: transformedFields,\n actions: {\n get: (entityId: string) => {\n return items.get(collectionId, entityId);\n },\n create: (entity) => {\n return items.insert(collectionId, entity);\n },\n update: (entity) => {\n return items.update(collectionId, entity);\n },\n delete: (entityId) => {\n return items.remove(collectionId, entityId);\n },\n bulkDelete: (entityIds) => {\n return items.bulkRemove(collectionId, entityIds);\n },\n find: async (\n query,\n options: {\n searchableFieldIds?: string[];\n filterFieldMapping?: Record<string, { fieldId: string }>;\n } = {},\n ) => {\n return fetchCmsData(collectionId, query, transformedFields, options);\n },\n },\n };\n\n return schemaConfig;\n}\n"],"mappings":"AACA,SAASA,WAAW,EAAEC,KAAK,QAAQ,WAAW;AAC9C,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SAASC,YAAY,QAAQ,iBAAiB;AAE9C,OAAO,MAAMC,+BAEZ,GAAG;EACF,CAACJ,WAAW,CAACK,IAAI,CAACC,IAAI,GAAG,YAAY;EACrC,CAACN,WAAW,CAACK,IAAI,CAACE,IAAI,GAAG,MAAM;EAC/B,CAACP,WAAW,CAACK,IAAI,CAACG,QAAQ,GAAG,UAAU;EACvC,CAACR,WAAW,CAACK,IAAI,CAACI,MAAM,GAAG,QAAQ;EACnC,CAACT,WAAW,CAACK,IAAI,CAACK,OAAO,GAAG,SAAS;EACrC,CAACV,WAAW,CAACK,IAAI,CAACM,GAAG,GAAG,KAAK;EAC7B,CAACX,WAAW,CAACK,IAAI,CAACO,OAAO,GAAG,YAAY;EACxC,CAACZ,WAAW,CAACK,IAAI,CAACQ,MAAM,GAAG,WAAW;EACtC,CAACb,WAAW,CAACK,IAAI,CAACS,SAAS,GAAG,WAAW;EACzC,CAACd,WAAW,CAACK,IAAI,CAACU,YAAY,GAAG,YAAY;EAC7C,CAACf,WAAW,CAACK,IAAI,CAACW,KAAK,GAAG,OAAO;EACjC,CAAChB,WAAW,CAACK,IAAI,CAACY,YAAY,GAAG,OAAO;EACxC,CAACjB,WAAW,CAACK,IAAI,CAACa,SAAS,GAAG,WAAW;EACzC,CAAClB,WAAW,CAACK,IAAI,CAACc,KAAK,GAAG;AAC5B,CAAC;AAED,OAAO,eAAeC,cAAcA,CAClCC,YAAoB,EACG;EACvB,MAAMC,MAAM,GAAG,MAAMnB,YAAY,CAACoB,gBAAgB,CAChD,YAAYvB,WAAW,CAACwB,iBAAiB,CAACH,YAAY,CAAC,EACvD,CAAC,CACH,CAAC;EACD,MAAMI,iBAAiB,
|
|
1
|
+
{"version":3,"names":["collections","items","fetchCmsData","errorHandler","CmsFieldTypeToPatternsFieldType","Type","TEXT","DATE","DATETIME","NUMBER","BOOLEAN","URL","ADDRESS","OBJECT","RICH_TEXT","RICH_CONTENT","ARRAY","ARRAY_STRING","REFERENCE","IMAGE","fetchCmsSchema","collectionId","schema","withErrorHandler","getDataCollection","transformedFields","fields","reduce","acc","field","_field$capabilities","_field$capabilities2","_field$typeMetadata","key","fieldType","type","baseField","id","displayName","validation","numberRange","min","undefined","max","stringLengthRange","minLength","maxLength","required","capabilities","supportedQueryOperators","queryOperators","sortable","typeMetadata","reference","referencedCollectionId","referenceField","referenceMetadata","nonReferenceType","nonReferenceField","schemaConfig","displayField","idField","actions","get","entityId","create","entity","insert","update","delete","remove","bulkDelete","entityIds","bulkRemove","find","query","options"],"sources":["../../../../src/dataSourceAdapters/cms/cmsAdapter.ts"],"sourcesContent":["import { Field, SchemaConfig, PatternsFieldType } from '../../types';\nimport { collections, items } from '@wix/data';\nimport { fetchCmsData } from './fetchCmsData';\nimport { errorHandler } from '@wix/essentials';\n\nexport const CmsFieldTypeToPatternsFieldType: Partial<\n Record<collections.Type, PatternsFieldType>\n> = {\n [collections.Type.TEXT]: 'SHORT_TEXT',\n [collections.Type.DATE]: 'DATE',\n [collections.Type.DATETIME]: 'DATETIME',\n [collections.Type.NUMBER]: 'NUMBER',\n [collections.Type.BOOLEAN]: 'BOOLEAN',\n [collections.Type.URL]: 'URL',\n [collections.Type.ADDRESS]: 'SHORT_TEXT',\n [collections.Type.OBJECT]: 'LONG_TEXT',\n [collections.Type.RICH_TEXT]: 'LONG_TEXT',\n [collections.Type.RICH_CONTENT]: 'SHORT_TEXT',\n [collections.Type.ARRAY]: 'ARRAY',\n [collections.Type.ARRAY_STRING]: 'ARRAY',\n [collections.Type.REFERENCE]: 'REFERENCE',\n [collections.Type.IMAGE]: 'IMAGE',\n};\n\nexport async function fetchCmsSchema(\n collectionId: string,\n): Promise<SchemaConfig> {\n const schema = await errorHandler.withErrorHandler(\n async () => collections.getDataCollection(collectionId),\n {},\n );\n const transformedFields = (schema.fields || []).reduce<Record<string, Field>>(\n (acc, field) => {\n if (!field.key) {\n return acc;\n }\n\n const fieldType = field.type\n ? CmsFieldTypeToPatternsFieldType[field.type] || 'SHORT_TEXT'\n : 'SHORT_TEXT';\n const baseField = {\n id: field.key,\n displayName: field.displayName || '',\n validation: {\n numberRange: field.numberRange\n ? {\n min: field.numberRange.min ?? undefined,\n max: field.numberRange.max ?? undefined,\n }\n : undefined,\n stringLengthRange: field.stringLengthRange\n ? {\n minLength: field.stringLengthRange.minLength ?? undefined,\n maxLength: field.stringLengthRange.maxLength ?? undefined,\n }\n : undefined,\n required: field.required ?? false,\n },\n capabilities: {\n supportedQueryOperators: field.capabilities?.queryOperators || [],\n sortable: field.capabilities?.sortable || false,\n },\n };\n\n if (\n fieldType === 'REFERENCE' &&\n field.typeMetadata?.reference?.referencedCollectionId\n ) {\n const referenceField: Field = {\n ...baseField,\n type: 'REFERENCE',\n referenceMetadata: {\n referencedCollectionId:\n field.typeMetadata.reference.referencedCollectionId,\n },\n };\n acc[field.key] = referenceField;\n } else {\n const nonReferenceType =\n fieldType === 'REFERENCE' ? 'SHORT_TEXT' : fieldType;\n const nonReferenceField: Field = {\n ...baseField,\n type: nonReferenceType,\n };\n acc[field.key] = nonReferenceField;\n }\n\n return acc;\n },\n {},\n );\n\n const schemaConfig: SchemaConfig = {\n id: collectionId,\n displayField: schema.displayField ?? '_id',\n idField: '_id',\n fields: transformedFields,\n actions: {\n get: (entityId: string) => {\n return items.get(collectionId, entityId);\n },\n create: (entity) => {\n return items.insert(collectionId, entity);\n },\n update: (entity) => {\n return items.update(collectionId, entity);\n },\n delete: (entityId) => {\n return items.remove(collectionId, entityId);\n },\n bulkDelete: (entityIds) => {\n return items.bulkRemove(collectionId, entityIds);\n },\n find: async (\n query,\n options: {\n searchableFieldIds?: string[];\n filterFieldMapping?: Record<string, { fieldId: string }>;\n } = {},\n ) => {\n return fetchCmsData(collectionId, query, transformedFields, options);\n },\n },\n };\n\n return schemaConfig;\n}\n"],"mappings":"A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