@wix/auto-patterns 1.22.0 → 1.24.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/AutoPatternsEntityPage/AutoPatternsEntityPage.js +12 -323
- package/dist/cjs/components/AutoPatternsEntityPage/AutoPatternsEntityPage.js.map +1 -1
- package/dist/cjs/components/AutoPatternsEntityPage/EditModeEntityPage.js +172 -0
- package/dist/cjs/components/AutoPatternsEntityPage/EditModeEntityPage.js.map +1 -0
- package/dist/cjs/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutCard.js +78 -0
- package/dist/cjs/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutCard.js.map +1 -0
- package/dist/cjs/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutContent.js +119 -0
- package/dist/cjs/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutContent.js.map +1 -0
- package/dist/cjs/components/AutoPatternsEntityPage/RenderLayout/RenderViewField.js +79 -0
- package/dist/cjs/components/AutoPatternsEntityPage/RenderLayout/RenderViewField.js.map +1 -0
- package/dist/cjs/components/AutoPatternsEntityPage/RenderLayout/index.js +16 -0
- package/dist/cjs/components/AutoPatternsEntityPage/RenderLayout/index.js.map +1 -0
- package/dist/cjs/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutCard.js +77 -0
- package/dist/cjs/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutCard.js.map +1 -0
- package/dist/cjs/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutContent.js +109 -0
- package/dist/cjs/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutContent.js.map +1 -0
- package/dist/cjs/components/AutoPatternsEntityPage/ViewModeEntityPage.js +196 -0
- package/dist/cjs/components/AutoPatternsEntityPage/ViewModeEntityPage.js.map +1 -0
- package/dist/cjs/components/AutoPatternsEntityPage/index.js +12 -0
- package/dist/cjs/components/AutoPatternsEntityPage/index.js.map +1 -1
- package/dist/cjs/hooks/useActionCell.js.map +1 -1
- package/dist/cjs/hooks/useEntityPageActions.js +105 -0
- package/dist/cjs/hooks/useEntityPageActions.js.map +1 -0
- package/dist/cjs/hooks/useEntityPageMoreActions.js +10 -0
- package/dist/cjs/hooks/useEntityPageMoreActions.js.map +1 -1
- package/dist/cjs/hooks/useNavigateEditEntityAction.js +50 -0
- package/dist/cjs/hooks/useNavigateEditEntityAction.js.map +1 -0
- package/dist/cjs/hooks/useNavigationUtils.js +12 -1
- package/dist/cjs/hooks/useNavigationUtils.js.map +1 -1
- package/dist/cjs/providers/PatternsWizardOverridesContext.js +1 -1
- package/dist/cjs/providers/PatternsWizardOverridesContext.js.map +1 -1
- package/dist/cjs/types/EntityPageConfig.js.map +1 -1
- package/dist/cjs/types/actions/base.js.map +1 -1
- package/dist/cjs/types/actions/entityPageActions.js.map +1 -1
- package/dist/cjs/utils/actions/types.js.map +1 -1
- package/dist/docs/action_cell.md +6 -2
- package/dist/docs/app_config_structure.md +48 -6
- package/dist/docs/auto-patterns-guide.md +391 -60
- package/dist/docs/bulk_actions.md +7 -6
- package/dist/docs/collection_page_actions.md +14 -4
- package/dist/docs/custom_overrides.md +86 -15
- package/dist/docs/entity_page.md +65 -1
- package/dist/docs/entity_page_actions.md +13 -11
- package/dist/docs/entity_page_view_actions.md +137 -0
- package/dist/docs/index.md +6 -2
- package/dist/docs/pages_configuration.md +1 -11
- package/dist/docs/sdk_utilities.md +11 -4
- package/dist/docs/wix_fqdn_custom_data_source.md +25 -5
- package/dist/esm/components/AutoPatternsEntityPage/AutoPatternsEntityPage.js +9 -201
- package/dist/esm/components/AutoPatternsEntityPage/AutoPatternsEntityPage.js.map +1 -1
- package/dist/esm/components/AutoPatternsEntityPage/EditModeEntityPage.js +115 -0
- package/dist/esm/components/AutoPatternsEntityPage/EditModeEntityPage.js.map +1 -0
- package/dist/esm/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutCard.js +33 -0
- package/dist/esm/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutCard.js.map +1 -0
- package/dist/esm/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutContent.js +70 -0
- package/dist/esm/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutContent.js.map +1 -0
- package/dist/esm/components/AutoPatternsEntityPage/RenderLayout/RenderViewField.js +48 -0
- package/dist/esm/components/AutoPatternsEntityPage/RenderLayout/RenderViewField.js.map +1 -0
- package/dist/esm/components/AutoPatternsEntityPage/RenderLayout/index.js +3 -0
- package/dist/esm/components/AutoPatternsEntityPage/RenderLayout/index.js.map +1 -0
- package/dist/esm/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutCard.js +31 -0
- package/dist/esm/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutCard.js.map +1 -0
- package/dist/esm/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutContent.js +66 -0
- package/dist/esm/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutContent.js.map +1 -0
- package/dist/esm/components/AutoPatternsEntityPage/ViewModeEntityPage.js +109 -0
- package/dist/esm/components/AutoPatternsEntityPage/ViewModeEntityPage.js.map +1 -0
- package/dist/esm/components/AutoPatternsEntityPage/index.js +2 -0
- package/dist/esm/components/AutoPatternsEntityPage/index.js.map +1 -1
- package/dist/esm/hooks/useActionCell.js.map +1 -1
- package/dist/esm/hooks/useEntityPageActions.js +82 -0
- package/dist/esm/hooks/useEntityPageActions.js.map +1 -0
- package/dist/esm/hooks/useEntityPageMoreActions.js +11 -1
- package/dist/esm/hooks/useEntityPageMoreActions.js.map +1 -1
- package/dist/esm/hooks/useNavigateEditEntityAction.js +46 -0
- package/dist/esm/hooks/useNavigateEditEntityAction.js.map +1 -0
- package/dist/esm/hooks/useNavigationUtils.js +12 -1
- package/dist/esm/hooks/useNavigationUtils.js.map +1 -1
- package/dist/esm/providers/PatternsWizardOverridesContext.js.map +1 -1
- package/dist/esm/types/EntityPageConfig.js.map +1 -1
- package/dist/esm/types/actions/base.js.map +1 -1
- package/dist/esm/types/actions/entityPageActions.js.map +1 -1
- package/dist/esm/utils/actions/types.js.map +1 -1
- package/dist/types/components/AutoPatternsEntityPage/AutoPatternsEntityPage.d.ts.map +1 -1
- package/dist/types/components/AutoPatternsEntityPage/EditModeEntityPage.d.ts +6 -0
- package/dist/types/components/AutoPatternsEntityPage/EditModeEntityPage.d.ts.map +1 -0
- package/dist/types/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutCard.d.ts +11 -0
- package/dist/types/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutCard.d.ts.map +1 -0
- package/dist/types/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutContent.d.ts +13 -0
- package/dist/types/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutContent.d.ts.map +1 -0
- package/dist/types/components/AutoPatternsEntityPage/RenderLayout/RenderViewField.d.ts +8 -0
- package/dist/types/components/AutoPatternsEntityPage/RenderLayout/RenderViewField.d.ts.map +1 -0
- package/dist/types/components/AutoPatternsEntityPage/RenderLayout/index.d.ts +3 -0
- package/dist/types/components/AutoPatternsEntityPage/RenderLayout/index.d.ts.map +1 -0
- package/dist/types/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutCard.d.ts +8 -0
- package/dist/types/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutCard.d.ts.map +1 -0
- package/dist/types/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutContent.d.ts +8 -0
- package/dist/types/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutContent.d.ts.map +1 -0
- package/dist/types/components/AutoPatternsEntityPage/ViewModeEntityPage.d.ts +8 -0
- package/dist/types/components/AutoPatternsEntityPage/ViewModeEntityPage.d.ts.map +1 -0
- package/dist/types/components/AutoPatternsEntityPage/index.d.ts +2 -0
- package/dist/types/components/AutoPatternsEntityPage/index.d.ts.map +1 -1
- package/dist/types/hooks/useEntityPageActions.d.ts +9 -0
- package/dist/types/hooks/useEntityPageActions.d.ts.map +1 -0
- package/dist/types/hooks/useEntityPageHeaderTexts.d.ts.map +1 -1
- package/dist/types/hooks/useEntityPageMoreActions.d.ts +2 -2
- package/dist/types/hooks/useEntityPageMoreActions.d.ts.map +1 -1
- package/dist/types/hooks/useNavigateEditEntityAction.d.ts +6 -0
- package/dist/types/hooks/useNavigateEditEntityAction.d.ts.map +1 -0
- package/dist/types/hooks/useNavigationUtils.d.ts +1 -0
- package/dist/types/hooks/useNavigationUtils.d.ts.map +1 -1
- package/dist/types/providers/PatternsWizardOverridesContext.d.ts +2 -5
- package/dist/types/providers/PatternsWizardOverridesContext.d.ts.map +1 -1
- package/dist/types/types/EntityPageConfig.d.ts +20 -4
- package/dist/types/types/EntityPageConfig.d.ts.map +1 -1
- package/dist/types/types/actions/base.d.ts +0 -4
- package/dist/types/types/actions/base.d.ts.map +1 -1
- package/dist/types/types/actions/entityPageActions.d.ts +24 -5
- package/dist/types/types/actions/entityPageActions.d.ts.map +1 -1
- package/dist/types/utils/actions/types.d.ts +1 -1
- package/dist/types/utils/actions/types.d.ts.map +1 -1
- package/package.json +15 -15
- package/dist/docs/config_schema.md +0 -184
|
@@ -1,26 +1,41 @@
|
|
|
1
1
|
# FQDN-Based Custom Data Source Implementation
|
|
2
2
|
|
|
3
|
+
**🛑 CRITICAL PREREQUISITE**: This guide explains a specialized feature that exists within the broader auto-patterns framework. You **CANNOT** implement this guide without first having the complete content of the WixAutoPatternsGuide.
|
|
4
|
+
|
|
5
|
+
**📋 MANDATORY FIRST STEP**: Before proceeding with this FQDN-specific implementation:
|
|
6
|
+
1. **You MUST call the `WixAutoPatternsGuide` tool first** to get the foundational auto-patterns knowledge
|
|
7
|
+
2. **This document is NOT standalone** - it's an advanced feature guide that builds upon the core auto-patterns concepts
|
|
8
|
+
3. **Without the WixAutoPatternsGuide content**, you will not understand the basic concepts, component structure, or implementation patterns required for this FQDN implementation
|
|
9
|
+
|
|
3
10
|
When implementing a custom data source based on a Wix Business API FQDN, you'll need to understand several key concepts and follow specific implementation patterns. This guide covers the complete process from schema extraction to creating a foundation structure that **you will need to complete**.
|
|
4
11
|
|
|
5
12
|
**⚠️ IMPORTANT**: This guide creates a foundation with helpful comments and unimplemented actions that throw exceptions. The actual data source implementation (CRUD operations) must be completed by you using the appropriate Wix Business API client library.
|
|
6
13
|
|
|
7
14
|
**📝 MINIMAL IMPLEMENTATION APPROACH**: This guide focuses on creating a basic, functional dashboard page. Custom overrides (actions, columns, components, etc.) should only be implemented when explicitly requested by the user. A simple dashboard page requires only the core custom data source implementation without any additional overrides.
|
|
8
15
|
|
|
9
|
-
## Prerequisites: Required Tools
|
|
16
|
+
## Prerequisites: Required Tools and Knowledge
|
|
17
|
+
|
|
18
|
+
**🛑 ABSOLUTE REQUIREMENT - WixAutoPatternsGuide Content**:
|
|
19
|
+
- **You MUST have the complete WixAutoPatternsGuide content** before starting this implementation
|
|
20
|
+
- **This FQDN guide is NOT self-contained** - it's a specialized extension of the main auto-patterns guide
|
|
21
|
+
- **If you haven't called the `WixAutoPatternsGuide` tool yet**, stop now and call it first
|
|
22
|
+
- **This guide will reference concepts, components, and patterns** that are only explained in the main guide
|
|
10
23
|
|
|
11
24
|
**🛑 CRITICAL**: Before proceeding with this guide, you must have the following tools available:
|
|
12
|
-
- `
|
|
25
|
+
- `WixAutoPatternsGuide` tool for understanding auto-patterns fundamentals and implementation patterns (**MANDATORY FIRST STEP**)
|
|
13
26
|
- `fqdn_schema` tool for extracting schema information from FQDNs
|
|
14
27
|
- `client_lib` tool for determining the correct client library package
|
|
15
28
|
|
|
16
29
|
**If these tools are not available, you CANNOT continue with this guide.**
|
|
17
30
|
|
|
18
31
|
**Auto-Patterns Context Requirement:**
|
|
19
|
-
If you haven't already used the `
|
|
32
|
+
If you haven't already used the `WixAutoPatternsGuide` tool in this conversation, you MUST call it first to understand:
|
|
20
33
|
- How AutoPatternsApp works
|
|
21
34
|
- AppConfig structure and requirements
|
|
22
35
|
- Custom data source implementation patterns
|
|
23
36
|
- Best practices for auto-patterns development
|
|
37
|
+
- Basic component structure and routing
|
|
38
|
+
- Provider setup and configuration
|
|
24
39
|
|
|
25
40
|
**Without this foundational knowledge, you cannot successfully implement FQDN-based custom data sources.**
|
|
26
41
|
|
|
@@ -65,7 +80,10 @@ This will tell you which library to import for your custom data source implement
|
|
|
65
80
|
|
|
66
81
|
Transform the FQDN schema from Step 1 into a AutoPatterns-compatible SchemaConfig by mapping the FQDN field types to AutoPatterns field types. Identify appropriate fields for `displayField` and `idField` based on your FQDN schema.
|
|
67
82
|
|
|
68
|
-
|
|
83
|
+
**🛑 MANDATORY - Query Operators Must Be Empty Array**: When implementing a custom data source, you **MUST** set `supportedQueryOperators: []` (empty array) for all fields. This is required because:
|
|
84
|
+
- Custom data sources handle all query operations directly through your implementation
|
|
85
|
+
- You don't need to specify individual operators for each field
|
|
86
|
+
- The custom data source `find` action will receive all queries regardless of declared operators
|
|
69
87
|
|
|
70
88
|
### ⚠️ CRITICAL: Field ID Conversion from snake_case to camelCase
|
|
71
89
|
|
|
@@ -112,7 +130,7 @@ export const myCustomDataSource = async (collectionId: string, context: any) =>
|
|
|
112
130
|
// Field definitions based on your FQDN schema mapping
|
|
113
131
|
},
|
|
114
132
|
displayField: 'name',
|
|
115
|
-
idField: '
|
|
133
|
+
idField: 'id',
|
|
116
134
|
actions: {
|
|
117
135
|
get: async (entityId: string) => {
|
|
118
136
|
// TODO: Implement using your FQDN client library
|
|
@@ -218,6 +236,7 @@ If the user specifically requests custom actions for your FQDN-based data source
|
|
|
218
236
|
✅ **Schema Extraction**: Used fqdn_schema tool to understand entity structure
|
|
219
237
|
✅ **Client Library**: Used client_lib tool to identify correct SDK package
|
|
220
238
|
✅ **Field Mapping**: Mapped FQDN field types to AutoPatterns field types
|
|
239
|
+
✅ **🛑 MANDATORY: Empty Query Operators**: Set `supportedQueryOperators: []` for ALL fields to avoid TypeScript errors
|
|
221
240
|
✅ **⚠️ CRITICAL: Field ID Conversion**: Converted individual field segments from snake_case to camelCase while preserving field path structure in SchemaConfig and AppConfig
|
|
222
241
|
✅ **AppConfig Update**: Set `entityTypeSource: "custom"` and provided custom.id
|
|
223
242
|
✅ **Custom Data Source Structure**: Followed "Custom Overrides" section for folder structure and registration
|
|
@@ -235,6 +254,7 @@ If the user specifically requests custom actions for your FQDN-based data source
|
|
|
235
254
|
- **⚠️ CRITICAL: Implementing Unnecessary Overrides**: Do NOT implement custom actions, column overrides, or custom components unless explicitly requested by the user - a basic dashboard page only needs the core custom data source
|
|
236
255
|
- **⚠️ CRITICAL: Inconsistent Field ID Casing**: Failing to convert individual field segments from snake_case to camelCase while preserving field path structure in SchemaConfig and AppConfig - this is the most common mistake and will cause field mapping failures
|
|
237
256
|
- **⚠️ CRITICAL: Implementing Actions**: DO NOT implement the schema actions - they should contain helpful comments and throw unimplemented exceptions for the user to complete
|
|
257
|
+
- **🛑 CRITICAL: Query Operators MUST Be Empty Array**: You **MUST** use `supportedQueryOperators: []` (empty array) for all fields - attempting to specify actual operators will cause TypeScript compilation errors and is not supported for custom data sources
|
|
238
258
|
- **Mismatched Field Types**: Ensure FQDN field types are correctly mapped to AutoPatterns types
|
|
239
259
|
- **Wrong Client Library**: Use the exact client library returned by the client_lib tool
|
|
240
260
|
- **ID Field Confusion**: Ensure the idField matches what your FQDN API actually uses (often `_id` for Wix APIs)
|
|
@@ -1,207 +1,15 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { useParams } from 'react-router-dom';
|
|
6
|
-
import { useSchema } from '../../providers/SchemaContext';
|
|
7
|
-
import { FormFieldInput } from './Fields/FormFieldInput';
|
|
8
|
-
import { useEntityPageHeaderTexts, useNavigation } from '../../hooks';
|
|
9
|
-
import { usePatternsWizardOverridesContext } from '../../providers';
|
|
10
|
-
import { useEntityPageMoreActions } from '../../hooks/useEntityPageMoreActions';
|
|
11
|
-
import { useActionsSDK } from '../../hooks/useActionsSDK';
|
|
12
|
-
const RenderLayoutContent = _ref => {
|
|
13
|
-
var _content$container$ch, _overrides$components;
|
|
14
|
-
let {
|
|
15
|
-
content,
|
|
16
|
-
level,
|
|
17
|
-
sectionId,
|
|
18
|
-
cardIndex,
|
|
19
|
-
contentIndex,
|
|
20
|
-
setInputRef
|
|
21
|
-
} = _ref;
|
|
22
|
-
const schema = useSchema();
|
|
23
|
-
const overrides = usePatternsWizardOverridesContext();
|
|
24
|
-
const pageState = useEntityPageContext();
|
|
25
|
-
switch (content.type) {
|
|
26
|
-
case 'field':
|
|
27
|
-
if (!content.field.fieldId) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
const field = schema.fields[content.field.fieldId];
|
|
31
|
-
if (!field) {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
return /*#__PURE__*/React.createElement(Cell, {
|
|
35
|
-
span: content.field.span
|
|
36
|
-
}, /*#__PURE__*/React.createElement(FormFieldInput, {
|
|
37
|
-
key: content.field.fieldId,
|
|
38
|
-
field: field,
|
|
39
|
-
inputRef: ref => setInputRef(content.field.fieldId, ref)
|
|
40
|
-
}));
|
|
41
|
-
case 'container':
|
|
42
|
-
if (!((_content$container$ch = content.container.children) != null && _content$container$ch.length)) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
return /*#__PURE__*/React.createElement(Cell, {
|
|
46
|
-
span: content.container.span
|
|
47
|
-
}, /*#__PURE__*/React.createElement(Layout, null, content.container.children.map((child, index) => /*#__PURE__*/React.createElement(RenderLayoutContent, {
|
|
48
|
-
key: `${sectionId}-card-${cardIndex}-content-${contentIndex}-level-${level}-child-${index}`,
|
|
49
|
-
content: child,
|
|
50
|
-
level: level + 1,
|
|
51
|
-
sectionId: sectionId,
|
|
52
|
-
cardIndex: cardIndex,
|
|
53
|
-
contentIndex: index,
|
|
54
|
-
setInputRef: setInputRef
|
|
55
|
-
}))));
|
|
56
|
-
case 'component':
|
|
57
|
-
if (!content.component.componentId) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
const Component = overrides == null || (_overrides$components = overrides.components) == null ? void 0 : _overrides$components[content.component.componentId];
|
|
61
|
-
if (!Component) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
return /*#__PURE__*/React.createElement(Cell, {
|
|
65
|
-
span: content.component.span
|
|
66
|
-
}, /*#__PURE__*/React.createElement(Component, {
|
|
67
|
-
form: pageState.form,
|
|
68
|
-
entity: pageState.entity
|
|
69
|
-
}));
|
|
70
|
-
default:
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
const RenderLayoutCard = _ref2 => {
|
|
75
|
-
var _layout$card$subtitle;
|
|
76
|
-
let {
|
|
77
|
-
layout,
|
|
78
|
-
sectionId,
|
|
79
|
-
cardIndex,
|
|
80
|
-
setInputRef
|
|
81
|
-
} = _ref2;
|
|
82
|
-
switch (layout.type) {
|
|
83
|
-
case 'card':
|
|
84
|
-
return /*#__PURE__*/React.createElement(EntityPage.Card, {
|
|
85
|
-
minHeight: "50px"
|
|
86
|
-
}, /*#__PURE__*/React.createElement(Card.Header, {
|
|
87
|
-
title: layout.card.title.text,
|
|
88
|
-
subtitle: (_layout$card$subtitle = layout.card.subtitle) == null ? void 0 : _layout$card$subtitle.text
|
|
89
|
-
}), /*#__PURE__*/React.createElement(Card.Divider, null), /*#__PURE__*/React.createElement(Card.Content, null, /*#__PURE__*/React.createElement(Layout, null, layout.card.children.map((child, index) => /*#__PURE__*/React.createElement(RenderLayoutContent, {
|
|
90
|
-
key: `${sectionId}-card-${cardIndex}-content-${index}`,
|
|
91
|
-
content: child,
|
|
92
|
-
level: 0,
|
|
93
|
-
sectionId: sectionId,
|
|
94
|
-
cardIndex: cardIndex,
|
|
95
|
-
contentIndex: index,
|
|
96
|
-
setInputRef: setInputRef
|
|
97
|
-
})))));
|
|
98
|
-
default:
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
export const AutoPatternsEntityPage = _ref3 => {
|
|
103
|
-
var _pageLayout$main, _pageLayout$sidebar;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ViewModeEntityPage } from './ViewModeEntityPage';
|
|
3
|
+
import { EditModeEntityPage } from './EditModeEntityPage';
|
|
4
|
+
export const AutoPatternsEntityPage = _ref => {
|
|
104
5
|
let {
|
|
105
6
|
configuration
|
|
106
|
-
} =
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
moreActions,
|
|
112
|
-
collectionId
|
|
113
|
-
} = configuration;
|
|
114
|
-
const form = useForm({
|
|
115
|
-
mode: 'onChange'
|
|
116
|
-
});
|
|
117
|
-
const params = useParams();
|
|
118
|
-
const entityId = params[route.params.id];
|
|
119
|
-
const schema = useSchema();
|
|
120
|
-
const isCreateMode = !entityId;
|
|
121
|
-
const inputRefs = useRef({});
|
|
122
|
-
const setInputRef = (id, input) => {
|
|
123
|
-
inputRefs.current[id] = input;
|
|
124
|
-
};
|
|
125
|
-
const validate = () => {
|
|
126
|
-
const invalidFieldId = Object.keys(inputRefs.current).find(fieldId => {
|
|
127
|
-
var _inputRefs$current$fi;
|
|
128
|
-
return (_inputRefs$current$fi = inputRefs.current[fieldId]) == null ? void 0 : _inputRefs$current$fi.invalid;
|
|
129
|
-
});
|
|
130
|
-
if (invalidFieldId) {
|
|
131
|
-
var _inputRefs$current$in;
|
|
132
|
-
(_inputRefs$current$in = inputRefs.current[invalidFieldId]) == null || _inputRefs$current$in.focus == null || _inputRefs$current$in.focus();
|
|
133
|
-
throw new Error('Invalid form');
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
const {
|
|
137
|
-
getParentPagePath
|
|
138
|
-
} = useNavigation();
|
|
139
|
-
const parentPath = useMemo(() => getParentPagePath(parentPageId), [parentPageId, getParentPagePath]);
|
|
140
|
-
const state = useEntityPage({
|
|
141
|
-
parentPath,
|
|
142
|
-
form,
|
|
143
|
-
onSave: async () => {
|
|
144
|
-
validate();
|
|
145
|
-
const formValues = form.getValues();
|
|
146
|
-
const baseEntity = state.entity || {};
|
|
147
|
-
const updatedEntity = {
|
|
148
|
-
...baseEntity,
|
|
149
|
-
...formValues
|
|
150
|
-
};
|
|
151
|
-
const newEntity = entityId ? await schema.actions.update(updatedEntity) : await schema.actions.create(updatedEntity);
|
|
152
|
-
return {
|
|
153
|
-
updatedEntity: newEntity
|
|
154
|
-
};
|
|
155
|
-
},
|
|
156
|
-
fetch: async () => {
|
|
157
|
-
if (!entityId) {
|
|
158
|
-
return {
|
|
159
|
-
entity: undefined
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
const entity = await schema.actions.get(entityId);
|
|
163
|
-
return {
|
|
164
|
-
entity
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
const entity = useEntity(state);
|
|
169
|
-
const {
|
|
170
|
-
title,
|
|
171
|
-
subtitle
|
|
172
|
-
} = useEntityPageHeaderTexts({
|
|
173
|
-
config: configuration,
|
|
174
|
-
isCreateMode,
|
|
175
|
-
entityDisplayName: entity == null ? void 0 : entity[schema.displayField]
|
|
176
|
-
});
|
|
177
|
-
const sdk = useActionsSDK({
|
|
178
|
-
collectionId
|
|
7
|
+
} = _ref;
|
|
8
|
+
return configuration.mode === 'view' ? /*#__PURE__*/React.createElement(ViewModeEntityPage, {
|
|
9
|
+
configuration: configuration
|
|
10
|
+
}) : /*#__PURE__*/React.createElement(EditModeEntityPage, {
|
|
11
|
+
configuration: configuration
|
|
179
12
|
});
|
|
180
|
-
const resolvedMoreActions = useEntityPageMoreActions(moreActions, entity, sdk, form);
|
|
181
|
-
return /*#__PURE__*/React.createElement(EntityPage, {
|
|
182
|
-
state: state,
|
|
183
|
-
dataHook: "auto-patterns-entity-page"
|
|
184
|
-
}, /*#__PURE__*/React.createElement(EntityPage.Header, {
|
|
185
|
-
title: title,
|
|
186
|
-
subtitle: subtitle,
|
|
187
|
-
moreActions: resolvedMoreActions.length > 0 ? /*#__PURE__*/React.createElement(MoreActions, {
|
|
188
|
-
items: resolvedMoreActions
|
|
189
|
-
}) : undefined
|
|
190
|
-
}), /*#__PURE__*/React.createElement(EntityPage.Content, null, /*#__PURE__*/React.createElement(EntityPage.MainContent, {
|
|
191
|
-
dataHook: "entity-page-main-content"
|
|
192
|
-
}, pageLayout == null || (_pageLayout$main = pageLayout.main) == null ? void 0 : _pageLayout$main.map((layout, layoutIndex) => /*#__PURE__*/React.createElement(RenderLayoutCard, {
|
|
193
|
-
key: `main-section-card-${layoutIndex}`,
|
|
194
|
-
layout: layout,
|
|
195
|
-
sectionId: "main",
|
|
196
|
-
cardIndex: layoutIndex,
|
|
197
|
-
setInputRef: setInputRef
|
|
198
|
-
}))), pageLayout != null && pageLayout.sidebar ? /*#__PURE__*/React.createElement(EntityPage.AdditionalContent, null, (_pageLayout$sidebar = pageLayout.sidebar) == null ? void 0 : _pageLayout$sidebar.map((layout, layoutIndex) => /*#__PURE__*/React.createElement(RenderLayoutCard, {
|
|
199
|
-
key: `sidebar-section-card-${layoutIndex}`,
|
|
200
|
-
layout: layout,
|
|
201
|
-
sectionId: "sidebar",
|
|
202
|
-
cardIndex: layoutIndex,
|
|
203
|
-
setInputRef: setInputRef
|
|
204
|
-
}))) : null));
|
|
205
13
|
};
|
|
206
14
|
|
|
207
15
|
/*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useMemo","useRef","EntityPage","useEntity","useEntityPage","useEntityPageContext","MoreActions","useForm","Card","Cell","Layout","useParams","useSchema","FormFieldInput","useEntityPageHeaderTexts","useNavigation","usePatternsWizardOverridesContext","useEntityPageMoreActions","useActionsSDK","RenderLayoutContent","_ref","_content$container$ch","_overrides$components","content","level","sectionId","cardIndex","contentIndex","setInputRef","schema","overrides","pageState","type","field","fieldId","fields","createElement","span","key","inputRef","ref","container","children","length","map","child","index","component","componentId","Component","components","form","entity","RenderLayoutCard","_ref2","_layout$card$subtitle","layout","minHeight","Header","title","card","text","subtitle","Divider","Content","AutoPatternsEntityPage","_ref3","_pageLayout$main","_pageLayout$sidebar","configuration","pageLayout","parentPageId","route","moreActions","collectionId","mode","params","entityId","id","isCreateMode","inputRefs","input","current","validate","invalidFieldId","Object","keys","find","_inputRefs$current$fi","invalid","_inputRefs$current$in","focus","Error","getParentPagePath","parentPath","state","onSave","formValues","getValues","baseEntity","updatedEntity","newEntity","actions","update","create","fetch","undefined","get","config","entityDisplayName","displayField","sdk","resolvedMoreActions","dataHook","items","MainContent","main","layoutIndex","sidebar","AdditionalContent"],"sources":["../../../../src/components/AutoPatternsEntityPage/AutoPatternsEntityPage.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react';\nimport { CardLayout, EntityPageConfig, LayoutContent } from '../../types';\nimport {\n EntityPage,\n EntityPageState,\n useEntity,\n useEntityPage,\n useEntityPageContext,\n MoreActions,\n} from '@wix/patterns';\nimport { useForm } from '@wix/patterns/form';\nimport { Card, Cell, Layout } from '@wix/design-system';\nimport { useParams } from 'react-router-dom';\nimport { useSchema } from '../../providers/SchemaContext';\nimport { BaseInputRef } from './Fields/types';\nimport { FormFieldInput } from './Fields/FormFieldInput';\nimport { useEntityPageHeaderTexts, useNavigation } from '../../hooks';\nimport { usePatternsWizardOverridesContext } from '../../providers';\nimport { useEntityPageMoreActions } from '../../hooks/useEntityPageMoreActions';\nimport { useActionsSDK } from '../../hooks/useActionsSDK';\n\nconst RenderLayoutContent: React.FC<{\n content: LayoutContent;\n level: number;\n sectionId: string;\n cardIndex: number;\n contentIndex: number;\n setInputRef: (id: string, input: BaseInputRef) => void;\n}> = ({ content, level, sectionId, cardIndex, contentIndex, setInputRef }) => {\n const schema = useSchema();\n const overrides = usePatternsWizardOverridesContext();\n const pageState = useEntityPageContext();\n\n switch (content.type) {\n case 'field':\n if (!content.field.fieldId) {\n return null;\n }\n\n const field = schema.fields[content.field.fieldId];\n\n if (!field) {\n return null;\n }\n\n return (\n <Cell span={content.field.span}>\n <FormFieldInput\n key={content.field.fieldId}\n field={field}\n inputRef={(ref) => setInputRef(content.field.fieldId, ref)}\n />\n </Cell>\n );\n\n case 'container':\n if (!content.container.children?.length) {\n return null;\n }\n\n return (\n <Cell span={content.container.span}>\n <Layout>\n {content.container.children.map((child, index) => (\n <RenderLayoutContent\n key={`${sectionId}-card-${cardIndex}-content-${contentIndex}-level-${level}-child-${index}`}\n content={child}\n level={level + 1}\n sectionId={sectionId}\n cardIndex={cardIndex}\n contentIndex={index}\n setInputRef={setInputRef}\n />\n ))}\n </Layout>\n </Cell>\n );\n\n case 'component':\n if (!content.component.componentId) {\n return null;\n }\n\n const Component = overrides?.components?.[content.component.componentId];\n\n if (!Component) {\n return null;\n }\n\n return (\n <Cell span={content.component.span}>\n <Component\n form={pageState.form as any}\n entity={pageState.entity as any as Record<string, any>}\n />\n </Cell>\n );\n\n default:\n return null;\n }\n};\n\nconst RenderLayoutCard: React.FC<{\n layout: CardLayout;\n sectionId: string;\n cardIndex: number;\n setInputRef: (id: string, input: BaseInputRef) => void;\n}> = ({ layout, sectionId, cardIndex, setInputRef }) => {\n switch (layout.type) {\n case 'card':\n return (\n <EntityPage.Card minHeight=\"50px\">\n <Card.Header\n title={layout.card.title.text}\n subtitle={layout.card.subtitle?.text}\n />\n <Card.Divider />\n <Card.Content>\n <Layout>\n {layout.card.children.map((child, index: number) => (\n <RenderLayoutContent\n key={`${sectionId}-card-${cardIndex}-content-${index}`}\n content={child}\n level={0}\n sectionId={sectionId}\n cardIndex={cardIndex}\n contentIndex={index}\n setInputRef={setInputRef}\n />\n ))}\n </Layout>\n </Card.Content>\n </EntityPage.Card>\n );\n default:\n return null;\n }\n};\n\nexport interface AutoPatternsEntityPageProps {\n configuration: EntityPageConfig;\n}\n\nexport const AutoPatternsEntityPage: React.FC<AutoPatternsEntityPageProps> = ({\n configuration,\n}) => {\n const {\n layout: pageLayout,\n parentPageId,\n route,\n moreActions,\n collectionId,\n } = configuration;\n\n const form = useForm<any>({\n mode: 'onChange',\n });\n const params = useParams();\n const entityId = params[route.params.id];\n const schema = useSchema();\n const isCreateMode = !entityId;\n\n const inputRefs = useRef<{ [fieldId: string]: BaseInputRef }>({});\n\n const setInputRef = (id: string, input: BaseInputRef) => {\n inputRefs.current[id] = input;\n };\n\n const validate = () => {\n const invalidFieldId = Object.keys(inputRefs.current).find((fieldId) => {\n return inputRefs.current[fieldId]?.invalid;\n });\n\n if (invalidFieldId) {\n inputRefs.current[invalidFieldId]?.focus?.();\n throw new Error('Invalid form');\n }\n };\n const { getParentPagePath } = useNavigation();\n\n const parentPath = useMemo(\n () => getParentPagePath(parentPageId),\n [parentPageId, getParentPagePath],\n );\n\n const state: EntityPageState<any> = useEntityPage<any, any>({\n parentPath,\n form,\n onSave: async () => {\n validate();\n\n const formValues = form.getValues();\n const baseEntity = state.entity || {};\n const updatedEntity = {\n ...baseEntity,\n ...formValues,\n };\n\n const newEntity = entityId\n ? await schema.actions.update(updatedEntity)\n : await schema.actions.create(updatedEntity);\n\n return { updatedEntity: newEntity };\n },\n fetch: async () => {\n if (!entityId) {\n return { entity: undefined };\n }\n const entity = await schema.actions.get(entityId);\n return { entity };\n },\n });\n\n const entity = useEntity(state);\n\n const { title, subtitle } = useEntityPageHeaderTexts({\n config: configuration,\n isCreateMode,\n entityDisplayName: entity?.[schema.displayField],\n });\n\n const sdk = useActionsSDK({\n collectionId,\n });\n\n const resolvedMoreActions = useEntityPageMoreActions(\n moreActions,\n entity,\n sdk,\n form,\n );\n\n return (\n <EntityPage state={state} dataHook=\"auto-patterns-entity-page\">\n <EntityPage.Header\n title={title}\n subtitle={subtitle}\n moreActions={\n resolvedMoreActions.length > 0 ? (\n <MoreActions items={resolvedMoreActions} />\n ) : undefined\n }\n />\n <EntityPage.Content>\n <EntityPage.MainContent dataHook=\"entity-page-main-content\">\n {pageLayout?.main?.map((layout, layoutIndex) => (\n <RenderLayoutCard\n key={`main-section-card-${layoutIndex}`}\n layout={layout}\n sectionId=\"main\"\n cardIndex={layoutIndex}\n setInputRef={setInputRef}\n />\n ))}\n </EntityPage.MainContent>\n {pageLayout?.sidebar ? (\n <EntityPage.AdditionalContent>\n {pageLayout.sidebar?.map((layout, layoutIndex) => (\n <RenderLayoutCard\n key={`sidebar-section-card-${layoutIndex}`}\n layout={layout}\n sectionId=\"sidebar\"\n cardIndex={layoutIndex}\n setInputRef={setInputRef}\n />\n ))}\n </EntityPage.AdditionalContent>\n ) : null}\n </EntityPage.Content>\n </EntityPage>\n );\n};\n\n/*\n Key structure explanation:\n\n Main cards: main-section-card-{layoutIndex}\n Sidebar cards: sidebar-section-card-{layoutIndex}\n\n Layout content:\n {sectionId}-card-{cardIndex}-content-{contentIndex}\n\n Nested children:\n {sectionId}-card-{cardIndex}-content-{parentContentIndex}-level-{level}-child-{childIndex}\n\n This ensures uniqueness across all levels and sections.\n*/\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAE9C,SACEC,UAAU,EAEVC,SAAS,EACTC,aAAa,EACbC,oBAAoB,EACpBC,WAAW,QACN,eAAe;AACtB,SAASC,OAAO,QAAQ,oBAAoB;AAC5C,SAASC,IAAI,EAAEC,IAAI,EAAEC,MAAM,QAAQ,oBAAoB;AACvD,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,SAAS,QAAQ,+BAA+B;AAEzD,SAASC,cAAc,QAAQ,yBAAyB;AACxD,SAASC,wBAAwB,EAAEC,aAAa,QAAQ,aAAa;AACrE,SAASC,iCAAiC,QAAQ,iBAAiB;AACnE,SAASC,wBAAwB,QAAQ,sCAAsC;AAC/E,SAASC,aAAa,QAAQ,2BAA2B;AAEzD,MAAMC,mBAOJ,GAAGC,IAAA,IAAyE;EAAA,IAAAC,qBAAA,EAAAC,qBAAA;EAAA,IAAxE;IAAEC,OAAO;IAAEC,KAAK;IAAEC,SAAS;IAAEC,SAAS;IAAEC,YAAY;IAAEC;EAAY,CAAC,GAAAR,IAAA;EACvE,MAAMS,MAAM,GAAGjB,SAAS,CAAC,CAAC;E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aAAA,CAAClC,UAAU,CAAC8D,OAAO,qBACjBjE,KAAA,CAAAqC,aAAA,CAAClC,UAAU,CAACiH,WAAW;IAACF,QAAQ,EAAC;EAA0B,GACxD3C,UAAU,aAAAH,gBAAA,GAAVG,UAAU,CAAE8C,IAAI,qBAAhBjD,gBAAA,CAAkBvB,GAAG,CAAC,CAACY,MAAM,EAAE6D,WAAW,kBACzCtH,KAAA,CAAAqC,aAAA,CAACiB,gBAAgB;IACff,GAAG,EAAE,qBAAqB+E,WAAW,EAAG;IACxC7D,MAAM,EAAEA,MAAO;IACf/B,SAAS,EAAC,MAAM;IAChBC,SAAS,EAAE2F,WAAY;IACvBzF,WAAW,EAAEA;EAAY,CAC1B,CACF,CACqB,CAAC,EACxB0C,UAAU,YAAVA,UAAU,CAAEgD,OAAO,gBAClBvH,KAAA,CAAAqC,aAAA,CAAClC,UAAU,CAACqH,iBAAiB,SAAAnD,mBAAA,GAC1BE,UAAU,CAACgD,OAAO,qBAAlBlD,mBAAA,CAAoBxB,GAAG,CAAC,CAACY,MAAM,EAAE6D,WAAW,kBAC3CtH,KAAA,CAAAqC,aAAA,CAACiB,gBAAgB;IACff,GAAG,EAAE,wBAAwB+E,WAAW,EAAG;IAC3C7D,MAAM,EAAEA,MAAO;IACf/B,SAAS,EAAC,SAAS;IACnBC,SAAS,EAAE2F,WAAY;IACvBzF,WAAW,EAAEA;EAAY,CAC1B,CACF,CAC2B,CAAC,GAC7B,IACc,CACV,CAAC;AAEjB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["React","ViewModeEntityPage","EditModeEntityPage","AutoPatternsEntityPage","_ref","configuration","mode","createElement"],"sources":["../../../../src/components/AutoPatternsEntityPage/AutoPatternsEntityPage.tsx"],"sourcesContent":["import React from 'react';\nimport { EntityPageConfig } from '../../types';\nimport { ViewModeEntityPage } from './ViewModeEntityPage';\nimport { EditModeEntityPage } from './EditModeEntityPage';\n\nexport interface AutoPatternsEntityPageProps {\n configuration: EntityPageConfig;\n}\n\nexport const AutoPatternsEntityPage: React.FC<AutoPatternsEntityPageProps> = ({\n configuration,\n}) => {\n return configuration.mode === 'view' ? (\n <ViewModeEntityPage configuration={configuration} />\n ) : (\n <EditModeEntityPage configuration={configuration} />\n );\n};\n\n/*\n Key structure explanation:\n\n Main cards: main-section-card-{layoutIndex}\n Sidebar cards: sidebar-section-card-{layoutIndex}\n\n Layout content:\n {sectionId}-card-{cardIndex}-content-{contentIndex}\n\n Nested children:\n {sectionId}-card-{cardIndex}-content-{parentContentIndex}-level-{level}-child-{childIndex}\n\n This ensures uniqueness across all levels and sections.\n*/\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,kBAAkB,QAAQ,sBAAsB;AACzD,SAASC,kBAAkB,QAAQ,sBAAsB;AAMzD,OAAO,MAAMC,sBAA6D,GAAGC,IAAA,IAEvE;EAAA,IAFwE;IAC5EC;EACF,CAAC,GAAAD,IAAA;EACC,OAAOC,aAAa,CAACC,IAAI,KAAK,MAAM,gBAClCN,KAAA,CAAAO,aAAA,CAACN,kBAAkB;IAACI,aAAa,EAAEA;EAAc,CAAE,CAAC,gBAEpDL,KAAA,CAAAO,aAAA,CAACL,kBAAkB;IAACG,aAAa,EAAEA;EAAc,CAAE,CACpD;AACH,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import React, { useMemo, useRef } from 'react';
|
|
2
|
+
import { EntityPage, useEntity, useEntityPage, MoreActions } from '@wix/patterns';
|
|
3
|
+
import { useForm } from '@wix/patterns/form';
|
|
4
|
+
import { useParams } from 'react-router-dom';
|
|
5
|
+
import { useSchema } from '../../providers/SchemaContext';
|
|
6
|
+
import { useEntityPageHeaderTexts, useNavigation } from '../../hooks';
|
|
7
|
+
import { useEntityPageMoreActions } from '../../hooks/useEntityPageMoreActions';
|
|
8
|
+
import { useActionsSDK } from '../../hooks/useActionsSDK';
|
|
9
|
+
import { RenderLayoutCard } from './RenderLayout';
|
|
10
|
+
export const EditModeEntityPage = _ref => {
|
|
11
|
+
var _pageLayout$main, _pageLayout$sidebar;
|
|
12
|
+
let {
|
|
13
|
+
configuration
|
|
14
|
+
} = _ref;
|
|
15
|
+
const {
|
|
16
|
+
layout: pageLayout,
|
|
17
|
+
parentPageId,
|
|
18
|
+
route,
|
|
19
|
+
actions,
|
|
20
|
+
collectionId
|
|
21
|
+
} = configuration;
|
|
22
|
+
const moreActions = actions == null ? void 0 : actions.moreActions;
|
|
23
|
+
const form = useForm({
|
|
24
|
+
mode: 'onChange'
|
|
25
|
+
});
|
|
26
|
+
const params = useParams();
|
|
27
|
+
const entityId = params[route.params.id];
|
|
28
|
+
const schema = useSchema();
|
|
29
|
+
const isCreateMode = !entityId;
|
|
30
|
+
const inputRefs = useRef({});
|
|
31
|
+
const setInputRef = (id, input) => {
|
|
32
|
+
inputRefs.current[id] = input;
|
|
33
|
+
};
|
|
34
|
+
const validate = () => {
|
|
35
|
+
const invalidFieldId = Object.keys(inputRefs.current).find(fieldId => {
|
|
36
|
+
var _inputRefs$current$fi;
|
|
37
|
+
return (_inputRefs$current$fi = inputRefs.current[fieldId]) == null ? void 0 : _inputRefs$current$fi.invalid;
|
|
38
|
+
});
|
|
39
|
+
if (invalidFieldId) {
|
|
40
|
+
var _inputRefs$current$in;
|
|
41
|
+
(_inputRefs$current$in = inputRefs.current[invalidFieldId]) == null || _inputRefs$current$in.focus == null || _inputRefs$current$in.focus();
|
|
42
|
+
throw new Error('Invalid form');
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const {
|
|
46
|
+
getParentPagePath
|
|
47
|
+
} = useNavigation();
|
|
48
|
+
const parentPath = useMemo(() => getParentPagePath(parentPageId), [parentPageId, getParentPagePath]);
|
|
49
|
+
const state = useEntityPage({
|
|
50
|
+
parentPath,
|
|
51
|
+
form,
|
|
52
|
+
onSave: async () => {
|
|
53
|
+
validate();
|
|
54
|
+
const formValues = form.getValues();
|
|
55
|
+
const baseEntity = state.entity || {};
|
|
56
|
+
const updatedEntity = {
|
|
57
|
+
...baseEntity,
|
|
58
|
+
...formValues
|
|
59
|
+
};
|
|
60
|
+
const newEntity = entityId ? await schema.actions.update(updatedEntity) : await schema.actions.create(updatedEntity);
|
|
61
|
+
return {
|
|
62
|
+
updatedEntity: newEntity
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
fetch: async () => {
|
|
66
|
+
if (!entityId) {
|
|
67
|
+
return {
|
|
68
|
+
entity: undefined
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const entity = await schema.actions.get(entityId);
|
|
72
|
+
return {
|
|
73
|
+
entity
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
const entity = useEntity(state);
|
|
78
|
+
const {
|
|
79
|
+
title,
|
|
80
|
+
subtitle
|
|
81
|
+
} = useEntityPageHeaderTexts({
|
|
82
|
+
config: configuration,
|
|
83
|
+
isCreateMode,
|
|
84
|
+
entityDisplayName: entity == null ? void 0 : entity[schema.displayField]
|
|
85
|
+
});
|
|
86
|
+
const sdk = useActionsSDK({
|
|
87
|
+
collectionId
|
|
88
|
+
});
|
|
89
|
+
const resolvedMoreActions = useEntityPageMoreActions(moreActions, entity, sdk, form);
|
|
90
|
+
return /*#__PURE__*/React.createElement(EntityPage, {
|
|
91
|
+
state: state,
|
|
92
|
+
dataHook: "auto-patterns-entity-page"
|
|
93
|
+
}, /*#__PURE__*/React.createElement(EntityPage.Header, {
|
|
94
|
+
title: title,
|
|
95
|
+
subtitle: subtitle,
|
|
96
|
+
moreActions: resolvedMoreActions.length > 0 ? /*#__PURE__*/React.createElement(MoreActions, {
|
|
97
|
+
items: resolvedMoreActions
|
|
98
|
+
}) : undefined
|
|
99
|
+
}), /*#__PURE__*/React.createElement(EntityPage.Content, null, /*#__PURE__*/React.createElement(EntityPage.MainContent, {
|
|
100
|
+
dataHook: "entity-page-main-content"
|
|
101
|
+
}, pageLayout == null || (_pageLayout$main = pageLayout.main) == null ? void 0 : _pageLayout$main.map((layout, layoutIndex) => /*#__PURE__*/React.createElement(RenderLayoutCard, {
|
|
102
|
+
key: `main-section-card-${layoutIndex}`,
|
|
103
|
+
layout: layout,
|
|
104
|
+
sectionId: "main",
|
|
105
|
+
cardIndex: layoutIndex,
|
|
106
|
+
setInputRef: setInputRef
|
|
107
|
+
}))), pageLayout != null && pageLayout.sidebar ? /*#__PURE__*/React.createElement(EntityPage.AdditionalContent, null, (_pageLayout$sidebar = pageLayout.sidebar) == null ? void 0 : _pageLayout$sidebar.map((layout, layoutIndex) => /*#__PURE__*/React.createElement(RenderLayoutCard, {
|
|
108
|
+
key: `sidebar-section-card-${layoutIndex}`,
|
|
109
|
+
layout: layout,
|
|
110
|
+
sectionId: "sidebar",
|
|
111
|
+
cardIndex: layoutIndex,
|
|
112
|
+
setInputRef: setInputRef
|
|
113
|
+
}))) : null));
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=EditModeEntityPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useMemo","useRef","EntityPage","useEntity","useEntityPage","MoreActions","useForm","useParams","useSchema","useEntityPageHeaderTexts","useNavigation","useEntityPageMoreActions","useActionsSDK","RenderLayoutCard","EditModeEntityPage","_ref","_pageLayout$main","_pageLayout$sidebar","configuration","layout","pageLayout","parentPageId","route","actions","collectionId","moreActions","form","mode","params","entityId","id","schema","isCreateMode","inputRefs","setInputRef","input","current","validate","invalidFieldId","Object","keys","find","fieldId","_inputRefs$current$fi","invalid","_inputRefs$current$in","focus","Error","getParentPagePath","parentPath","state","onSave","formValues","getValues","baseEntity","entity","updatedEntity","newEntity","update","create","fetch","undefined","get","title","subtitle","config","entityDisplayName","displayField","sdk","resolvedMoreActions","createElement","dataHook","Header","length","items","Content","MainContent","main","map","layoutIndex","key","sectionId","cardIndex","sidebar","AdditionalContent"],"sources":["../../../../src/components/AutoPatternsEntityPage/EditModeEntityPage.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react';\nimport {\n EntityPage,\n EntityPageState,\n useEntity,\n useEntityPage,\n MoreActions,\n} from '@wix/patterns';\nimport { useForm } from '@wix/patterns/form';\nimport { useParams } from 'react-router-dom';\nimport { useSchema } from '../../providers/SchemaContext';\nimport { BaseInputRef } from './Fields/types';\nimport { useEntityPageHeaderTexts, useNavigation } from '../../hooks';\nimport { useEntityPageMoreActions } from '../../hooks/useEntityPageMoreActions';\nimport { useActionsSDK } from '../../hooks/useActionsSDK';\nimport { RenderLayoutCard } from './RenderLayout';\nimport { EditEntityPageConfig } from '../../types';\n\nexport const EditModeEntityPage: React.FC<{\n configuration: EditEntityPageConfig;\n}> = ({ configuration }) => {\n const {\n layout: pageLayout,\n parentPageId,\n route,\n actions,\n collectionId,\n } = configuration;\n\n const moreActions = actions?.moreActions;\n\n const form = useForm<any>({\n mode: 'onChange',\n });\n const params = useParams();\n const entityId = params[route.params.id];\n const schema = useSchema();\n const isCreateMode = !entityId;\n\n const inputRefs = useRef<{ [fieldId: string]: BaseInputRef }>({});\n\n const setInputRef = (id: string, input: BaseInputRef) => {\n inputRefs.current[id] = input;\n };\n\n const validate = () => {\n const invalidFieldId = Object.keys(inputRefs.current).find((fieldId) => {\n return inputRefs.current[fieldId]?.invalid;\n });\n\n if (invalidFieldId) {\n inputRefs.current[invalidFieldId]?.focus?.();\n throw new Error('Invalid form');\n }\n };\n const { getParentPagePath } = useNavigation();\n\n const parentPath = useMemo(\n () => getParentPagePath(parentPageId),\n [parentPageId, getParentPagePath],\n );\n\n const state: EntityPageState<any> = useEntityPage<any, any>({\n parentPath,\n form,\n onSave: async () => {\n validate();\n\n const formValues = form.getValues();\n const baseEntity = state.entity || {};\n const updatedEntity = {\n ...baseEntity,\n ...formValues,\n };\n\n const newEntity = entityId\n ? await schema.actions.update(updatedEntity)\n : await schema.actions.create(updatedEntity);\n\n return { updatedEntity: newEntity };\n },\n fetch: async () => {\n if (!entityId) {\n return { entity: undefined };\n }\n const entity = await schema.actions.get(entityId);\n return { entity };\n },\n });\n\n const entity = useEntity(state);\n\n const { title, subtitle } = useEntityPageHeaderTexts({\n config: configuration,\n isCreateMode,\n entityDisplayName: entity?.[schema.displayField],\n });\n\n const sdk = useActionsSDK({\n collectionId,\n });\n\n const resolvedMoreActions = useEntityPageMoreActions(\n moreActions,\n entity,\n sdk,\n form,\n );\n\n return (\n <EntityPage state={state} dataHook=\"auto-patterns-entity-page\">\n <EntityPage.Header\n title={title}\n subtitle={subtitle}\n moreActions={\n resolvedMoreActions.length > 0 ? (\n <MoreActions items={resolvedMoreActions} />\n ) : undefined\n }\n />\n <EntityPage.Content>\n <EntityPage.MainContent dataHook=\"entity-page-main-content\">\n {pageLayout?.main?.map((layout, layoutIndex) => (\n <RenderLayoutCard\n key={`main-section-card-${layoutIndex}`}\n layout={layout}\n sectionId=\"main\"\n cardIndex={layoutIndex}\n setInputRef={setInputRef}\n />\n ))}\n </EntityPage.MainContent>\n {pageLayout?.sidebar ? (\n <EntityPage.AdditionalContent>\n {pageLayout.sidebar?.map((layout, layoutIndex) => (\n <RenderLayoutCard\n key={`sidebar-section-card-${layoutIndex}`}\n layout={layout}\n sectionId=\"sidebar\"\n cardIndex={layoutIndex}\n setInputRef={setInputRef}\n />\n ))}\n </EntityPage.AdditionalContent>\n ) : null}\n </EntityPage.Content>\n </EntityPage>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAC9C,SACEC,UAAU,EAEVC,SAAS,EACTC,aAAa,EACbC,WAAW,QACN,eAAe;AACtB,SAASC,OAAO,QAAQ,oBAAoB;AAC5C,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,SAAS,QAAQ,+BAA+B;AAEzD,SAASC,wBAAwB,EAAEC,a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UAAU,CAAE+D,OAAO,gBAClBpF,KAAA,CAAAuE,aAAA,CAACpE,UAAU,CAACkF,iBAAiB,SAAAnE,mBAAA,GAC1BG,UAAU,CAAC+D,OAAO,qBAAlBlE,mBAAA,CAAoB6D,GAAG,CAAC,CAAC3D,MAAM,EAAE4D,WAAW,kBAC3ChF,KAAA,CAAAuE,aAAA,CAACzD,gBAAgB;IACfmE,GAAG,EAAE,wBAAwBD,WAAW,EAAG;IAC3C5D,MAAM,EAAEA,MAAO;IACf8D,SAAS,EAAC,SAAS;IACnBC,SAAS,EAAEH,WAAY;IACvB7C,WAAW,EAAEA;EAAY,CAC1B,CACF,CAC2B,CAAC,GAC7B,IACc,CACV,CAAC;AAEjB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Card, Layout } from '@wix/design-system';
|
|
3
|
+
import { EntityPage } from '@wix/patterns';
|
|
4
|
+
import { RenderLayoutContent } from './RenderLayoutContent';
|
|
5
|
+
export const RenderLayoutCard = _ref => {
|
|
6
|
+
var _layout$card$subtitle;
|
|
7
|
+
let {
|
|
8
|
+
layout,
|
|
9
|
+
sectionId,
|
|
10
|
+
cardIndex,
|
|
11
|
+
setInputRef
|
|
12
|
+
} = _ref;
|
|
13
|
+
switch (layout.type) {
|
|
14
|
+
case 'card':
|
|
15
|
+
return /*#__PURE__*/React.createElement(EntityPage.Card, {
|
|
16
|
+
minHeight: "50px"
|
|
17
|
+
}, /*#__PURE__*/React.createElement(Card.Header, {
|
|
18
|
+
title: layout.card.title.text,
|
|
19
|
+
subtitle: (_layout$card$subtitle = layout.card.subtitle) == null ? void 0 : _layout$card$subtitle.text
|
|
20
|
+
}), /*#__PURE__*/React.createElement(Card.Divider, null), /*#__PURE__*/React.createElement(Card.Content, null, /*#__PURE__*/React.createElement(Layout, null, layout.card.children.map((child, index) => /*#__PURE__*/React.createElement(RenderLayoutContent, {
|
|
21
|
+
key: `${sectionId}-card-${cardIndex}-content-${index}`,
|
|
22
|
+
content: child,
|
|
23
|
+
level: 0,
|
|
24
|
+
sectionId: sectionId,
|
|
25
|
+
cardIndex: cardIndex,
|
|
26
|
+
contentIndex: index,
|
|
27
|
+
setInputRef: setInputRef
|
|
28
|
+
})))));
|
|
29
|
+
default:
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=RenderLayoutCard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","Card","Layout","EntityPage","RenderLayoutContent","RenderLayoutCard","_ref","_layout$card$subtitle","layout","sectionId","cardIndex","setInputRef","type","createElement","minHeight","Header","title","card","text","subtitle","Divider","Content","children","map","child","index","key","content","level","contentIndex"],"sources":["../../../../../src/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutCard.tsx"],"sourcesContent":["import React from 'react';\nimport { Card, Layout } from '@wix/design-system';\nimport { EntityPage } from '@wix/patterns';\nimport { RenderLayoutContent } from './RenderLayoutContent';\nimport { CardLayout } from '../../../types';\nimport { BaseInputRef } from '../Fields/types';\n\nexport interface RenderLayoutCardProps {\n layout: CardLayout;\n sectionId: string;\n cardIndex: number;\n setInputRef: (id: string, input: BaseInputRef) => void;\n}\n\nexport const RenderLayoutCard: React.FC<RenderLayoutCardProps> = ({\n layout,\n sectionId,\n cardIndex,\n setInputRef,\n}) => {\n switch (layout.type) {\n case 'card':\n return (\n <EntityPage.Card minHeight=\"50px\">\n <Card.Header\n title={layout.card.title.text}\n subtitle={layout.card.subtitle?.text}\n />\n <Card.Divider />\n <Card.Content>\n <Layout>\n {layout.card.children.map((child, index: number) => (\n <RenderLayoutContent\n key={`${sectionId}-card-${cardIndex}-content-${index}`}\n content={child}\n level={0}\n sectionId={sectionId}\n cardIndex={cardIndex}\n contentIndex={index}\n setInputRef={setInputRef}\n />\n ))}\n </Layout>\n </Card.Content>\n </EntityPage.Card>\n );\n default:\n return null;\n }\n};\n"],"mappings":"AAAA,OA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List":[]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Cell, Layout } from '@wix/design-system';
|
|
3
|
+
import { useSchema } from '../../../providers/SchemaContext';
|
|
4
|
+
import { usePatternsWizardOverridesContext } from '../../../providers';
|
|
5
|
+
import { useEntityPageContext } from '@wix/patterns';
|
|
6
|
+
import { FormFieldInput } from '../Fields/FormFieldInput';
|
|
7
|
+
export const RenderLayoutContent = _ref => {
|
|
8
|
+
var _content$container$ch, _overrides$components;
|
|
9
|
+
let {
|
|
10
|
+
content,
|
|
11
|
+
level,
|
|
12
|
+
sectionId,
|
|
13
|
+
cardIndex,
|
|
14
|
+
contentIndex,
|
|
15
|
+
setInputRef
|
|
16
|
+
} = _ref;
|
|
17
|
+
const schema = useSchema();
|
|
18
|
+
const overrides = usePatternsWizardOverridesContext();
|
|
19
|
+
const pageState = useEntityPageContext();
|
|
20
|
+
const entity = pageState.entity;
|
|
21
|
+
switch (content.type) {
|
|
22
|
+
case 'field':
|
|
23
|
+
if (!content.field.fieldId) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const field = schema.fields[content.field.fieldId];
|
|
27
|
+
if (!field) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return /*#__PURE__*/React.createElement(Cell, {
|
|
31
|
+
span: content.field.span
|
|
32
|
+
}, /*#__PURE__*/React.createElement(FormFieldInput, {
|
|
33
|
+
key: content.field.fieldId,
|
|
34
|
+
field: field,
|
|
35
|
+
inputRef: ref => setInputRef(content.field.fieldId, ref)
|
|
36
|
+
}));
|
|
37
|
+
case 'container':
|
|
38
|
+
if (!((_content$container$ch = content.container.children) != null && _content$container$ch.length)) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return /*#__PURE__*/React.createElement(Cell, {
|
|
42
|
+
span: content.container.span
|
|
43
|
+
}, /*#__PURE__*/React.createElement(Layout, null, content.container.children.map((child, index) => /*#__PURE__*/React.createElement(RenderLayoutContent, {
|
|
44
|
+
key: `${sectionId}-card-${cardIndex}-content-${contentIndex}-level-${level}-child-${index}`,
|
|
45
|
+
content: child,
|
|
46
|
+
level: level + 1,
|
|
47
|
+
sectionId: sectionId,
|
|
48
|
+
cardIndex: cardIndex,
|
|
49
|
+
contentIndex: index,
|
|
50
|
+
setInputRef: setInputRef
|
|
51
|
+
}))));
|
|
52
|
+
case 'component':
|
|
53
|
+
if (!content.component.componentId) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const Component = overrides == null || (_overrides$components = overrides.components) == null ? void 0 : _overrides$components[content.component.componentId];
|
|
57
|
+
if (!Component) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
return /*#__PURE__*/React.createElement(Cell, {
|
|
61
|
+
span: content.component.span
|
|
62
|
+
}, /*#__PURE__*/React.createElement(Component, {
|
|
63
|
+
form: pageState == null ? void 0 : pageState.form,
|
|
64
|
+
entity: entity
|
|
65
|
+
}));
|
|
66
|
+
default:
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=RenderLayoutContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","Cell","Layout","useSchema","usePatternsWizardOverridesContext","useEntityPageContext","FormFieldInput","RenderLayoutContent","_ref","_content$container$ch","_overrides$components","content","level","sectionId","cardIndex","contentIndex","setInputRef","schema","overrides","pageState","entity","type","field","fieldId","fields","createElement","span","key","inputRef","ref","container","children","length","map","child","index","component","componentId","Component","components","form"],"sources":["../../../../../src/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutContent.tsx"],"sourcesContent":["import React from 'react';\nimport { Cell, Layout } from '@wix/design-system';\nimport { useSchema } from '../../../providers/SchemaContext';\nimport { usePatternsWizardOverridesContext } from '../../../providers';\nimport { useEntityPageContext } from '@wix/patterns';\nimport { FormFieldInput } from '../Fields/FormFieldInput';\nimport { LayoutContent } from '../../../types';\nimport { BaseInputRef } from '../Fields/types';\n\nexport interface RenderLayoutContentProps {\n content: LayoutContent;\n level: number;\n sectionId: string;\n cardIndex: number;\n contentIndex: number;\n setInputRef: (id: string, input: BaseInputRef) => void;\n}\n\nexport const RenderLayoutContent: React.FC<RenderLayoutContentProps> = ({\n content,\n level,\n sectionId,\n cardIndex,\n contentIndex,\n setInputRef,\n}) => {\n const schema = useSchema();\n const overrides = usePatternsWizardOverridesContext();\n const pageState = useEntityPageContext();\n\n const entity = pageState.entity;\n\n switch (content.type) {\n case 'field':\n if (!content.field.fieldId) {\n return null;\n }\n\n const field = schema.fields[content.field.fieldId];\n if (!field) {\n return null;\n }\n\n return (\n <Cell span={content.field.span}>\n <FormFieldInput\n key={content.field.fieldId}\n field={field}\n inputRef={(ref) => setInputRef(content.field.fieldId, ref)}\n />\n </Cell>\n );\n\n case 'container':\n if (!content.container.children?.length) {\n return null;\n }\n\n return (\n <Cell span={content.container.span}>\n <Layout>\n {content.container.children.map((child, index) => (\n <RenderLayoutContent\n key={`${sectionId}-card-${cardIndex}-content-${contentIndex}-level-${level}-child-${index}`}\n content={child}\n level={level + 1}\n sectionId={sectionId}\n cardIndex={cardIndex}\n contentIndex={index}\n setInputRef={setInputRef}\n />\n ))}\n </Layout>\n </Cell>\n );\n\n case 'component':\n if (!content.component.componentId) {\n return null;\n }\n\n const Component = overrides?.components?.[content.component.componentId];\n if (!Component) {\n return null;\n }\n\n return (\n <Cell span={content.component.span}>\n <Component\n form={pageState?.form as any}\n entity={entity as Record<string, any>}\n />\n </Cell>\n );\n\n default:\n return null;\n }\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,IAAI,EAAEC,MAAM,QAAQ,oBAAoB;AACjD,SAASC,SAAS,QAAQ,kCAAkC;AAC5D,SAASC,iCAAiC,QAAQ,oBAAoB;AACtE,SAASC,oBAAoB,QAAQ,eAAe;AACpD,SAASC,cAAc,QAAQ,0BAA0B;AAazD,OAAO,MAAMC,mBAAuD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