|
@@ -1,7 +1,14 @@
|
|
|
import React, { Component } from "react";
|
|
import React, { Component } from "react";
|
|
|
import styled from "styled-components";
|
|
import styled from "styled-components";
|
|
|
|
|
|
|
|
-import { Section, FormElement } from "shared/types";
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ Section,
|
|
|
|
|
+ FormElement,
|
|
|
|
|
+ ShowIf,
|
|
|
|
|
+ ShowIfOr,
|
|
|
|
|
+ ShowIfAnd,
|
|
|
|
|
+ ShowIfNot,
|
|
|
|
|
+} from "shared/types";
|
|
|
import { Context } from "shared/Context";
|
|
import { Context } from "shared/Context";
|
|
|
|
|
|
|
|
import CheckboxRow from "./CheckboxRow";
|
|
import CheckboxRow from "./CheckboxRow";
|
|
@@ -305,17 +312,45 @@ export default class ValuesForm extends Component<PropsType, StateType> {
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ evalShowIf = (vals: ShowIf): boolean => {
|
|
|
|
|
+ if (!vals) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (typeof vals == "string") {
|
|
|
|
|
+ return !!this.props.metaState[vals]?.value;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ((vals as ShowIfOr).or) {
|
|
|
|
|
+ vals = vals as ShowIfOr;
|
|
|
|
|
+ for (let i = 0; i < vals.or.length; i++) {
|
|
|
|
|
+ if (this.evalShowIf(vals.or[i])) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ((vals as ShowIfAnd).and) {
|
|
|
|
|
+ vals = vals as ShowIfAnd;
|
|
|
|
|
+ for (let i = 0; i < vals.and.length; i++) {
|
|
|
|
|
+ if (!this.evalShowIf(vals.and[i])) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ((vals as ShowIfNot).not) {
|
|
|
|
|
+ vals = vals as ShowIfNot;
|
|
|
|
|
+ return !this.evalShowIf(vals.not);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
renderFormContents = () => {
|
|
renderFormContents = () => {
|
|
|
if (this.props.metaState) {
|
|
if (this.props.metaState) {
|
|
|
return this.props.sections?.map((section: Section, i: number) => {
|
|
return this.props.sections?.map((section: Section, i: number) => {
|
|
|
// Hide collapsible section if deciding field is false
|
|
// Hide collapsible section if deciding field is false
|
|
|
- if (section.show_if) {
|
|
|
|
|
- if (
|
|
|
|
|
- !this.props.metaState[section.show_if] ||
|
|
|
|
|
- this.props.metaState[section.show_if].value === false
|
|
|
|
|
- ) {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (section.show_if && !this.evalShowIf(section.show_if)) {
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return <div key={i}>{this.renderSection(section)}</div>;
|
|
return <div key={i}>{this.renderSection(section)}</div>;
|