@payloadcms/ui 3.71.0-internal-debug.80dab4c → 3.71.0-internal-debug.dea9d74
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/fields/Tabs/index.d.ts.map +1 -1
- package/dist/fields/Tabs/index.js +34 -66
- package/dist/fields/Tabs/index.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts +2 -2
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js +125 -99
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/iterateFields.d.ts +2 -2
- package/dist/forms/fieldSchemasToFormState/iterateFields.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/iterateFields.js +1 -1
- package/dist/forms/fieldSchemasToFormState/iterateFields.js.map +1 -1
- package/dist/utilities/buildClientFieldSchemaMap/traverseFields.d.ts +2 -2
- package/dist/utilities/buildClientFieldSchemaMap/traverseFields.d.ts.map +1 -1
- package/dist/utilities/buildClientFieldSchemaMap/traverseFields.js +40 -33
- package/dist/utilities/buildClientFieldSchemaMap/traverseFields.js.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/traverseFields.d.ts +2 -2
- package/dist/utilities/buildFieldSchemaMap/traverseFields.d.ts.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/traverseFields.js +40 -35
- package/dist/utilities/buildFieldSchemaMap/traverseFields.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Tabs/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/Tabs/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EAMrB,MAAM,SAAS,CAAA;AAIhB,OAAO,KAA2C,MAAM,OAAO,CAAA;AAa/D,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,OAAO,cAAc,CAAA;AAIrB,OAAO,EAAE,YAAY,EAAE,CAAA;AAsKvB,eAAO,MAAM,SAAS;;6DAAoC,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
|
|
3
3
|
import { getTranslation } from '@payloadcms/translations';
|
|
4
|
-
import {
|
|
4
|
+
import { getFieldPaths, toKebabCase } from 'payload/shared';
|
|
5
5
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
6
6
|
import { useCollapsible } from '../../elements/Collapsible/provider.js';
|
|
7
7
|
import { RenderCustomComponent } from '../../elements/RenderCustomComponent/index.js';
|
|
@@ -19,19 +19,8 @@ import { TabComponent } from './Tab/index.js';
|
|
|
19
19
|
import './index.scss';
|
|
20
20
|
const baseClass = 'tabs-field';
|
|
21
21
|
export { TabsProvider };
|
|
22
|
-
function generateTabPath({ activeTabConfig, path }) {
|
|
23
|
-
let tabPath = path;
|
|
24
|
-
if (tabHasName(activeTabConfig) && activeTabConfig.name) {
|
|
25
|
-
if (path) {
|
|
26
|
-
tabPath = `${path}.${activeTabConfig.name}`;
|
|
27
|
-
} else {
|
|
28
|
-
tabPath = activeTabConfig.name;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return tabPath;
|
|
32
|
-
}
|
|
33
22
|
const TabsFieldComponent = (props)=>{
|
|
34
|
-
const { field: { admin: { className } = {}, tabs = [] }, forceRender = false, indexPath = '', parentPath = '', parentSchemaPath = '', path = '', permissions, readOnly } = props;
|
|
23
|
+
const { field: { admin: { className } = {}, tabs = [] }, forceRender = false, indexPath = '', parentPath = '', parentSchemaPath = '', path = '', permissions, readOnly, schemaPath = '' } = props;
|
|
35
24
|
const { getPreference, setPreference } = usePreferences();
|
|
36
25
|
const { preferencesKey } = useDocumentInfo();
|
|
37
26
|
const { i18n } = useTranslation();
|
|
@@ -48,18 +37,8 @@ const TabsFieldComponent = (props)=>{
|
|
|
48
37
|
});
|
|
49
38
|
const [activeTabIndex, setActiveTabIndex] = useState(()=>tabStates.filter(({ passesCondition })=>passesCondition)?.[0]?.index ?? 0);
|
|
50
39
|
const tabsPrefKey = `tabs-${indexPath}`;
|
|
51
|
-
const [activeTabPath, setActiveTabPath] = useState(()=>generateTabPath({
|
|
52
|
-
activeTabConfig: tabs[activeTabIndex],
|
|
53
|
-
path: parentPath
|
|
54
|
-
}));
|
|
55
|
-
const [activeTabSchemaPath, setActiveTabSchemaPath] = useState(()=>generateTabPath({
|
|
56
|
-
activeTabConfig: tabs[0],
|
|
57
|
-
path: parentSchemaPath
|
|
58
|
-
}));
|
|
59
|
-
const activePathChildrenPath = tabHasName(tabs[activeTabIndex]) ? activeTabPath : parentPath;
|
|
60
40
|
const activeTabInfo = tabStates[activeTabIndex];
|
|
61
41
|
const activeTabConfig = activeTabInfo?.tab;
|
|
62
|
-
const activePathSchemaChildrenPath = tabHasName(tabs[activeTabIndex]) ? activeTabSchemaPath : parentSchemaPath;
|
|
63
42
|
const activeTabDescription = activeTabConfig.admin?.description ?? activeTabConfig.description;
|
|
64
43
|
const activeTabStaticDescription = typeof activeTabDescription === 'function' ? activeTabDescription({
|
|
65
44
|
i18n,
|
|
@@ -68,14 +47,6 @@ const TabsFieldComponent = (props)=>{
|
|
|
68
47
|
const hasVisibleTabs = tabStates.some(({ passesCondition })=>passesCondition);
|
|
69
48
|
const handleTabChange = useCallback(async (incomingTabIndex)=>{
|
|
70
49
|
setActiveTabIndex(incomingTabIndex);
|
|
71
|
-
setActiveTabPath(generateTabPath({
|
|
72
|
-
activeTabConfig: tabs[incomingTabIndex],
|
|
73
|
-
path: parentPath
|
|
74
|
-
}));
|
|
75
|
-
setActiveTabSchemaPath(generateTabPath({
|
|
76
|
-
activeTabConfig: tabs[incomingTabIndex],
|
|
77
|
-
path: parentSchemaPath
|
|
78
|
-
}));
|
|
79
50
|
const existingPreferences = await getPreference(preferencesKey);
|
|
80
51
|
if (preferencesKey) {
|
|
81
52
|
void setPreference(preferencesKey, {
|
|
@@ -100,9 +71,6 @@ const TabsFieldComponent = (props)=>{
|
|
|
100
71
|
});
|
|
101
72
|
}
|
|
102
73
|
}, [
|
|
103
|
-
tabs,
|
|
104
|
-
parentPath,
|
|
105
|
-
parentSchemaPath,
|
|
106
74
|
getPreference,
|
|
107
75
|
preferencesKey,
|
|
108
76
|
setPreference,
|
|
@@ -116,14 +84,6 @@ const TabsFieldComponent = (props)=>{
|
|
|
116
84
|
const initialIndex = path ? existingPreferences?.fields?.[path]?.tabIndex : existingPreferences?.fields?.[tabsPrefKey]?.tabIndex;
|
|
117
85
|
const newIndex = initialIndex || 0;
|
|
118
86
|
setActiveTabIndex(newIndex);
|
|
119
|
-
setActiveTabPath(generateTabPath({
|
|
120
|
-
activeTabConfig: tabs[newIndex],
|
|
121
|
-
path: parentPath
|
|
122
|
-
}));
|
|
123
|
-
setActiveTabSchemaPath(generateTabPath({
|
|
124
|
-
activeTabConfig: tabs[newIndex],
|
|
125
|
-
path: parentSchemaPath
|
|
126
|
-
}));
|
|
127
87
|
};
|
|
128
88
|
void getInitialPref();
|
|
129
89
|
}
|
|
@@ -172,61 +132,69 @@ const TabsFieldComponent = (props)=>{
|
|
|
172
132
|
tab: tab
|
|
173
133
|
}, index, false, {
|
|
174
134
|
fileName: "src/fields/Tabs/index.tsx",
|
|
175
|
-
lineNumber:
|
|
135
|
+
lineNumber: 155,
|
|
176
136
|
columnNumber: 15
|
|
177
137
|
}, this))
|
|
178
138
|
}, void 0, false, {
|
|
179
139
|
fileName: "src/fields/Tabs/index.tsx",
|
|
180
|
-
lineNumber:
|
|
140
|
+
lineNumber: 153,
|
|
181
141
|
columnNumber: 11
|
|
182
142
|
}, this)
|
|
183
143
|
}, void 0, false, {
|
|
184
144
|
fileName: "src/fields/Tabs/index.tsx",
|
|
185
|
-
lineNumber:
|
|
145
|
+
lineNumber: 152,
|
|
186
146
|
columnNumber: 9
|
|
187
147
|
}, this),
|
|
188
148
|
/*#__PURE__*/ _jsxDEV("div", {
|
|
189
149
|
className: `${baseClass}__content-wrap`,
|
|
190
150
|
children: activeTabConfig && /*#__PURE__*/ _jsxDEV(TabContent, {
|
|
191
151
|
description: activeTabStaticDescription,
|
|
192
|
-
|
|
152
|
+
field: activeTabConfig,
|
|
193
153
|
forceRender: forceRender,
|
|
194
154
|
hidden: false,
|
|
195
|
-
parentIndexPath:
|
|
196
|
-
parentPath:
|
|
197
|
-
parentSchemaPath:
|
|
198
|
-
path:
|
|
155
|
+
parentIndexPath: indexPath,
|
|
156
|
+
parentPath: path,
|
|
157
|
+
parentSchemaPath: schemaPath,
|
|
158
|
+
path: path,
|
|
199
159
|
permissions: permissions && typeof permissions === 'object' && 'name' in activeTabConfig ? permissions[activeTabConfig.name] && typeof permissions[activeTabConfig.name] === 'object' && 'fields' in permissions[activeTabConfig.name] ? permissions[activeTabConfig.name].fields : permissions[activeTabConfig.name] : permissions,
|
|
200
|
-
readOnly: readOnly
|
|
160
|
+
readOnly: readOnly,
|
|
161
|
+
tabIndex: activeTabIndex
|
|
201
162
|
}, void 0, false, {
|
|
202
163
|
fileName: "src/fields/Tabs/index.tsx",
|
|
203
|
-
lineNumber:
|
|
164
|
+
lineNumber: 170,
|
|
204
165
|
columnNumber: 13
|
|
205
166
|
}, this)
|
|
206
167
|
}, void 0, false, {
|
|
207
168
|
fileName: "src/fields/Tabs/index.tsx",
|
|
208
|
-
lineNumber:
|
|
169
|
+
lineNumber: 168,
|
|
209
170
|
columnNumber: 9
|
|
210
171
|
}, this)
|
|
211
172
|
]
|
|
212
173
|
}, void 0, true, {
|
|
213
174
|
fileName: "src/fields/Tabs/index.tsx",
|
|
214
|
-
lineNumber:
|
|
175
|
+
lineNumber: 151,
|
|
215
176
|
columnNumber: 7
|
|
216
177
|
}, this)
|
|
217
178
|
}, void 0, false, {
|
|
218
179
|
fileName: "src/fields/Tabs/index.tsx",
|
|
219
|
-
lineNumber:
|
|
180
|
+
lineNumber: 140,
|
|
220
181
|
columnNumber: 5
|
|
221
182
|
}, this);
|
|
222
183
|
};
|
|
223
184
|
export const TabsField = withCondition(TabsFieldComponent);
|
|
224
|
-
function TabContent({ description,
|
|
185
|
+
function TabContent({ description, field, forceRender, hidden, label, parentIndexPath, parentPath, parentSchemaPath, permissions, readOnly, tabIndex }) {
|
|
225
186
|
const { i18n } = useTranslation();
|
|
226
|
-
const { customComponents: { AfterInput, BeforeInput, Description, Field } = {}
|
|
187
|
+
const { customComponents: { AfterInput, BeforeInput, Description, Field } = {} } = useField();
|
|
227
188
|
if (Field) {
|
|
228
189
|
return Field;
|
|
229
190
|
}
|
|
191
|
+
const { indexPath, path, schemaPath } = getFieldPaths({
|
|
192
|
+
field,
|
|
193
|
+
index: tabIndex,
|
|
194
|
+
parentIndexPath,
|
|
195
|
+
parentPath,
|
|
196
|
+
parentSchemaPath
|
|
197
|
+
});
|
|
230
198
|
return /*#__PURE__*/ _jsxDEV("div", {
|
|
231
199
|
className: [
|
|
232
200
|
hidden && `${baseClass}__tab--hidden`,
|
|
@@ -239,36 +207,36 @@ function TabContent({ description, fields, forceRender, hidden, label, parentInd
|
|
|
239
207
|
Fallback: /*#__PURE__*/ _jsxDEV(FieldDescription, {
|
|
240
208
|
description: description,
|
|
241
209
|
marginPlacement: "bottom",
|
|
242
|
-
path:
|
|
210
|
+
path: parentPath
|
|
243
211
|
}, void 0, false, {
|
|
244
212
|
fileName: "src/fields/Tabs/index.tsx",
|
|
245
|
-
lineNumber:
|
|
213
|
+
lineNumber: 256,
|
|
246
214
|
columnNumber: 11
|
|
247
215
|
}, void 0)
|
|
248
216
|
}, void 0, false, {
|
|
249
217
|
fileName: "src/fields/Tabs/index.tsx",
|
|
250
|
-
lineNumber:
|
|
218
|
+
lineNumber: 253,
|
|
251
219
|
columnNumber: 7
|
|
252
220
|
}, this),
|
|
253
221
|
BeforeInput,
|
|
254
222
|
/*#__PURE__*/ _jsxDEV(RenderFields, {
|
|
255
|
-
fields: fields,
|
|
223
|
+
fields: field.fields,
|
|
256
224
|
forceRender: forceRender,
|
|
257
|
-
parentIndexPath:
|
|
258
|
-
parentPath:
|
|
259
|
-
parentSchemaPath:
|
|
225
|
+
parentIndexPath: indexPath,
|
|
226
|
+
parentPath: path,
|
|
227
|
+
parentSchemaPath: schemaPath,
|
|
260
228
|
permissions: permissions,
|
|
261
229
|
readOnly: readOnly
|
|
262
230
|
}, void 0, false, {
|
|
263
231
|
fileName: "src/fields/Tabs/index.tsx",
|
|
264
|
-
lineNumber:
|
|
232
|
+
lineNumber: 260,
|
|
265
233
|
columnNumber: 7
|
|
266
234
|
}, this),
|
|
267
235
|
AfterInput
|
|
268
236
|
]
|
|
269
237
|
}, void 0, true, {
|
|
270
238
|
fileName: "src/fields/Tabs/index.tsx",
|
|
271
|
-
lineNumber:
|
|
239
|
+
lineNumber: 244,
|
|
272
240
|
columnNumber: 5
|
|
273
241
|
}, this);
|
|
274
242
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/fields/Tabs/index.tsx"],"sourcesContent":["'use client'\nimport type {\n ClientComponentProps,\n ClientField,\n ClientTab,\n DocumentPreferences,\n SanitizedFieldPermissions,\n StaticDescription,\n TabsFieldClientComponent,\n} from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { tabHasName, toKebabCase } from 'payload/shared'\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport { useCollapsible } from '../../elements/Collapsible/provider.js'\nimport { RenderCustomComponent } from '../../elements/RenderCustomComponent/index.js'\nimport { useFormFields } from '../../forms/Form/index.js'\nimport { RenderFields } from '../../forms/RenderFields/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { usePreferences } from '../../providers/Preferences/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport { TabsProvider } from './provider.js'\nimport { TabComponent } from './Tab/index.js'\nimport './index.scss'\n\nconst baseClass = 'tabs-field'\n\nexport { TabsProvider }\n\nfunction generateTabPath({ activeTabConfig, path }: { activeTabConfig: ClientTab; path: string }) {\n let tabPath = path\n\n if (tabHasName(activeTabConfig) && activeTabConfig.name) {\n if (path) {\n tabPath = `${path}.${activeTabConfig.name}`\n } else {\n tabPath = activeTabConfig.name\n }\n }\n\n return tabPath\n}\n\nconst TabsFieldComponent: TabsFieldClientComponent = (props) => {\n const {\n field: { admin: { className } = {}, tabs = [] },\n forceRender = false,\n indexPath = '',\n parentPath = '',\n parentSchemaPath = '',\n path = '',\n permissions,\n readOnly,\n } = props\n\n const { getPreference, setPreference } = usePreferences()\n const { preferencesKey } = useDocumentInfo()\n const { i18n } = useTranslation()\n const { isWithinCollapsible } = useCollapsible()\n\n const tabStates = useFormFields(([fields]) => {\n return tabs.map((tab, index) => {\n const id = tab?.id\n\n return {\n index,\n passesCondition: fields?.[id]?.passesCondition ?? true,\n tab,\n }\n })\n })\n\n const [activeTabIndex, setActiveTabIndex] = useState<number>(\n () => tabStates.filter(({ passesCondition }) => passesCondition)?.[0]?.index ?? 0,\n )\n\n const tabsPrefKey = `tabs-${indexPath}`\n const [activeTabPath, setActiveTabPath] = useState<string>(() =>\n generateTabPath({ activeTabConfig: tabs[activeTabIndex], path: parentPath }),\n )\n\n const [activeTabSchemaPath, setActiveTabSchemaPath] = useState<string>(() =>\n generateTabPath({ activeTabConfig: tabs[0], path: parentSchemaPath }),\n )\n\n const activePathChildrenPath = tabHasName(tabs[activeTabIndex]) ? activeTabPath : parentPath\n const activeTabInfo = tabStates[activeTabIndex]\n const activeTabConfig = activeTabInfo?.tab\n const activePathSchemaChildrenPath = tabHasName(tabs[activeTabIndex])\n ? activeTabSchemaPath\n : parentSchemaPath\n\n const activeTabDescription = activeTabConfig.admin?.description ?? activeTabConfig.description\n\n const activeTabStaticDescription =\n typeof activeTabDescription === 'function'\n ? activeTabDescription({ i18n, t: i18n.t })\n : activeTabDescription\n\n const hasVisibleTabs = tabStates.some(({ passesCondition }) => passesCondition)\n\n const handleTabChange = useCallback(\n async (incomingTabIndex: number): Promise<void> => {\n setActiveTabIndex(incomingTabIndex)\n\n setActiveTabPath(\n generateTabPath({ activeTabConfig: tabs[incomingTabIndex], path: parentPath }),\n )\n setActiveTabSchemaPath(\n generateTabPath({ activeTabConfig: tabs[incomingTabIndex], path: parentSchemaPath }),\n )\n\n const existingPreferences: DocumentPreferences = await getPreference(preferencesKey)\n\n if (preferencesKey) {\n void setPreference(preferencesKey, {\n ...existingPreferences,\n ...(path\n ? {\n fields: {\n ...(existingPreferences?.fields || {}),\n [path]: {\n ...existingPreferences?.fields?.[path],\n tabIndex: incomingTabIndex,\n },\n },\n }\n : {\n fields: {\n ...existingPreferences?.fields,\n [tabsPrefKey]: {\n ...existingPreferences?.fields?.[tabsPrefKey],\n tabIndex: incomingTabIndex,\n },\n },\n }),\n })\n }\n },\n [\n tabs,\n parentPath,\n parentSchemaPath,\n getPreference,\n preferencesKey,\n setPreference,\n path,\n tabsPrefKey,\n ],\n )\n\n useEffect(() => {\n if (preferencesKey) {\n const getInitialPref = async () => {\n const existingPreferences: DocumentPreferences = await getPreference(preferencesKey)\n const initialIndex = path\n ? existingPreferences?.fields?.[path]?.tabIndex\n : existingPreferences?.fields?.[tabsPrefKey]?.tabIndex\n\n const newIndex = initialIndex || 0\n setActiveTabIndex(newIndex)\n\n setActiveTabPath(generateTabPath({ activeTabConfig: tabs[newIndex], path: parentPath }))\n setActiveTabSchemaPath(\n generateTabPath({ activeTabConfig: tabs[newIndex], path: parentSchemaPath }),\n )\n }\n void getInitialPref()\n }\n }, [path, getPreference, preferencesKey, tabsPrefKey, tabs, parentPath, parentSchemaPath])\n\n useEffect(() => {\n if (activeTabInfo?.passesCondition === false) {\n const nextTab = tabStates.find(({ passesCondition }) => passesCondition)\n if (nextTab) {\n void handleTabChange(nextTab.index)\n }\n }\n }, [activeTabInfo, tabStates, handleTabChange])\n\n return (\n <div\n className={[\n fieldBaseClass,\n className,\n baseClass,\n isWithinCollapsible && `${baseClass}--within-collapsible`,\n !hasVisibleTabs && `${baseClass}--hidden`,\n ]\n .filter(Boolean)\n .join(' ')}\n >\n <TabsProvider>\n <div className={`${baseClass}__tabs-wrap`}>\n <div className={`${baseClass}__tabs`}>\n {tabStates.map(({ index, passesCondition, tab }) => (\n <TabComponent\n hidden={!passesCondition}\n isActive={activeTabIndex === index}\n key={index}\n parentPath={path}\n setIsActive={() => {\n void handleTabChange(index)\n }}\n tab={tab}\n />\n ))}\n </div>\n </div>\n <div className={`${baseClass}__content-wrap`}>\n {activeTabConfig && (\n <TabContent\n description={activeTabStaticDescription}\n fields={activeTabConfig.fields}\n forceRender={forceRender}\n hidden={false}\n parentIndexPath={\n tabHasName(activeTabConfig)\n ? ''\n : `${indexPath ? indexPath + '-' : ''}` + String(activeTabInfo.index)\n }\n parentPath={activePathChildrenPath}\n parentSchemaPath={activePathSchemaChildrenPath}\n path={activeTabPath}\n permissions={\n permissions && typeof permissions === 'object' && 'name' in activeTabConfig\n ? permissions[activeTabConfig.name] &&\n typeof permissions[activeTabConfig.name] === 'object' &&\n 'fields' in permissions[activeTabConfig.name]\n ? permissions[activeTabConfig.name].fields\n : permissions[activeTabConfig.name]\n : permissions\n }\n readOnly={readOnly}\n />\n )}\n </div>\n </TabsProvider>\n </div>\n )\n}\n\nexport const TabsField = withCondition(TabsFieldComponent)\n\ntype ActiveTabProps = {\n readonly description: StaticDescription\n readonly fields: ClientField[]\n readonly hidden: boolean\n readonly label?: string\n readonly parentIndexPath: string\n readonly parentPath: string\n readonly parentSchemaPath: string\n readonly path: string\n readonly permissions: SanitizedFieldPermissions\n readonly readOnly: boolean\n} & Pick<ClientComponentProps, 'forceRender'>\n\nfunction TabContent({\n description,\n fields,\n forceRender,\n hidden,\n label,\n parentIndexPath,\n parentPath,\n parentSchemaPath,\n permissions,\n readOnly,\n}: ActiveTabProps) {\n const { i18n } = useTranslation()\n\n const { customComponents: { AfterInput, BeforeInput, Description, Field } = {}, path } =\n useField()\n\n if (Field) {\n return Field\n }\n\n return (\n <div\n className={[\n hidden && `${baseClass}__tab--hidden`,\n `${baseClass}__tab`,\n label && `${baseClass}__tabConfigLabel-${toKebabCase(getTranslation(label, i18n))}`,\n ]\n .filter(Boolean)\n .join(' ')}\n >\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={\n <FieldDescription description={description} marginPlacement=\"bottom\" path={path} />\n }\n />\n {BeforeInput}\n <RenderFields\n fields={fields}\n forceRender={forceRender}\n parentIndexPath={parentIndexPath}\n parentPath={parentPath}\n parentSchemaPath={parentSchemaPath}\n permissions={permissions}\n readOnly={readOnly}\n />\n {AfterInput}\n </div>\n )\n}\n"],"names":["getTranslation","tabHasName","toKebabCase","React","useCallback","useEffect","useState","useCollapsible","RenderCustomComponent","useFormFields","RenderFields","useField","withCondition","useDocumentInfo","usePreferences","useTranslation","FieldDescription","fieldBaseClass","TabsProvider","TabComponent","baseClass","generateTabPath","activeTabConfig","path","tabPath","name","TabsFieldComponent","props","field","admin","className","tabs","forceRender","indexPath","parentPath","parentSchemaPath","permissions","readOnly","getPreference","setPreference","preferencesKey","i18n","isWithinCollapsible","tabStates","fields","map","tab","index","id","passesCondition","activeTabIndex","setActiveTabIndex","filter","tabsPrefKey","activeTabPath","setActiveTabPath","activeTabSchemaPath","setActiveTabSchemaPath","activePathChildrenPath","activeTabInfo","activePathSchemaChildrenPath","activeTabDescription","description","activeTabStaticDescription","t","hasVisibleTabs","some","handleTabChange","incomingTabIndex","existingPreferences","tabIndex","getInitialPref","initialIndex","newIndex","nextTab","find","div","Boolean","join","hidden","isActive","setIsActive","TabContent","parentIndexPath","String","TabsField","label","customComponents","AfterInput","BeforeInput","Description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iBA;gBACjBjD,YAAYA;gBACZC,kBAAkBA;gBAClBC,aAAaA;gBACbC,UAAUA;;;;;;YAEXmD;;;;;;;AAGP"}
|
|
1
|
+
{"version":3,"sources":["../../../src/fields/Tabs/index.tsx"],"sourcesContent":["'use client'\nimport type {\n ClientComponentProps,\n ClientTab,\n DocumentPreferences,\n SanitizedFieldPermissions,\n StaticDescription,\n TabsFieldClientComponent,\n} from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { getFieldPaths, toKebabCase } from 'payload/shared'\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport { useCollapsible } from '../../elements/Collapsible/provider.js'\nimport { RenderCustomComponent } from '../../elements/RenderCustomComponent/index.js'\nimport { useFormFields } from '../../forms/Form/index.js'\nimport { RenderFields } from '../../forms/RenderFields/index.js'\nimport { useField } from '../../forms/useField/index.js'\nimport { withCondition } from '../../forms/withCondition/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { usePreferences } from '../../providers/Preferences/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { FieldDescription } from '../FieldDescription/index.js'\nimport { fieldBaseClass } from '../shared/index.js'\nimport { TabsProvider } from './provider.js'\nimport { TabComponent } from './Tab/index.js'\nimport './index.scss'\n\nconst baseClass = 'tabs-field'\n\nexport { TabsProvider }\n\nconst TabsFieldComponent: TabsFieldClientComponent = (props) => {\n const {\n field: { admin: { className } = {}, tabs = [] },\n forceRender = false,\n indexPath = '',\n parentPath = '',\n parentSchemaPath = '',\n path = '',\n permissions,\n readOnly,\n schemaPath = '',\n } = props\n\n const { getPreference, setPreference } = usePreferences()\n const { preferencesKey } = useDocumentInfo()\n const { i18n } = useTranslation()\n const { isWithinCollapsible } = useCollapsible()\n\n const tabStates = useFormFields(([fields]) => {\n return tabs.map((tab, index) => {\n const id = tab?.id\n\n return {\n index,\n passesCondition: fields?.[id]?.passesCondition ?? true,\n tab,\n }\n })\n })\n\n const [activeTabIndex, setActiveTabIndex] = useState<number>(\n () => tabStates.filter(({ passesCondition }) => passesCondition)?.[0]?.index ?? 0,\n )\n\n const tabsPrefKey = `tabs-${indexPath}`\n\n const activeTabInfo = tabStates[activeTabIndex]\n const activeTabConfig = activeTabInfo?.tab\n const activeTabDescription = activeTabConfig.admin?.description ?? activeTabConfig.description\n\n const activeTabStaticDescription =\n typeof activeTabDescription === 'function'\n ? activeTabDescription({ i18n, t: i18n.t })\n : activeTabDescription\n\n const hasVisibleTabs = tabStates.some(({ passesCondition }) => passesCondition)\n\n const handleTabChange = useCallback(\n async (incomingTabIndex: number): Promise<void> => {\n setActiveTabIndex(incomingTabIndex)\n\n const existingPreferences: DocumentPreferences = await getPreference(preferencesKey)\n\n if (preferencesKey) {\n void setPreference(preferencesKey, {\n ...existingPreferences,\n ...(path\n ? {\n fields: {\n ...(existingPreferences?.fields || {}),\n [path]: {\n ...existingPreferences?.fields?.[path],\n tabIndex: incomingTabIndex,\n },\n },\n }\n : {\n fields: {\n ...existingPreferences?.fields,\n [tabsPrefKey]: {\n ...existingPreferences?.fields?.[tabsPrefKey],\n tabIndex: incomingTabIndex,\n },\n },\n }),\n })\n }\n },\n [getPreference, preferencesKey, setPreference, path, tabsPrefKey],\n )\n\n useEffect(() => {\n if (preferencesKey) {\n const getInitialPref = async () => {\n const existingPreferences: DocumentPreferences = await getPreference(preferencesKey)\n const initialIndex = path\n ? existingPreferences?.fields?.[path]?.tabIndex\n : existingPreferences?.fields?.[tabsPrefKey]?.tabIndex\n\n const newIndex = initialIndex || 0\n setActiveTabIndex(newIndex)\n }\n void getInitialPref()\n }\n }, [path, getPreference, preferencesKey, tabsPrefKey, tabs, parentPath, parentSchemaPath])\n\n useEffect(() => {\n if (activeTabInfo?.passesCondition === false) {\n const nextTab = tabStates.find(({ passesCondition }) => passesCondition)\n if (nextTab) {\n void handleTabChange(nextTab.index)\n }\n }\n }, [activeTabInfo, tabStates, handleTabChange])\n\n return (\n <div\n className={[\n fieldBaseClass,\n className,\n baseClass,\n isWithinCollapsible && `${baseClass}--within-collapsible`,\n !hasVisibleTabs && `${baseClass}--hidden`,\n ]\n .filter(Boolean)\n .join(' ')}\n >\n <TabsProvider>\n <div className={`${baseClass}__tabs-wrap`}>\n <div className={`${baseClass}__tabs`}>\n {tabStates.map(({ index, passesCondition, tab }) => (\n <TabComponent\n hidden={!passesCondition}\n isActive={activeTabIndex === index}\n key={index}\n parentPath={path}\n setIsActive={() => {\n void handleTabChange(index)\n }}\n tab={tab}\n />\n ))}\n </div>\n </div>\n <div className={`${baseClass}__content-wrap`}>\n {activeTabConfig && (\n <TabContent\n description={activeTabStaticDescription}\n field={activeTabConfig}\n forceRender={forceRender}\n hidden={false}\n parentIndexPath={indexPath}\n parentPath={path}\n parentSchemaPath={schemaPath}\n path={path}\n permissions={\n permissions && typeof permissions === 'object' && 'name' in activeTabConfig\n ? permissions[activeTabConfig.name] &&\n typeof permissions[activeTabConfig.name] === 'object' &&\n 'fields' in permissions[activeTabConfig.name]\n ? permissions[activeTabConfig.name].fields\n : permissions[activeTabConfig.name]\n : permissions\n }\n readOnly={readOnly}\n tabIndex={activeTabIndex}\n />\n )}\n </div>\n </TabsProvider>\n </div>\n )\n}\n\nexport const TabsField = withCondition(TabsFieldComponent)\n\ntype ActiveTabProps = {\n readonly description: StaticDescription\n readonly field: ClientTab\n readonly hidden: boolean\n readonly label?: string\n readonly parentIndexPath: string\n readonly parentPath: string\n readonly parentSchemaPath: string\n readonly path: string\n readonly permissions: SanitizedFieldPermissions\n readonly readOnly: boolean\n readonly tabIndex: number\n} & Pick<ClientComponentProps, 'forceRender'>\n\nfunction TabContent({\n description,\n field,\n forceRender,\n hidden,\n label,\n parentIndexPath,\n parentPath,\n parentSchemaPath,\n permissions,\n readOnly,\n tabIndex,\n}: ActiveTabProps) {\n const { i18n } = useTranslation()\n\n const { customComponents: { AfterInput, BeforeInput, Description, Field } = {} } = useField()\n\n if (Field) {\n return Field\n }\n\n const { indexPath, path, schemaPath } = getFieldPaths({\n field,\n index: tabIndex,\n parentIndexPath,\n parentPath,\n parentSchemaPath,\n })\n\n return (\n <div\n className={[\n hidden && `${baseClass}__tab--hidden`,\n `${baseClass}__tab`,\n label && `${baseClass}__tabConfigLabel-${toKebabCase(getTranslation(label, i18n))}`,\n ]\n .filter(Boolean)\n .join(' ')}\n >\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={\n <FieldDescription description={description} marginPlacement=\"bottom\" path={parentPath} />\n }\n />\n {BeforeInput}\n <RenderFields\n fields={field.fields}\n forceRender={forceRender}\n parentIndexPath={indexPath}\n parentPath={path}\n parentSchemaPath={schemaPath}\n permissions={permissions}\n readOnly={readOnly}\n />\n {AfterInput}\n </div>\n )\n}\n"],"names":["getTranslation","getFieldPaths","toKebabCase","React","useCallback","useEffect","useState","useCollapsible","RenderCustomComponent","useFormFields","RenderFields","useField","withCondition","useDocumentInfo","usePreferences","useTranslation","FieldDescription","fieldBaseClass","TabsProvider","TabComponent","baseClass","TabsFieldComponent","props","field","admin","className","tabs","forceRender","indexPath","parentPath","parentSchemaPath","path","permissions","readOnly","schemaPath","getPreference","setPreference","preferencesKey","i18n","isWithinCollapsible","tabStates","fields","map","tab","index","id","passesCondition","activeTabIndex","setActiveTabIndex","filter","tabsPrefKey","activeTabInfo","activeTabConfig","activeTabDescription","description","activeTabStaticDescription","t","hasVisibleTabs","some","handleTabChange","incomingTabIndex","existingPreferences","tabIndex","getInitialPref","initialIndex","newIndex","nextTab","find","div","Boolean","join","hidden","isActive","setIsActive","TabContent","parentIndexPath","name","TabsField","label","customComponents","AfterInput","BeforeInput","Description","Field","CustomComponent","Fallback","marginPlacement"],"mappings":"AAAA;;AAUA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,SAASC,aAAa,EAAEC,WAAW,QAAQ,iBAAgB;AAC3D,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAE/D,SAASC,cAAc,QAAQ,yCAAwC;AACvE,SAASC,qBAAqB,QAAQ,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aA;gBACbgD,iBAAiB/C;gBACjBC,YAAYE;gBACZD,kBAAkBI;gBAClBF,aAAaA;gBACbC,UAAUA;;;;;;YAEX+C;;;;;;;AAGP"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BuildFormStateArgs, ClientFieldSchemaMap, Data, DocumentPreferences, Field, FieldSchemaMap, FormState, FormStateWithoutComponents, PayloadRequest, SanitizedFieldsPermissions, SelectMode, SelectType } from 'payload';
|
|
1
|
+
import type { BuildFormStateArgs, ClientFieldSchemaMap, Data, DocumentPreferences, Field, FieldSchemaMap, FormState, FormStateWithoutComponents, PayloadRequest, SanitizedFieldsPermissions, SelectMode, SelectType, TabAsField } from 'payload';
|
|
2
2
|
import type { RenderFieldMethod } from './types.js';
|
|
3
3
|
export type AddFieldStatePromiseArgs = {
|
|
4
4
|
addErrorPathToParent: (fieldPath: string) => void;
|
|
@@ -13,7 +13,7 @@ export type AddFieldStatePromiseArgs = {
|
|
|
13
13
|
clientFieldSchemaMap?: ClientFieldSchemaMap;
|
|
14
14
|
collectionSlug?: string;
|
|
15
15
|
data: Data;
|
|
16
|
-
field: Field;
|
|
16
|
+
field: Field | TabAsField;
|
|
17
17
|
fieldIndex: number;
|
|
18
18
|
fieldSchemaMap: FieldSchemaMap;
|
|
19
19
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addFieldStatePromise.d.ts","sourceRoot":"","sources":["../../../src/forms/fieldSchemasToFormState/addFieldStatePromise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,IAAI,EACJ,mBAAmB,EACnB,KAAK,EACL,cAAc,EAGd,SAAS,EACT,0BAA0B,EAC1B,cAAc,EAGd,0BAA0B,EAC1B,UAAU,EACV,UAAU,
|
|
1
|
+
{"version":3,"file":"addFieldStatePromise.d.ts","sourceRoot":"","sources":["../../../src/forms/fieldSchemasToFormState/addFieldStatePromise.ts"],"names":[],"mappings":"AAAA,OA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B,eAAe,EAAE,OAAO,CAAA;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,mBAAmB,CAAA;IAChC,iBAAiB,EAAE,SAAS,CAAA;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,eAAe,EAAE,OAAO,CAAA;IACxB,aAAa,EAAE,iBAAiB,CAAA;IAChC;;;OAGG;IACH,GAAG,EAAE,cAAc,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,KAAK,EAAE,0BAA0B,CAAA;CAClC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,SAAgB,wBAAwB,KAAG,OAAO,CAAC,IAAI,CA25BvF,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ObjectIdImport from 'bson-objectid';
|
|
2
2
|
import { getBlockSelect, stripUnselectedFields, validateBlocksFilterOptions } from 'payload';
|
|
3
|
-
import { deepCopyObjectSimple, fieldAffectsData, fieldHasSubFields, fieldIsHiddenOrDisabled, fieldIsID, fieldIsLocalized,
|
|
3
|
+
import { deepCopyObjectSimple, fieldAffectsData, fieldHasSubFields, fieldIsHiddenOrDisabled, fieldIsID, fieldIsLocalized, tabHasName } from 'payload/shared';
|
|
4
4
|
import { resolveFilterOptions } from '../../utilities/resolveFilterOptions.js';
|
|
5
5
|
import { isRowCollapsed } from './isRowCollapsed.js';
|
|
6
6
|
import { iterateFields } from './iterateFields.js';
|
|
@@ -54,7 +54,7 @@ const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectId
|
|
|
54
54
|
if (includeSchema) {
|
|
55
55
|
fieldState.fieldSchema = field;
|
|
56
56
|
}
|
|
57
|
-
if (fieldAffectsData(field) && !fieldIsHiddenOrDisabled(field)) {
|
|
57
|
+
if (fieldAffectsData(field) && !fieldIsHiddenOrDisabled(field) && field.type !== 'tab') {
|
|
58
58
|
fieldPermissions = parentPermissions === true ? parentPermissions : deepCopyObjectSimple(parentPermissions?.[field.name]);
|
|
59
59
|
let hasPermission = fieldPermissions === true || deepCopyObjectSimple(fieldPermissions?.read);
|
|
60
60
|
if (typeof field?.access?.read === 'function') {
|
|
@@ -71,7 +71,7 @@ const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectId
|
|
|
71
71
|
if (!hasPermission) {
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
|
-
const validate = field.validate;
|
|
74
|
+
const validate = 'validate' in field ? field.validate : undefined;
|
|
75
75
|
let validationResult = true;
|
|
76
76
|
if (typeof validate === 'function' && !skipValidation && passesCondition) {
|
|
77
77
|
let jsonError;
|
|
@@ -133,11 +133,11 @@ const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectId
|
|
|
133
133
|
{
|
|
134
134
|
const arrayValue = Array.isArray(data[field.name]) ? data[field.name] : [];
|
|
135
135
|
const arraySelect = select?.[field.name];
|
|
136
|
-
const { promises, rows } = arrayValue.reduce((acc, row,
|
|
137
|
-
const
|
|
136
|
+
const { promises, rows } = arrayValue.reduce((acc, row, rowIndex)=>{
|
|
137
|
+
const rowPath = path + '.' + rowIndex;
|
|
138
138
|
row.id = row?.id || new ObjectId().toHexString();
|
|
139
139
|
if (!omitParents && (!filter || filter(args))) {
|
|
140
|
-
const idKey =
|
|
140
|
+
const idKey = rowPath + '.id';
|
|
141
141
|
state[idKey] = {
|
|
142
142
|
initialValue: row.id,
|
|
143
143
|
value: row.id
|
|
@@ -165,7 +165,7 @@ const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectId
|
|
|
165
165
|
operation,
|
|
166
166
|
parentIndexPath: '',
|
|
167
167
|
parentPassesCondition: passesCondition,
|
|
168
|
-
parentPath,
|
|
168
|
+
parentPath: rowPath,
|
|
169
169
|
parentSchemaPath: schemaPath,
|
|
170
170
|
permissions: fieldPermissions === true ? fieldPermissions : fieldPermissions?.fields || {},
|
|
171
171
|
preferences,
|
|
@@ -257,12 +257,12 @@ const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectId
|
|
|
257
257
|
select: select?.[field.name],
|
|
258
258
|
selectMode
|
|
259
259
|
});
|
|
260
|
-
const
|
|
260
|
+
const rowPath = path + '.' + i;
|
|
261
261
|
if (block) {
|
|
262
262
|
row.id = row?.id || new ObjectId().toHexString();
|
|
263
263
|
if (!omitParents && (!filter || filter(args))) {
|
|
264
264
|
// Handle block `id` field
|
|
265
|
-
const idKey =
|
|
265
|
+
const idKey = rowPath + '.id';
|
|
266
266
|
state[idKey] = {
|
|
267
267
|
initialValue: row.id,
|
|
268
268
|
value: row.id
|
|
@@ -284,7 +284,7 @@ const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectId
|
|
|
284
284
|
state[idKey].fieldSchema = includeSchema ? block.fields.find((blockField)=>fieldIsID(blockField)) : undefined;
|
|
285
285
|
}
|
|
286
286
|
// Handle `blockType` field
|
|
287
|
-
const fieldKey =
|
|
287
|
+
const fieldKey = rowPath + '.blockType';
|
|
288
288
|
state[fieldKey] = {
|
|
289
289
|
initialValue: row.blockType,
|
|
290
290
|
value: row.blockType
|
|
@@ -296,7 +296,7 @@ const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectId
|
|
|
296
296
|
state[fieldKey].fieldSchema = block.fields.find((blockField)=>'name' in blockField && blockField.name === 'blockType');
|
|
297
297
|
}
|
|
298
298
|
// Handle `blockName` field
|
|
299
|
-
const blockNameKey =
|
|
299
|
+
const blockNameKey = rowPath + '.blockName';
|
|
300
300
|
state[blockNameKey] = {};
|
|
301
301
|
if (row.blockName) {
|
|
302
302
|
state[blockNameKey].initialValue = row.blockName;
|
|
@@ -325,7 +325,7 @@ const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectId
|
|
|
325
325
|
operation,
|
|
326
326
|
parentIndexPath: '',
|
|
327
327
|
parentPassesCondition: passesCondition,
|
|
328
|
-
parentPath,
|
|
328
|
+
parentPath: rowPath,
|
|
329
329
|
parentSchemaPath: schemaPath + '.' + block.slug,
|
|
330
330
|
permissions: fieldPermissions === true ? fieldPermissions : parentPermissions?.[field.name]?.blocks?.[block.slug] === true ? true : parentPermissions?.[field.name]?.blocks?.[block.slug]?.fields || {},
|
|
331
331
|
preferences,
|
|
@@ -556,8 +556,8 @@ const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectId
|
|
|
556
556
|
operation,
|
|
557
557
|
parentIndexPath: indexPath,
|
|
558
558
|
parentPassesCondition: passesCondition,
|
|
559
|
-
parentPath,
|
|
560
|
-
parentSchemaPath,
|
|
559
|
+
parentPath: path,
|
|
560
|
+
parentSchemaPath: schemaPath,
|
|
561
561
|
permissions: parentPermissions,
|
|
562
562
|
// TODO: Verify this is correct
|
|
563
563
|
preferences,
|
|
@@ -570,102 +570,128 @@ const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectId
|
|
|
570
570
|
skipValidation,
|
|
571
571
|
state
|
|
572
572
|
});
|
|
573
|
-
} else if (field.type === '
|
|
574
|
-
const
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
573
|
+
} else if (field.type === 'tab') {
|
|
574
|
+
const isNamedTab = tabHasName(field);
|
|
575
|
+
let tabSelect;
|
|
576
|
+
const tabField = {
|
|
577
|
+
...field,
|
|
578
|
+
type: 'tab'
|
|
579
|
+
};
|
|
580
|
+
let childPermissions = undefined;
|
|
581
|
+
if (isNamedTab) {
|
|
582
|
+
const shouldContinue = stripUnselectedFields({
|
|
582
583
|
field: tabField,
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
parentSchemaPath
|
|
584
|
+
select,
|
|
585
|
+
selectMode,
|
|
586
|
+
siblingDoc: data?.[field.name] || {}
|
|
587
587
|
});
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
if (!shouldContinue) {
|
|
597
|
-
return;
|
|
598
|
-
}
|
|
599
|
-
if (parentPermissions === true) {
|
|
588
|
+
if (!shouldContinue) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
if (parentPermissions === true) {
|
|
592
|
+
childPermissions = true;
|
|
593
|
+
} else {
|
|
594
|
+
const tabPermissions = parentPermissions?.[field.name];
|
|
595
|
+
if (tabPermissions === true) {
|
|
600
596
|
childPermissions = true;
|
|
601
597
|
} else {
|
|
602
|
-
|
|
603
|
-
if (tabPermissions === true) {
|
|
604
|
-
childPermissions = true;
|
|
605
|
-
} else {
|
|
606
|
-
childPermissions = tabPermissions?.fields;
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
if (typeof select?.[tab.name] === 'object') {
|
|
610
|
-
tabSelect = select?.[tab.name];
|
|
598
|
+
childPermissions = tabPermissions?.fields;
|
|
611
599
|
}
|
|
612
|
-
} else {
|
|
613
|
-
childPermissions = parentPermissions;
|
|
614
|
-
tabSelect = select;
|
|
615
|
-
}
|
|
616
|
-
const pathSegments = path ? path.split('.') : [];
|
|
617
|
-
// If passesCondition is false then this should always result to false
|
|
618
|
-
// If the tab has no admin.condition provided then fallback to passesCondition and let that decide the result
|
|
619
|
-
let tabPassesCondition = passesCondition;
|
|
620
|
-
if (passesCondition && typeof tab.admin?.condition === 'function') {
|
|
621
|
-
tabPassesCondition = tab.admin.condition(fullData, data, {
|
|
622
|
-
blockData,
|
|
623
|
-
operation,
|
|
624
|
-
path: pathSegments,
|
|
625
|
-
user: req.user
|
|
626
|
-
});
|
|
627
600
|
}
|
|
628
|
-
if (
|
|
629
|
-
|
|
630
|
-
passesCondition: tabPassesCondition
|
|
631
|
-
};
|
|
601
|
+
if (typeof select?.[field.name] === 'object') {
|
|
602
|
+
tabSelect = select?.[field.name];
|
|
632
603
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
604
|
+
} else {
|
|
605
|
+
childPermissions = parentPermissions;
|
|
606
|
+
tabSelect = select;
|
|
607
|
+
}
|
|
608
|
+
const pathSegments = path ? path.split('.') : [];
|
|
609
|
+
// If passesCondition is false then this should always result to false
|
|
610
|
+
// If the tab has no admin.condition provided then fallback to passesCondition and let that decide the result
|
|
611
|
+
let tabPassesCondition = passesCondition;
|
|
612
|
+
if (passesCondition && typeof field.admin?.condition === 'function') {
|
|
613
|
+
tabPassesCondition = field.admin.condition(fullData, data, {
|
|
637
614
|
blockData,
|
|
638
|
-
clientFieldSchemaMap,
|
|
639
|
-
collectionSlug,
|
|
640
|
-
data: isNamedTab ? data?.[tab.name] || {} : data,
|
|
641
|
-
fields: tab.fields,
|
|
642
|
-
fieldSchemaMap,
|
|
643
|
-
filter,
|
|
644
|
-
forceFullValue,
|
|
645
|
-
fullData,
|
|
646
|
-
includeSchema,
|
|
647
|
-
mockRSCs,
|
|
648
|
-
omitParents,
|
|
649
615
|
operation,
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
parentPath: isNamedTab ? tabPath : parentPath,
|
|
653
|
-
parentSchemaPath: isNamedTab ? tabSchemaPath : parentSchemaPath,
|
|
654
|
-
permissions: childPermissions,
|
|
655
|
-
preferences,
|
|
656
|
-
previousFormState,
|
|
657
|
-
readOnly,
|
|
658
|
-
renderAllFields,
|
|
659
|
-
renderFieldFn,
|
|
660
|
-
req,
|
|
661
|
-
select: tabSelect,
|
|
662
|
-
selectMode,
|
|
663
|
-
skipConditionChecks,
|
|
664
|
-
skipValidation,
|
|
665
|
-
state
|
|
616
|
+
path: pathSegments,
|
|
617
|
+
user: req.user
|
|
666
618
|
});
|
|
619
|
+
}
|
|
620
|
+
if (field?.id) {
|
|
621
|
+
state[field.id] = {
|
|
622
|
+
passesCondition: tabPassesCondition
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
return iterateFields({
|
|
626
|
+
id,
|
|
627
|
+
addErrorPathToParent: addErrorPathToParentArg,
|
|
628
|
+
anyParentLocalized: field.localized || anyParentLocalized,
|
|
629
|
+
blockData,
|
|
630
|
+
clientFieldSchemaMap,
|
|
631
|
+
collectionSlug,
|
|
632
|
+
data: isNamedTab ? data?.[field.name] || {} : data,
|
|
633
|
+
fields: field.fields,
|
|
634
|
+
fieldSchemaMap,
|
|
635
|
+
filter,
|
|
636
|
+
forceFullValue,
|
|
637
|
+
fullData,
|
|
638
|
+
includeSchema,
|
|
639
|
+
mockRSCs,
|
|
640
|
+
omitParents,
|
|
641
|
+
operation,
|
|
642
|
+
parentIndexPath: indexPath,
|
|
643
|
+
parentPassesCondition: tabPassesCondition,
|
|
644
|
+
parentPath: path,
|
|
645
|
+
parentSchemaPath: schemaPath,
|
|
646
|
+
permissions: childPermissions,
|
|
647
|
+
preferences,
|
|
648
|
+
previousFormState,
|
|
649
|
+
readOnly,
|
|
650
|
+
renderAllFields,
|
|
651
|
+
renderFieldFn,
|
|
652
|
+
req,
|
|
653
|
+
select: tabSelect,
|
|
654
|
+
selectMode,
|
|
655
|
+
skipConditionChecks,
|
|
656
|
+
skipValidation,
|
|
657
|
+
state
|
|
658
|
+
});
|
|
659
|
+
} else if (field.type === 'tabs') {
|
|
660
|
+
return iterateFields({
|
|
661
|
+
id,
|
|
662
|
+
addErrorPathToParent: addErrorPathToParentArg,
|
|
663
|
+
anyParentLocalized: fieldIsLocalized(field) || anyParentLocalized,
|
|
664
|
+
blockData,
|
|
665
|
+
clientFieldSchemaMap,
|
|
666
|
+
collectionSlug,
|
|
667
|
+
data,
|
|
668
|
+
fields: field.tabs.map((tab)=>({
|
|
669
|
+
...tab,
|
|
670
|
+
type: 'tab'
|
|
671
|
+
})),
|
|
672
|
+
fieldSchemaMap,
|
|
673
|
+
filter,
|
|
674
|
+
forceFullValue,
|
|
675
|
+
fullData,
|
|
676
|
+
includeSchema,
|
|
677
|
+
omitParents,
|
|
678
|
+
operation,
|
|
679
|
+
parentIndexPath: indexPath,
|
|
680
|
+
parentPassesCondition: passesCondition,
|
|
681
|
+
parentPath: path,
|
|
682
|
+
parentSchemaPath: schemaPath,
|
|
683
|
+
permissions: parentPermissions,
|
|
684
|
+
preferences,
|
|
685
|
+
previousFormState,
|
|
686
|
+
renderAllFields,
|
|
687
|
+
renderFieldFn,
|
|
688
|
+
req,
|
|
689
|
+
select,
|
|
690
|
+
selectMode,
|
|
691
|
+
skipConditionChecks,
|
|
692
|
+
skipValidation,
|
|
693
|
+
state
|
|
667
694
|
});
|
|
668
|
-
await Promise.all(promises);
|
|
669
695
|
} else if (field.type === 'ui') {
|
|
670
696
|
if (!filter || filter(args)) {
|
|
671
697
|
state[path] = fieldState;
|