| 72 | } |
| 73 | |
| 74 | public validate() { |
| 75 | const { specContext } = this; |
| 76 | const { specCapabilities } = this.props; |
| 77 | const { roles } = specCapabilities; |
| 78 | const required = roles.filter(r => { |
| 79 | switch (typeof r.allowNone) { |
| 80 | case 'boolean': |
| 81 | return !r.allowNone; |
| 82 | case 'undefined': |
| 83 | return true; |
| 84 | case 'function': |
| 85 | return !r.allowNone(specContext); |
| 86 | } |
| 87 | }); |
| 88 | const numeric = roles.filter(r => r.excludeCategoric); |
| 89 | const errors = required |
| 90 | .map( |
| 91 | r => { |
| 92 | if (specContext.specColumns[r.role]) { |
| 93 | return null; |
| 94 | } else { |
| 95 | return `Field ${r.role} is required.`; |
| 96 | } |
| 97 | }, |
| 98 | ) |
| 99 | .concat( |
| 100 | numeric.map( |
| 101 | r => { |
| 102 | if (specContext.specColumns[r.role] && !specContext.specColumns[r.role].quantitative) { |
| 103 | return `Field ${r.role} must be quantitative.`; |
| 104 | } else { |
| 105 | return null; |
| 106 | } |
| 107 | }, |
| 108 | ), |
| 109 | ) |
| 110 | .filter(Boolean); |
| 111 | return errors; |
| 112 | } |
| 113 | |
| 114 | public build(): SpecResult { |
| 115 | const { globalSignals, specContext } = this; |