@wix/auto-patterns 1.17.0 → 1.18.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.
Files changed (43) hide show
  1. package/dist/cjs/dataSourceAdapters/cms/cmsAdapter.js +0 -2
  2. package/dist/cjs/dataSourceAdapters/cms/cmsAdapter.js.map +1 -1
  3. package/dist/cjs/dataSourceAdapters/cms/fetchCmsData.js.map +1 -1
  4. package/dist/cjs/dataSourceAdapters/cms/filterUtils.js.map +1 -1
  5. package/dist/cjs/dataSourceAdapters/cms/sortUtils.js.map +1 -1
  6. package/dist/cjs/hooks/useColumns.js +7 -5
  7. package/dist/cjs/hooks/useColumns.js.map +1 -1
  8. package/dist/cjs/types/types.js.map +1 -1
  9. package/dist/docs/action_cell.md +1 -1
  10. package/dist/docs/app_config_structure.md +65 -1
  11. package/dist/docs/auto-patterns-guide.md +358 -76
  12. package/dist/docs/bulk_actions.md +1 -1
  13. package/dist/docs/collection_page.md +1 -1
  14. package/dist/docs/config_schema.md +184 -0
  15. package/dist/docs/custom_overrides.md +163 -4
  16. package/dist/docs/index.md +5 -7
  17. package/dist/docs/schema_config.md +174 -0
  18. package/dist/docs/sdk_utilities.md +97 -0
  19. package/dist/docs/wix_fqdn_custom_data_source.md +201 -0
  20. package/dist/esm/dataSourceAdapters/cms/cmsAdapter.js +0 -2
  21. package/dist/esm/dataSourceAdapters/cms/cmsAdapter.js.map +1 -1
  22. package/dist/esm/dataSourceAdapters/cms/fetchCmsData.js.map +1 -1
  23. package/dist/esm/dataSourceAdapters/cms/filterUtils.js.map +1 -1
  24. package/dist/esm/dataSourceAdapters/cms/sortUtils.js.map +1 -1
  25. package/dist/esm/hooks/useColumns.js +3 -1
  26. package/dist/esm/hooks/useColumns.js.map +1 -1
  27. package/dist/esm/types/types.js.map +1 -1
  28. package/dist/types/dataSourceAdapters/cms/cmsAdapter.d.ts.map +1 -1
  29. package/dist/types/dataSourceAdapters/cms/fetchCmsData.d.ts +2 -3
  30. package/dist/types/dataSourceAdapters/cms/fetchCmsData.d.ts.map +1 -1
  31. package/dist/types/dataSourceAdapters/cms/filterUtils.d.ts +3 -4
  32. package/dist/types/dataSourceAdapters/cms/filterUtils.d.ts.map +1 -1
  33. package/dist/types/dataSourceAdapters/cms/sortUtils.d.ts +2 -3
  34. package/dist/types/dataSourceAdapters/cms/sortUtils.d.ts.map +1 -1
  35. package/dist/types/hooks/useColumns.d.ts.map +1 -1
  36. package/dist/types/types/types.d.ts +13 -3
  37. package/dist/types/types/types.d.ts.map +1 -1
  38. package/package.json +4 -4
  39. package/dist/docs/recipe-bulk-operations.md +0 -1352
  40. package/dist/docs/recipe-crud-operations.md +0 -805
  41. package/dist/docs/recipe-customization.md +0 -1703
  42. package/dist/docs/recipe-first-dashboard.md +0 -795
  43. package/dist/docs/sdk_and_schema.md +0 -215
