@strapi/content-manager 5.12.5 → 5.13.0-beta.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/admin/hooks/useDocumentActions.js +5 -1
- package/dist/admin/hooks/useDocumentActions.js.map +1 -1
- package/dist/admin/hooks/useDocumentActions.mjs +5 -1
- package/dist/admin/hooks/useDocumentActions.mjs.map +1 -1
- package/dist/admin/hooks/useDocumentContext.js.map +1 -1
- package/dist/admin/hooks/useDocumentContext.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/DocumentActions.js +206 -21
- package/dist/admin/pages/EditView/components/DocumentActions.js.map +1 -1
- package/dist/admin/pages/EditView/components/DocumentActions.mjs +208 -23
- package/dist/admin/pages/EditView/components/DocumentActions.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.js +7 -12
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.mjs +8 -13
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/EditorLayout.js +46 -95
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/EditorLayout.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/EditorLayout.mjs +48 -78
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/EditorLayout.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js +2 -0
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs +2 -0
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.js +199 -137
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.mjs +199 -137
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js +89 -50
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs +91 -52
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.js +50 -97
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.mjs +51 -79
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.mjs.map +1 -1
- package/dist/admin/preview/components/PreviewHeader.js +1 -1
- package/dist/admin/preview/components/PreviewHeader.js.map +1 -1
- package/dist/admin/preview/components/PreviewHeader.mjs +1 -1
- package/dist/admin/preview/components/PreviewHeader.mjs.map +1 -1
- package/dist/admin/services/homepage.js +9 -5
- package/dist/admin/services/homepage.js.map +1 -1
- package/dist/admin/services/homepage.mjs +9 -5
- package/dist/admin/services/homepage.mjs.map +1 -1
- package/dist/admin/src/hooks/useDocumentContext.d.ts +1 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/EditorLayout.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Relations/RelationModal.d.ts +26 -5
- package/dist/admin/translations/en.json.js +2 -1
- package/dist/admin/translations/en.json.js.map +1 -1
- package/dist/admin/translations/en.json.mjs +2 -1
- package/dist/admin/translations/en.json.mjs.map +1 -1
- package/dist/server/controllers/index.js +3 -1
- package/dist/server/controllers/index.js.map +1 -1
- package/dist/server/controllers/index.mjs +3 -1
- package/dist/server/controllers/index.mjs.map +1 -1
- package/dist/server/homepage/controllers/homepage.js +57 -0
- package/dist/server/homepage/controllers/homepage.js.map +1 -0
- package/dist/server/homepage/controllers/homepage.mjs +36 -0
- package/dist/server/homepage/controllers/homepage.mjs.map +1 -0
- package/dist/server/homepage/controllers/index.js +10 -0
- package/dist/server/homepage/controllers/index.js.map +1 -0
- package/dist/server/homepage/controllers/index.mjs +8 -0
- package/dist/server/homepage/controllers/index.mjs.map +1 -0
- package/dist/server/homepage/index.js +14 -0
- package/dist/server/homepage/index.js.map +1 -0
- package/dist/server/homepage/index.mjs +12 -0
- package/dist/server/homepage/index.mjs.map +1 -0
- package/dist/server/homepage/routes/homepage.js +25 -0
- package/dist/server/homepage/routes/homepage.js.map +1 -0
- package/dist/server/homepage/routes/homepage.mjs +23 -0
- package/dist/server/homepage/routes/homepage.mjs.map +1 -0
- package/dist/server/homepage/routes/index.js +13 -0
- package/dist/server/homepage/routes/index.js.map +1 -0
- package/dist/server/homepage/routes/index.mjs +11 -0
- package/dist/server/homepage/routes/index.mjs.map +1 -0
- package/dist/server/homepage/services/homepage.js +157 -0
- package/dist/server/homepage/services/homepage.js.map +1 -0
- package/dist/server/homepage/services/homepage.mjs +155 -0
- package/dist/server/homepage/services/homepage.mjs.map +1 -0
- package/dist/server/homepage/services/index.js +10 -0
- package/dist/server/homepage/services/index.js.map +1 -0
- package/dist/server/homepage/services/index.mjs +8 -0
- package/dist/server/homepage/services/index.mjs.map +1 -0
- package/dist/server/preview/services/preview.js +0 -1
- package/dist/server/preview/services/preview.js.map +1 -1
- package/dist/server/preview/services/preview.mjs +0 -1
- package/dist/server/preview/services/preview.mjs.map +1 -1
- package/dist/server/routes/index.js +3 -1
- package/dist/server/routes/index.js.map +1 -1
- package/dist/server/routes/index.mjs +3 -1
- package/dist/server/routes/index.mjs.map +1 -1
- package/dist/server/services/index.js +3 -1
- package/dist/server/services/index.js.map +1 -1
- package/dist/server/services/index.mjs +3 -1
- package/dist/server/services/index.mjs.map +1 -1
- package/dist/server/src/controllers/index.d.ts.map +1 -1
- package/dist/server/src/homepage/controllers/homepage.d.ts +7 -0
- package/dist/server/src/homepage/controllers/homepage.d.ts.map +1 -0
- package/dist/server/src/homepage/controllers/index.d.ts +2 -0
- package/dist/server/src/homepage/controllers/index.d.ts.map +1 -0
- package/dist/server/src/homepage/index.d.ts +16 -0
- package/dist/server/src/homepage/index.d.ts.map +1 -0
- package/dist/server/src/homepage/routes/homepage.d.ts +4 -0
- package/dist/server/src/homepage/routes/homepage.d.ts.map +1 -0
- package/dist/server/src/homepage/routes/index.d.ts +8 -0
- package/dist/server/src/homepage/routes/index.d.ts.map +1 -0
- package/dist/server/src/{services → homepage/services}/homepage.d.ts +1 -1
- package/dist/server/src/homepage/services/homepage.d.ts.map +1 -0
- package/dist/server/src/homepage/services/index.d.ts +9 -0
- package/dist/server/src/homepage/services/index.d.ts.map +1 -0
- package/dist/server/src/index.d.ts +7 -0
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/preview/services/preview.d.ts.map +1 -1
- package/dist/server/src/routes/index.d.ts +1 -0
- package/dist/server/src/routes/index.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +6 -0
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/package.json +7 -7
- package/dist/server/src/services/homepage.d.ts.map +0 -1
@@ -51,23 +51,37 @@ const StyledModalContent = styledComponents.styled(designSystem.Modal.Content)`
|
|
51
51
|
height: 90%;
|
52
52
|
max-height: 100%;
|
53
53
|
`;
|
54
|
+
const getFullPageUrl = (currentDocumentMeta)=>{
|
55
|
+
const isSingleType = currentDocumentMeta.collectionType === collections.SINGLE_TYPES;
|
56
|
+
const queryParams = currentDocumentMeta.params?.locale ? `?plugins[i18n][locale]=${currentDocumentMeta.params.locale}` : '';
|
57
|
+
return `/content-manager/${currentDocumentMeta.collectionType}/${currentDocumentMeta.model}${isSingleType ? '' : '/' + currentDocumentMeta.documentId}${queryParams}`;
|
58
|
+
};
|
54
59
|
function reducer(state, action) {
|
55
60
|
switch(action.type){
|
56
61
|
case 'GO_TO_RELATION':
|
57
62
|
if (state.hasUnsavedChanges && !action.payload.shouldBypassConfirmation) {
|
58
63
|
return {
|
59
64
|
...state,
|
60
|
-
confirmDialogIntent: action.payload.document
|
65
|
+
confirmDialogIntent: action.payload.document,
|
66
|
+
fieldToConnect: action.payload.fieldToConnect,
|
67
|
+
fieldToConnectUID: action.payload.fieldToConnectUID
|
61
68
|
};
|
62
69
|
}
|
70
|
+
const lastItemDocumentHistory = state.documentHistory.at(-1);
|
71
|
+
const hasToResetDocumentHistory = lastItemDocumentHistory && !lastItemDocumentHistory.documentId;
|
63
72
|
return {
|
64
73
|
...state,
|
65
|
-
|
74
|
+
// Reset document history if the last item has documentId undefined
|
75
|
+
documentHistory: hasToResetDocumentHistory ? [
|
76
|
+
action.payload.document
|
77
|
+
] : [
|
66
78
|
...state.documentHistory,
|
67
79
|
action.payload.document
|
68
80
|
],
|
69
81
|
confirmDialogIntent: null,
|
70
|
-
isModalOpen: true
|
82
|
+
isModalOpen: true,
|
83
|
+
fieldToConnect: hasToResetDocumentHistory ? undefined : action.payload.fieldToConnect,
|
84
|
+
fieldToConnectUID: hasToResetDocumentHistory ? undefined : action.payload.fieldToConnectUID
|
71
85
|
};
|
72
86
|
case 'GO_BACK':
|
73
87
|
if (state.hasUnsavedChanges && !action.payload.shouldBypassConfirmation) {
|
@@ -95,6 +109,21 @@ function reducer(state, action) {
|
|
95
109
|
isModalOpen: false,
|
96
110
|
confirmDialogIntent: null
|
97
111
|
};
|
112
|
+
case 'GO_TO_CREATED_RELATION':
|
113
|
+
return {
|
114
|
+
...state,
|
115
|
+
// Reset document history if the last item has documentId undefined
|
116
|
+
documentHistory: state.documentHistory ? [
|
117
|
+
...state.documentHistory.slice(0, -1),
|
118
|
+
action.payload.document
|
119
|
+
] : [
|
120
|
+
action.payload.document
|
121
|
+
],
|
122
|
+
confirmDialogIntent: null,
|
123
|
+
isModalOpen: true,
|
124
|
+
fieldToConnect: undefined,
|
125
|
+
fieldToConnectUID: undefined
|
126
|
+
};
|
98
127
|
case 'CANCEL_CONFIRM_DIALOG':
|
99
128
|
return {
|
100
129
|
...state,
|
@@ -124,21 +153,17 @@ function reducer(state, action) {
|
|
124
153
|
}
|
125
154
|
}
|
126
155
|
const [RelationModalProvider, useRelationModal] = strapiAdmin.createContext('RelationModal');
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
};
|
132
|
-
/**
|
133
|
-
* Component responsible of rendering its children wrapped in a modal, form and context if needed
|
134
|
-
*/ const RelationModalRenderer = ({ children, trigger, relation })=>{
|
135
|
-
const { formatMessage } = reactIntl.useIntl();
|
136
|
-
const navigate = reactRouterDom.useNavigate();
|
156
|
+
function isRenderProp(children) {
|
157
|
+
return typeof children === 'function';
|
158
|
+
}
|
159
|
+
const RootRelationRenderer = (props)=>{
|
160
|
+
const { children } = props;
|
137
161
|
const [state, dispatch] = React__namespace.useReducer(reducer, {
|
138
162
|
documentHistory: [],
|
139
163
|
confirmDialogIntent: null,
|
140
164
|
isModalOpen: false,
|
141
|
-
hasUnsavedChanges: false
|
165
|
+
hasUnsavedChanges: false,
|
166
|
+
fieldToConnect: undefined
|
142
167
|
});
|
143
168
|
const rootDocument = useDocument.useDoc();
|
144
169
|
const [{ query }] = strapiAdmin.useQueryParams();
|
@@ -153,11 +178,9 @@ const getFullPageUrl = (currentDocumentMeta)=>{
|
|
153
178
|
};
|
154
179
|
const currentDocumentMeta = state.documentHistory.at(-1) ?? rootDocumentMeta;
|
155
180
|
const currentDocument = useDocument.useDocument(currentDocumentMeta);
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
return trigger;
|
160
|
-
}
|
181
|
+
// TODO: check if we can remove the single type check
|
182
|
+
const isSingleType = currentDocumentMeta.collectionType === collections.SINGLE_TYPES;
|
183
|
+
const isCreating = !currentDocumentMeta.documentId && !isSingleType;
|
161
184
|
/**
|
162
185
|
* There is no parent relation, so the relation modal doesn't exist. Create it and set up all the
|
163
186
|
* pieces that will be used by potential child relations: the context, header, form, and footer.
|
@@ -167,113 +190,156 @@ const getFullPageUrl = (currentDocumentMeta)=>{
|
|
167
190
|
rootDocumentMeta: rootDocumentMeta,
|
168
191
|
currentDocumentMeta: currentDocumentMeta,
|
169
192
|
currentDocument: currentDocument,
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
193
|
+
isCreating: isCreating,
|
194
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(RelationModal, {
|
195
|
+
children: isRenderProp(children) ? children({
|
196
|
+
dispatch
|
197
|
+
}) : props.relation && /*#__PURE__*/ jsxRuntime.jsx(RelationModalTrigger, {
|
198
|
+
relation: props.relation,
|
199
|
+
children: children
|
200
|
+
})
|
201
|
+
})
|
202
|
+
});
|
203
|
+
};
|
204
|
+
const NestedRelationRenderer = (props)=>{
|
205
|
+
const { children } = props;
|
206
|
+
const dispatch = useRelationModal('NestedRelation', (state)=>state.dispatch);
|
207
|
+
return isRenderProp(children) ? children({
|
208
|
+
dispatch
|
209
|
+
}) : props.relation && /*#__PURE__*/ jsxRuntime.jsx(RelationModalTrigger, {
|
210
|
+
relation: props.relation,
|
211
|
+
children: children
|
212
|
+
}); /* This is the trigger that will be rendered in the parent relation */
|
213
|
+
};
|
214
|
+
/**
|
215
|
+
* Component responsible for rendering its children wrapped in a modal, form and context if needed
|
216
|
+
*/ const RelationModalRenderer = (props)=>{
|
217
|
+
// We're in a nested relation if the relation modal context is not undefined
|
218
|
+
const isNested = useRelationModal('RelationContextWrapper', (state)=>state != undefined, false);
|
219
|
+
return isNested ? /*#__PURE__*/ jsxRuntime.jsx(NestedRelationRenderer, {
|
220
|
+
...props
|
221
|
+
}) : /*#__PURE__*/ jsxRuntime.jsx(RootRelationRenderer, {
|
222
|
+
...props
|
223
|
+
});
|
224
|
+
};
|
225
|
+
/* -------------------------------------------------------------------------------------------------
|
226
|
+
* RelationModal
|
227
|
+
* -----------------------------------------------------------------------------------------------*/ const generateCreateUrl = (currentDocumentMeta)=>{
|
228
|
+
return `/content-manager/${currentDocumentMeta.collectionType}/${currentDocumentMeta.model}/create${currentDocumentMeta.params?.locale ? `?plugins[i18n][locale]=${currentDocumentMeta.params.locale}` : ''}`;
|
229
|
+
};
|
230
|
+
const RelationModal = ({ children })=>{
|
231
|
+
const { formatMessage } = reactIntl.useIntl();
|
232
|
+
const navigate = reactRouterDom.useNavigate();
|
233
|
+
const state = useRelationModal('RelationModalForm', (state)=>state.state);
|
234
|
+
const dispatch = useRelationModal('RelationModalForm', (state)=>state.dispatch);
|
235
|
+
const currentDocumentMeta = useRelationModal('RelationModalForm', (state)=>state.currentDocumentMeta);
|
236
|
+
const currentDocument = useRelationModal('RelationModalForm', (state)=>state.currentDocument);
|
237
|
+
const isCreating = useRelationModal('RelationModalForm', (state)=>state.isCreating);
|
238
|
+
return /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Modal.Root, {
|
239
|
+
open: state.isModalOpen,
|
240
|
+
onOpenChange: (open)=>{
|
241
|
+
if (!open) {
|
242
|
+
dispatch({
|
243
|
+
type: 'CLOSE_MODAL',
|
244
|
+
payload: {
|
245
|
+
shouldBypassConfirmation: false
|
246
|
+
}
|
247
|
+
});
|
248
|
+
}
|
249
|
+
},
|
250
|
+
children: [
|
251
|
+
children,
|
252
|
+
/*#__PURE__*/ jsxRuntime.jsxs(StyledModalContent, {
|
253
|
+
children: [
|
254
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Modal.Header, {
|
255
|
+
gap: 2,
|
256
|
+
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
|
257
|
+
justifyContent: "space-between",
|
258
|
+
alignItems: "center",
|
259
|
+
width: "100%",
|
260
|
+
children: [
|
261
|
+
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
|
262
|
+
gap: 2,
|
263
|
+
children: [
|
264
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.IconButton, {
|
265
|
+
withTooltip: false,
|
266
|
+
label: formatMessage({
|
267
|
+
id: 'global.back',
|
268
|
+
defaultMessage: 'Back'
|
222
269
|
}),
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
270
|
+
variant: "ghost",
|
271
|
+
disabled: state.documentHistory.length < 2,
|
272
|
+
onClick: ()=>{
|
273
|
+
dispatch({
|
274
|
+
type: 'GO_BACK',
|
275
|
+
payload: {
|
276
|
+
shouldBypassConfirmation: false
|
277
|
+
}
|
278
|
+
});
|
279
|
+
},
|
280
|
+
marginRight: 1,
|
281
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(Icons.ArrowLeft, {})
|
282
|
+
}),
|
283
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
|
284
|
+
tag: "span",
|
285
|
+
fontWeight: 600,
|
286
|
+
children: isCreating ? formatMessage({
|
287
|
+
id: 'content-manager.relation.create',
|
288
|
+
defaultMessage: 'Create a relation'
|
289
|
+
}) : formatMessage({
|
290
|
+
id: 'content-manager.components.RelationInputModal.modal-title',
|
291
|
+
defaultMessage: 'Edit a relation'
|
230
292
|
})
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
293
|
+
})
|
294
|
+
]
|
295
|
+
}),
|
296
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.IconButton, {
|
297
|
+
onClick: ()=>{
|
298
|
+
dispatch({
|
299
|
+
type: 'GO_FULL_PAGE'
|
300
|
+
});
|
301
|
+
if (!state.hasUnsavedChanges) {
|
302
|
+
if (isCreating) {
|
303
|
+
navigate(generateCreateUrl(currentDocumentMeta));
|
304
|
+
} else {
|
239
305
|
navigate(getFullPageUrl(currentDocumentMeta));
|
240
306
|
}
|
241
|
-
}
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
})
|
249
|
-
|
250
|
-
|
251
|
-
}),
|
252
|
-
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Modal.Body, {
|
253
|
-
children: /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Form, {
|
254
|
-
method: "PUT",
|
255
|
-
initialValues: currentDocument.getInitialFormValues(),
|
256
|
-
validate: (values, options)=>{
|
257
|
-
const yupSchema = validation.createYupSchema(currentDocument.schema?.attributes, currentDocument.components, {
|
258
|
-
status: currentDocument.document?.status,
|
259
|
-
...options
|
260
|
-
});
|
261
|
-
return yupSchema.validate(values, {
|
262
|
-
abortEarly: false
|
263
|
-
});
|
264
|
-
},
|
265
|
-
children: children
|
266
|
-
})
|
307
|
+
}
|
308
|
+
},
|
309
|
+
variant: "tertiary",
|
310
|
+
label: formatMessage({
|
311
|
+
id: 'content-manager.components.RelationInputModal.button-fullpage',
|
312
|
+
defaultMessage: 'Go to entry'
|
313
|
+
}),
|
314
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(Icons.ArrowsOut, {})
|
315
|
+
})
|
316
|
+
]
|
267
317
|
})
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
318
|
+
}),
|
319
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Modal.Body, {
|
320
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Form, {
|
321
|
+
method: isCreating ? 'POST' : 'PUT',
|
322
|
+
initialValues: currentDocument.getInitialFormValues(isCreating),
|
323
|
+
validate: (values, options)=>{
|
324
|
+
const yupSchema = validation.createYupSchema(currentDocument.schema?.attributes, currentDocument.components, {
|
325
|
+
status: currentDocument.document?.status,
|
326
|
+
...options
|
327
|
+
});
|
328
|
+
return yupSchema.validate(values, {
|
329
|
+
abortEarly: false
|
330
|
+
});
|
331
|
+
},
|
332
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(RelationModalBody, {})
|
333
|
+
})
|
334
|
+
})
|
335
|
+
]
|
336
|
+
})
|
337
|
+
]
|
272
338
|
});
|
273
339
|
};
|
274
340
|
/**
|
275
341
|
* All the main content (not header and footer) of the relation modal, plus the confirmation dialog.
|
276
|
-
* Will be wrapped in a Modal.Body by the
|
342
|
+
* Will be wrapped in a Modal.Body by the RelationModal component.
|
277
343
|
* Cannot be moved directly inside RelationModal because it needs access to the context via hooks.
|
278
344
|
*/ const RelationModalBody = ()=>{
|
279
345
|
const navigate = reactRouterDom.useNavigate();
|
@@ -284,6 +350,7 @@ const getFullPageUrl = (currentDocumentMeta)=>{
|
|
284
350
|
const dispatch = useRelationModal('RelationModalForm', (state)=>state.dispatch);
|
285
351
|
const rootDocumentMeta = useRelationModal('RelationModalForm', (state)=>state.rootDocumentMeta);
|
286
352
|
const currentDocumentMeta = useRelationModal('RelationModalForm', (state)=>state.currentDocumentMeta);
|
353
|
+
const isCreating = useRelationModal('RelationModalForm', (state)=>state.isCreating);
|
287
354
|
/**
|
288
355
|
* One-way sync the modified state from the form to the modal state.
|
289
356
|
* It is needed because we need to consume state from the form context in order to lift it up
|
@@ -325,7 +392,11 @@ const getFullPageUrl = (currentDocumentMeta)=>{
|
|
325
392
|
if (isRootDocumentUrl) {
|
326
393
|
handleCloseModal(true);
|
327
394
|
} else {
|
328
|
-
|
395
|
+
if (isCreating) {
|
396
|
+
navigate(generateCreateUrl(currentDocumentMeta));
|
397
|
+
} else {
|
398
|
+
navigate(fullPageUrl);
|
399
|
+
}
|
329
400
|
}
|
330
401
|
};
|
331
402
|
const handleConfirm = ()=>{
|
@@ -355,7 +426,7 @@ const getFullPageUrl = (currentDocumentMeta)=>{
|
|
355
426
|
};
|
356
427
|
return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
357
428
|
children: [
|
358
|
-
/*#__PURE__*/ jsxRuntime.jsx(
|
429
|
+
/*#__PURE__*/ jsxRuntime.jsx(RelationModalForm, {}),
|
359
430
|
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Root, {
|
360
431
|
open: state.confirmDialogIntent != null,
|
361
432
|
children: /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.ConfirmDialog, {
|
@@ -373,7 +444,7 @@ const getFullPageUrl = (currentDocumentMeta)=>{
|
|
373
444
|
]
|
374
445
|
});
|
375
446
|
};
|
376
|
-
const
|
447
|
+
const RelationModalTrigger = ({ children, relation })=>{
|
377
448
|
const dispatch = useRelationModal('ModalTrigger', (state)=>state.dispatch);
|
378
449
|
return /*#__PURE__*/ jsxRuntime.jsx(StyledTextButton, {
|
379
450
|
onClick: ()=>{
|
@@ -388,16 +459,6 @@ const ModalTrigger = ({ children, relation })=>{
|
|
388
459
|
children: children
|
389
460
|
});
|
390
461
|
};
|
391
|
-
const RelationModal = /*#__PURE__*/ React__namespace.memo(({ relation, children })=>{
|
392
|
-
return /*#__PURE__*/ jsxRuntime.jsx(RelationModalRenderer, {
|
393
|
-
relation: relation,
|
394
|
-
trigger: /*#__PURE__*/ jsxRuntime.jsx(ModalTrigger, {
|
395
|
-
relation: relation,
|
396
|
-
children: children
|
397
|
-
}),
|
398
|
-
children: /*#__PURE__*/ jsxRuntime.jsx(RelationModalBody, {})
|
399
|
-
});
|
400
|
-
});
|
401
462
|
const StyledTextButton = styledComponents.styled(designSystem.TextButton)`
|
402
463
|
max-width: 100%;
|
403
464
|
& > span {
|
@@ -411,13 +472,14 @@ const StyledTextButton = styledComponents.styled(designSystem.TextButton)`
|
|
411
472
|
/**
|
412
473
|
* The mini edit view for a relation that is displayed inside a modal.
|
413
474
|
* It's complete with its header, document actions and form layout.
|
414
|
-
*/ const
|
475
|
+
*/ const RelationModalForm = ()=>{
|
415
476
|
const { formatMessage } = reactIntl.useIntl();
|
416
|
-
const currentDocumentMeta = useRelationModal('
|
417
|
-
const
|
477
|
+
const currentDocumentMeta = useRelationModal('RelationModalForm', (state)=>state.currentDocumentMeta);
|
478
|
+
const isCreating = useRelationModal('RelationModalForm', (state)=>state.isCreating);
|
479
|
+
const currentDocument = useRelationModal('RelationModalForm', (state)=>state.currentDocument);
|
418
480
|
const documentLayoutResponse = useDocumentLayout.useDocumentLayout(currentDocumentMeta.model);
|
419
|
-
const plugins = strapiAdmin.useStrapiApp('
|
420
|
-
const initialValues = currentDocument.getInitialFormValues();
|
481
|
+
const plugins = strapiAdmin.useStrapiApp('RelationModalForm', (state)=>state.plugins);
|
482
|
+
const initialValues = isCreating ? currentDocument.getInitialFormValues(isCreating) : currentDocument.getInitialFormValues();
|
421
483
|
const { permissions = [], isLoading: isLoadingPermissions, error } = strapiAdmin.useRBAC(plugin.PERMISSIONS.map((action)=>({
|
422
484
|
action,
|
423
485
|
subject: currentDocumentMeta.model
|
@@ -432,7 +494,7 @@ const StyledTextButton = styledComponents.styled(designSystem.TextButton)`
|
|
432
494
|
})
|
433
495
|
});
|
434
496
|
}
|
435
|
-
if (error || !currentDocumentMeta.model || documentLayoutResponse.error || !currentDocument.document || !currentDocument.meta || !currentDocument.schema || !initialValues) {
|
497
|
+
if (error || !currentDocumentMeta.model || documentLayoutResponse.error || !isCreating && !currentDocument.document || !isCreating && !currentDocument.meta || !currentDocument.schema || !initialValues) {
|
436
498
|
return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Flex, {
|
437
499
|
alignItems: "center",
|
438
500
|
height: "100%",
|
@@ -541,7 +603,7 @@ const StyledTextButton = styledComponents.styled(designSystem.TextButton)`
|
|
541
603
|
});
|
542
604
|
};
|
543
605
|
|
544
|
-
exports.
|
606
|
+
exports.RelationModalRenderer = RelationModalRenderer;
|
545
607
|
exports.getCollectionType = getCollectionType;
|
546
608
|
exports.reducer = reducer;
|
547
609
|
exports.useRelationModal = useRelationModal;
|