@pie-element/charting 7.1.2-next.36 → 7.1.2-next.44

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.
@@ -7,7 +7,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
- exports["default"] = exports.CorrectResponse = void 0;
10
+ exports.getUpdatedCategories = exports["default"] = exports.CorrectResponse = void 0;
11
11
 
12
12
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
13
 
@@ -39,6 +39,8 @@ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
39
39
 
40
40
  var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
41
41
 
42
+ var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
43
+
42
44
  var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));
43
45
 
44
46
  var _excluded = ["editable", "interactive", "deletable"],
@@ -147,6 +149,45 @@ var removeCategory = function removeCategory(correctAnswer, data, positionToRemo
147
149
  return addCategoryProps(correctAnswerData, data);
148
150
  };
149
151
 
152
+ var getUpdatedCategories = function getUpdatedCategories(nextProps, prevProps, prevState) {
153
+ var nextData = nextProps && nextProps.model && nextProps.model.data || [];
154
+ var data = prevProps && prevProps.model && prevProps.model.data || [];
155
+ var nextCorrectAnswerDataCopy = (0, _cloneDeep["default"])(nextProps && nextProps.model && nextProps.model.correctAnswer && nextProps.model.correctAnswer.data || []);
156
+ var categoriesCopy = (0, _cloneDeep["default"])(prevState ? prevState.categories : []);
157
+ var nextCategories = []; // Handle categories insertion in Define Chart
158
+
159
+ if (nextData.length > data.length) {
160
+ nextCategories = insertCategory(nextCorrectAnswerDataCopy, nextData);
161
+ return nextCategories;
162
+ } // Handle categories removal from Define Chart
163
+
164
+
165
+ if (nextData.length < data.length) {
166
+ var removedIndex = data.findIndex(function (item, index) {
167
+ return item.index !== index;
168
+ });
169
+ removedIndex = removedIndex === -1 ? nextData.length : removedIndex;
170
+ nextCategories = removeCategory(categoriesCopy, nextData, removedIndex);
171
+ return nextCategories;
172
+ } // Handle category value or label changes in Define Chart
173
+ // Handle categories update in Define Correct Response Chart
174
+
175
+
176
+ nextCategories = updateCorrectResponseData(nextCorrectAnswerDataCopy, nextData);
177
+ nextCorrectAnswerDataCopy.forEach(function (answer, currentIndex) {
178
+ var dataExists = currentIndex < nextData.length;
179
+ nextCorrectAnswerDataCopy[currentIndex] = {
180
+ editable: dataExists ? nextData[currentIndex].editable : true,
181
+ interactive: dataExists ? nextData[currentIndex].interactive : true,
182
+ label: dataExists && nextData[currentIndex].editable ? answer.label : dataExists ? nextData[currentIndex].label : answer.label,
183
+ value: dataExists && nextData[currentIndex].interactive ? answer.value : dataExists ? nextData[currentIndex].value : answer.value
184
+ };
185
+ });
186
+ return nextCategories;
187
+ };
188
+
189
+ exports.getUpdatedCategories = getUpdatedCategories;
190
+
150
191
  var CorrectResponse = /*#__PURE__*/function (_React$Component) {
151
192
  (0, _inherits2["default"])(CorrectResponse, _React$Component);
152
193
 
@@ -185,75 +226,9 @@ var CorrectResponse = /*#__PURE__*/function (_React$Component) {
185
226
  }
186
227
 
187
228
  (0, _createClass2["default"])(CorrectResponse, [{
188
- key: "getUpdatedCategories",
189
- value: function getUpdatedCategories(nextProps) {
190
- var prevProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.props;
191
- var prevState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.state;
192
- var nextData = nextProps.model.data || [];
193
- var data = prevProps.model.data || [];
194
- var nextCorrectAnswerData = nextProps.model.correctAnswer.data || [];
195
- var categories = prevState ? prevState.categories : [];
196
- var nextCategories = [];
197
-
198
- if (nextData.length > data.length) {
199
- nextCategories = insertCategory(nextCorrectAnswerData, nextData);
200
- }
201
-
202
- if (nextData.length < data.length) {
203
- var removedIndex = nextData.length; // we need to remove the category from the correct answer data and categories, from the same index it was removed from the data
204
- // index is a property of the nextData category
205
-
206
- for (var index = 0; index < nextData.length; index++) {
207
- if (nextData[index].index !== index) {
208
- removedIndex = index;
209
- break;
210
- }
211
- }
212
-
213
- (this.props.model.correctAnswer.data || []).splice(removedIndex, 1);
214
- nextCategories = removeCategory(categories, nextData, removedIndex);
215
- return nextCategories;
216
- }
217
-
218
- if (nextCorrectAnswerData.length > 0 && !(0, _isEqual["default"])(nextCorrectAnswerData, this.props.model.correctAnswer.data)) {
219
- nextCategories = nextCorrectAnswerData.map(function (correct, index) {
220
- return _objectSpread(_objectSpread({}, correct), {}, {
221
- editable: index < data.length ? data[index].editable : true,
222
- interactive: index < data.length ? data[index].interactive : true
223
- });
224
- });
225
- } else if ((0, _isEmpty["default"])(nextCategories)) {
226
- nextCategories = updateCorrectResponseData(nextCorrectAnswerData, nextData);
227
- nextCorrectAnswerData.map(function (answer, currentIndex) {
228
- var dataExists = currentIndex < nextData.length;
229
- var label;
230
- var value;
231
-
232
- if (dataExists) {
233
- label = nextData[currentIndex].editable ? answer.label : nextData[currentIndex].label;
234
- value = nextData[currentIndex].interactive ? answer.value : nextData[currentIndex].value;
235
- } else {
236
- label = answer.label;
237
- value = answer.value;
238
- }
239
-
240
- nextCorrectAnswerData[currentIndex] = {
241
- label: label,
242
- value: value
243
- };
244
- });
245
- }
246
-
247
- if (!(0, _isEqual["default"])(nextCategories, data) || !(0, _isEqual["default"])(nextCorrectAnswerData, prevProps.model.correctAnswer.data) || !(0, _isEqual["default"])(nextCategories, categories) || (0, _isEmpty["default"])(nextCategories) && (0, _isEmpty["default"])(data)) {
248
- return nextCategories;
249
- }
250
-
251
- return null;
252
- }
253
- }, {
254
229
  key: "componentDidMount",
255
230
  value: function componentDidMount() {
256
- var initialCategories = this.getUpdatedCategories(this.props, this.props, null);
231
+ var initialCategories = getUpdatedCategories(this.props, this.props, null);
257
232
  this.setState({
258
233
  categories: initialCategories || updateCorrectResponseData(this.props.model.correctAnswer.data, this.props.model.data)
259
234
  });
@@ -261,15 +236,7 @@ var CorrectResponse = /*#__PURE__*/function (_React$Component) {
261
236
  }, {
262
237
  key: "componentDidUpdate",
263
238
  value: function componentDidUpdate(prevProps, prevState) {
264
- var _this$state$categorie;
265
-
266
- var nextCategories = this.getUpdatedCategories(this.props, prevProps, prevState); // this check is needed when all the categories are removed from Chart1
267
-
268
- if ((nextCategories === null || nextCategories === void 0 ? void 0 : nextCategories.length) === 0 && ((_this$state$categorie = this.state.categories) === null || _this$state$categorie === void 0 ? void 0 : _this$state$categorie.length) === 0 && prevProps.model.data.length > 0) {
269
- this.setState({
270
- categories: nextCategories
271
- });
272
- }
239
+ var nextCategories = getUpdatedCategories(this.props, prevProps, prevState);
273
240
 
274
241
  if (nextCategories && !(0, _isEqual["default"])(nextCategories, this.state.categories)) {
275
242
  this.changeData(nextCategories);
@@ -281,8 +248,6 @@ var CorrectResponse = /*#__PURE__*/function (_React$Component) {
281
248
  }, {
282
249
  key: "render",
283
250
  value: function render() {
284
- var _this2 = this;
285
-
286
251
  var _this$props2 = this.props,
287
252
  classes = _this$props2.classes,
288
253
  model = _this$props2.model,
@@ -325,9 +290,7 @@ var CorrectResponse = /*#__PURE__*/function (_React$Component) {
325
290
  charts: charts,
326
291
  data: categories,
327
292
  title: model.title,
328
- onDataChange: function onDataChange(data) {
329
- return _this2.changeData(data);
330
- },
293
+ onDataChange: this.changeData,
331
294
  addCategoryEnabled: model.addCategoryEnabled,
332
295
  categoryDefaultLabel: studentNewCategoryDefaultLabel,
333
296
  error: error,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/correct-response.jsx"],"names":["styles","theme","container","marginBottom","spacing","unit","display","flex","button","marginTop","cursor","background","palette","grey","padding","width","borderRadius","column","chartError","border","error","main","errorText","fontSize","typography","color","paddingTop","title","addCategoryProps","correctAnswer","data","map","correct","index","editable","length","interactive","deletable","updateCorrectResponseData","correctAnswerData","correctResponseDefinition","forEach","category","currentIndex","label","value","missingCategories","slice","concat","insertCategory","positionToInsert","categoryToInsert","splice","removeCategory","positionToRemove","CorrectResponse","props","model","onChange","keepAttrs","state","categories","nextProps","prevProps","prevState","nextData","nextCorrectAnswerData","nextCategories","removedIndex","answer","dataExists","initialCategories","getUpdatedCategories","setState","changeData","classes","charts","studentNewCategoryDefaultLabel","correctAnswerErrors","mathMlOptions","domain","range","identicalError","categoriesError","name","chartType","graph","addCategoryEnabled","React","Component","PropTypes","object","isRequired","string","func","array"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;;;;;;;;;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS,CAACC,KAAD;AAAA,SAAY;AACzBC,IAAAA,SAAS,EAAE;AACTC,MAAAA,YAAY,EAAEF,KAAK,CAACG,OAAN,CAAcC,IAAd,GAAqB,GAD1B;AAETC,MAAAA,OAAO,EAAE,MAFA;AAGTC,MAAAA,IAAI,EAAE;AAHG,KADc;AAMzBC,IAAAA,MAAM,EAAE;AACNC,MAAAA,SAAS,EAAER,KAAK,CAACG,OAAN,CAAcC,IAAd,GAAqB,CAD1B;AAENK,MAAAA,MAAM,EAAE,SAFF;AAGNC,MAAAA,UAAU,EAAEV,KAAK,CAACW,OAAN,CAAcC,IAAd,CAAmB,GAAnB,CAHN;AAINC,MAAAA,OAAO,EAAEb,KAAK,CAACG,OAAN,CAAcC,IAAd,GAAqB,CAJxB;AAKNU,MAAAA,KAAK,EAAE,aALD;AAMNC,MAAAA,YAAY,EAAE;AANR,KANiB;AAczBC,IAAAA,MAAM,EAAE;AACNV,MAAAA,IAAI,EAAE;AADA,KAdiB;AAiBzBW,IAAAA,UAAU,EAAE;AACVC,MAAAA,MAAM,sBAAelB,KAAK,CAACW,OAAN,CAAcQ,KAAd,CAAoBC,IAAnC;AADI,KAjBa;AAoBzBC,IAAAA,SAAS,EAAE;AACTC,MAAAA,QAAQ,EAAEtB,KAAK,CAACuB,UAAN,CAAiBD,QAAjB,GAA4B,CAD7B;AAETE,MAA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EAAAA,KAAK,EAAEiC,sBAAUC,MAAV,CAAiBC,UAJP;AAKjBlC,EAAAA,QAAQ,EAAEgC,sBAAUI,IAAV,CAAeF,UALR;AAMjBhB,EAAAA,MAAM,EAAEc,sBAAUK,KAND;AAOjB3E,EAAAA,KAAK,EAAEsE,sBAAUG;AAPA,C;;eA0KN,wBAAW7F,MAAX,EAAmBuD,eAAnB,C","sourcesContent":["import * as React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport { Chart } from '@pie-lib/pie-toolbox/charting';\nimport isEqual from 'lodash/isEqual';\nimport isEmpty from 'lodash/isEmpty';\n\nimport Typography from '@material-ui/core/Typography';\n\nconst styles = (theme) => ({\n container: {\n marginBottom: theme.spacing.unit * 2.5,\n display: 'flex',\n flex: 1,\n },\n button: {\n marginTop: theme.spacing.unit * 3,\n cursor: 'pointer',\n background: theme.palette.grey[200],\n padding: theme.spacing.unit * 2,\n width: 'fit-content',\n borderRadius: '4px',\n },\n column: {\n flex: 1,\n },\n chartError: {\n border: `2px solid ${theme.palette.error.main}`,\n },\n errorText: {\n fontSize: theme.typography.fontSize - 2,\n color: theme.palette.error.main,\n paddingTop: theme.spacing.unit,\n },\n title: {\n marginBottom: theme.spacing.unit,\n },\n});\n\nconst addCategoryProps = (correctAnswer, data) =>\n correctAnswer.map((correct, index) => ({\n ...correct,\n editable: index < data.length ? data[index].editable : true,\n interactive: index < data.length ? data[index].interactive : true,\n deletable: index >= data.length ? true : false,\n }));\n\nconst updateCorrectResponseData = (correctAnswer, data) => {\n if (!correctAnswer) {\n return data;\n }\n\n const correctAnswerData = [...correctAnswer];\n let correctResponseDefinition = [];\n\n (data || []).forEach((category, currentIndex) => {\n const editable = category.editable;\n const interactive = category.interactive;\n const label = editable && correctAnswer[currentIndex]?.label ? correctAnswer[currentIndex].label : category.label;\n const value =\n (interactive && correctAnswer[currentIndex]?.value) || (interactive && correctAnswer[currentIndex]?.value == 0)\n ? correctAnswer[currentIndex].value\n : category.value;\n\n correctResponseDefinition[currentIndex] = {\n label: label,\n value: value,\n editable: category.editable,\n interactive: category.interactive,\n };\n });\n\n if (correctResponseDefinition.length < correctAnswer.length) {\n const missingCategories = (correctAnswerData || []).slice(correctResponseDefinition.length, correctAnswer.length);\n\n return addCategoryProps((correctResponseDefinition || []).concat(missingCategories), data);\n }\n\n return correctResponseDefinition;\n};\n\nconst insertCategory = (correctAnswer, data) => {\n const positionToInsert = data.length - 1;\n // eslint-disable-next-line no-unused-vars\n const { editable, interactive, deletable, ...categoryToInsert } = data[data.length - 1];\n\n (correctAnswer || []).splice(positionToInsert, 0, categoryToInsert);\n const correctAnswerData = [...correctAnswer];\n\n return addCategoryProps(correctAnswerData, data);\n};\n\nconst removeCategory = (correctAnswer, data, positionToRemove) => {\n (correctAnswer || []).splice(positionToRemove, 1);\n const correctAnswerData = [...correctAnswer];\n\n return addCategoryProps(correctAnswerData, data);\n};\n\nexport class CorrectResponse extends React.Component {\n static propTypes = {\n classes: PropTypes.object.isRequired,\n correctAnswerErrors: PropTypes.object,\n studentNewCategoryDefaultLabel: PropTypes.string,\n model: PropTypes.object.isRequired,\n onChange: PropTypes.func.isRequired,\n charts: PropTypes.array,\n error: PropTypes.string,\n };\n\n constructor(props) {\n super(props);\n this.state = {\n categories: [],\n };\n }\n\n changeData = (data) => {\n const { model, onChange } = this.props;\n const { correctAnswer } = model || {};\n\n onChange({\n ...model,\n correctAnswer: {\n ...correctAnswer,\n // eslint-disable-next-line no-unused-vars\n data: data.map(({ interactive, editable, index, ...keepAttrs }) => keepAttrs),\n },\n });\n };\n\n getUpdatedCategories(nextProps, prevProps = this.props, prevState = this.state) {\n const nextData = nextProps.model.data || [];\n const data = prevProps.model.data || [];\n const nextCorrectAnswerData = nextProps.model.correctAnswer.data || [];\n const categories = prevState ? prevState.categories : [];\n\n let nextCategories = [];\n if (nextData.length > data.length) {\n nextCategories = insertCategory(nextCorrectAnswerData, nextData);\n }\n\n if (nextData.length < data.length) {\n let removedIndex = nextData.length;\n\n // we need to remove the category from the correct answer data and categories, from the same index it was removed from the data\n // index is a property of the nextData category\n for (let index = 0; index < nextData.length; index++) {\n if (nextData[index].index !== index) {\n removedIndex = index;\n break;\n }\n }\n\n (this.props.model.correctAnswer.data || []).splice(removedIndex, 1);\n nextCategories = removeCategory(categories, nextData, removedIndex);\n return nextCategories;\n }\n\n if (nextCorrectAnswerData.length > 0 && !isEqual(nextCorrectAnswerData, this.props.model.correctAnswer.data)) {\n nextCategories = nextCorrectAnswerData.map((correct, index) => ({\n ...correct,\n editable: index < data.length ? data[index].editable : true,\n interactive: index < data.length ? data[index].interactive : true,\n }));\n } else if (isEmpty(nextCategories)) {\n nextCategories = updateCorrectResponseData(nextCorrectAnswerData, nextData);\n\n nextCorrectAnswerData.map((answer, currentIndex) => {\n const dataExists = currentIndex < nextData.length;\n let label;\n let value;\n\n if (dataExists) {\n label = nextData[currentIndex].editable ? answer.label : nextData[currentIndex].label;\n value = nextData[currentIndex].interactive ? answer.value : nextData[currentIndex].value;\n } else {\n label = answer.label;\n value = answer.value;\n }\n\n nextCorrectAnswerData[currentIndex] = {\n label: label,\n value: value,\n };\n });\n }\n\n if (\n !isEqual(nextCategories, data) ||\n !isEqual(nextCorrectAnswerData, prevProps.model.correctAnswer.data) ||\n !isEqual(nextCategories, categories) ||\n (isEmpty(nextCategories) && isEmpty(data))\n ) {\n return nextCategories;\n }\n\n return null;\n }\n\n componentDidMount() {\n const initialCategories = this.getUpdatedCategories(this.props, this.props, null);\n\n this.setState({\n categories:\n initialCategories || updateCorrectResponseData(this.props.model.correctAnswer.data, this.props.model.data),\n });\n }\n\n componentDidUpdate(prevProps, prevState) {\n const nextCategories = this.getUpdatedCategories(this.props, prevProps, prevState);\n\n // this check is needed when all the categories are removed from Chart1\n if (nextCategories?.length === 0 && this.state.categories?.length === 0 && prevProps.model.data.length > 0) {\n this.setState({ categories: nextCategories });\n }\n\n if (nextCategories && !isEqual(nextCategories, this.state.categories)) {\n this.changeData(nextCategories);\n this.setState({ categories: nextCategories });\n }\n }\n\n render() {\n const { classes, model, charts, error, studentNewCategoryDefaultLabel, correctAnswerErrors, mathMlOptions = {} } = this.props;\n const { categories } = this.state;\n const { domain = {}, range = {} } = model || {};\n const { identicalError, categoriesError } = correctAnswerErrors || {};\n\n return (\n <div>\n <div className={classes.title}>Define Correct Response</div>\n <div className={classes.container}>\n <div className={classes.column} key=\"graph\">\n <Typography component=\"div\" type=\"body1\">\n <span>Use the tools below to define the correct answer.</span>\n </Typography>\n\n <div\n key={`correct-response-graph-${model.correctAnswer.name}`}\n className={identicalError || categoriesError ? classes.chartError : ''}\n >\n <Chart\n chartType={model.chartType}\n size={model.graph}\n domain={domain}\n range={range}\n charts={charts}\n data={categories}\n title={model.title}\n onDataChange={(data) => this.changeData(data)}\n addCategoryEnabled={model.addCategoryEnabled}\n categoryDefaultLabel={studentNewCategoryDefaultLabel}\n error={error}\n mathMlOptions={mathMlOptions}\n />\n </div>\n\n {(identicalError || categoriesError) && (\n <Typography component=\"div\" type=\"body1\" className={classes.errorText}>\n <span>{identicalError || categoriesError}</span>\n </Typography>\n )}\n </div>\n </div>\n </div>\n );\n }\n}\n\nexport default withStyles(styles)(CorrectResponse);\n"],"file":"correct-response.js"}
1
+ {"version":3,"sources":["../src/correct-response.jsx"],"names":["styles","theme","container","marginBottom","spacing","unit","display","flex","button","marginTop","cursor","background","palette","grey","padding","width","borderRadius","column","chartError","border","error","main","errorText","fontSize","typography","color","paddingTop","title","addCategoryProps","correctAnswer","data","map","correct","index","editable","length","interactive","deletable","updateCorrectResponseData","correctAnswerData","correctResponseDefinition","forEach","category","currentIndex","label","value","missingCategories","slice","concat","insertCategory","positionToInsert","categoryToInsert","splice","removeCategory","positionToRemove","getUpdatedCategories","nextProps","prevProps","prevState","nextData","model","nextCorrectAnswerDataCopy","categoriesCopy","categories","nextCategories","removedIndex","findIndex","item","answer","dataExists","CorrectResponse","props","onChange","keepAttrs","state","initialCategories","setState","changeData","classes","charts","studentNewCategoryDefaultLabel","correctAnswerErrors","mathMlOptions","domain","range","identicalError","categoriesError","name","chartType","graph","addCategoryEnabled","React","Component","PropTypes","object","isRequired","string","func","array"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;;;;;;;;;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS,CAACC,KAAD;AAAA,SAAY;AACzBC,IAAAA,SAAS,EAAE;AACTC,MAAAA,YAAY,EAAEF,KAAK,CAACG,OAAN,CAAcC,IAAd,GAAqB,GAD1B;AAETC,MAAAA,OAAO,EAAE,MAFA;AAGTC,MAAAA,IAAI,EAAE;AAHG,KADc;AAMzBC,IAAAA,MAAM,EAAE;AACNC,MAAAA,SAAS,EAAER,KAAK,CAACG,OAAN,CAAcC,IAAd,GAAqB,CAD1B;AAENK,MAAAA,MAAM,EAAE,SAFF;AAGNC,MAAAA,UAAU,EAAEV,KAAK,CAACW,OAAN,CAAcC,IAAd,CAAmB,GAAnB,CAHN;AAINC,MAAAA,OAAO,EAAEb,KAAK,CAACG,OAAN,CAAcC,IAAd,GAAqB,CAJxB;AAKNU,MAAAA,KAAK,EAAE,aALD;AAMNC,MAAAA,YAAY,EAAE;AANR,KANiB;AAczBC,IAAAA,MAAM,EAAE;AACNV,MAAAA,IAAI,EAAE;AADA,KAdiB;AAiBzBW,IAAAA,UAAU,EAAE;AACVC,MAAAA,MAAM,sBAAelB,KAAK,CAACW,OAAN,CAAcQ,KAAd,CAAoBC,IAAnC;AADI,KAjBa;AAoBzBC,IAAAA,SAAS,EAAE;AACTC,MAAAA,QAAQ,EAAEtB,KAAK,CAACuB,UAAN,CAAiBD,QAAjB,GAA4B,CAD7B;AAETE,MAAAA,KAAK,EAAExB,KAAK,CAACW,OAAN,CAAcQ,KAAd,CAAoBC,IAFlB;AAGTK,MAAAA,UAAU,EAAEzB,KAAK,CAACG,OAAN,CAAcC;AAHjB,KApBc;A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AOjB9E,EAAAA,KAAK,EAAEyE,sBAAUG;AAPA,C;;eAyGN,wBAAWhG,MAAX,EAAmBsE,eAAnB,C","sourcesContent":["import * as React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport { Chart } from '@pie-lib/pie-toolbox/charting';\nimport isEqual from 'lodash/isEqual';\nimport isEmpty from 'lodash/isEmpty';\nimport cloneDeep from 'lodash/cloneDeep';\n\nimport Typography from '@material-ui/core/Typography';\n\nconst styles = (theme) => ({\n container: {\n marginBottom: theme.spacing.unit * 2.5,\n display: 'flex',\n flex: 1,\n },\n button: {\n marginTop: theme.spacing.unit * 3,\n cursor: 'pointer',\n background: theme.palette.grey[200],\n padding: theme.spacing.unit * 2,\n width: 'fit-content',\n borderRadius: '4px',\n },\n column: {\n flex: 1,\n },\n chartError: {\n border: `2px solid ${theme.palette.error.main}`,\n },\n errorText: {\n fontSize: theme.typography.fontSize - 2,\n color: theme.palette.error.main,\n paddingTop: theme.spacing.unit,\n },\n title: {\n marginBottom: theme.spacing.unit,\n },\n});\n\nconst addCategoryProps = (correctAnswer, data) =>\n correctAnswer.map((correct, index) => ({\n ...correct,\n editable: index < data.length ? data[index].editable : true,\n interactive: index < data.length ? data[index].interactive : true,\n deletable: index >= data.length ? true : false,\n }));\n\nconst updateCorrectResponseData = (correctAnswer, data) => {\n if (!correctAnswer) {\n return data;\n }\n\n const correctAnswerData = [...correctAnswer];\n let correctResponseDefinition = [];\n\n (data || []).forEach((category, currentIndex) => {\n const editable = category.editable;\n const interactive = category.interactive;\n const label = editable && correctAnswer[currentIndex]?.label ? correctAnswer[currentIndex].label : category.label;\n const value =\n (interactive && correctAnswer[currentIndex]?.value) || (interactive && correctAnswer[currentIndex]?.value == 0)\n ? correctAnswer[currentIndex].value\n : category.value;\n\n correctResponseDefinition[currentIndex] = {\n label: label,\n value: value,\n editable: category.editable,\n interactive: category.interactive,\n };\n });\n\n if (correctResponseDefinition.length < correctAnswer.length) {\n const missingCategories = (correctAnswerData || []).slice(correctResponseDefinition.length, correctAnswer.length);\n\n return addCategoryProps((correctResponseDefinition || []).concat(missingCategories), data);\n }\n\n return correctResponseDefinition;\n};\n\nconst insertCategory = (correctAnswer, data) => {\n const positionToInsert = data.length - 1;\n // eslint-disable-next-line no-unused-vars\n const { editable, interactive, deletable, ...categoryToInsert } = data[data.length - 1];\n\n (correctAnswer || []).splice(positionToInsert, 0, categoryToInsert);\n const correctAnswerData = [...correctAnswer];\n\n return addCategoryProps(correctAnswerData, data);\n};\n\nconst removeCategory = (correctAnswer, data, positionToRemove) => {\n (correctAnswer || []).splice(positionToRemove, 1);\n const correctAnswerData = [...correctAnswer];\n\n return addCategoryProps(correctAnswerData, data);\n};\n\nexport const getUpdatedCategories = (nextProps, prevProps, prevState) => {\n const nextData = (nextProps && nextProps.model && nextProps.model.data) || [];\n const data = (prevProps && prevProps.model && prevProps.model.data) || [];\n const nextCorrectAnswerDataCopy = cloneDeep((nextProps && nextProps.model && nextProps.model.correctAnswer && nextProps.model.correctAnswer.data) || []);\n\n const categoriesCopy = cloneDeep(prevState ? prevState.categories : []);\n\n let nextCategories = [];\n\n // Handle categories insertion in Define Chart\n if (nextData.length > data.length) {\n nextCategories = insertCategory(nextCorrectAnswerDataCopy, nextData);\n return nextCategories;\n }\n\n // Handle categories removal from Define Chart\n if (nextData.length < data.length) {\n let removedIndex = data.findIndex((item, index) => item.index !== index);\n removedIndex = removedIndex === -1 ? nextData.length : removedIndex;\n\n nextCategories = removeCategory(categoriesCopy, nextData, removedIndex);\n return nextCategories;\n }\n\n // Handle category value or label changes in Define Chart\n // Handle categories update in Define Correct Response Chart\n nextCategories = updateCorrectResponseData(nextCorrectAnswerDataCopy, nextData);\n\n nextCorrectAnswerDataCopy.forEach((answer, currentIndex) => {\n const dataExists = currentIndex < nextData.length;\n nextCorrectAnswerDataCopy[currentIndex] = {\n editable: dataExists ? nextData[currentIndex].editable : true,\n interactive: dataExists ? nextData[currentIndex].interactive : true,\n label:\n dataExists && nextData[currentIndex].editable\n ? answer.label\n : dataExists\n ? nextData[currentIndex].label\n : answer.label,\n value:\n dataExists && nextData[currentIndex].interactive\n ? answer.value\n : dataExists\n ? nextData[currentIndex].value\n : answer.value,\n };\n });\n\n return nextCategories;\n};\n\nexport class CorrectResponse extends React.Component {\n static propTypes = {\n classes: PropTypes.object.isRequired,\n correctAnswerErrors: PropTypes.object,\n studentNewCategoryDefaultLabel: PropTypes.string,\n model: PropTypes.object.isRequired,\n onChange: PropTypes.func.isRequired,\n charts: PropTypes.array,\n error: PropTypes.string,\n };\n\n constructor(props) {\n super(props);\n this.state = {\n categories: [],\n };\n }\n\n changeData = (data) => {\n const { model, onChange } = this.props;\n const { correctAnswer } = model || {};\n\n onChange({\n ...model,\n correctAnswer: {\n ...correctAnswer,\n // eslint-disable-next-line no-unused-vars\n data: data.map(({ interactive, editable, index, ...keepAttrs }) => keepAttrs),\n },\n });\n };\n\n componentDidMount() {\n const initialCategories = getUpdatedCategories(this.props, this.props, null);\n\n this.setState({\n categories:\n initialCategories || updateCorrectResponseData(this.props.model.correctAnswer.data, this.props.model.data),\n });\n }\n\n componentDidUpdate(prevProps, prevState) {\n const nextCategories = getUpdatedCategories(this.props, prevProps, prevState);\n\n if (nextCategories && !isEqual(nextCategories, this.state.categories)) {\n this.changeData(nextCategories);\n this.setState({ categories: nextCategories });\n }\n }\n\n render() {\n const {\n classes,\n model,\n charts,\n error,\n studentNewCategoryDefaultLabel,\n correctAnswerErrors,\n mathMlOptions = {},\n } = this.props;\n const { categories } = this.state;\n\n const { domain = {}, range = {} } = model || {};\n const { identicalError, categoriesError } = correctAnswerErrors || {};\n\n return (\n <div>\n <div className={classes.title}>Define Correct Response</div>\n <div className={classes.container}>\n <div className={classes.column} key=\"graph\">\n <Typography component=\"div\" type=\"body1\">\n <span>Use the tools below to define the correct answer.</span>\n </Typography>\n\n <div\n key={`correct-response-graph-${model.correctAnswer.name}`}\n className={identicalError || categoriesError ? classes.chartError : ''}\n >\n <Chart\n chartType={model.chartType}\n size={model.graph}\n domain={domain}\n range={range}\n charts={charts}\n data={categories}\n title={model.title}\n onDataChange={this.changeData}\n addCategoryEnabled={model.addCategoryEnabled}\n categoryDefaultLabel={studentNewCategoryDefaultLabel}\n error={error}\n mathMlOptions={mathMlOptions}\n />\n </div>\n\n {(identicalError || categoriesError) && (\n <Typography component=\"div\" type=\"body1\" className={classes.errorText}>\n <span>{identicalError || categoriesError}</span>\n </Typography>\n )}\n </div>\n </div>\n </div>\n );\n }\n}\n\nexport default withStyles(styles)(CorrectResponse);\n"],"file":"correct-response.js"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "repository": "pie-framework/pie-elements",
7
- "version": "7.1.2-next.36+2bab7efc9",
7
+ "version": "7.1.2-next.44+0e15a9c76",
8
8
  "description": "",
9
9
  "scripts": {
10
10
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "author": "",
24
24
  "license": "ISC",
25
- "gitHead": "2bab7efc9b28299846e506a28fd67395aae5243a",
25
+ "gitHead": "0e15a9c76e19cff2dd791799dbc94b4fdecd2417",
26
26
  "main": "lib/index.js",
27
27
  "module": "src/index.js"
28
28
  }