@@ -1,215 +0,0 @@
1
- ## SDK Utilities
2
-
3
- The `sdk` parameter provides access to Auto Patterns utilities and context. Available in custom actions across all action types (ActionCell, BulkActions, CollectionPage actions, and EntityPage Actions).
4
-
5
- ### Key SDK Utilities
6
- The only functions exist in sdk are:
7
-
8
- • **closeModal** - `closeModal(): void`
9
- - Closes the currently open modal
10
- - Example: `sdk.closeModal()` after saving or canceling
11
-
12
- • **getOptimisticActions** - `getOptimisticActions(collectionId): OptimisticActions`
13
- - Provides optimistic UI updates for immediate user feedback
14
- - Supports create, update, delete operations with automatic rollback on failure
15
- - Example: `sdk.getOptimisticActions(sdk.collectionId).updateOne(item, { ... })`
16
-
17
- • **getSchema** - `getSchema(collectionId): SchemaConfig | undefined`
18
- - Access to collection schema information (fields, types, validation)
19
- - Useful for dynamic operations based on collection structure
20
- - Example: `const schema = sdk.getSchema(sdk.collectionId)`
21
-
22
- • **collectionId** - `string`
23
- - Current collection context identifier
24
- - Available in all action contexts for referencing the active collection
25
- - Example: `sdk.collectionId` to get the current collection ID
26
-
27
- ---
28
-
29
- ## OptimisticActions
30
-
31
- Provides immediate UI updates with automatic server synchronization and error recovery.
32
-
33
- ### Usage Rules
34
-
35
- **Use OptimisticActions for:**
36
- - Data modification operations (create, update, delete)
37
- - Operations requiring immediate visual feedback
38
-
39
- **Do NOT use for:**
40
- - Read-only operations
41
- - Operations requiring server confirmation first
42
-
43
- ### Core Pattern
44
-
45
- ```typescript
46
- // Get instances from SDK (see SDK Utilities section)
47
- const optimisticActions = sdk.getOptimisticActions(sdk.collectionId);
48
- const schema = sdk.getSchema(sdk.collectionId);
49
-
50
- optimisticActions.operation(items, {
51
- submit: async (items) => schema.actions.serverMethod(items),
52
- successToast: 'Success message',
53
- errorToast: (err, {retry}) => ({ text: 'Error message', action: { text: 'Retry', onClick: retry }})
54
- });
55
- ```
56
-
57
- ### Available Operations
58
-
59
- #### Create Operations
60
- - `createOne(item: T, params: OptimisticParams<T>): void`
61
- - `createMany(items: T[], params: OptimisticParams<T>): void`
62
-
63
- #### Update Operations
64
- - `updateOne(item: T, params: OptimisticParams<T>): void`
65
- - `updateMany(items: T[], params: OptimisticParams<T>): void`
66
- - `updateAll(transformFn: (item: T) => Partial<T>, params: OptimisticParams<T>): void`
67
-
68
- #### Delete Operations
69
- - `deleteOne(item: T, params: OptimisticParams<T> & { showUndoToast: true }): void`
70
- - `deleteMany(items: T[], params: OptimisticParams<T> & { showUndoToast: true }): void`
71
- - `deleteAll(params: OptimisticParams<T> & { showUndoToast: true }): void`
72
-
73
- ### Type Definitions
74
-
75
- ```typescript
76
- interface OptimisticParams<T> {
77
- submit: (items: T[]) => Promise<any>;
78
- successToast: string | ToastConfig;
79
- errorToast: (error: Error, actions: { retry: () => void }) => ToastConfig | string;
80
- showUndoToast?: boolean; // Required: true for delete operations
81
- }
82
-
83
- interface ToastConfig {
84
- text: string;
85
- action?: { text: string; onClick: () => void };
86
- }
87
- ```
88
-
89
- ### Validation Requirements
90
-
91
- **Before using optimistic actions:**
92
- - Verify `sdk.getOptimisticActions(collectionId)` returns valid instance
93
- - Verify `sdk.getSchema(collectionId)` returns valid schema
94
- - For delete operations: `showUndoToast: true` is mandatory
95
- - All `submit` functions must return a Promise
96
-
97
- **SDK Parameter:** Available in custom actions and modals. See SDK Utilities section for complete interface.
98
-
99
- ---
100
-
101
- ## SchemaConfig Usage
102
-
103
- SchemaConfig provides complete collection metadata and server actions. Essential for dynamic operations and accessing collection structure information.
104
-
105
- ### Key Properties
106
-
107
- • **id** - `string`
108
- - Collection identifier (e.g., "WixPets")
109
- - Example: `schema.id === "WixPets"`
110
-
111
- • **idField** - `string`
112
- - Primary key field name (usually "_id")
113
- - Required for all update/delete operations
114
- - Example: `const id = item[schema.idField]`
115
-
116
- • **displayField** - `string`
117
- - Main field for displaying items (name, title, etc.)
118
- - Used in UI components for item identification
119
- - Example: `const label = item[schema.displayField]`
120
-
121
- • **fields** - `Record<string, Field | undefined>`
122
- - Complete field definitions with types and metadata
123
- - Useful for dynamic form generation or validation
124
- - Example: `schema.fields.name.type === 'TEXT'`
125
-
126
- • **actions** - Server operation functions
127
- - Pre-configured API calls for CRUD operations
128
- - Use with optimistic actions for best UX
129
- - Example: `await schema.actions.update(item)`
130
-
131
- ### Available Schema Actions
132
-
133
- - schema.actions.create(item) // Create single item
134
- - schema.actions.update(item) // Update single item
135
- - schema.actions.delete(itemId) // Delete by ID
136
- - schema.actions.bulkUpdate(updates) // Update multiple items
137
- - schema.actions.bulkDelete(itemIds) // Delete multiple items
138
-
139
- ### Schema Validation Checklist
140
-
141
- Before using schema in operations:
142
-
143
- ✓ Check if schema exists: `if (!schema) return;`
144
- ✓ Verify required fields exist on items
145
- ✓ Use `schema.idField` for ID operations
146
- ✓ Use `schema.displayField` for UI display
147
- ✓ Use `schema.actions` for server operations
148
-
149
- ### Common Usage Patterns
150
-
151
- - **ActionCell**: Use `schema.actions.update()` or `schema.actions.delete()` for single item operations
152
- - **BulkActions**: Use `schema.actions.bulkUpdate()` or `schema.actions.bulkDelete()` for multiple items
153
- - **Dynamic UI**: Use `schema.fields` to build forms or validate data
154
- - **Error Messages**: Use `schema.displayField` to create meaningful user feedback
155
-
156
- ---
157
-
158
- ## Filters Configuration Notes
159
-
160
- To configure filters in a `collectionPage`, add a `filters` property inside the page's component configuration object. Each filter must reference a valid field by its `fieldId`, and the supported types are:
161
-
162
- * `numberConfig`: used with fields of type `NUMBER`
163
- * `dateConfig`: used with fields of type `DATETIME`
164
- * `booleanConfig`: used with fields of type `BOOLEAN`
165
- * `enumConfig`: used with fields of type `ARRAY` or `ARRAY_STRING`
166
-
167
- ### Enum Configuration Implementation
168
-
169
- When implementing enum filters, you must ask the user to provide the possible option values. Never invent or assume enum values. Here's how to properly handle enumConfig:
170
-
171
- #### Example: User-Provided Enum Implementation
172
-
173
- 1. First, collect the possible values from the user:
174
- ```
175
- User requests: "I need a filter for pet types."
176
- You ask: "What are the possible values for pet types that should be available in the filter?"
177
- User responds: "dog, cat, bird, rabbit, fish"
178
- ```
179
-
180
- 2. Then, create the `enumConfig` structure:
181
- ```json
182
- "enumConfig": {
183
- "options": [
184
- { "value": "dog", "label": "Dog" },
185
- { "value": "cat", "label": "Cat" },
186
- { "value": "bird", "label": "Bird" },
187
- { "value": "rabbit", "label": "Rabbit" },
188
- { "value": "fish", "label": "Fish" }
189
- ],
190
- "selectionMode": "multiple",
191
- "optionType": "checkbox"
192
- }
193
- ```
194
-
195
- Notice how the `label` is derived from the `value` by capitalizing the first letter. The user's exact values become the `value` property.
196
-
197
- ### Grouping Filters with Section Title
198
-
199
- * Filters can be grouped by sections using the `sectionTitle` property.
200
- * If multiple filter items share the same `sectionTitle`, they will be displayed together in a grouped section in the UI.
201
- * Filters without a `sectionTitle` will appear in a default section or be displayed individually.
202
- * Grouping helps maintain clarity, especially when dealing with multiple filter options.
203
-
204
- ### Key Guidelines
205
-
206
- * **openByDefault**: Automatically expands the filter accordion when the filters panel is opened.
207
- * **tagLabel**: Specifies the label displayed in a Tag component on the table or grid once the filter is active. For example, if the tagLabel is "Age", the filter display might show: `Age: 7`.
208
- * **maxInlineFilters**: Limits the number of filters shown inline in the table toolbar. Others are accessible via the panel. Default is 0.
209
- * **dateConfig.mode**:
210
-
211
- * `ONLY_PREDEFINED`: user can select only from preset options
212
- * `ONLY_CUSTOM`: user must select a custom date range manually (no presets)
213
- * `COMBINE`: both options available
214
- * **dateConfig.presets** must be omitted if mode is `ONLY_CUSTOM`.
215
- * **dateConfig.includeTime**: Controls whether time selection is also enabled alongside date (default is `true`).