@elice/material-quiz 1.221217.0 → 1.221222.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/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.js +105 -125
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.d.ts +1 -0
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.js +206 -119
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.js +60 -141
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.d.ts +8 -0
- package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.js +139 -0
- package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.js +107 -127
- package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.d.ts +1 -0
- package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.js +207 -120
- package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.js +63 -144
- package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.d.ts +8 -0
- package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.js +132 -0
- package/package.json +4 -4
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { useFormContext, Controller } from 'react-hook-form';
|
|
3
3
|
import { useIntl } from 'react-intl';
|
|
4
4
|
import { config, postGlobalRemoteFileAttachmentUpload } from '@elice/api-client';
|
|
5
|
-
import { SortableListItem, Input, Dropdown, Flex, Text, Hspace, IconButton, Notification } from '@elice/blocks';
|
|
5
|
+
import { SortableListItem, Input, Dropdown, Flex, Text, Hspace, IconButton, Notification, Tooltip } from '@elice/blocks';
|
|
6
6
|
import { base } from '@elice/design-tokens';
|
|
7
7
|
import { eilMathsignMultiplyBasic } from '@elice/icons';
|
|
8
8
|
import { useMaterialConfigApiClientUpdate } from '@elice/material-shared-utils';
|
|
@@ -11,54 +11,59 @@ import styled from 'styled-components';
|
|
|
11
11
|
import { checkTwoDimensionArray } from '../../utils/checkTwoDimensionArray.js';
|
|
12
12
|
|
|
13
13
|
const SHEET_Z_INDEX = 982;
|
|
14
|
-
const OPTION_CONTENT_WIDTH = 205;
|
|
15
|
-
const OPTION_GROUP_WIDTH = 180;
|
|
16
14
|
const DEFAULT_OPTION_VALUE = -1;
|
|
15
|
+
const MIN_OPTION_INFO_COUNT = 2;
|
|
17
16
|
const FILE_LABEL = 'file-label';
|
|
18
17
|
const FILE_ACCEPT = '.mp3, .mp4, .mov, .png, .jpg, .svg, .gif';
|
|
19
18
|
const MAX_FILE_SIZE = 3 * 1024 * 1024;
|
|
20
19
|
const StyledSortableListItem = styled(SortableListItem).withConfig({
|
|
21
20
|
componentId: "sc-18q96lt-0"
|
|
22
|
-
})(["display:flex;
|
|
23
|
-
const
|
|
21
|
+
})(["display:flex;flex:1;z-index:", ";padding:0;background:transparent;box-shadow:none;"], SHEET_Z_INDEX + 1);
|
|
22
|
+
const StyledSortableListItemOptionWrapper = styled.div.withConfig({
|
|
24
23
|
componentId: "sc-18q96lt-1"
|
|
25
|
-
})(["height:100
|
|
26
|
-
const
|
|
24
|
+
})(["display:flex;align-items:center;overflow:hidden;width:100%;height:100%;border:1px solid ", ";border-radius:4px;background:", ";"], base.color.gray3, base.color.white);
|
|
25
|
+
const StyledSortableListItemOption = styled.div.withConfig({
|
|
27
26
|
componentId: "sc-18q96lt-2"
|
|
28
|
-
})(["
|
|
29
|
-
const
|
|
27
|
+
})(["height:3.5rem;&:not(:last-child){border-right:1px solid ", ";}"], base.color.gray3);
|
|
28
|
+
const StyledQuizOptionContent = styled.div.withConfig({
|
|
30
29
|
componentId: "sc-18q96lt-3"
|
|
31
|
-
})(["display:flex;align-items:center;width:
|
|
32
|
-
const
|
|
30
|
+
})(["display:flex;align-items:center;width:100%;height:100%;padding:0 1rem;"]);
|
|
31
|
+
const StyledQuizOptionContentLabel = styled.label.withConfig({
|
|
33
32
|
componentId: "sc-18q96lt-4"
|
|
33
|
+
})(["display:flex;align-items:center;width:100%;height:100%;padding:0 1rem;cursor:pointer;"]);
|
|
34
|
+
const StyledQuizOptionTextInput = styled(Input).withConfig({
|
|
35
|
+
componentId: "sc-18q96lt-5"
|
|
34
36
|
})(["& > div{border:0;}"]);
|
|
35
37
|
const StyledQuizOptionContentInput = styled.input.withConfig({
|
|
36
|
-
componentId: "sc-18q96lt-
|
|
38
|
+
componentId: "sc-18q96lt-6"
|
|
37
39
|
})(["display:none;"]);
|
|
38
40
|
const StyledDropdown = styled(Dropdown).withConfig({
|
|
39
|
-
componentId: "sc-18q96lt-
|
|
40
|
-
})(["border:0;&.eb-dropdown__inner{width:
|
|
41
|
+
componentId: "sc-18q96lt-7"
|
|
42
|
+
})(["border:0;&.eb-dropdown__inner{width:100%;height:3.5rem;}"]); //
|
|
41
43
|
//
|
|
42
44
|
//
|
|
43
45
|
|
|
44
46
|
const OptionGroupAnswerListItem = ({
|
|
45
|
-
optionId
|
|
47
|
+
optionId,
|
|
48
|
+
onRemoveItem
|
|
46
49
|
}) => {
|
|
47
|
-
var _a, _b, _c, _d;
|
|
50
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
48
51
|
|
|
49
52
|
const intl = useIntl();
|
|
50
53
|
const {
|
|
51
54
|
control,
|
|
55
|
+
formState,
|
|
52
56
|
watch,
|
|
53
57
|
setValue
|
|
54
58
|
} = useFormContext();
|
|
55
59
|
const watchedOptions = watch('options');
|
|
56
60
|
const watchedAnswerInfo = watch('answerInfo');
|
|
57
61
|
const watchedGroupList = watch('groups');
|
|
58
|
-
const
|
|
62
|
+
const errorMessage = (_d = (_c = (_b = (_a = formState.errors) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b[optionId]) === null || _c === void 0 ? void 0 : _c.title) === null || _d === void 0 ? void 0 : _d.message;
|
|
59
63
|
const groupIndex = watchedAnswerInfo.findIndex(answer => answer === null || answer === void 0 ? void 0 : answer.includes(optionId));
|
|
60
|
-
const
|
|
61
|
-
const
|
|
64
|
+
const isReady = useMaterialConfigApiClientUpdate(config.init);
|
|
65
|
+
const isOptionTitle = (_f = (_e = watchedOptions[optionId]) === null || _e === void 0 ? void 0 : _e.title) === null || _f === void 0 ? void 0 : _f.length;
|
|
66
|
+
const isOptionContent = (_h = (_g = watchedOptions[optionId]) === null || _g === void 0 ? void 0 : _g.content) === null || _h === void 0 ? void 0 : _h.length;
|
|
62
67
|
/**
|
|
63
68
|
* File upload function.
|
|
64
69
|
*/
|
|
@@ -87,122 +92,204 @@ const OptionGroupAnswerListItem = ({
|
|
|
87
92
|
}
|
|
88
93
|
|
|
89
94
|
return contentUrl;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
*
|
|
98
|
+
*/
|
|
93
99
|
|
|
94
100
|
|
|
95
|
-
|
|
96
|
-
return
|
|
97
|
-
|
|
101
|
+
const renderOptionTitleInput = () => {
|
|
102
|
+
return React.createElement(StyledSortableListItemOption, {
|
|
103
|
+
style: {
|
|
104
|
+
width: '33.3%'
|
|
105
|
+
}
|
|
106
|
+
}, React.createElement(Controller, {
|
|
107
|
+
control: control,
|
|
108
|
+
name: `options.${optionId}.title`,
|
|
109
|
+
rules: {
|
|
110
|
+
required: {
|
|
111
|
+
value: !isOptionTitle && !isOptionContent,
|
|
112
|
+
message: intl.formatMessage({
|
|
113
|
+
id: 'answer.option.errorMessage'
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
render: ({
|
|
118
|
+
field
|
|
119
|
+
}) => React.createElement(StyledQuizOptionTextInput, Object.assign({}, field, {
|
|
120
|
+
width: "full",
|
|
121
|
+
onChange: e => {
|
|
122
|
+
field.onChange(e.target.value.replace(' ', ''));
|
|
123
|
+
}
|
|
124
|
+
}))
|
|
125
|
+
}));
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
*
|
|
129
|
+
*/
|
|
98
130
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
131
|
+
|
|
132
|
+
const renderOptionContentInput = () => {
|
|
133
|
+
return React.createElement(StyledSortableListItemOption, {
|
|
134
|
+
style: {
|
|
135
|
+
width: '33.3%'
|
|
136
|
+
}
|
|
137
|
+
}, React.createElement(Controller, {
|
|
138
|
+
control: control,
|
|
139
|
+
name: `options.${optionId}.content`,
|
|
140
|
+
render: ({
|
|
141
|
+
field
|
|
142
|
+
}) => React.createElement(React.Fragment, null, field.value ? React.createElement(StyledQuizOptionContent, null, React.createElement(Flex, {
|
|
143
|
+
justify: "space-between",
|
|
144
|
+
align: "center",
|
|
145
|
+
width: "100%",
|
|
146
|
+
height: "100%"
|
|
147
|
+
}, React.createElement(Text, {
|
|
148
|
+
ellipsis: true
|
|
149
|
+
}, React.createElement("a", {
|
|
150
|
+
href: getContentUrl(field.value),
|
|
151
|
+
target: "_blank",
|
|
152
|
+
rel: "noreferrer"
|
|
153
|
+
}, getContentUrl(field.value))), React.createElement(Flex, {
|
|
154
|
+
align: "center"
|
|
155
|
+
}, React.createElement(Hspace, {
|
|
156
|
+
width: 0.5
|
|
157
|
+
}), React.createElement(IconButton, {
|
|
158
|
+
icon: eilMathsignMultiplyBasic,
|
|
159
|
+
role: "gray6",
|
|
160
|
+
size: "micro",
|
|
161
|
+
border: false,
|
|
162
|
+
transparent: true,
|
|
163
|
+
onClick: () => field.onChange('')
|
|
164
|
+
})))) : React.createElement(React.Fragment, null, React.createElement(StyledQuizOptionContentLabel, {
|
|
165
|
+
htmlFor: `${FILE_LABEL}_${optionId}`
|
|
166
|
+
}, React.createElement(Text, {
|
|
167
|
+
role: "primary",
|
|
168
|
+
underline: true
|
|
169
|
+
}, intl.formatMessage({
|
|
170
|
+
id: 'answer.option.file.label'
|
|
171
|
+
}))), React.createElement(StyledQuizOptionContentInput, Object.assign({}, field, {
|
|
172
|
+
id: `${FILE_LABEL}_${optionId}`,
|
|
173
|
+
type: "file",
|
|
174
|
+
accept: FILE_ACCEPT,
|
|
175
|
+
onChange: async e => {
|
|
176
|
+
var _a, _b;
|
|
177
|
+
|
|
178
|
+
const file = (_b = (_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b[0];
|
|
179
|
+
|
|
180
|
+
if (!file) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (file.size > MAX_FILE_SIZE) {
|
|
185
|
+
return Notification.error(intl.formatMessage({
|
|
186
|
+
id: 'answer.option.file.errorMessage.maxSize'
|
|
187
|
+
}, {
|
|
188
|
+
size: 3
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const contentFileUrl = await uploadContentFile(file);
|
|
193
|
+
field.onChange(`})`);
|
|
194
|
+
}
|
|
195
|
+
}))))
|
|
196
|
+
}));
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
*
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
const renderOptionGroupDropdown = () => {
|
|
204
|
+
return React.createElement(StyledSortableListItemOption, {
|
|
205
|
+
style: {
|
|
206
|
+
width: '33.3%'
|
|
114
207
|
}
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
field
|
|
118
|
-
}) => React.createElement(StyledQuizOptionTextInput, Object.assign({}, field, {
|
|
119
|
-
width: "full",
|
|
208
|
+
}, React.createElement(StyledDropdown, {
|
|
209
|
+
value: groupIndex,
|
|
120
210
|
onChange: e => {
|
|
121
|
-
|
|
211
|
+
const cloneAnswerList = cloneDeep(watchedAnswerInfo);
|
|
212
|
+
const answerList = cloneAnswerList.map(answers => answers.filter(answer => answer !== optionId));
|
|
213
|
+
|
|
214
|
+
if (e === DEFAULT_OPTION_VALUE) {
|
|
215
|
+
return setValue('answerInfo', answerList);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (answerList[e]) {
|
|
219
|
+
answerList[e] = [...answerList[e], optionId];
|
|
220
|
+
} else {
|
|
221
|
+
answerList[e] = [optionId];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
setValue('answerInfo', answerList);
|
|
122
225
|
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
226
|
+
}, React.createElement("option", {
|
|
227
|
+
value: DEFAULT_OPTION_VALUE
|
|
228
|
+
}, intl.formatMessage({
|
|
229
|
+
id: 'answer.option.default.group'
|
|
230
|
+
})), watchedGroupList.map((group, index) => React.createElement("option", {
|
|
231
|
+
key: index,
|
|
232
|
+
value: index
|
|
233
|
+
}, group.group))));
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
*
|
|
237
|
+
*/
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
const renderOptionRemoveButton = () => {
|
|
241
|
+
const isMinimumOptions = (watchedOptions === null || watchedOptions === void 0 ? void 0 : watchedOptions.length) <= MIN_OPTION_INFO_COUNT;
|
|
242
|
+
return React.createElement(React.Fragment, null, React.createElement(Hspace, {
|
|
140
243
|
width: 0.5
|
|
141
|
-
}), React.createElement(
|
|
244
|
+
}), React.createElement(Tooltip, {
|
|
245
|
+
title: isMinimumOptions ? intl.formatMessage({
|
|
246
|
+
id: 'answer.option.tooltip.minDisabled'
|
|
247
|
+
}) : undefined,
|
|
248
|
+
placement: "top"
|
|
249
|
+
}, React.createElement("span", null, React.createElement(IconButton, {
|
|
250
|
+
transparent: true,
|
|
142
251
|
icon: eilMathsignMultiplyBasic,
|
|
143
252
|
role: "gray6",
|
|
144
253
|
size: "micro",
|
|
145
254
|
border: false,
|
|
146
|
-
|
|
147
|
-
onClick:
|
|
148
|
-
}))))
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}, intl.formatMessage({
|
|
154
|
-
id: 'answer.option.file.label'
|
|
155
|
-
}))), React.createElement(StyledQuizOptionContentInput, Object.assign({}, field, {
|
|
156
|
-
id: `${FILE_LABEL}_${optionId}`,
|
|
157
|
-
type: "file",
|
|
158
|
-
accept: FILE_ACCEPT,
|
|
159
|
-
onChange: async e => {
|
|
160
|
-
var _a, _b;
|
|
161
|
-
|
|
162
|
-
const file = (_b = (_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b[0];
|
|
163
|
-
|
|
164
|
-
if (!file) {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
255
|
+
disabled: isMinimumOptions,
|
|
256
|
+
onClick: onRemoveItem
|
|
257
|
+
}))));
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
*
|
|
261
|
+
*/
|
|
167
262
|
|
|
168
|
-
if (file.size > MAX_FILE_SIZE) {
|
|
169
|
-
return Notification.error(intl.formatMessage({
|
|
170
|
-
id: 'answer.option.file.errorMessage.maxSize'
|
|
171
|
-
}, {
|
|
172
|
-
size: 3
|
|
173
|
-
}));
|
|
174
|
-
}
|
|
175
263
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
})), React.createElement(StyledSortableListItemOption, null, React.createElement(StyledDropdown, {
|
|
181
|
-
value: groupIndex,
|
|
182
|
-
onChange: e => {
|
|
183
|
-
const cloneAnswerList = cloneDeep(watchedAnswerInfo);
|
|
184
|
-
const answerList = cloneAnswerList.map(answers => answers.filter(answer => answer !== optionId));
|
|
185
|
-
|
|
186
|
-
if (e === DEFAULT_OPTION_VALUE) {
|
|
187
|
-
return setValue('answerInfo', answerList);
|
|
188
|
-
}
|
|
264
|
+
const renderErrorMessage = () => {
|
|
265
|
+
if (!errorMessage) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
189
268
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
269
|
+
return React.createElement(Flex, {
|
|
270
|
+
paddingleft: "0.25rem"
|
|
271
|
+
}, React.createElement(Text, {
|
|
272
|
+
size: "small",
|
|
273
|
+
role: "danger"
|
|
274
|
+
}, errorMessage));
|
|
275
|
+
}; //
|
|
276
|
+
//
|
|
277
|
+
//
|
|
195
278
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
279
|
+
|
|
280
|
+
if (!checkTwoDimensionArray(watchedAnswerInfo)) {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return React.createElement(StyledSortableListItem, {
|
|
285
|
+
index: optionId
|
|
286
|
+
}, React.createElement(Flex, {
|
|
287
|
+
justify: "center",
|
|
288
|
+
width: "calc(100% - 1.5rem)",
|
|
289
|
+
column: true
|
|
290
|
+
}, React.createElement(Flex, {
|
|
291
|
+
align: "center"
|
|
292
|
+
}, React.createElement(StyledSortableListItemOptionWrapper, null, renderOptionTitleInput(), renderOptionContentInput(), renderOptionGroupDropdown()), renderOptionRemoveButton()), renderErrorMessage()));
|
|
206
293
|
};
|
|
207
294
|
|
|
208
295
|
export { OptionGroupAnswerListItem as default };
|
|
@@ -1,98 +1,30 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { useFormContext, useFieldArray
|
|
2
|
+
import { useFormContext, useFieldArray } from 'react-hook-form';
|
|
3
3
|
import { useIntl } from 'react-intl';
|
|
4
4
|
import { arrayMove } from 'react-sortable-hoc';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { eilMathsignMultiplyBasic, eilMathsignAddBasic } from '@elice/icons';
|
|
5
|
+
import { Flex, Text, SortableListGroup, Tooltip, Button, Icon } from '@elice/blocks';
|
|
6
|
+
import { eilMathsignAddBasic } from '@elice/icons';
|
|
8
7
|
import cloneDeep from 'lodash-es/cloneDeep';
|
|
9
8
|
import styled from 'styled-components';
|
|
10
9
|
import { createRandomId } from '../../utils/randomId.js';
|
|
10
|
+
import OptionGroupGroupListItem from './OptionGroupGroupListItem.js';
|
|
11
11
|
|
|
12
|
-
const SHEET_Z_INDEX = 982;
|
|
13
|
-
const MIN_GROUP_INFO_COUNT = 2;
|
|
14
12
|
const MAX_GROUP_INFO_COUNT = 6;
|
|
15
|
-
const StyledSortableList = styled.
|
|
13
|
+
const StyledSortableList = styled.div.withConfig({
|
|
16
14
|
componentId: "sc-9aq3yn-0"
|
|
17
15
|
})(["margin:1rem 0;padding:0;"]);
|
|
18
|
-
const StyledSortableListItemWrapper = styled.
|
|
16
|
+
const StyledSortableListItemWrapper = styled.div.withConfig({
|
|
19
17
|
componentId: "sc-9aq3yn-1"
|
|
20
|
-
})(["display:flex;
|
|
21
|
-
const StyledSortableListItem = styled(SortableListItem).withConfig({
|
|
22
|
-
componentId: "sc-9aq3yn-2"
|
|
23
|
-
})(["display:flex;overflow:hidden;z-index:", ";width:100%;padding:0 0 0 1rem;border-radius:4px;border:1px solid ", ";background:", ";box-shadow:none;"], SHEET_Z_INDEX + 1, ({
|
|
24
|
-
isGroupChildAnswer
|
|
25
|
-
}) => isGroupChildAnswer ? base.color.red8 : base.color.gray3, base.color.white);
|
|
26
|
-
const StyledInputGroup = styled(Input).withConfig({
|
|
27
|
-
componentId: "sc-9aq3yn-3"
|
|
28
|
-
})(["& > div{border:0;}"]); //
|
|
18
|
+
})(["display:flex;flex-direction:column;&:not(:last-child){margin-bottom:0.5rem;}"]); //
|
|
29
19
|
//
|
|
30
20
|
//
|
|
31
21
|
|
|
32
|
-
const
|
|
33
|
-
groupId
|
|
34
|
-
}) => {
|
|
35
|
-
var _a;
|
|
36
|
-
|
|
22
|
+
const OptionGroupGroupInfo = () => {
|
|
37
23
|
const intl = useIntl();
|
|
38
24
|
const {
|
|
39
|
-
|
|
25
|
+
setValue,
|
|
40
26
|
watch
|
|
41
27
|
} = useFormContext();
|
|
42
|
-
const watchedAnswerInfo = watch('answerInfo');
|
|
43
|
-
const isGroupChildAnswer = Boolean((_a = watchedAnswerInfo[groupId]) === null || _a === void 0 ? void 0 : _a.length); //
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
return React.createElement(StyledSortableListItem, {
|
|
48
|
-
index: groupId,
|
|
49
|
-
isGroupChildAnswer: !isGroupChildAnswer
|
|
50
|
-
}, React.createElement(Controller, {
|
|
51
|
-
control: control,
|
|
52
|
-
name: `groups.${groupId}.group`,
|
|
53
|
-
rules: {
|
|
54
|
-
required: {
|
|
55
|
-
value: true,
|
|
56
|
-
message: intl.formatMessage({
|
|
57
|
-
id: 'group.option.errorMessage.required'
|
|
58
|
-
})
|
|
59
|
-
},
|
|
60
|
-
validate: () => {
|
|
61
|
-
if (!isGroupChildAnswer) {
|
|
62
|
-
return intl.formatMessage({
|
|
63
|
-
id: 'group.option.errorMessage.notChild'
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
render: ({
|
|
69
|
-
field,
|
|
70
|
-
fieldState
|
|
71
|
-
}) => {
|
|
72
|
-
var _a;
|
|
73
|
-
|
|
74
|
-
return React.createElement(StyledInputGroup, Object.assign({}, field, {
|
|
75
|
-
invalid: fieldState.invalid || !isGroupChildAnswer,
|
|
76
|
-
invalidText: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message,
|
|
77
|
-
width: "full",
|
|
78
|
-
onChange: e => {
|
|
79
|
-
field.onChange(e.target.value.replace(' ', ''));
|
|
80
|
-
}
|
|
81
|
-
}));
|
|
82
|
-
}
|
|
83
|
-
}));
|
|
84
|
-
}; //
|
|
85
|
-
//
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const OptionGroupGroupList = () => {
|
|
90
|
-
const intl = useIntl();
|
|
91
|
-
const {
|
|
92
|
-
watch,
|
|
93
|
-
setValue
|
|
94
|
-
} = useFormContext();
|
|
95
|
-
const watchedAnswerInfo = watch('answerInfo');
|
|
96
28
|
const {
|
|
97
29
|
fields: groupInfoFields,
|
|
98
30
|
append: appendGroupInfoFieldItem,
|
|
@@ -102,7 +34,8 @@ const OptionGroupGroupList = () => {
|
|
|
102
34
|
keyName: 'id',
|
|
103
35
|
shouldUnregister: true
|
|
104
36
|
});
|
|
105
|
-
const
|
|
37
|
+
const watchedGroups = watch('groups');
|
|
38
|
+
const watchedAnswerInfo = watch('answerInfo');
|
|
106
39
|
const isMaximumGroups = groupInfoFields.length >= MAX_GROUP_INFO_COUNT;
|
|
107
40
|
/**
|
|
108
41
|
*
|
|
@@ -123,72 +56,12 @@ const OptionGroupGroupList = () => {
|
|
|
123
56
|
cloneAnswerList.splice(index, 1);
|
|
124
57
|
setValue('answerInfo', cloneAnswerList.filter(Boolean));
|
|
125
58
|
removeGroupInfoFieldItem(Number(index));
|
|
126
|
-
};
|
|
127
|
-
//
|
|
128
|
-
//
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return React.createElement(React.Fragment, null, React.createElement(StyledSortableList, null, groupInfoFields.map((group, index) => {
|
|
132
|
-
return React.createElement(StyledSortableListItemWrapper, {
|
|
133
|
-
key: group.id
|
|
134
|
-
}, React.createElement(OptionGroupGroupListItem, {
|
|
135
|
-
groupId: index
|
|
136
|
-
}), React.createElement(Hspace, {
|
|
137
|
-
width: 0.5
|
|
138
|
-
}), React.createElement(Tooltip, {
|
|
139
|
-
title: isMinimumGroups ? intl.formatMessage({
|
|
140
|
-
id: 'group.option.tooltip.minDisabled'
|
|
141
|
-
}) : undefined,
|
|
142
|
-
placement: "top"
|
|
143
|
-
}, React.createElement("span", null, React.createElement(IconButton, {
|
|
144
|
-
transparent: true,
|
|
145
|
-
icon: eilMathsignMultiplyBasic,
|
|
146
|
-
role: "gray6",
|
|
147
|
-
size: "micro",
|
|
148
|
-
border: false,
|
|
149
|
-
disabled: isMinimumGroups,
|
|
150
|
-
onClick: () => removeGroupAnswerInfo(Number(index))
|
|
151
|
-
}))));
|
|
152
|
-
})), React.createElement(Tooltip, {
|
|
153
|
-
title: isMaximumGroups ? intl.formatMessage({
|
|
154
|
-
id: 'group.option.tooltip.maxDisabled'
|
|
155
|
-
}) : undefined,
|
|
156
|
-
placement: "top"
|
|
157
|
-
}, React.createElement("span", null, React.createElement(Button, {
|
|
158
|
-
borderDashed: true,
|
|
159
|
-
block: true,
|
|
160
|
-
transparent: true,
|
|
161
|
-
icon: React.createElement(Icon, {
|
|
162
|
-
icon: eilMathsignAddBasic
|
|
163
|
-
}),
|
|
164
|
-
disabled: isMaximumGroups,
|
|
165
|
-
onClick: () => {
|
|
166
|
-
appendGroupInfoFieldItem({
|
|
167
|
-
id: createRandomId(),
|
|
168
|
-
group: ''
|
|
169
|
-
});
|
|
170
|
-
addGroupAnswerInfo();
|
|
171
|
-
}
|
|
172
|
-
}, intl.formatMessage({
|
|
173
|
-
id: 'group.option.addButton'
|
|
174
|
-
})))));
|
|
175
|
-
}; //
|
|
176
|
-
//
|
|
177
|
-
//
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const OptionGroupGroupInfo = () => {
|
|
181
|
-
const intl = useIntl();
|
|
182
|
-
const {
|
|
183
|
-
setValue,
|
|
184
|
-
watch
|
|
185
|
-
} = useFormContext();
|
|
186
|
-
const watchedGroups = watch('groups');
|
|
187
|
-
const watchedAnswerInfo = watch('answerInfo');
|
|
59
|
+
};
|
|
188
60
|
/**
|
|
189
61
|
*
|
|
190
62
|
*/
|
|
191
63
|
|
|
64
|
+
|
|
192
65
|
const onSortEnd = ({
|
|
193
66
|
oldIndex,
|
|
194
67
|
newIndex
|
|
@@ -201,6 +74,55 @@ const OptionGroupGroupInfo = () => {
|
|
|
201
74
|
shouldDirty: true
|
|
202
75
|
});
|
|
203
76
|
setValue('answerInfo', cloneAnswerList);
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
const renderGroupOptionList = () => {
|
|
84
|
+
return React.createElement(SortableListGroup, {
|
|
85
|
+
onSortEnd: onSortEnd,
|
|
86
|
+
useDragHandle: true
|
|
87
|
+
}, React.createElement(StyledSortableList, null, groupInfoFields.map((group, index) => {
|
|
88
|
+
return React.createElement(StyledSortableListItemWrapper, {
|
|
89
|
+
key: group.id
|
|
90
|
+
}, React.createElement(OptionGroupGroupListItem, {
|
|
91
|
+
groupId: index,
|
|
92
|
+
groupsCount: groupInfoFields.length,
|
|
93
|
+
onRemoveOption: () => removeGroupAnswerInfo(index)
|
|
94
|
+
}));
|
|
95
|
+
})));
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
const renderGroupOptionAddButton = () => {
|
|
103
|
+
return React.createElement(Tooltip, {
|
|
104
|
+
title: isMaximumGroups ? intl.formatMessage({
|
|
105
|
+
id: 'group.option.tooltip.maxDisabled'
|
|
106
|
+
}) : undefined,
|
|
107
|
+
placement: "top"
|
|
108
|
+
}, React.createElement("span", null, React.createElement(Button, {
|
|
109
|
+
borderDashed: true,
|
|
110
|
+
block: true,
|
|
111
|
+
transparent: true,
|
|
112
|
+
icon: React.createElement(Icon, {
|
|
113
|
+
icon: eilMathsignAddBasic
|
|
114
|
+
}),
|
|
115
|
+
disabled: isMaximumGroups,
|
|
116
|
+
onClick: () => {
|
|
117
|
+
appendGroupInfoFieldItem({
|
|
118
|
+
id: createRandomId(),
|
|
119
|
+
group: ''
|
|
120
|
+
});
|
|
121
|
+
addGroupAnswerInfo();
|
|
122
|
+
}
|
|
123
|
+
}, intl.formatMessage({
|
|
124
|
+
id: 'group.option.addButton'
|
|
125
|
+
}))));
|
|
204
126
|
}; //
|
|
205
127
|
//
|
|
206
128
|
//
|
|
@@ -213,10 +135,7 @@ const OptionGroupGroupInfo = () => {
|
|
|
213
135
|
bold: true
|
|
214
136
|
}, intl.formatMessage({
|
|
215
137
|
id: 'group.option.title'
|
|
216
|
-
})),
|
|
217
|
-
onSortEnd: onSortEnd,
|
|
218
|
-
useDragHandle: true
|
|
219
|
-
}, React.createElement(OptionGroupGroupList, null)));
|
|
138
|
+
})), renderGroupOptionList(), renderGroupOptionAddButton());
|
|
220
139
|
};
|
|
221
140
|
|
|
222
141
|
export { OptionGroupGroupInfo as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface OptionGroupGroupListItemProps {
|
|
3
|
+
groupId: number;
|
|
4
|
+
groupsCount: number;
|
|
5
|
+
onRemoveOption: () => void;
|
|
6
|
+
}
|
|
7
|
+
declare const OptionGroupGroupListItem: React.FC<OptionGroupGroupListItemProps>;
|
|
8
|
+
export default OptionGroupGroupListItem;
|