@strapi/admin 4.0.0-beta.16 → 4.0.0-beta.17
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/admin/src/content-manager/components/DragLayer/index.js +3 -1
- package/admin/src/content-manager/components/EditViewDataManagerProvider/utils/schema.js +19 -19
- package/admin/src/content-manager/components/Inputs/index.js +10 -4
- package/admin/src/content-manager/pages/EditSettingsView/components/DisplayedFieldButton.js +393 -0
- package/admin/src/content-manager/pages/EditSettingsView/components/DisplayedFields.js +7 -36
- package/admin/src/content-manager/pages/EditSettingsView/components/FieldButtonContent.js +84 -0
- package/admin/src/content-manager/pages/EditSettingsView/components/RelationalFieldButton.js +135 -0
- package/admin/src/content-manager/pages/EditSettingsView/components/RelationalFields.js +9 -7
- package/admin/src/content-manager/pages/EditSettingsView/components/RowItemsLayout.js +39 -0
- package/admin/src/content-manager/pages/EditSettingsView/components/RowsLayout.js +32 -0
- package/admin/src/content-manager/pages/EditSettingsView/index.js +51 -0
- package/build/5881.deb18c91.chunk.js +2 -0
- package/build/5881.deb18c91.chunk.js.LICENSE.txt +4 -0
- package/build/9138.86a2c5ad.chunk.js +2 -0
- package/build/9138.86a2c5ad.chunk.js.LICENSE.txt +15 -0
- package/build/Admin-authenticatedApp.7e29e95b.chunk.js +1 -0
- package/build/content-manager.473d2b84.chunk.js +1 -0
- package/build/content-type-builder.2a6a7156.chunk.js +1 -0
- package/build/index.html +1 -1
- package/build/main.ff33c0c2.js +2 -0
- package/build/main.ff33c0c2.js.LICENSE.txt +91 -0
- package/build/runtime~main.0685316b.js +1 -0
- package/build/users-roles-settings-page.9d5895d6.chunk.js +1 -0
- package/package.json +7 -7
- package/admin/src/content-manager/pages/EditSettingsView/components/FieldButton.js +0 -118
|
@@ -54,7 +54,9 @@ const CustomDragLayer = () => {
|
|
|
54
54
|
<LayoutDndProvider>
|
|
55
55
|
<div style={layerStyles}>
|
|
56
56
|
<div style={getItemStyles(initialOffset, currentOffset, mouseOffset)} className="col-md-2">
|
|
57
|
-
{
|
|
57
|
+
{[ItemTypes.EDIT_RELATION, ItemTypes.EDIT_FIELD].includes(itemType) && (
|
|
58
|
+
<CardPreview labelField={item.labelField} />
|
|
59
|
+
)}
|
|
58
60
|
{itemType === ItemTypes.COMPONENT && (
|
|
59
61
|
<RepeatableComponentPreview displayedValue={item.displayedValue} />
|
|
60
62
|
)}
|
|
@@ -100,10 +100,11 @@ const createYupSchema = (
|
|
|
100
100
|
|
|
101
101
|
if (attribute.repeatable === true) {
|
|
102
102
|
const { min, max, required } = attribute;
|
|
103
|
+
|
|
103
104
|
let componentSchema = yup.lazy(value => {
|
|
104
105
|
let baseSchema = yup.array().of(componentFieldSchema);
|
|
105
106
|
|
|
106
|
-
if (min
|
|
107
|
+
if (min) {
|
|
107
108
|
if (required) {
|
|
108
109
|
baseSchema = baseSchema.min(min, errorsTrads.min);
|
|
109
110
|
} else if (required !== true && isEmpty(value)) {
|
|
@@ -111,6 +112,8 @@ const createYupSchema = (
|
|
|
111
112
|
} else {
|
|
112
113
|
baseSchema = baseSchema.min(min, errorsTrads.min);
|
|
113
114
|
}
|
|
115
|
+
} else if (required && !options.isDraft) {
|
|
116
|
+
baseSchema = baseSchema.min(1, errorsTrads.required);
|
|
114
117
|
}
|
|
115
118
|
|
|
116
119
|
if (max) {
|
|
@@ -152,20 +155,8 @@ const createYupSchema = (
|
|
|
152
155
|
|
|
153
156
|
const { max, min } = attribute;
|
|
154
157
|
|
|
155
|
-
if (
|
|
156
|
-
|
|
157
|
-
if (options.isCreatingEntry) {
|
|
158
|
-
return value !== null || value !== undefined;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (value === undefined) {
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return value !== null;
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
if (min) {
|
|
158
|
+
if (min) {
|
|
159
|
+
if (attribute.required) {
|
|
169
160
|
dynamicZoneSchema = dynamicZoneSchema
|
|
170
161
|
.test('min', errorsTrads.min, value => {
|
|
171
162
|
if (options.isCreatingEntry) {
|
|
@@ -189,12 +180,21 @@ const createYupSchema = (
|
|
|
189
180
|
|
|
190
181
|
return value !== null;
|
|
191
182
|
});
|
|
192
|
-
}
|
|
193
|
-
} else {
|
|
194
|
-
// eslint-disable-next-line no-lonely-if
|
|
195
|
-
if (min) {
|
|
183
|
+
} else {
|
|
196
184
|
dynamicZoneSchema = dynamicZoneSchema.notEmptyMin(min);
|
|
197
185
|
}
|
|
186
|
+
} else if (attribute.required && !options.isDraft) {
|
|
187
|
+
dynamicZoneSchema = dynamicZoneSchema.test('required', errorsTrads.required, value => {
|
|
188
|
+
if (options.isCreatingEntry) {
|
|
189
|
+
return value !== null || value !== undefined;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (value === undefined) {
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return value !== null;
|
|
197
|
+
});
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
if (max) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { memo, useMemo } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
+
import { useIntl } from 'react-intl';
|
|
3
4
|
import get from 'lodash/get';
|
|
4
5
|
import omit from 'lodash/omit';
|
|
5
6
|
import take from 'lodash/take';
|
|
@@ -36,6 +37,7 @@ function Inputs({
|
|
|
36
37
|
value,
|
|
37
38
|
}) {
|
|
38
39
|
const { fields } = useLibrary();
|
|
40
|
+
const { formatMessage } = useIntl();
|
|
39
41
|
const { contentType: currentContentTypeLayout } = useContentTypeLayout();
|
|
40
42
|
|
|
41
43
|
const disabled = useMemo(() => !get(metadatas, 'editable', true), [metadatas]);
|
|
@@ -187,10 +189,14 @@ function Inputs({
|
|
|
187
189
|
<SelectWrapper
|
|
188
190
|
{...metadatas}
|
|
189
191
|
{...fieldSchema}
|
|
190
|
-
description={
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
description={
|
|
193
|
+
metadatas.description
|
|
194
|
+
? formatMessage({
|
|
195
|
+
id: metadatas.description,
|
|
196
|
+
defaultMessage: metadatas.description,
|
|
197
|
+
})
|
|
198
|
+
: undefined
|
|
199
|
+
}
|
|
194
200
|
intlLabel={{
|
|
195
201
|
id: metadatas.label,
|
|
196
202
|
defaultMessage: metadatas.label,
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import React, { useRef, useEffect, useState } from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { useDrop, useDrag } from 'react-dnd';
|
|
5
|
+
import { getEmptyImage } from 'react-dnd-html5-backend';
|
|
6
|
+
import { Flex } from '@strapi/design-system/Flex';
|
|
7
|
+
import { Box } from '@strapi/design-system/Box';
|
|
8
|
+
import { GridItem } from '@strapi/design-system/Grid';
|
|
9
|
+
import Drag from '@strapi/icons/Drag';
|
|
10
|
+
import { ItemTypes } from '../../../utils';
|
|
11
|
+
import FieldButtonContent from './FieldButtonContent';
|
|
12
|
+
import { useLayoutDnd } from '../../../hooks';
|
|
13
|
+
|
|
14
|
+
const Wrapper = styled(Flex)`
|
|
15
|
+
position: relative;
|
|
16
|
+
${({ isFirst, isLast, hasHorizontalPadding }) => {
|
|
17
|
+
if (isFirst) {
|
|
18
|
+
return `
|
|
19
|
+
padding-right: 4px;
|
|
20
|
+
`;
|
|
21
|
+
}
|
|
22
|
+
if (isLast) {
|
|
23
|
+
return `
|
|
24
|
+
padding-left: 4px;
|
|
25
|
+
`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (hasHorizontalPadding) {
|
|
29
|
+
return `
|
|
30
|
+
padding: 0 4px;
|
|
31
|
+
`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return '';
|
|
35
|
+
}}
|
|
36
|
+
${({ showRightCarret, showLeftCarret, theme }) => {
|
|
37
|
+
if (showRightCarret) {
|
|
38
|
+
return `
|
|
39
|
+
&:after {
|
|
40
|
+
content: '';
|
|
41
|
+
position: absolute;
|
|
42
|
+
right: -1px;
|
|
43
|
+
background-color: ${theme.colors.primary600};
|
|
44
|
+
width: 2px;
|
|
45
|
+
height: 100%;
|
|
46
|
+
align-self: stretch;
|
|
47
|
+
z-index: 1;
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (showLeftCarret) {
|
|
53
|
+
return `
|
|
54
|
+
&:before {
|
|
55
|
+
content: '';
|
|
56
|
+
position: absolute;
|
|
57
|
+
left: -1px;
|
|
58
|
+
background-color: ${theme.colors.primary600};
|
|
59
|
+
width: 2px;
|
|
60
|
+
height: 100%;
|
|
61
|
+
align-self: stretch;
|
|
62
|
+
z-index: 1;
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return '';
|
|
68
|
+
}};
|
|
69
|
+
`;
|
|
70
|
+
const CustomDragIcon = styled(Drag)`
|
|
71
|
+
height: ${12 / 16}rem;
|
|
72
|
+
width: ${12 / 16}rem;
|
|
73
|
+
path {
|
|
74
|
+
fill: ${({ theme }) => theme.colors.neutral600};
|
|
75
|
+
}
|
|
76
|
+
`;
|
|
77
|
+
const CustomFlex = styled(Flex)`
|
|
78
|
+
display: ${({ dragStart }) => (dragStart ? 'none' : 'flex')};
|
|
79
|
+
opacity: ${({ isDragging, isFullSize, isHidden }) => {
|
|
80
|
+
if (isDragging && !isFullSize) {
|
|
81
|
+
return 0.2;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if ((isDragging && isFullSize) || isHidden) {
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return 1;
|
|
89
|
+
}};
|
|
90
|
+
`;
|
|
91
|
+
const DragButton = styled(Flex)`
|
|
92
|
+
cursor: all-scroll;
|
|
93
|
+
border-right: 1px solid ${({ theme }) => theme.colors.neutral200};
|
|
94
|
+
`;
|
|
95
|
+
|
|
96
|
+
const DisplayedFieldButton = ({
|
|
97
|
+
attribute,
|
|
98
|
+
children,
|
|
99
|
+
index,
|
|
100
|
+
lastIndex,
|
|
101
|
+
moveItem,
|
|
102
|
+
moveRow,
|
|
103
|
+
name,
|
|
104
|
+
onDeleteField,
|
|
105
|
+
onEditField,
|
|
106
|
+
rowIndex,
|
|
107
|
+
size,
|
|
108
|
+
}) => {
|
|
109
|
+
const [dragStart, setDragStart] = useState(false);
|
|
110
|
+
const isHidden = name === '_TEMP_';
|
|
111
|
+
const { setIsDraggingSibling } = useLayoutDnd();
|
|
112
|
+
const isFullSize = size === 12;
|
|
113
|
+
|
|
114
|
+
const dragRef = useRef(null);
|
|
115
|
+
const dropRef = useRef(null);
|
|
116
|
+
const [{ clientOffset, isOver }, drop] = useDrop({
|
|
117
|
+
accept: ItemTypes.EDIT_FIELD,
|
|
118
|
+
hover(item, monitor) {
|
|
119
|
+
if (!dropRef.current) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// We use the hover only to reorder full size items
|
|
124
|
+
if (item.size !== 12) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const dragIndex = monitor.getItem().index;
|
|
129
|
+
const hoverIndex = index;
|
|
130
|
+
const dragRow = monitor.getItem().rowIndex;
|
|
131
|
+
const targetRow = rowIndex;
|
|
132
|
+
|
|
133
|
+
// Don't replace item with themselves
|
|
134
|
+
if (dragIndex === hoverIndex && dragRow === targetRow) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Determine rectangle on screen
|
|
139
|
+
const hoverBoundingRect = dropRef.current.getBoundingClientRect();
|
|
140
|
+
|
|
141
|
+
// Get vertical middle
|
|
142
|
+
const hoverMiddleY = (hoverBoundingRect.bottom - hoverBoundingRect.top) / 2;
|
|
143
|
+
// Determine mouse position
|
|
144
|
+
const clientOffset = monitor.getClientOffset();
|
|
145
|
+
|
|
146
|
+
// Get pixels to the top
|
|
147
|
+
const hoverClientY = clientOffset.y - hoverBoundingRect.top;
|
|
148
|
+
|
|
149
|
+
// Only perform the move when the mouse has crossed half of the items height
|
|
150
|
+
// When dragging downwards, only move when the cursor is below 50%
|
|
151
|
+
// When dragging upwards, only move when the cursor is above 50%
|
|
152
|
+
|
|
153
|
+
// Dragging downwards
|
|
154
|
+
if (dragRow < targetRow && hoverClientY < hoverMiddleY) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Dragging upwards
|
|
159
|
+
if (dragRow > targetRow && hoverClientY > hoverMiddleY) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
moveRow(dragRow, targetRow);
|
|
164
|
+
|
|
165
|
+
item.rowIndex = targetRow;
|
|
166
|
+
item.itemIndex = hoverIndex;
|
|
167
|
+
},
|
|
168
|
+
drop(item, monitor) {
|
|
169
|
+
if (!dropRef.current) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const dragIndex = monitor.getItem().index;
|
|
174
|
+
const hoverIndex = index;
|
|
175
|
+
const dragRow = monitor.getItem().rowIndex;
|
|
176
|
+
const targetRow = rowIndex;
|
|
177
|
+
|
|
178
|
+
// Don't reorder on drop for full size elements since it is already done in the hover
|
|
179
|
+
if (item.size === 12) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Don't replace item with themselves
|
|
184
|
+
if (dragIndex === hoverIndex && dragRow === targetRow) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Determine rectangle on screen
|
|
189
|
+
const hoverBoundingRect = dropRef.current.getBoundingClientRect();
|
|
190
|
+
|
|
191
|
+
// Scroll window if mouse near vertical edge(100px)
|
|
192
|
+
|
|
193
|
+
// Horizontal Check --
|
|
194
|
+
if (
|
|
195
|
+
Math.abs(monitor.getClientOffset().x - hoverBoundingRect.left) >
|
|
196
|
+
hoverBoundingRect.width / 1.8
|
|
197
|
+
) {
|
|
198
|
+
moveItem(dragIndex, hoverIndex + 1, dragRow, targetRow);
|
|
199
|
+
|
|
200
|
+
item.itemIndex = hoverIndex + 1;
|
|
201
|
+
item.rowIndex = targetRow;
|
|
202
|
+
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Vertical Check |
|
|
207
|
+
|
|
208
|
+
// Time to actually perform the action
|
|
209
|
+
moveItem(dragIndex, hoverIndex, dragRow, targetRow);
|
|
210
|
+
// Note: we're mutating the monitor item here!
|
|
211
|
+
// Generally it's better to avoid mutations,
|
|
212
|
+
// but it's good here for the sake of performance
|
|
213
|
+
// to avoid expensive index searches.
|
|
214
|
+
|
|
215
|
+
item.itemIndex = hoverIndex;
|
|
216
|
+
item.rowIndex = targetRow;
|
|
217
|
+
},
|
|
218
|
+
collect: monitor => ({
|
|
219
|
+
canDrop: monitor.canDrop(),
|
|
220
|
+
clientOffset: monitor.getClientOffset(),
|
|
221
|
+
isOver: monitor.isOver(),
|
|
222
|
+
isOverCurrent: monitor.isOver({ shallow: true }),
|
|
223
|
+
itemType: monitor.getItemType(),
|
|
224
|
+
}),
|
|
225
|
+
});
|
|
226
|
+
const [{ isDragging, getItem }, drag, dragPreview] = useDrag({
|
|
227
|
+
type: ItemTypes.EDIT_FIELD,
|
|
228
|
+
item: () => {
|
|
229
|
+
setIsDraggingSibling(true);
|
|
230
|
+
|
|
231
|
+
return {
|
|
232
|
+
index,
|
|
233
|
+
labelField: name,
|
|
234
|
+
rowIndex,
|
|
235
|
+
name,
|
|
236
|
+
size,
|
|
237
|
+
};
|
|
238
|
+
},
|
|
239
|
+
canDrag() {
|
|
240
|
+
// Each row of the layout has a max size of 12 (based on bootstrap grid system)
|
|
241
|
+
// So in order to offer a better drop zone we add the _TEMP_ div to complete the remaining substract (12 - existing)
|
|
242
|
+
// Those divs cannot be dragged
|
|
243
|
+
// If we wanted to offer the ability to create new lines in the layout (which will come later)
|
|
244
|
+
// We will need to add a 12 size _TEMP_ div to offer a drop target between each existing row.
|
|
245
|
+
return name !== '_TEMP_';
|
|
246
|
+
},
|
|
247
|
+
collect: monitor => ({
|
|
248
|
+
isDragging: monitor.isDragging(),
|
|
249
|
+
getItem: monitor.getItem(),
|
|
250
|
+
}),
|
|
251
|
+
end: () => {
|
|
252
|
+
setIsDraggingSibling(false);
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// Remove the default preview when the item is being dragged
|
|
257
|
+
// The preview is handled by the DragLayer
|
|
258
|
+
useEffect(() => {
|
|
259
|
+
dragPreview(getEmptyImage(), { captureDraggingState: true });
|
|
260
|
+
}, [dragPreview]);
|
|
261
|
+
|
|
262
|
+
// Create the refs
|
|
263
|
+
// We need 1 for the drop target
|
|
264
|
+
// 1 for the drag target
|
|
265
|
+
const refs = {
|
|
266
|
+
dragRef: drag(dragRef),
|
|
267
|
+
dropRef: drop(dropRef),
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
let showLeftCarret = false;
|
|
271
|
+
let showRightCarret = false;
|
|
272
|
+
|
|
273
|
+
if (dropRef.current && clientOffset) {
|
|
274
|
+
const hoverBoundingRect = dropRef.current.getBoundingClientRect();
|
|
275
|
+
|
|
276
|
+
showLeftCarret =
|
|
277
|
+
isOver &&
|
|
278
|
+
getItem.size !== 12 &&
|
|
279
|
+
Math.abs(clientOffset.x - hoverBoundingRect.left) < hoverBoundingRect.width / 2;
|
|
280
|
+
showRightCarret =
|
|
281
|
+
isOver &&
|
|
282
|
+
getItem.size !== 12 &&
|
|
283
|
+
Math.abs(clientOffset.x - hoverBoundingRect.left) > hoverBoundingRect.width / 2;
|
|
284
|
+
|
|
285
|
+
if (name === '_TEMP_') {
|
|
286
|
+
showLeftCarret = isOver && getItem.size !== 12;
|
|
287
|
+
showRightCarret = false;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const getHeight = () => {
|
|
292
|
+
if (attribute && isFullSize) {
|
|
293
|
+
return `${74 / 16}rem`;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return `${32 / 16}rem`;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
const isFirst = index === 0 && !isFullSize;
|
|
300
|
+
const isLast = index === lastIndex && !isFullSize;
|
|
301
|
+
const hasHorizontalPadding = index !== 0 && !isFullSize;
|
|
302
|
+
|
|
303
|
+
return (
|
|
304
|
+
<GridItem col={size}>
|
|
305
|
+
<Wrapper
|
|
306
|
+
ref={refs.dropRef}
|
|
307
|
+
showLeftCarret={showLeftCarret}
|
|
308
|
+
showRightCarret={showRightCarret}
|
|
309
|
+
isFirst={isFirst}
|
|
310
|
+
isLast={isLast}
|
|
311
|
+
hasHorizontalPadding={hasHorizontalPadding}
|
|
312
|
+
onDrag={() => {
|
|
313
|
+
if (isFullSize && !dragStart) {
|
|
314
|
+
setDragStart(true);
|
|
315
|
+
}
|
|
316
|
+
}}
|
|
317
|
+
onDragEnd={() => {
|
|
318
|
+
if (isFullSize) {
|
|
319
|
+
setDragStart(false);
|
|
320
|
+
}
|
|
321
|
+
}}
|
|
322
|
+
>
|
|
323
|
+
{dragStart && isFullSize && (
|
|
324
|
+
<Box
|
|
325
|
+
// style={{ display: isDragging ? 'block' : 'none' }}
|
|
326
|
+
width="100%"
|
|
327
|
+
height="2px"
|
|
328
|
+
background="primary600"
|
|
329
|
+
/>
|
|
330
|
+
)}
|
|
331
|
+
<CustomFlex
|
|
332
|
+
width={isFullSize && dragStart ? 0 : '100%'}
|
|
333
|
+
borderColor="neutral150"
|
|
334
|
+
hasRadius
|
|
335
|
+
background="neutral100"
|
|
336
|
+
minHeight={getHeight()}
|
|
337
|
+
alignItems="stretch"
|
|
338
|
+
isDragging={isDragging}
|
|
339
|
+
dragStart={dragStart}
|
|
340
|
+
isFullSize={isFullSize}
|
|
341
|
+
isHidden={isHidden}
|
|
342
|
+
>
|
|
343
|
+
<DragButton
|
|
344
|
+
as="button"
|
|
345
|
+
type="button"
|
|
346
|
+
ref={refs.dragRef}
|
|
347
|
+
onClick={e => e.stopPropagation()}
|
|
348
|
+
alignItems="center"
|
|
349
|
+
paddingLeft={3}
|
|
350
|
+
paddingRight={3}
|
|
351
|
+
// Disable the keyboard navigation since the drag n drop isn't accessible with the keyboard for the moment
|
|
352
|
+
tabIndex={-1}
|
|
353
|
+
>
|
|
354
|
+
<CustomDragIcon />
|
|
355
|
+
</DragButton>
|
|
356
|
+
{!isHidden && (
|
|
357
|
+
<FieldButtonContent
|
|
358
|
+
attribute={attribute}
|
|
359
|
+
onEditField={onEditField}
|
|
360
|
+
onDeleteField={onDeleteField}
|
|
361
|
+
>
|
|
362
|
+
{children}
|
|
363
|
+
</FieldButtonContent>
|
|
364
|
+
)}
|
|
365
|
+
</CustomFlex>
|
|
366
|
+
</Wrapper>
|
|
367
|
+
</GridItem>
|
|
368
|
+
);
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
DisplayedFieldButton.defaultProps = {
|
|
372
|
+
attribute: undefined,
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
DisplayedFieldButton.propTypes = {
|
|
376
|
+
attribute: PropTypes.shape({
|
|
377
|
+
components: PropTypes.array,
|
|
378
|
+
component: PropTypes.string,
|
|
379
|
+
type: PropTypes.string,
|
|
380
|
+
}),
|
|
381
|
+
children: PropTypes.string.isRequired,
|
|
382
|
+
index: PropTypes.number.isRequired,
|
|
383
|
+
moveItem: PropTypes.func.isRequired,
|
|
384
|
+
moveRow: PropTypes.func.isRequired,
|
|
385
|
+
name: PropTypes.string.isRequired,
|
|
386
|
+
onDeleteField: PropTypes.func.isRequired,
|
|
387
|
+
onEditField: PropTypes.func.isRequired,
|
|
388
|
+
rowIndex: PropTypes.number.isRequired,
|
|
389
|
+
lastIndex: PropTypes.number.isRequired,
|
|
390
|
+
size: PropTypes.number.isRequired,
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
export default DisplayedFieldButton;
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { useIntl } from 'react-intl';
|
|
4
|
-
import get from 'lodash/get';
|
|
5
4
|
import { Button } from '@strapi/design-system/Button';
|
|
6
5
|
import { Box } from '@strapi/design-system/Box';
|
|
7
6
|
import { Typography } from '@strapi/design-system/Typography';
|
|
8
|
-
import { Grid, GridItem } from '@strapi/design-system/Grid';
|
|
9
7
|
import { Stack } from '@strapi/design-system/Stack';
|
|
10
8
|
import { Flex } from '@strapi/design-system/Flex';
|
|
11
|
-
import { VisuallyHidden } from '@strapi/design-system/VisuallyHidden';
|
|
12
9
|
import { SimpleMenu, MenuItem } from '@strapi/design-system/SimpleMenu';
|
|
13
10
|
import Plus from '@strapi/icons/Plus';
|
|
14
11
|
import { getTrad } from '../../../utils';
|
|
15
|
-
import
|
|
16
|
-
import FieldButton from './FieldButton';
|
|
12
|
+
import RowsLayout from './RowsLayout';
|
|
17
13
|
import LinkToCTB from './LinkToCTB';
|
|
18
14
|
|
|
19
15
|
const DisplayedFields = ({ editLayout, editLayoutRemainingFields, onRemoveField, onAddField }) => {
|
|
20
16
|
const { formatMessage } = useIntl();
|
|
21
|
-
const { setEditFieldToSelect, attributes, modifiedData } = useLayoutDnd();
|
|
22
17
|
|
|
23
18
|
return (
|
|
24
19
|
<Stack size={4}>
|
|
@@ -32,47 +27,23 @@ const DisplayedFields = ({ editLayout, editLayoutRemainingFields, onRemoveField,
|
|
|
32
27
|
})}
|
|
33
28
|
</Typography>
|
|
34
29
|
</Box>
|
|
35
|
-
|
|
36
|
-
{/* <Box>
|
|
30
|
+
<Box>
|
|
37
31
|
<Typography variant="pi" textColor="neutral600">
|
|
38
32
|
{formatMessage({
|
|
39
33
|
id: 'containers.SettingPage.editSettings.description',
|
|
40
34
|
defaultMessage: 'Drag & drop the fields to build the layout',
|
|
41
35
|
})}
|
|
42
36
|
</Typography>
|
|
43
|
-
</Box>
|
|
37
|
+
</Box>
|
|
44
38
|
</div>
|
|
45
39
|
<LinkToCTB />
|
|
46
40
|
</Flex>
|
|
47
41
|
<Box padding={4} hasRadius borderStyle="dashed" borderWidth="1px" borderColor="neutral300">
|
|
48
42
|
<Stack size={2}>
|
|
49
|
-
{editLayout.map(row => (
|
|
50
|
-
<
|
|
51
|
-
{row
|
|
52
|
-
|
|
53
|
-
const attributeLabel = get(
|
|
54
|
-
modifiedData,
|
|
55
|
-
['metadatas', rowItem.name, 'edit', 'label'],
|
|
56
|
-
''
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
return (
|
|
60
|
-
<GridItem key={rowItem.name} col={rowItem.size}>
|
|
61
|
-
{rowItem.name !== '_TEMP_' ? (
|
|
62
|
-
<FieldButton
|
|
63
|
-
onEditField={() => setEditFieldToSelect(rowItem.name)}
|
|
64
|
-
onDeleteField={() => onRemoveField(row.rowId, index)}
|
|
65
|
-
attribute={attribute}
|
|
66
|
-
>
|
|
67
|
-
{attributeLabel || rowItem.name}
|
|
68
|
-
</FieldButton>
|
|
69
|
-
) : (
|
|
70
|
-
<VisuallyHidden />
|
|
71
|
-
)}
|
|
72
|
-
</GridItem>
|
|
73
|
-
);
|
|
74
|
-
})}
|
|
75
|
-
</Grid>
|
|
43
|
+
{editLayout.map((row, index) => (
|
|
44
|
+
<React.Fragment key={row.rowId}>
|
|
45
|
+
<RowsLayout row={row} rowIndex={index} onRemoveField={onRemoveField} />
|
|
46
|
+
</React.Fragment>
|
|
76
47
|
))}
|
|
77
48
|
<SimpleMenu
|
|
78
49
|
id="label"
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { useIntl } from 'react-intl';
|
|
5
|
+
import { Box } from '@strapi/design-system/Box';
|
|
6
|
+
import { Flex } from '@strapi/design-system/Flex';
|
|
7
|
+
import { IconButton } from '@strapi/design-system/IconButton';
|
|
8
|
+
import { Text } from '@strapi/design-system/Text';
|
|
9
|
+
import Pencil from '@strapi/icons/Pencil';
|
|
10
|
+
import Trash from '@strapi/icons/Trash';
|
|
11
|
+
import { getTrad } from '../../../utils';
|
|
12
|
+
import ComponentFieldList from './ComponentFieldList';
|
|
13
|
+
import DynamicZoneList from './DynamicZoneList';
|
|
14
|
+
|
|
15
|
+
const CustomIconButton = styled(IconButton)`
|
|
16
|
+
background-color: transparent;
|
|
17
|
+
path {
|
|
18
|
+
fill: ${({ theme }) => theme.colors.neutral600};
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
const FieldButtonContent = ({ attribute, onEditField, onDeleteField, children }) => {
|
|
23
|
+
const { formatMessage } = useIntl();
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<Box overflow="hidden" width="100%">
|
|
27
|
+
<Flex paddingLeft={3} alignItems="baseline" justifyContent="space-between">
|
|
28
|
+
<Box>
|
|
29
|
+
<Text textColor="neutral800" bold>
|
|
30
|
+
{children}
|
|
31
|
+
</Text>
|
|
32
|
+
</Box>
|
|
33
|
+
<Flex>
|
|
34
|
+
<CustomIconButton
|
|
35
|
+
label={formatMessage(
|
|
36
|
+
{
|
|
37
|
+
id: getTrad('containers.ListSettingsView.modal-form.edit-label'),
|
|
38
|
+
defaultMessage: `Edit {fieldName}`,
|
|
39
|
+
},
|
|
40
|
+
{ fieldName: children }
|
|
41
|
+
)}
|
|
42
|
+
onClick={onEditField}
|
|
43
|
+
icon={<Pencil />}
|
|
44
|
+
noBorder
|
|
45
|
+
/>
|
|
46
|
+
<CustomIconButton
|
|
47
|
+
label={formatMessage(
|
|
48
|
+
{
|
|
49
|
+
id: getTrad('app.component.table.delete'),
|
|
50
|
+
defaultMessage: `Delete {target}`,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
target: children,
|
|
54
|
+
}
|
|
55
|
+
)}
|
|
56
|
+
data-testid="delete-field"
|
|
57
|
+
onClick={onDeleteField}
|
|
58
|
+
icon={<Trash />}
|
|
59
|
+
noBorder
|
|
60
|
+
/>
|
|
61
|
+
</Flex>
|
|
62
|
+
</Flex>
|
|
63
|
+
{attribute?.type === 'component' && <ComponentFieldList componentUid={attribute.component} />}
|
|
64
|
+
{attribute?.type === 'dynamiczone' && <DynamicZoneList components={attribute.components} />}
|
|
65
|
+
</Box>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
FieldButtonContent.defaultProps = {
|
|
70
|
+
attribute: undefined,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
FieldButtonContent.propTypes = {
|
|
74
|
+
attribute: PropTypes.shape({
|
|
75
|
+
components: PropTypes.array,
|
|
76
|
+
component: PropTypes.string,
|
|
77
|
+
type: PropTypes.string,
|
|
78
|
+
}),
|
|
79
|
+
onEditField: PropTypes.func.isRequired,
|
|
80
|
+
onDeleteField: PropTypes.func.isRequired,
|
|
81
|
+
children: PropTypes.string.isRequired,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export default FieldButtonContent;
|