-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathQuestionItem.js
More file actions
136 lines (109 loc) · 4.32 KB
/
QuestionItem.js
File metadata and controls
136 lines (109 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import {Segment } from 'semantic-ui-react';
//Application
import Nadia from 'src/Application/Nadia';
//component
import QuestionIntType from './QuestionItems/QuestionIntType/QuestionIntType';
import QuestionBoolType from './QuestionItems/QuestionBoolType/QuestionBoolType';
import QuestionDateType from './QuestionItems/QuestionDateType/QuestionDateType';
import QuestionStringType from './QuestionItems/QuestionStringType/QuestionStringType';
import QuestionDoubleType from './QuestionItems/QuestionDoubleType';
import QuestionHashType from './QuestionItems/QuestionHashType';
import QuestionUrlType from './QuestionItems/QuestionUrlType';
import QuestionUuidType from './QuestionItems/QuestionUuidType';
import GoalRuleBoolType from './GoalRuleItems/GoalRuleBoolType';
import GoalRuleDateType from './GoalRuleItems/GoalRuleDateType';
import GoalRuleStringType from './GoalRuleItems/GoalRuleStringType';
export default class QuestionItem extends React.Component {
constructor(props) {
super(props);
}
componentDidMount = () => {
this.setState({questionData: this.props.questionData});
}
// initialise component state
state = {
questionData:null,
}
// prop types and default values
static propTypes = {
questionData: PropTypes.object,
// isGoalRule: PropTypes.boolean,
goalRuleData: PropTypes.object,
}
_onSaveClick=(question, inputValue)=>{
if(this.props.feedAnswer){
this.props.feedAnswer(question, inputValue);
}
}
_displayGoalRule=()=>{
let goalRuleText = this.props.goalRuleData.goalRuleName;
let goalRuleValue = this.props.goalRuleData.goalRuleValue;
let questionItem;
switch(this.props.goalRuleData.goalRuleType)
{
case 'boolean':
questionItem = <GoalRuleBoolType goalRuleName = {goalRuleText} goalRuleValue={goalRuleValue}/>
break;
case 'date':
questionItem = <GoalRuleDateType goalRuleName = {goalRuleText} goalRuleValue={goalRuleValue}/>
break;
case 'uuid':
case 'url':
case 'hash':
case 'double':
case 'integer':
case 'defistring':
case 'string':
questionItem = <GoalRuleStringType goalRuleName = {goalRuleText} goalRuleValue={goalRuleValue}/>
break;
}
return questionItem;
}
_createQuestionItem=()=>{
let questionItem;
let questionText = this.props.questionData.questionText;
switch(this.props.questionData.questionValueType)
{
case 'integer':
questionItem = <QuestionIntType question = {questionText} onSave={this._onSaveClick}/>
break;
case 'boolean':
questionItem = <QuestionBoolType question = {questionText} onSave={this._onSaveClick}/>
break;
case 'date':
questionItem = <QuestionDateType question = {questionText} onSave={this._onSaveClick}/>
break;
case 'defistring':
case 'string':
questionItem = <QuestionStringType question = {questionText} onSave={this._onSaveClick}/>
break;
case 'double':
questionItem = <QuestionDoubleType question = {questionText} onSave={this._onSaveClick}/>
break;
case 'hash':
questionItem = <QuestionHashType question = {questionText} onSave={this._onSaveClick}/>
break;
case 'url':
questionItem = <QuestionUrlType question = {questionText} onSave={this._onSaveClick}/>
break;
case 'uuid':
questionItem = <QuestionUuidType question = {questionText} onSave={this._onSaveClick}/>
break;
}
return questionItem;
}
// component render method
render() {
return (
<Segment className='questionItem'>
{this.props.isGoalRule?
this._displayGoalRule()
:
this._createQuestionItem()}
</Segment>
);
}
}