@wix/auto-patterns 1.41.0 → 1.43.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/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/hooks/useCommonCollectionFeatures.js +12 -7
- package/dist/cjs/hooks/useCommonCollectionFeatures.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/types/CollectionPageConfig.js.map +1 -1
- 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/hooks/useCommonCollectionFeatures.js +8 -3
- package/dist/esm/hooks/useCommonCollectionFeatures.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/types/CollectionPageConfig.js.map +1 -1
- 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/hooks/useCommonCollectionFeatures.d.ts +3 -2
- package/dist/types/hooks/useCommonCollectionFeatures.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/testkit/playwright.d.ts +1 -1
- package/dist/types/testkit/playwright.d.ts.map +1 -1
- package/dist/types/types/CollectionPageConfig.d.ts +187 -1
- package/dist/types/types/CollectionPageConfig.d.ts.map +1 -1
- package/mcp-docs/app_config_structure.md +92 -0
- package/mcp-docs/auto-patterns-guide.md +467 -0
- package/mcp-docs/custom_overrides.md +37 -0
- package/mcp-docs/index.md +4 -0
- package/mcp-docs/views.md +335 -0
- package/package.json +20 -14
|
@@ -237,6 +237,47 @@ export interface AppConfig {
|
|
|
237
237
|
};
|
|
238
238
|
showTotal?: boolean; // Show total items on toolbar. Default: false
|
|
239
239
|
};
|
|
240
|
+
views?: {
|
|
241
|
+
enabled?: boolean; // Whether to enable the views feature. Default: false
|
|
242
|
+
saveViewModalProps?: {
|
|
243
|
+
placeholderName?: string; // Placeholder text for the "new view" input when saving a new view
|
|
244
|
+
learnMore?: {
|
|
245
|
+
url?: string; // URL for the help/learn-more link in the Save View modal
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
viewsDropdownProps?: {
|
|
249
|
+
showTotal?: boolean; // Show total items count next to the current view name. Default: false
|
|
250
|
+
hideAllItemsView?: boolean; // Hide the built-in "All Items" view from the dropdown. Only works when custom presets exist. Default: false
|
|
251
|
+
customAllItemsViewLabel?: string; // Custom label for the "All Items" view. Ignored if a preset has `isDefaultView: true`. Default: "All items"
|
|
252
|
+
};
|
|
253
|
+
presets?:
|
|
254
|
+
| {
|
|
255
|
+
type: 'categories';
|
|
256
|
+
categories: {
|
|
257
|
+
id: string; // Unique category identifier. ⚠️ Don't use `predefined-views` and `saved-views` as these are reserved
|
|
258
|
+
label: string; // Category display name shown in the views control
|
|
259
|
+
views: {}[]; // Views included in this category (same structure as presets.views)
|
|
260
|
+
icon?: {
|
|
261
|
+
tooltipContent: string; // Tooltip text shown on hover over the help icon
|
|
262
|
+
size?: 'small' | 'medium'; // Size of the help icon. Default: 'small'
|
|
263
|
+
};
|
|
264
|
+
}[];
|
|
265
|
+
}
|
|
266
|
+
| {
|
|
267
|
+
type: 'views';
|
|
268
|
+
views: {
|
|
269
|
+
id: string; // Unique view identifier. ⚠️ Don't use `all-items-view` as this is reserved
|
|
270
|
+
label: string; // Display name for the view shown in the dropdown
|
|
271
|
+
filters?: Record<string, AutoFilterValue | null>; // Filters to apply when the view is selected. Keys must match filter IDs declared in the filters configuration
|
|
272
|
+
columnPreferences?: { // Column preferences controlling column visibility, sort, and order for this view
|
|
273
|
+
id: string; // Column unique identifier
|
|
274
|
+
direction?: 'asc' | 'desc'; // Sorting direction of the column in the view
|
|
275
|
+
show?: boolean; // Pass false to hide the column from the view
|
|
276
|
+
}[];
|
|
277
|
+
isDefaultView?: boolean; // Makes this view the default selection instead of the "All Items" view. Default: false
|
|
278
|
+
}[];
|
|
279
|
+
};
|
|
280
|
+
};
|
|
240
281
|
search?: {
|
|
241
282
|
shown?: boolean; // Show/hide the search
|
|
242
283
|
};
|
|
@@ -477,6 +518,57 @@ type LayoutContent =
|
|
|
477
518
|
};
|
|
478
519
|
};
|
|
479
520
|
|
|
521
|
+
type AutoFilterValue =
|
|
522
|
+
| {
|
|
523
|
+
filterType: 'date';
|
|
524
|
+
value:
|
|
525
|
+
| {
|
|
526
|
+
preset: DateRangeOptions | DateRangePredefinedPresetOptions;
|
|
527
|
+
}
|
|
528
|
+
| {
|
|
529
|
+
// Start date. format: MM-DD-YYYY
|
|
530
|
+
from?: string;
|
|
531
|
+
// End date. format: MM-DD-YYYY
|
|
532
|
+
to?: string;
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
| {
|
|
536
|
+
filterType: 'number';
|
|
537
|
+
value: {
|
|
538
|
+
// Minimum allowed value. default is negative infinity
|
|
539
|
+
from?: number;
|
|
540
|
+
// Maximum allowed value. default is infinity
|
|
541
|
+
to?: number;
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
| {
|
|
545
|
+
filterType: 'boolean';
|
|
546
|
+
value: {
|
|
547
|
+
// checked for true, unchecked for false, all for all
|
|
548
|
+
id: 'checked' | 'unchecked' | 'all';
|
|
549
|
+
// A string that will appear on the filter tag, after the field name, when the filter is active (appears as <field-name>: <name>)
|
|
550
|
+
name: string;
|
|
551
|
+
}[];
|
|
552
|
+
}
|
|
553
|
+
| {
|
|
554
|
+
filterType: 'enum';
|
|
555
|
+
value: {
|
|
556
|
+
// The option value (from the filter config)
|
|
557
|
+
id: string;
|
|
558
|
+
// A string that will appear on the filter tag, after the field name, when the filter is active (appears as <field-name>: <name>)
|
|
559
|
+
name: string;
|
|
560
|
+
}[];
|
|
561
|
+
}
|
|
562
|
+
| {
|
|
563
|
+
filterType: 'reference';
|
|
564
|
+
value: {
|
|
565
|
+
// The option value (from the filter config)
|
|
566
|
+
id: string;
|
|
567
|
+
// A string that will appear on the filter tag, after the field name, when the filter is active (appears as <field-name>: <name>)
|
|
568
|
+
name: string;
|
|
569
|
+
}[];
|
|
570
|
+
};
|
|
571
|
+
|
|
480
572
|
---
|
|
481
573
|
|
|
482
574
|
## Filters Configuration Notes
|
|
@@ -315,6 +315,47 @@ export interface AppConfig {
|
|
|
315
315
|
};
|
|
316
316
|
showTotal?: boolean; // Show total items on toolbar. Default: false
|
|
317
317
|
};
|
|
318
|
+
views?: {
|
|
319
|
+
enabled?: boolean; // Whether to enable the views feature. Default: false
|
|
320
|
+
saveViewModalProps?: {
|
|
321
|
+
placeholderName?: string; // Placeholder text for the "new view" input when saving a new view
|
|
322
|
+
learnMore?: {
|
|
323
|
+
url?: string; // URL for the help/learn-more link in the Save View modal
|
|
324
|
+
};
|
|
325
|
+
};
|
|
326
|
+
viewsDropdownProps?: {
|
|
327
|
+
showTotal?: boolean; // Show total items count next to the current view name. Default: false
|
|
328
|
+
hideAllItemsView?: boolean; // Hide the built-in "All Items" view from the dropdown. Only works when custom presets exist. Default: false
|
|
329
|
+
customAllItemsViewLabel?: string; // Custom label for the "All Items" view. Ignored if a preset has `isDefaultView: true`. Default: "All items"
|
|
330
|
+
};
|
|
331
|
+
presets?:
|
|
332
|
+
| {
|
|
333
|
+
type: 'categories';
|
|
334
|
+
categories: {
|
|
335
|
+
id: string; // Unique category identifier. ⚠️ Don't use `predefined-views` and `saved-views` as these are reserved
|
|
336
|
+
label: string; // Category display name shown in the views control
|
|
337
|
+
views: {}[]; // Views included in this category (same structure as presets.views)
|
|
338
|
+
icon?: {
|
|
339
|
+
tooltipContent: string; // Tooltip text shown on hover over the help icon
|
|
340
|
+
size?: 'small' | 'medium'; // Size of the help icon. Default: 'small'
|
|
341
|
+
};
|
|
342
|
+
}[];
|
|
343
|
+
}
|
|
344
|
+
| {
|
|
345
|
+
type: 'views';
|
|
346
|
+
views: {
|
|
347
|
+
id: string; // Unique view identifier. ⚠️ Don't use `all-items-view` as this is reserved
|
|
348
|
+
label: string; // Display name for the view shown in the dropdown
|
|
349
|
+
filters?: Record<string, AutoFilterValue | null>; // Filters to apply when the view is selected. Keys must match filter IDs declared in the filters configuration
|
|
350
|
+
columnPreferences?: { // Column preferences controlling column visibility, sort, and order for this view
|
|
351
|
+
id: string; // Column unique identifier
|
|
352
|
+
direction?: 'asc' | 'desc'; // Sorting direction of the column in the view
|
|
353
|
+
show?: boolean; // Pass false to hide the column from the view
|
|
354
|
+
}[];
|
|
355
|
+
isDefaultView?: boolean; // Makes this view the default selection instead of the "All Items" view. Default: false
|
|
356
|
+
}[];
|
|
357
|
+
};
|
|
358
|
+
};
|
|
318
359
|
search?: {
|
|
319
360
|
shown?: boolean; // Show/hide the search
|
|
320
361
|
};
|
|
@@ -555,6 +596,57 @@ type LayoutContent =
|
|
|
555
596
|
};
|
|
556
597
|
};
|
|
557
598
|
|
|
599
|
+
type AutoFilterValue =
|
|
600
|
+
| {
|
|
601
|
+
filterType: 'date';
|
|
602
|
+
value:
|
|
603
|
+
| {
|
|
604
|
+
preset: DateRangeOptions | DateRangePredefinedPresetOptions;
|
|
605
|
+
}
|
|
606
|
+
| {
|
|
607
|
+
// Start date. format: MM-DD-YYYY
|
|
608
|
+
from?: string;
|
|
609
|
+
// End date. format: MM-DD-YYYY
|
|
610
|
+
to?: string;
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
| {
|
|
614
|
+
filterType: 'number';
|
|
615
|
+
value: {
|
|
616
|
+
// Minimum allowed value. default is negative infinity
|
|
617
|
+
from?: number;
|
|
618
|
+
// Maximum allowed value. default is infinity
|
|
619
|
+
to?: number;
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
| {
|
|
623
|
+
filterType: 'boolean';
|
|
624
|
+
value: {
|
|
625
|
+
// checked for true, unchecked for false, all for all
|
|
626
|
+
id: 'checked' | 'unchecked' | 'all';
|
|
627
|
+
// A string that will appear on the filter tag, after the field name, when the filter is active (appears as <field-name>: <name>)
|
|
628
|
+
name: string;
|
|
629
|
+
}[];
|
|
630
|
+
}
|
|
631
|
+
| {
|
|
632
|
+
filterType: 'enum';
|
|
633
|
+
value: {
|
|
634
|
+
// The option value (from the filter config)
|
|
635
|
+
id: string;
|
|
636
|
+
// A string that will appear on the filter tag, after the field name, when the filter is active (appears as <field-name>: <name>)
|
|
637
|
+
name: string;
|
|
638
|
+
}[];
|
|
639
|
+
}
|
|
640
|
+
| {
|
|
641
|
+
filterType: 'reference';
|
|
642
|
+
value: {
|
|
643
|
+
// The option value (from the filter config)
|
|
644
|
+
id: string;
|
|
645
|
+
// A string that will appear on the filter tag, after the field name, when the filter is active (appears as <field-name>: <name>)
|
|
646
|
+
name: string;
|
|
647
|
+
}[];
|
|
648
|
+
};
|
|
649
|
+
|
|
558
650
|
---
|
|
559
651
|
|
|
560
652
|
## Filters Configuration Notes
|
|
@@ -3664,6 +3756,40 @@ function columnOverride(props: IColumnValue<string>) {
|
|
|
3664
3756
|
}
|
|
3665
3757
|
```
|
|
3666
3758
|
|
|
3759
|
+
### Important Guidelines for Column Functions
|
|
3760
|
+
|
|
3761
|
+
**Column ID Naming**: Column IDs are always in camelCase, and your function names should match exactly:
|
|
3762
|
+
- Column ID: `petName` → Function name: `petName`
|
|
3763
|
+
- Column ID: `isVaccinated` → Function name: `isVaccinated`
|
|
3764
|
+
- Column ID: `lastActivity` → Function name: `lastActivity`
|
|
3765
|
+
|
|
3766
|
+
**React Limitations**: Column override functions are **NOT React function components**, which means:
|
|
3767
|
+
- ❌ **No React hooks allowed** (useState, useEffect, useContext, etc.)
|
|
3768
|
+
- ❌ **No custom hook calls** inside the function
|
|
3769
|
+
- ✅ **Only pure rendering logic** with JSX return
|
|
3770
|
+
|
|
3771
|
+
**Using Hooks in Column Overrides**: If you need React hooks, create a separate React component and return it from your column function:
|
|
3772
|
+
|
|
3773
|
+
```typescript
|
|
3774
|
+
// ❌ WRONG - Hooks directly in column function
|
|
3775
|
+
export function myColumn({ value, row }: IColumnValue<string>) {
|
|
3776
|
+
const [state, setState] = useState(value); // ERROR: Hooks not allowed!
|
|
3777
|
+
return <span>{state}</span>;
|
|
3778
|
+
}
|
|
3779
|
+
|
|
3780
|
+
// ✅ CORRECT - Hooks in separate component
|
|
3781
|
+
function MyColumnComponent({ value, row }: IColumnValue<string>) {
|
|
3782
|
+
const [state, setState] = useState(value); // ✅ Hooks allowed in React components
|
|
3783
|
+
const contextValue = useContext(MyContext); // ✅ Context hooks work here
|
|
3784
|
+
|
|
3785
|
+
return <span>{state} - {contextValue}</span>;
|
|
3786
|
+
}
|
|
3787
|
+
|
|
3788
|
+
export function myColumn(props: IColumnValue<string>) {
|
|
3789
|
+
return <MyColumnComponent {...props} />; // ✅ Return React component
|
|
3790
|
+
}
|
|
3791
|
+
```
|
|
3792
|
+
|
|
3667
3793
|
### Type-Specific Examples
|
|
3668
3794
|
|
|
3669
3795
|
The generic type `T` in `IColumnValue<T>` should match your field's data type:
|
|
@@ -3925,6 +4051,9 @@ AutoPatternsOverridesProvider
|
|
|
3925
4051
|
|
|
3926
4052
|
### Important Guidelines
|
|
3927
4053
|
|
|
4054
|
+
- **Function Naming**: Column function names must be in camelCase and match the column ID exactly
|
|
4055
|
+
- **No React Hooks**: Column functions are NOT React components - no useState, useEffect, useContext, etc.
|
|
4056
|
+
- **Hook Workaround**: If you need hooks, create a separate React component and return it from your column function
|
|
3928
4057
|
- **TypeScript Usage**: Always use `IColumnValue<T>` and import it from `@wix/auto-patterns/types`
|
|
3929
4058
|
- **Type Matching**: Ensure the generic type `T` matches your field's actual data type (string, number, boolean, etc.)
|
|
3930
4059
|
- **Performance**: Remember that column functions are called for every row, so keep calculations lightweight
|
|
@@ -5431,3 +5560,341 @@ export const quickUpdate: CustomActionCellActionResolver = (params) => {
|
|
|
5431
5560
|
};
|
|
5432
5561
|
};
|
|
5433
5562
|
```
|
|
5563
|
+
|
|
5564
|
+
---
|
|
5565
|
+
|
|
5566
|
+
# Views Configuration (Collection Level)
|
|
5567
|
+
|
|
5568
|
+
Views let users quickly switch between predefined table or grid configurations (filters, column visibility/sort), and optionally save their own configurations.
|
|
5569
|
+
|
|
5570
|
+
To configure views in a `collectionPage`, add a `views` property inside the page's component configuration object.
|
|
5571
|
+
|
|
5572
|
+
### Key Guidelines
|
|
5573
|
+
|
|
5574
|
+
* **enabled**: Must be set to `true` to activate the views feature.
|
|
5575
|
+
* **Precedence over toolbarTitle**: When views are enabled, they take precedence over `toolbarTitle` configuration.
|
|
5576
|
+
* **Column preferences**: To control column visibility and order in views, you must enable custom columns in your table config (`table.customColumns.enabled: true`).
|
|
5577
|
+
* **Filter references**: Filters used in preset views must reference existing filter IDs from your `filters.items` configuration.
|
|
5578
|
+
* **Reserved identifiers**: Don't use reserved IDs like `predefined-views`, `saved-views`, or `all-items-view`.
|
|
5579
|
+
|
|
5580
|
+
### Views vs Categories
|
|
5581
|
+
|
|
5582
|
+
* **Individual views** (`type: 'views'`): Use for simple preset configurations
|
|
5583
|
+
* **Categories** (`type: 'categories'`): Use to group related views together under labeled sections
|
|
5584
|
+
|
|
5585
|
+
### Default View Behavior
|
|
5586
|
+
|
|
5587
|
+
* By default, the "All Items" view is shown as the first option
|
|
5588
|
+
* Set `isDefaultView: true` on any preset view to make it the default instead
|
|
5589
|
+
* Use `hideAllItemsView: true` to hide the "All Items" view when custom presets exist
|
|
5590
|
+
* Use `customAllItemsViewLabel` to change the "All Items" label (ignored if a preset is set as default)
|
|
5591
|
+
|
|
5592
|
+
## Configuration
|
|
5593
|
+
|
|
5594
|
+
For the complete interface definitions and detailed field documentation, see the views section in [app_config_structure.md](./app_config_structure.md#views-configuration-notes)
|
|
5595
|
+
|
|
5596
|
+
## Usage Examples - Basic
|
|
5597
|
+
|
|
5598
|
+
### Simple setup
|
|
5599
|
+
Enable the views feature and manage views (save, rename, delete, set as default).
|
|
5600
|
+
|
|
5601
|
+
```ts
|
|
5602
|
+
views: {
|
|
5603
|
+
enabled: true
|
|
5604
|
+
}
|
|
5605
|
+
```
|
|
5606
|
+
|
|
5607
|
+
### Preset view
|
|
5608
|
+
Create a preset view.
|
|
5609
|
+
|
|
5610
|
+
For example a view that displays the `name` column in ascending order.
|
|
5611
|
+
```ts
|
|
5612
|
+
views: {
|
|
5613
|
+
enabled: true,
|
|
5614
|
+
presets: {
|
|
5615
|
+
type: 'views',
|
|
5616
|
+
views: [
|
|
5617
|
+
{
|
|
5618
|
+
id: 'ascending-name',
|
|
5619
|
+
label: 'Ascending names',
|
|
5620
|
+
columnPreferences: [{ id: 'name', direction: 'asc' }],
|
|
5621
|
+
},
|
|
5622
|
+
],
|
|
5623
|
+
},
|
|
5624
|
+
}
|
|
5625
|
+
```
|
|
5626
|
+
|
|
5627
|
+
### Presets Categories
|
|
5628
|
+
Group views under labeled categories.
|
|
5629
|
+
|
|
5630
|
+
For example, two views that sort the `price` column ascending and descending, grouped under 'Price' category
|
|
5631
|
+
|
|
5632
|
+
```ts
|
|
5633
|
+
views: {
|
|
5634
|
+
enabled: true,
|
|
5635
|
+
presets: {
|
|
5636
|
+
type: 'categories',
|
|
5637
|
+
categories: [
|
|
5638
|
+
{
|
|
5639
|
+
id: 'price',
|
|
5640
|
+
label: 'Price',
|
|
5641
|
+
views: [
|
|
5642
|
+
{
|
|
5643
|
+
id: 'price-low-to-high',
|
|
5644
|
+
label: 'Low to High',
|
|
5645
|
+
columnPreferences: [{ id: 'price', direction: 'asc' }],
|
|
5646
|
+
},
|
|
5647
|
+
{
|
|
5648
|
+
id: 'price-high-to-low',
|
|
5649
|
+
label: 'High to Low',
|
|
5650
|
+
columnPreferences: [{ id: 'price', direction: 'desc' }],
|
|
5651
|
+
},
|
|
5652
|
+
],
|
|
5653
|
+
},
|
|
5654
|
+
],
|
|
5655
|
+
},
|
|
5656
|
+
}
|
|
5657
|
+
```
|
|
5658
|
+
|
|
5659
|
+
### Category help tooltip icon
|
|
5660
|
+
Add a help tooltip icon next to the category name using the `icon` property.
|
|
5661
|
+
|
|
5662
|
+
```ts
|
|
5663
|
+
views: {
|
|
5664
|
+
enabled: true,
|
|
5665
|
+
presets: {
|
|
5666
|
+
type: 'categories',
|
|
5667
|
+
categories: [
|
|
5668
|
+
{
|
|
5669
|
+
id: 'price',
|
|
5670
|
+
label: 'Price',
|
|
5671
|
+
icon: {
|
|
5672
|
+
tooltipContent: 'These views sort by the item price.',
|
|
5673
|
+
size: 'small',
|
|
5674
|
+
},
|
|
5675
|
+
views: [
|
|
5676
|
+
// some views...
|
|
5677
|
+
],
|
|
5678
|
+
},
|
|
5679
|
+
],
|
|
5680
|
+
},
|
|
5681
|
+
}
|
|
5682
|
+
```
|
|
5683
|
+
|
|
5684
|
+
## Usage Examples - Advanced presets
|
|
5685
|
+
|
|
5686
|
+
### Columns visibility and order
|
|
5687
|
+
```
|
|
5688
|
+
Note that when controlling columns visibility, you always need to specify which columns you wish to show. a column without `{show: true}` will be hidden.
|
|
5689
|
+
If you wish to hide a certain column or columns - you must pass all the other ids.
|
|
5690
|
+
```
|
|
5691
|
+
|
|
5692
|
+
The `columnPreferences` array controls both visibility and order together. The array order determines the display order, and `show: true` controls visibility.
|
|
5693
|
+
|
|
5694
|
+
Examples:
|
|
5695
|
+
|
|
5696
|
+
```ts
|
|
5697
|
+
views: {
|
|
5698
|
+
enabled: true,
|
|
5699
|
+
presets: {
|
|
5700
|
+
type: 'views',
|
|
5701
|
+
views: [
|
|
5702
|
+
{
|
|
5703
|
+
id: 'compact-view',
|
|
5704
|
+
label: 'Compact',
|
|
5705
|
+
columnPreferences: [
|
|
5706
|
+
// The columns will be displayed in this order, re-order the array to control the columns' order
|
|
5707
|
+
{ id: 'name', show: true},
|
|
5708
|
+
{ id: 'price', show: true },
|
|
5709
|
+
{ id: 'age', show: true },
|
|
5710
|
+
],
|
|
5711
|
+
}
|
|
5712
|
+
],
|
|
5713
|
+
},
|
|
5714
|
+
}
|
|
5715
|
+
```
|
|
5716
|
+
|
|
5717
|
+
### Filters
|
|
5718
|
+
|
|
5719
|
+
#### Date filter
|
|
5720
|
+
Apply a filter for date data type. A 'fixed' period can be used (last week, last month, next week...) or a custom range between actual dates.
|
|
5721
|
+
|
|
5722
|
+
Examples:
|
|
5723
|
+
```ts
|
|
5724
|
+
filters: {
|
|
5725
|
+
// some date filter definition with filterId: 'createdAt-filter', supporting presets and custom ranges
|
|
5726
|
+
},
|
|
5727
|
+
views: {
|
|
5728
|
+
enabled: true,
|
|
5729
|
+
presets: {
|
|
5730
|
+
type: 'views',
|
|
5731
|
+
views: [
|
|
5732
|
+
{
|
|
5733
|
+
// Fixed preset (last 7 days)
|
|
5734
|
+
id: 'recent-created',
|
|
5735
|
+
label: 'Created: Last 7 days',
|
|
5736
|
+
filters: {
|
|
5737
|
+
'createdAt-filter': { filterType: 'date', value: { preset: 'SEVEN_DAYS' } },
|
|
5738
|
+
},
|
|
5739
|
+
},
|
|
5740
|
+
{
|
|
5741
|
+
// Closed range (between two dates)
|
|
5742
|
+
id: 'created-in-2025',
|
|
5743
|
+
label: 'Created in 2025',
|
|
5744
|
+
filters: {
|
|
5745
|
+
'createdAt-filter': { filterType: 'date', value: { from: '01-01-2025', to: '12-31-2025' } },
|
|
5746
|
+
},
|
|
5747
|
+
},
|
|
5748
|
+
],
|
|
5749
|
+
},
|
|
5750
|
+
}
|
|
5751
|
+
```
|
|
5752
|
+
|
|
5753
|
+
#### Number filter
|
|
5754
|
+
Apply a filter for numeric data type. You can filter by minimum only, maximum only, or a closed range.
|
|
5755
|
+
|
|
5756
|
+
Examples:
|
|
5757
|
+
```ts
|
|
5758
|
+
filters: {
|
|
5759
|
+
// some number filter definition with filterId: 'price-filter' and lower boundary of 0
|
|
5760
|
+
},
|
|
5761
|
+
views: {
|
|
5762
|
+
enabled: true,
|
|
5763
|
+
presets: {
|
|
5764
|
+
type: 'views',
|
|
5765
|
+
views: [
|
|
5766
|
+
{
|
|
5767
|
+
// Closed range — 10 ≤ price ≤ 100
|
|
5768
|
+
id: 'price-10-to-100',
|
|
5769
|
+
label: 'Price: 10–100',
|
|
5770
|
+
filters: {
|
|
5771
|
+
'price-filter': { filterType: 'number', value: { from: 10, to: 100 } },
|
|
5772
|
+
},
|
|
5773
|
+
},
|
|
5774
|
+
],
|
|
5775
|
+
},
|
|
5776
|
+
}
|
|
5777
|
+
```
|
|
5778
|
+
|
|
5779
|
+
#### Boolean filter
|
|
5780
|
+
Apply a filter for boolean data type. Choose items where the value is true or false. You can use the `name` field to control what will be written in the filter label when it's applied.
|
|
5781
|
+
|
|
5782
|
+
Examples:
|
|
5783
|
+
```ts
|
|
5784
|
+
filters: {
|
|
5785
|
+
// some boolean filter definition with filterId: 'inStock-filter'
|
|
5786
|
+
},
|
|
5787
|
+
views: {
|
|
5788
|
+
enabled: true,
|
|
5789
|
+
presets: {
|
|
5790
|
+
type: 'views',
|
|
5791
|
+
views: [
|
|
5792
|
+
{
|
|
5793
|
+
// Items where value is true
|
|
5794
|
+
id: 'only-in-stock',
|
|
5795
|
+
label: 'In stock only',
|
|
5796
|
+
// we will use id: 'unchecked' for false
|
|
5797
|
+
filters: {
|
|
5798
|
+
'inStock-filter': { filterType: 'boolean', value: [{ id: 'checked', name: 'In stock' }] },
|
|
5799
|
+
},
|
|
5800
|
+
},
|
|
5801
|
+
],
|
|
5802
|
+
},
|
|
5803
|
+
}
|
|
5804
|
+
```
|
|
5805
|
+
|
|
5806
|
+
#### Enum filter
|
|
5807
|
+
Apply a filter for enum (options) data type. The value is an array of selected options. You can use the `name` field to control what will be written in the filter label when it's applied
|
|
5808
|
+
|
|
5809
|
+
Examples:
|
|
5810
|
+
```ts
|
|
5811
|
+
filters: {
|
|
5812
|
+
// some enum filter definiton with filterId: 'category-filter', and options that include the values 'pets' and 'toys'
|
|
5813
|
+
},
|
|
5814
|
+
views: {
|
|
5815
|
+
enabled: true,
|
|
5816
|
+
presets: {
|
|
5817
|
+
type: 'views',
|
|
5818
|
+
views: [
|
|
5819
|
+
{
|
|
5820
|
+
id: 'pets-and-toys',
|
|
5821
|
+
label: 'Categories: Pets & Toys',
|
|
5822
|
+
filters: {
|
|
5823
|
+
'category-filter': {
|
|
5824
|
+
filterType: 'enum',
|
|
5825
|
+
value: [
|
|
5826
|
+
{ id: 'pets', name: 'Pets' },
|
|
5827
|
+
{ id: 'toys', name: 'Toys' },
|
|
5828
|
+
],
|
|
5829
|
+
},
|
|
5830
|
+
},
|
|
5831
|
+
},
|
|
5832
|
+
],
|
|
5833
|
+
},
|
|
5834
|
+
}
|
|
5835
|
+
```
|
|
5836
|
+
|
|
5837
|
+
#### Reference filter
|
|
5838
|
+
Apply a filter for reference data type. The value is an array of selected options. You can use the `name` field to control what will be written in the filter label when it's applied
|
|
5839
|
+
|
|
5840
|
+
Examples:
|
|
5841
|
+
```ts
|
|
5842
|
+
filters: {
|
|
5843
|
+
// some reference filter definition with filterId: 'owner-filter'
|
|
5844
|
+
},
|
|
5845
|
+
views: {
|
|
5846
|
+
enabled: true,
|
|
5847
|
+
presets: {
|
|
5848
|
+
type: 'views',
|
|
5849
|
+
views: [
|
|
5850
|
+
{
|
|
5851
|
+
id: 'owners-a-b',
|
|
5852
|
+
label: 'Owners: A & B',
|
|
5853
|
+
filters: {
|
|
5854
|
+
'owner-filter': {
|
|
5855
|
+
filterType: 'reference',
|
|
5856
|
+
value: [
|
|
5857
|
+
{ id: 'owner-a-id', name: 'Owner A' },
|
|
5858
|
+
{ id: 'owner-b-id', name: 'Owner B' },
|
|
5859
|
+
],
|
|
5860
|
+
},
|
|
5861
|
+
},
|
|
5862
|
+
},
|
|
5863
|
+
],
|
|
5864
|
+
},
|
|
5865
|
+
}
|
|
5866
|
+
```
|
|
5867
|
+
|
|
5868
|
+
## About Column Preferences
|
|
5869
|
+
⚠️ **Note**: To control column visibility and order in a view, you must enable custom columns in your table config (`table.customColumns.enabled: true`). See the App Config Structure doc: [app_config_structure.md](./app_config_structure.md).
|
|
5870
|
+
|
|
5871
|
+
Column preferences allows to control:
|
|
5872
|
+
1. Column's sorting
|
|
5873
|
+
2. Column's visibility and order
|
|
5874
|
+
|
|
5875
|
+
### Sorting
|
|
5876
|
+
The `direction` field can be used to decide the sorting for a column in a preset view.
|
|
5877
|
+
|
|
5878
|
+
Note that the column must be configured with `sortable: true` in the columns config.
|
|
5879
|
+
|
|
5880
|
+
For example, to sort the column `age`:
|
|
5881
|
+
```ts
|
|
5882
|
+
columnPreferences: [
|
|
5883
|
+
{
|
|
5884
|
+
id: `age`, // the column id
|
|
5885
|
+
direction: 'asc', // we can also use 'desc'
|
|
5886
|
+
}
|
|
5887
|
+
]
|
|
5888
|
+
```
|
|
5889
|
+
|
|
5890
|
+
### Visibility & Order
|
|
5891
|
+
Columns visibility and order are controlled together via the `show` field on `columnPreferences`.
|
|
5892
|
+
If you wish to change visibility and order: list ALL the columns you want to see with `{ show: true }` and they’ll be shown in exactly that order. Columns that can’t be hidden (`hideable: false` or `hiddenFromCustomColumnsSelection: true`) are always shown even if you don’t list them. Columns marked `reorderDisabled: true` keep their original position and ignore reordering.
|
|
5893
|
+
|
|
5894
|
+
## About Filters (in a preset view)
|
|
5895
|
+
Filters used in a preset are referenced by their filter item `id` from your app config. If a referenced filter id does not exist in the app config, it is ignored. Ensure all used filters are defined under `filters.items`.
|
|
5896
|
+
|
|
5897
|
+
Example usages available here: [Filters examples](#filters)
|
|
5898
|
+
|
|
5899
|
+
**Supported filter value shapes**: See the complete `AutoFilterValue` type definition and all related filter value types (`DateFilterValue`, `NumberFilterValue`, `BooleanFilterValue`, `EnumFilterValue`, `ReferenceFilterValue`) in [app_config_structure.md](./app_config_structure.md).
|
|
5900
|
+
|
|
@@ -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
|
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
|