@coorpacademy/app-review 0.1.9 → 0.1.11
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/es/actions/ui/navigation.d.ts +1 -1
- package/es/fixtures/qcm-slide.js +1 -1
- package/es/helpers/map-api-slide-to-ui.d.ts +8 -0
- package/es/helpers/map-api-slide-to-ui.js +175 -0
- package/es/helpers/test/fixtures/free-text.d.ts +4 -0
- package/es/helpers/test/fixtures/free-text.js +24 -0
- package/es/helpers/test/fixtures/qcm-drag.d.ts +4 -0
- package/es/helpers/test/fixtures/qcm-drag.js +106 -0
- package/es/helpers/test/fixtures/qcm-graphic.d.ts +4 -0
- package/es/helpers/test/fixtures/qcm-graphic.js +70 -0
- package/es/helpers/test/fixtures/qcm.d.ts +4 -0
- package/es/helpers/test/fixtures/qcm.js +99 -0
- package/es/helpers/test/fixtures/select-template.d.ts +4 -0
- package/es/helpers/test/fixtures/select-template.js +88 -0
- package/es/helpers/test/fixtures/slider.d.ts +4 -0
- package/es/helpers/test/fixtures/slider.js +27 -0
- package/es/helpers/test/fixtures/text-template.d.ts +4 -0
- package/es/helpers/test/fixtures/text-template.js +48 -0
- package/es/helpers/test/map-api-slide-to-ui.test.d.ts +1 -0
- package/es/helpers/test/map-api-slide-to-ui.test.js +32 -0
- package/es/index.js +29 -9
- package/es/reducers/ui/navigation.d.ts +1 -1
- package/es/test/index.test.js +18 -15
- package/es/test/util/services.mock.js +2 -32
- package/es/types/common.d.ts +62 -5
- package/es/types/slides.d.ts +27 -16
- package/lib/actions/ui/navigation.d.ts +1 -1
- package/lib/fixtures/qcm-slide.js +1 -1
- package/lib/helpers/map-api-slide-to-ui.d.ts +8 -0
- package/lib/helpers/map-api-slide-to-ui.js +181 -0
- package/lib/helpers/test/fixtures/free-text.d.ts +4 -0
- package/lib/helpers/test/fixtures/free-text.js +24 -0
- package/lib/helpers/test/fixtures/qcm-drag.d.ts +4 -0
- package/lib/helpers/test/fixtures/qcm-drag.js +106 -0
- package/lib/helpers/test/fixtures/qcm-graphic.d.ts +4 -0
- package/lib/helpers/test/fixtures/qcm-graphic.js +70 -0
- package/lib/helpers/test/fixtures/qcm.d.ts +4 -0
- package/lib/helpers/test/fixtures/qcm.js +99 -0
- package/lib/helpers/test/fixtures/select-template.d.ts +4 -0
- package/lib/helpers/test/fixtures/select-template.js +88 -0
- package/lib/helpers/test/fixtures/slider.d.ts +4 -0
- package/lib/helpers/test/fixtures/slider.js +27 -0
- package/lib/helpers/test/fixtures/text-template.d.ts +4 -0
- package/lib/helpers/test/fixtures/text-template.js +48 -0
- package/lib/helpers/test/map-api-slide-to-ui.test.d.ts +1 -0
- package/lib/helpers/test/map-api-slide-to-ui.test.js +43 -0
- package/lib/index.js +29 -9
- package/lib/reducers/ui/navigation.d.ts +1 -1
- package/lib/test/index.test.js +19 -16
- package/lib/test/util/services.mock.js +13 -32
- package/lib/types/common.d.ts +62 -5
- package/lib/types/slides.d.ts +27 -16
- package/package.json +4 -3
- package/src/actions/ui/navigation.ts +1 -1
- package/src/fixtures/qcm-slide.ts +1 -1
- package/src/helpers/map-api-slide-to-ui.ts +253 -0
- package/src/helpers/test/fixtures/free-text.ts +28 -0
- package/src/helpers/test/fixtures/qcm-drag.ts +110 -0
- package/src/helpers/test/fixtures/qcm-graphic.ts +74 -0
- package/src/helpers/test/fixtures/qcm.ts +108 -0
- package/src/helpers/test/fixtures/select-template.ts +92 -0
- package/src/helpers/test/fixtures/slider.ts +31 -0
- package/src/helpers/test/fixtures/text-template.ts +52 -0
- package/src/helpers/test/map-api-slide-to-ui.test.ts +55 -0
- package/src/index.tsx +35 -11
- package/src/reducers/ui/navigation.ts +1 -1
- package/src/test/index.test.tsx +23 -12
- package/src/test/util/services.mock.ts +2 -32
- package/src/types/common.ts +74 -5
- package/src/types/slides.ts +29 -12
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { qcmSlide } from '../../helpers/test/fixtures/qcm';
|
|
1
13
|
export var services = {
|
|
2
14
|
fetchSkills: function () {
|
|
3
15
|
return Promise.resolve([
|
|
@@ -16,38 +28,7 @@ export var services = {
|
|
|
16
28
|
]);
|
|
17
29
|
},
|
|
18
30
|
fetchSlide: function (ref) {
|
|
19
|
-
|
|
20
|
-
return Promise.resolve({
|
|
21
|
-
question: {
|
|
22
|
-
content: {
|
|
23
|
-
choices: [
|
|
24
|
-
{
|
|
25
|
-
selected: false,
|
|
26
|
-
title: 'choix1',
|
|
27
|
-
help: '(help choix1)',
|
|
28
|
-
ariaLabel: '__ariaLabel1',
|
|
29
|
-
onClick: function () { return undefined; }
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
selected: false,
|
|
33
|
-
title: 'choix2',
|
|
34
|
-
help: '(help choix2)',
|
|
35
|
-
ariaLabel: '__ariaLabel2',
|
|
36
|
-
onClick: function () { return undefined; }
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
selected: false,
|
|
40
|
-
title: 'choix3',
|
|
41
|
-
help: '(help choix3)',
|
|
42
|
-
ariaLabel: '__ariaLabel3',
|
|
43
|
-
onClick: function () { return undefined; }
|
|
44
|
-
}
|
|
45
|
-
]
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
klf: '___klf',
|
|
49
|
-
universalRef: ref
|
|
50
|
-
});
|
|
31
|
+
return Promise.resolve(__assign(__assign({}, qcmSlide), { universalRef: ref, id: ref }));
|
|
51
32
|
},
|
|
52
33
|
postProgression: function () {
|
|
53
34
|
return Promise.resolve({
|
package/lib/types/common.d.ts
CHANGED
|
@@ -4,14 +4,71 @@ declare type TemplateContextValues = {
|
|
|
4
4
|
theme?: unknown;
|
|
5
5
|
translations?: unknown;
|
|
6
6
|
};
|
|
7
|
-
export declare type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export declare type ChoiceFromAPI = {
|
|
8
|
+
_id: string;
|
|
9
|
+
id?: string;
|
|
10
|
+
value?: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
type?: 'text' | 'select';
|
|
13
|
+
label?: string;
|
|
14
|
+
items: {
|
|
15
|
+
text: string;
|
|
16
|
+
value: string;
|
|
17
|
+
_id: string;
|
|
18
|
+
}[];
|
|
19
|
+
media?: unknown;
|
|
20
|
+
};
|
|
21
|
+
declare type BaseContent = {
|
|
22
|
+
media?: unknown;
|
|
23
|
+
choices: ChoiceFromAPI[];
|
|
24
|
+
};
|
|
25
|
+
declare type Question = {
|
|
26
|
+
header?: string;
|
|
27
|
+
content: BaseContent;
|
|
28
|
+
explanation?: string;
|
|
29
|
+
};
|
|
30
|
+
export declare type QcmQuestion = Question & {
|
|
31
|
+
type: 'qcm';
|
|
32
|
+
};
|
|
33
|
+
export declare type QcmGraphicQuestion = Question & {
|
|
34
|
+
type: 'qcmGraphic';
|
|
35
|
+
};
|
|
36
|
+
export declare type QcmDragQuestion = Question & {
|
|
37
|
+
type: 'qcmDrag';
|
|
38
|
+
};
|
|
39
|
+
export declare type BasicQuestion = Omit<Question, 'content'> & {
|
|
40
|
+
type: 'basic';
|
|
41
|
+
content: {
|
|
42
|
+
media?: unknown;
|
|
43
|
+
label?: string;
|
|
44
|
+
placeholder?: string;
|
|
45
|
+
id: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export declare type SliderQuestion = Omit<Question, 'content'> & {
|
|
49
|
+
content: {
|
|
50
|
+
media?: unknown;
|
|
51
|
+
unitLabel: string;
|
|
52
|
+
min: number;
|
|
53
|
+
max: number;
|
|
54
|
+
step?: number;
|
|
12
55
|
};
|
|
56
|
+
type: 'slider';
|
|
57
|
+
};
|
|
58
|
+
export declare type TemplateQuestion = Omit<Question, 'content'> & {
|
|
59
|
+
content: BaseContent & {
|
|
60
|
+
template: string;
|
|
61
|
+
};
|
|
62
|
+
type: 'template';
|
|
63
|
+
};
|
|
64
|
+
export declare type SlideFromAPI = {
|
|
65
|
+
question: QcmQuestion | QcmGraphicQuestion | QcmDragQuestion | BasicQuestion | SliderQuestion | TemplateQuestion;
|
|
13
66
|
klf: string;
|
|
14
67
|
universalRef: string;
|
|
68
|
+
tips?: string;
|
|
69
|
+
clue?: string;
|
|
70
|
+
hasClue?: boolean;
|
|
71
|
+
id?: string;
|
|
15
72
|
};
|
|
16
73
|
export declare type ProgressionFromAPI = {
|
|
17
74
|
_id: string;
|
package/lib/types/slides.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export declare type Choice = {
|
|
2
2
|
order?: number;
|
|
3
3
|
selected: boolean;
|
|
4
|
-
title
|
|
5
|
-
help
|
|
4
|
+
title?: string;
|
|
5
|
+
help?: string;
|
|
6
6
|
onClick: Function;
|
|
7
|
+
ariaLabel?: string;
|
|
7
8
|
};
|
|
8
9
|
export declare type QcmDrag = {
|
|
9
10
|
type: 'qcmDrag';
|
|
@@ -12,22 +13,20 @@ export declare type QcmDrag = {
|
|
|
12
13
|
};
|
|
13
14
|
export declare type Qcm = {
|
|
14
15
|
type: 'qcm';
|
|
15
|
-
|
|
16
|
-
ariaLabel: string;
|
|
17
|
-
})[];
|
|
16
|
+
answers: Choice[];
|
|
18
17
|
};
|
|
19
18
|
export declare type QcmGraphic = {
|
|
20
19
|
type: 'qcmGraphic';
|
|
21
|
-
|
|
20
|
+
answers: (Choice & {
|
|
22
21
|
image: string;
|
|
23
22
|
})[];
|
|
24
23
|
};
|
|
25
24
|
export declare type FreeText = {
|
|
26
25
|
type: 'freeText';
|
|
27
26
|
placeholder: string;
|
|
28
|
-
value
|
|
27
|
+
value?: string;
|
|
29
28
|
onChange: Function;
|
|
30
|
-
ariaLabel
|
|
29
|
+
ariaLabel?: string;
|
|
31
30
|
};
|
|
32
31
|
export declare type DropDownOption = {
|
|
33
32
|
name: string;
|
|
@@ -37,26 +36,38 @@ export declare type DropDownOption = {
|
|
|
37
36
|
};
|
|
38
37
|
export declare type DropDown = {
|
|
39
38
|
type: 'dropDown';
|
|
40
|
-
onChange
|
|
39
|
+
onChange?: Function;
|
|
41
40
|
options: DropDownOption[];
|
|
42
|
-
theme
|
|
41
|
+
theme?: 'filter' | 'invalid' | 'header' | 'mooc' | 'question' | 'sort' | 'thematiques' | 'player' | 'template' | 'coorpmanager';
|
|
43
42
|
};
|
|
44
43
|
export declare type QuestionRange = {
|
|
45
44
|
type: 'slider';
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
placeholder?: string;
|
|
46
|
+
onChange?: Function;
|
|
47
|
+
onChangeEnd?: Function;
|
|
48
|
+
multi?: boolean;
|
|
49
49
|
value: number | number[];
|
|
50
50
|
title: string;
|
|
51
51
|
minLabel: string;
|
|
52
52
|
maxLabel: string;
|
|
53
53
|
};
|
|
54
|
+
export declare type TextTemplate = {
|
|
55
|
+
type: 'text';
|
|
56
|
+
name: string;
|
|
57
|
+
placeholder: string;
|
|
58
|
+
value?: string;
|
|
59
|
+
onChange: Function;
|
|
60
|
+
};
|
|
61
|
+
export declare type SelectionTemplate = {
|
|
62
|
+
type: 'select';
|
|
63
|
+
name: string;
|
|
64
|
+
onChange?: Function;
|
|
65
|
+
options?: DropDownOption[];
|
|
66
|
+
};
|
|
54
67
|
export declare type Template = {
|
|
55
68
|
type: 'template';
|
|
56
69
|
template: string;
|
|
57
|
-
|
|
58
|
-
type?: string;
|
|
59
|
-
})[];
|
|
70
|
+
answers: (TextTemplate | SelectionTemplate)[];
|
|
60
71
|
};
|
|
61
72
|
export declare type AnswerUI = {
|
|
62
73
|
model: QcmDrag | Qcm | QcmGraphic | FreeText | DropDown | QuestionRange | Template;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coorpacademy/app-review",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=16.15.0"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"./package.json": "./package.json"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@coorpacademy/components": "10.22.
|
|
43
|
+
"@coorpacademy/components": "10.22.5",
|
|
44
44
|
"@coorpacademy/redux-task": "^1.1.5",
|
|
45
45
|
"cross-fetch": "^3.1.5",
|
|
46
46
|
"jwt-decode": "^3.1.2",
|
|
@@ -76,5 +76,6 @@
|
|
|
76
76
|
"react-dom": "^17.0.2",
|
|
77
77
|
"ts-node": "^10.8.1",
|
|
78
78
|
"typescript": "^4.7.4"
|
|
79
|
-
}
|
|
79
|
+
},
|
|
80
|
+
"gitHead": "e122753738bf826311ebb638b49ac8c6aad0d5e2"
|
|
80
81
|
}
|
|
@@ -4,7 +4,7 @@ export const NAVIGATE_TO = '@@navigation/NAVIGATE_TO';
|
|
|
4
4
|
export const NAVIGATE_BACK = '@@navigation/NAVIGATE_BACK';
|
|
5
5
|
export const START_APP = '@@navigation/START_APP';
|
|
6
6
|
|
|
7
|
-
export type ViewPath = 'skills' | 'onboarding' | 'slides';
|
|
7
|
+
export type ViewPath = 'skills' | 'onboarding' | 'slides' | 'loader';
|
|
8
8
|
|
|
9
9
|
export type NavigateTo = {
|
|
10
10
|
type: '@@navigation/NAVIGATE_TO';
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import {
|
|
2
|
+
concat,
|
|
3
|
+
divide,
|
|
4
|
+
get,
|
|
5
|
+
getOr,
|
|
6
|
+
head,
|
|
7
|
+
includes,
|
|
8
|
+
indexOf,
|
|
9
|
+
isEmpty,
|
|
10
|
+
map,
|
|
11
|
+
noop,
|
|
12
|
+
pipe,
|
|
13
|
+
rangeStep,
|
|
14
|
+
size,
|
|
15
|
+
toInteger
|
|
16
|
+
} from 'lodash/fp';
|
|
17
|
+
import {
|
|
18
|
+
AnswerUI,
|
|
19
|
+
FreeText,
|
|
20
|
+
Qcm,
|
|
21
|
+
QcmDrag,
|
|
22
|
+
QcmGraphic,
|
|
23
|
+
QuestionRange,
|
|
24
|
+
SelectionTemplate,
|
|
25
|
+
Template,
|
|
26
|
+
TextTemplate
|
|
27
|
+
} from '../types/slides';
|
|
28
|
+
import {
|
|
29
|
+
ChoiceFromAPI,
|
|
30
|
+
QcmDragQuestion,
|
|
31
|
+
QcmGraphicQuestion,
|
|
32
|
+
QcmQuestion,
|
|
33
|
+
SlideFromAPI,
|
|
34
|
+
SliderQuestion,
|
|
35
|
+
TemplateQuestion
|
|
36
|
+
} from '../types/common';
|
|
37
|
+
|
|
38
|
+
type UiUtils = {translate: (text: string) => string};
|
|
39
|
+
|
|
40
|
+
const qcmProps = (question: QcmQuestion): Qcm => {
|
|
41
|
+
// TODO: EDIT_CHOICES -> getAnswerValues
|
|
42
|
+
const answers: string[] = [];
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
type: 'qcm',
|
|
46
|
+
answers: map(
|
|
47
|
+
choice => ({
|
|
48
|
+
title: choice.label,
|
|
49
|
+
selected: includes(choice.label, answers),
|
|
50
|
+
// TODO: EDIT_CHOICES
|
|
51
|
+
onClick: noop,
|
|
52
|
+
ariaLabel: choice.label
|
|
53
|
+
}),
|
|
54
|
+
// TODO: EDIT_CHOICES -> getChoices
|
|
55
|
+
question.content.choices
|
|
56
|
+
)
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const qcmDragProps = (question: QcmDragQuestion): QcmDrag => {
|
|
61
|
+
// mock the answers
|
|
62
|
+
// TODO: EDIT_CHOICES -> getAnswerValues
|
|
63
|
+
const answers: string[] = [];
|
|
64
|
+
return {
|
|
65
|
+
type: 'qcmDrag',
|
|
66
|
+
answers: map(choice => {
|
|
67
|
+
const indexInAnswer = indexOf(choice.label, answers);
|
|
68
|
+
return {
|
|
69
|
+
title: choice.label,
|
|
70
|
+
selected: indexInAnswer !== -1,
|
|
71
|
+
order: indexInAnswer,
|
|
72
|
+
// TODO: EDIT_CHOICES
|
|
73
|
+
onClick: noop
|
|
74
|
+
};
|
|
75
|
+
// TODO: EDIT_CHOICES -> getChoices
|
|
76
|
+
}, question.content.choices)
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const qcmGraphicProps = (question: QcmGraphicQuestion): QcmGraphic => {
|
|
81
|
+
// mock the answers
|
|
82
|
+
// TODO: EDIT_CHOICES -> getAnswerValues
|
|
83
|
+
const answers: string[] = [];
|
|
84
|
+
return {
|
|
85
|
+
type: 'qcmGraphic',
|
|
86
|
+
answers: map(
|
|
87
|
+
choice => ({
|
|
88
|
+
title: choice.label,
|
|
89
|
+
image: get('media.src.0.url', choice),
|
|
90
|
+
selected: includes(choice.label, answers),
|
|
91
|
+
// TODO: EDIT_CHOICES
|
|
92
|
+
onClick: noop
|
|
93
|
+
}),
|
|
94
|
+
// TODO: EDIT_CHOICES -> getChoices
|
|
95
|
+
question.content.choices
|
|
96
|
+
)
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const templateTextProps =
|
|
101
|
+
(uiUtils: UiUtils) =>
|
|
102
|
+
(choice: ChoiceFromAPI, index: number): TextTemplate => {
|
|
103
|
+
const {translate} = uiUtils;
|
|
104
|
+
// TODO: EDIT_CHOICES -> getAnswerValues
|
|
105
|
+
const answers: string[] = [];
|
|
106
|
+
return {
|
|
107
|
+
type: 'text',
|
|
108
|
+
name: getOr('', 'name', choice),
|
|
109
|
+
placeholder: translate('Type here'),
|
|
110
|
+
value: get(index, answers),
|
|
111
|
+
// TODO: EDIT_CHOICES
|
|
112
|
+
onChange: noop
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// const getItemText = (item: ChoiceFromAPI['items'][0]): item['text'] is string =>
|
|
117
|
+
|
|
118
|
+
const templateSelectProps = (uiUtils: UiUtils) => {
|
|
119
|
+
return (choice: ChoiceFromAPI, index: number): SelectionTemplate => {
|
|
120
|
+
const {translate} = uiUtils;
|
|
121
|
+
// TODO: EDIT_CHOICES -> getAnswerValues
|
|
122
|
+
const answers: string[] = [];
|
|
123
|
+
const answer = get(index, answers);
|
|
124
|
+
const temporaryOption = {
|
|
125
|
+
name: translate('Select an answer'),
|
|
126
|
+
value: '',
|
|
127
|
+
validOption: false,
|
|
128
|
+
selected: true
|
|
129
|
+
};
|
|
130
|
+
const selectOptions = choice.items.map(item => {
|
|
131
|
+
const itemText = getOr('', 'text', item);
|
|
132
|
+
return {
|
|
133
|
+
name: itemText,
|
|
134
|
+
value: itemText,
|
|
135
|
+
validOption: true,
|
|
136
|
+
selected: itemText === answer
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
type: 'select',
|
|
142
|
+
name: getOr('', 'name', choice),
|
|
143
|
+
// TODO: EDIT_CHOICES
|
|
144
|
+
onChange: noop,
|
|
145
|
+
options: isEmpty(answer) ? concat([temporaryOption], selectOptions) : selectOptions
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const templateProps = (uiUtils: UiUtils): ((question: TemplateQuestion) => Template) => {
|
|
151
|
+
const templateTextProps_ = templateTextProps(uiUtils);
|
|
152
|
+
const templateSelectProps_ = templateSelectProps(uiUtils);
|
|
153
|
+
|
|
154
|
+
return question => {
|
|
155
|
+
// TODO: EDIT_CHOICES -> getChoices
|
|
156
|
+
const choices = question.content.choices;
|
|
157
|
+
return {
|
|
158
|
+
type: 'template',
|
|
159
|
+
template: get('content.template', question),
|
|
160
|
+
answers: choices.map((choice, index) =>
|
|
161
|
+
choice.type === 'text'
|
|
162
|
+
? templateTextProps_(choice, index)
|
|
163
|
+
: templateSelectProps_(choice, index)
|
|
164
|
+
)
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const basicProps = (uiUtils: UiUtils): (() => FreeText) => {
|
|
170
|
+
const {translate} = uiUtils;
|
|
171
|
+
// TODO: EDIT_CHOICES -> getAnswerValues
|
|
172
|
+
const answers: string[] = [];
|
|
173
|
+
|
|
174
|
+
return () => {
|
|
175
|
+
return {
|
|
176
|
+
type: 'freeText',
|
|
177
|
+
placeholder: translate('Type here'),
|
|
178
|
+
value: head(answers),
|
|
179
|
+
// TODO: EDIT_CHOICES
|
|
180
|
+
onChange: noop
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const sliderProps = (question: SliderQuestion): QuestionRange => {
|
|
186
|
+
const values: number[] = rangeStep(
|
|
187
|
+
getOr(1, 'content.step', question),
|
|
188
|
+
getOr(Number.NaN, 'content.min', question),
|
|
189
|
+
getOr(Number.NaN, 'content.max', question) + 1
|
|
190
|
+
// Lodash doesn't infere the type very well here
|
|
191
|
+
) as unknown as number[];
|
|
192
|
+
|
|
193
|
+
// TODO: EDIT_CHOICES -> getAnswerValues
|
|
194
|
+
const answers: string[] = [];
|
|
195
|
+
|
|
196
|
+
const stateValue = head(answers);
|
|
197
|
+
const currentValue = toInteger(stateValue);
|
|
198
|
+
|
|
199
|
+
const indexValue = indexOf(currentValue, values);
|
|
200
|
+
const sliderPosition = divide(indexValue, size(values) - 1);
|
|
201
|
+
|
|
202
|
+
const unitLabel = get('question.content.unitLabel', question);
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
type: 'slider',
|
|
206
|
+
placeholder: question.explanation,
|
|
207
|
+
minLabel: `${question.content.min} ${unitLabel}`,
|
|
208
|
+
maxLabel: `${question.content.max} ${unitLabel}`,
|
|
209
|
+
title: `${currentValue} ${question.content.unitLabel}`,
|
|
210
|
+
value: sliderPosition,
|
|
211
|
+
// TODO: EDIT_CHOICES
|
|
212
|
+
onChange: noop
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
export const getQuestionType = (slide: SlideFromAPI): SlideFromAPI['question']['type'] =>
|
|
217
|
+
slide.question.type;
|
|
218
|
+
|
|
219
|
+
export const mapApiSlideToUi = (
|
|
220
|
+
uiUtils: UiUtils
|
|
221
|
+
): ((slide: SlideFromAPI) => AnswerUI['model'] | void) => {
|
|
222
|
+
const basicProps_ = basicProps(uiUtils);
|
|
223
|
+
const templateProps_ = templateProps(uiUtils);
|
|
224
|
+
|
|
225
|
+
return (slide: SlideFromAPI): AnswerUI['model'] | void => {
|
|
226
|
+
if (!slide) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const type = getQuestionType(slide);
|
|
230
|
+
switch (type) {
|
|
231
|
+
case 'qcm':
|
|
232
|
+
return pipe(get('question'), qcmProps)(slide);
|
|
233
|
+
|
|
234
|
+
case 'qcmGraphic':
|
|
235
|
+
return pipe(get('question'), qcmGraphicProps)(slide);
|
|
236
|
+
|
|
237
|
+
case 'qcmDrag':
|
|
238
|
+
return pipe(get('question'), qcmDragProps)(slide);
|
|
239
|
+
|
|
240
|
+
case 'basic':
|
|
241
|
+
return basicProps_();
|
|
242
|
+
|
|
243
|
+
case 'template':
|
|
244
|
+
return pipe(get('question'), templateProps_)(slide);
|
|
245
|
+
|
|
246
|
+
case 'slider':
|
|
247
|
+
return pipe(get('question'), sliderProps)(slide);
|
|
248
|
+
|
|
249
|
+
default:
|
|
250
|
+
throw new Error(`${type} is not an handled question.type`);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import noop from 'lodash/fp/noop';
|
|
2
|
+
import {FreeText} from '../../../types/slides';
|
|
3
|
+
import {SlideFromAPI} from '../../../types/common';
|
|
4
|
+
|
|
5
|
+
export const freeTextSlide: SlideFromAPI = {
|
|
6
|
+
id: 'sli_E1Pcl-XAYbi',
|
|
7
|
+
universalRef: 'sli_E1Pcl-XAYbi',
|
|
8
|
+
question: {
|
|
9
|
+
type: 'basic',
|
|
10
|
+
header: 'sli_E1Pcl-XAYbi.header',
|
|
11
|
+
explanation: 'sli_E1Pcl-XAYbi.explanation',
|
|
12
|
+
content: {
|
|
13
|
+
label: 'sli_E1Pcl-XAYbi.label',
|
|
14
|
+
placeholder: 'sli_E1Pcl-XAYbi.placeholder',
|
|
15
|
+
id: 'sli_E1Pcl-XAYbi.choice_1'
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
clue: 'sli_E1Pcl-XAYbi.clue',
|
|
19
|
+
klf: 'sli_E1Pcl-XAYbi.klf',
|
|
20
|
+
tips: 'sli_E1Pcl-XAYbi.tips'
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const freeTextUISlide: FreeText = {
|
|
24
|
+
type: 'freeText',
|
|
25
|
+
placeholder: 'Type here',
|
|
26
|
+
value: undefined,
|
|
27
|
+
onChange: noop
|
|
28
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import noop from 'lodash/fp/noop';
|
|
2
|
+
import {QcmDrag} from '../../../types/slides';
|
|
3
|
+
import {SlideFromAPI} from '../../../types/common';
|
|
4
|
+
|
|
5
|
+
export const qcmDragSlide: SlideFromAPI = {
|
|
6
|
+
id: 'sli_419IlQQnf',
|
|
7
|
+
universalRef: 'sli_419IlQQnf',
|
|
8
|
+
question: {
|
|
9
|
+
type: 'qcmDrag',
|
|
10
|
+
header: 'sli_419IlQQnf.header',
|
|
11
|
+
explanation: 'sli_419IlQQnf.explanation',
|
|
12
|
+
content: {
|
|
13
|
+
choices: [
|
|
14
|
+
{
|
|
15
|
+
media: {
|
|
16
|
+
src: [],
|
|
17
|
+
posters: [],
|
|
18
|
+
subtitles: []
|
|
19
|
+
},
|
|
20
|
+
_id: '62b1ba3ec4f4015504212571',
|
|
21
|
+
label: 'sli_419IlQQnf.choice_4kWwlQXhG',
|
|
22
|
+
value: 'sli_419IlQQnf.choice_4kWwlQXhG',
|
|
23
|
+
items: []
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
media: {
|
|
27
|
+
src: [],
|
|
28
|
+
posters: [],
|
|
29
|
+
subtitles: []
|
|
30
|
+
},
|
|
31
|
+
_id: '62b1ba3ec4f4015504212572',
|
|
32
|
+
label: 'sli_419IlQQnf.choice_NJxbwgXm2G',
|
|
33
|
+
value: 'sli_419IlQQnf.choice_NJxbwgXm2G',
|
|
34
|
+
items: []
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
media: {
|
|
38
|
+
src: [],
|
|
39
|
+
posters: [],
|
|
40
|
+
subtitles: []
|
|
41
|
+
},
|
|
42
|
+
_id: '62b1ba3ec4f4015504212573',
|
|
43
|
+
label: 'sli_419IlQQnf.choice_41fwgQXnf',
|
|
44
|
+
value: 'sli_419IlQQnf.choice_41fwgQXnf',
|
|
45
|
+
items: []
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
media: {
|
|
49
|
+
src: [],
|
|
50
|
+
posters: [],
|
|
51
|
+
subtitles: []
|
|
52
|
+
},
|
|
53
|
+
_id: '62b1ba3ec4f4015504212574',
|
|
54
|
+
label: 'sli_419IlQQnf.choice_VJmweQ7nz',
|
|
55
|
+
value: 'sli_419IlQQnf.choice_VJmweQ7nz',
|
|
56
|
+
items: []
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
media: {
|
|
60
|
+
src: [],
|
|
61
|
+
posters: [],
|
|
62
|
+
subtitles: []
|
|
63
|
+
},
|
|
64
|
+
_id: '62b1ba3ec4f4015504212575',
|
|
65
|
+
label: 'sli_419IlQQnf.choice_4kDDgXQhz',
|
|
66
|
+
value: 'sli_419IlQQnf.choice_4kDDgXQhz',
|
|
67
|
+
items: []
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
klf: 'sli_419IlQQnf.klf',
|
|
73
|
+
tips: 'sli_419IlQQnf.tips'
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const qcmDragUISlide: QcmDrag = {
|
|
77
|
+
type: 'qcmDrag',
|
|
78
|
+
answers: [
|
|
79
|
+
{
|
|
80
|
+
title: 'sli_419IlQQnf.choice_4kWwlQXhG',
|
|
81
|
+
selected: false,
|
|
82
|
+
order: -1,
|
|
83
|
+
onClick: noop
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
title: 'sli_419IlQQnf.choice_NJxbwgXm2G',
|
|
87
|
+
selected: false,
|
|
88
|
+
order: -1,
|
|
89
|
+
onClick: noop
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
title: 'sli_419IlQQnf.choice_41fwgQXnf',
|
|
93
|
+
selected: false,
|
|
94
|
+
order: -1,
|
|
95
|
+
onClick: noop
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
title: 'sli_419IlQQnf.choice_VJmweQ7nz',
|
|
99
|
+
selected: false,
|
|
100
|
+
order: -1,
|
|
101
|
+
onClick: noop
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
title: 'sli_419IlQQnf.choice_4kDDgXQhz',
|
|
105
|
+
selected: false,
|
|
106
|
+
order: -1,
|
|
107
|
+
onClick: noop
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
};
|