@pie-element/rubric 1.5.16 → 1.5.17-beta.587

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.
@@ -3,16 +3,16 @@ import React from 'react';
3
3
  import Rubric from '../main';
4
4
  import Link from '@material-ui/core/Link';
5
5
 
6
-
7
6
  describe('rubric viewer', () => {
8
-
9
-
10
- const wrapper = extras => {
11
- const props = {value: {
12
- points: ['nothing right', 'a teeny bit right', 'mostly right', 'bingo'],
13
- excludeZero: false,
14
- ...extras
15
- }};
7
+ const wrapper = (extras) => {
8
+ const props = {
9
+ value: {
10
+ points: ['nothing right', 'a teeny bit right', 'mostly right', 'bingo'],
11
+ sampleAnswers: [null, 'just right', 'not left', null],
12
+ excludeZero: false,
13
+ ...extras,
14
+ },
15
+ };
16
16
 
17
17
  return mount(<Rubric {...props} />);
18
18
  };
@@ -36,12 +36,11 @@ describe('rubric viewer', () => {
36
36
  it('renders correctly with exluded zeroes', () => {
37
37
  let w = wrapper({ excludeZero: true });
38
38
  w.find(Link).simulate('click');
39
- expect(w.find('li').length).toEqual(3);
39
+ expect(w.find('li').length).toEqual(5);
40
40
 
41
41
  w = wrapper({ excludeZero: false });
42
42
  w.find(Link).simulate('click');
43
- expect(w.find('li').length).toEqual(4);
43
+ expect(w.find('li').length).toEqual(6);
44
44
  });
45
45
  });
46
-
47
46
  });
package/src/index.js CHANGED
@@ -3,9 +3,7 @@ import React from 'react';
3
3
  import ReactDOM from 'react-dom';
4
4
  import debug from 'debug';
5
5
 
6
-
7
6
  export default class RubricRender extends HTMLElement {
8
-
9
7
  constructor() {
10
8
  super();
11
9
  debug.log('constructor called');
@@ -28,9 +26,8 @@ export default class RubricRender extends HTMLElement {
28
26
 
29
27
  _render() {
30
28
  if (this._model) {
31
- const el = (
32
- <Rubric value={this._model}/>
33
- );
29
+ const el = <Rubric value={this._model} />;
30
+
34
31
  ReactDOM.render(el, this);
35
32
  }
36
33
  }
package/src/main.jsx CHANGED
@@ -10,6 +10,7 @@ import PropTypes from 'prop-types';
10
10
  export const RubricType = PropTypes.shape({
11
11
  excludeZero: PropTypes.bool,
12
12
  points: PropTypes.arrayOf(PropTypes.string),
13
+ sampleAnswers: PropTypes.arrayOf(PropTypes.string),
13
14
  });
14
15
 
15
16
  class Rubric extends React.Component {
@@ -26,6 +27,7 @@ class Rubric extends React.Component {
26
27
 
27
28
  static propTypes = {
28
29
  classes: PropTypes.object.isRequired,
30
+ animationsDisabled: PropTypes.bool,
29
31
  value: RubricType,
30
32
  };
31
33
 
@@ -43,34 +45,59 @@ class Rubric extends React.Component {
43
45
  };
44
46
 
45
47
  render() {
46
- const { value, classes } = this.props;
48
+ const { value, classes, animationsDisabled } = this.props;
49
+
47
50
  if (value && value.points) {
48
- const points = value.points;
49
- return (
50
- <div className={classes.root}>
51
- <Link href={this.dudUrl} onClick={this.toggleRubric}>
52
- {this.state.linkPrefix} Rubric
53
- </Link>
54
- <Collapse in={this.state.rubricOpen} timeout="auto">
55
- <List component="nav">
56
- {points.map(
57
- (desc, index) =>
58
- this.shouldRenderPoint(index, value) && (
59
- <ListItem key={index}>
51
+ const { points, sampleAnswers } = value;
52
+
53
+ const rubricList = (
54
+ <List component="nav">
55
+ {points
56
+ .slice(0)
57
+ .reverse()
58
+ .map((desc, index) => {
59
+ index = points.length - index - 1;
60
+ return (
61
+ this.shouldRenderPoint(index, value) && (
62
+ <React.Fragment key={index}>
63
+ <ListItem key={`P${index}`}>
60
64
  <ListItemText
61
65
  className={classes.rubricCol}
62
- primary={`${index} PTS`}
63
- />
64
- <ListItemText
65
- primary={
66
- <div dangerouslySetInnerHTML={{ __html: desc }} />
67
- }
66
+ primary={index === 1 ? `${index} PT` : `${index} PTS`}
68
67
  />
68
+ <ListItemText primary={<div dangerouslySetInnerHTML={{ __html: desc }} />} />
69
69
  </ListItem>
70
- )
71
- )}
72
- </List>
73
- </Collapse>
70
+ {sampleAnswers && sampleAnswers[index] && (
71
+ <ListItem key={`S${index}`}>
72
+ <ListItemText
73
+ className={classes.rubricCol}
74
+ style={{ marginLeft: '20px' }}
75
+ primary={'Sample Answer'}
76
+ />
77
+ <ListItemText primary={<div dangerouslySetInnerHTML={{ __html: sampleAnswers[index] }} />} />
78
+ </ListItem>
79
+ )}
80
+ </React.Fragment>
81
+ )
82
+ );
83
+ })}
84
+ </List>
85
+ );
86
+
87
+ return (
88
+ <div className={classes.root}>
89
+ {!animationsDisabled ? (
90
+ <React.Fragment>
91
+ <Link href={this.dudUrl} onClick={this.toggleRubric}>
92
+ {this.state.linkPrefix} Rubric
93
+ </Link>
94
+ <Collapse in={this.state.rubricOpen} timeout="auto">
95
+ {rubricList}
96
+ </Collapse>
97
+ </React.Fragment>
98
+ ) : (
99
+ rubricList
100
+ )}
74
101
  </div>
75
102
  );
76
103
  } else {
@@ -82,6 +109,7 @@ class Rubric extends React.Component {
82
109
  const styles = () => ({
83
110
  rubricCol: {
84
111
  flex: '0 1 auto',
112
+ minWidth: 'fit-content',
85
113
  },
86
114
  });
87
115
 
package/src/print.js ADDED
@@ -0,0 +1,63 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import debounce from 'lodash/debounce';
4
+ import Main from './main';
5
+ import { renderMath } from '@pie-lib/math-rendering';
6
+ import debug from 'debug';
7
+
8
+ const log = debug('pie-element:rubric:print');
9
+
10
+ const preparePrintModel = (model, opts) => {
11
+ const instr = opts.role === 'instructor';
12
+
13
+ if (!instr) {
14
+ return {};
15
+ }
16
+
17
+ model.value = { ...model };
18
+ model.mode = 'evaluate';
19
+ model.animationsDisabled = true;
20
+
21
+ return model;
22
+ };
23
+
24
+ export default class RubricPrint extends HTMLElement {
25
+ constructor() {
26
+ super();
27
+ this._options = null;
28
+ this._model = null;
29
+ this._session = [];
30
+ this._rerender = debounce(
31
+ () => {
32
+ if (this._model && this._session) {
33
+ const printModel = preparePrintModel(this._model, this._options);
34
+
35
+ const element =
36
+ this._options &&
37
+ React.createElement(Main, {
38
+ ...printModel,
39
+ });
40
+
41
+ ReactDOM.render(element, this, () => {
42
+ log('render complete - render math');
43
+ renderMath(this);
44
+ });
45
+ } else {
46
+ log('skip');
47
+ }
48
+ },
49
+ 50,
50
+ { leading: false, trailing: true },
51
+ );
52
+ }
53
+ set options(o) {
54
+ this._options = o;
55
+ }
56
+
57
+ set model(s) {
58
+ this._model = s;
59
+ this._rerender();
60
+ }
61
+
62
+ connectedCallback() {}
63
+ }