2019-01-13 17:16:22 -07:00
|
|
|
import * as React from "react";
|
2019-10-21 09:47:13 -06:00
|
|
|
import { Row, Col, FBSelect } from "../../ui";
|
2019-01-16 18:51:25 -07:00
|
|
|
import { locationFormList, NO_VALUE_SELECTED_DDI } from "./location_form_list";
|
2019-02-22 19:09:40 -07:00
|
|
|
import { convertDDItoVariable } from "../locals_list/handle_select";
|
2019-01-13 17:16:22 -07:00
|
|
|
import {
|
2019-02-22 19:09:40 -07:00
|
|
|
LocationFormProps, PARENT, AllowedVariableNodes, VariableNode,
|
2019-01-13 17:16:22 -07:00
|
|
|
} from "../locals_list/locals_list_support";
|
|
|
|
import {
|
2019-06-06 17:54:48 -06:00
|
|
|
determineVector, determineDropdown, SequenceMeta, determineVarDDILabel,
|
2019-01-13 17:16:22 -07:00
|
|
|
} from "../../resources/sequence_meta";
|
|
|
|
import { ResourceIndex, UUID } from "../../resources/interfaces";
|
2019-02-22 19:09:40 -07:00
|
|
|
import { DefaultValueForm } from "./default_value_form";
|
2019-04-02 13:59:37 -06:00
|
|
|
import { t } from "../../i18next_wrapper";
|
2019-06-06 17:54:48 -06:00
|
|
|
import { CoordinateInputBoxes } from "./location_form_coordinate_input_boxes";
|
2019-01-13 17:16:22 -07:00
|
|
|
|
|
|
|
/**
|
2019-02-22 19:09:40 -07:00
|
|
|
* If a variable with a matching label exists in local parameter applications
|
2019-01-13 17:16:22 -07:00
|
|
|
* (step body, etc.), use it instead of the one in scope declarations.
|
|
|
|
*/
|
2019-02-22 19:09:40 -07:00
|
|
|
const maybeUseStepData = ({ resources, bodyVariables, variable, uuid }: {
|
2019-01-13 17:16:22 -07:00
|
|
|
resources: ResourceIndex,
|
2019-02-22 19:09:40 -07:00
|
|
|
bodyVariables: VariableNode[] | undefined,
|
2019-01-13 17:16:22 -07:00
|
|
|
variable: SequenceMeta,
|
|
|
|
uuid: UUID,
|
|
|
|
}): SequenceMeta => {
|
2019-02-22 19:09:40 -07:00
|
|
|
if (bodyVariables) {
|
|
|
|
const executeStepData = bodyVariables
|
2019-01-13 17:16:22 -07:00
|
|
|
.filter(v => v.args.label === variable.celeryNode.args.label)[0];
|
|
|
|
if (executeStepData) {
|
|
|
|
return {
|
|
|
|
celeryNode: executeStepData,
|
|
|
|
vector: determineVector(executeStepData, resources, uuid),
|
2019-06-04 16:07:52 -06:00
|
|
|
dropdown: determineDropdown(executeStepData, resources, uuid),
|
2019-01-13 17:16:22 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return variable;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2019-06-06 17:54:48 -06:00
|
|
|
* Form with an "import from" dropdown and coordinate input boxes.
|
2019-01-13 17:16:22 -07:00
|
|
|
* Can be used to set a specific value, import a value, or declare a variable.
|
|
|
|
*/
|
|
|
|
export const LocationForm =
|
|
|
|
(props: LocationFormProps) => {
|
2019-06-06 17:54:48 -06:00
|
|
|
const { sequenceUuid, resources, bodyVariables, variable,
|
2019-10-22 10:03:00 -06:00
|
|
|
allowedVariableNodes, hideGroups } = props;
|
2019-06-06 17:54:48 -06:00
|
|
|
const { celeryNode, dropdown, vector } = maybeUseStepData({
|
|
|
|
resources, bodyVariables, variable, uuid: sequenceUuid
|
|
|
|
});
|
2020-04-23 13:11:25 -06:00
|
|
|
const displayVariables = allowedVariableNodes !== AllowedVariableNodes.variable;
|
2019-06-14 16:59:11 -06:00
|
|
|
const headerForm = allowedVariableNodes === AllowedVariableNodes.parameter;
|
|
|
|
const variableListItems = displayVariables ? [PARENT(determineVarDDILabel({
|
|
|
|
label: "parent", resources, uuid: sequenceUuid, forceExternal: headerForm
|
|
|
|
}))] : [];
|
2020-04-23 13:11:25 -06:00
|
|
|
const displayGroups = !hideGroups;
|
2019-10-22 10:03:00 -06:00
|
|
|
const unfiltered = locationFormList(resources, variableListItems, displayGroups);
|
2019-10-21 09:47:13 -06:00
|
|
|
const list = props.customFilterRule ?
|
|
|
|
unfiltered.filter(props.customFilterRule) : unfiltered;
|
2019-01-13 17:16:22 -07:00
|
|
|
/** Variable name. */
|
|
|
|
const { label } = celeryNode.args;
|
2019-06-21 15:46:11 -06:00
|
|
|
if (variable.default) {
|
|
|
|
const defaultDDI = determineDropdown(variable.celeryNode, resources);
|
|
|
|
defaultDDI.label = `${t("Default value")} - ${defaultDDI.label}`;
|
|
|
|
list.unshift(defaultDDI);
|
|
|
|
}
|
2019-02-22 19:09:40 -07:00
|
|
|
const formTitleWithType =
|
|
|
|
props.hideVariableLabel ? t("Location") : `${label} (${t("Location")})`;
|
|
|
|
const formTitle = props.hideTypeLabel ? label : formTitleWithType;
|
2019-01-13 17:16:22 -07:00
|
|
|
return <div className="location-form">
|
2019-09-13 12:02:09 -06:00
|
|
|
{!props.hideHeader &&
|
2019-09-07 05:01:44 -06:00
|
|
|
<div className="location-form-header">
|
|
|
|
<label>{formTitle}</label>
|
|
|
|
{props.collapsible &&
|
|
|
|
<i className={`fa fa-caret-${props.collapsed ? "down" : "up"}`}
|
|
|
|
onClick={props.toggleVarShow} />}
|
|
|
|
</div>}
|
2019-04-09 19:32:18 -06:00
|
|
|
{!props.collapsed &&
|
|
|
|
<div className="location-form-content">
|
|
|
|
<Row>
|
|
|
|
<Col xs={12}>
|
|
|
|
<FBSelect
|
2019-06-06 17:54:48 -06:00
|
|
|
key={props.locationDropdownKey}
|
2019-04-09 19:32:18 -06:00
|
|
|
list={list}
|
2019-06-14 16:59:11 -06:00
|
|
|
selectedItem={dropdown}
|
2019-04-09 19:32:18 -06:00
|
|
|
customNullLabel={NO_VALUE_SELECTED_DDI().label}
|
2019-09-26 08:24:26 -06:00
|
|
|
onChange={ddi => {
|
2019-09-26 14:07:51 -06:00
|
|
|
props.onChange(convertDDItoVariable({
|
2019-09-26 14:48:10 -06:00
|
|
|
identifierLabel: label,
|
2019-09-26 14:07:51 -06:00
|
|
|
allowedVariableNodes,
|
|
|
|
dropdown: ddi
|
|
|
|
}));
|
2019-09-26 08:24:26 -06:00
|
|
|
}} />
|
2019-04-09 19:32:18 -06:00
|
|
|
</Col>
|
|
|
|
</Row>
|
2019-06-06 17:54:48 -06:00
|
|
|
<CoordinateInputBoxes
|
|
|
|
variableNode={celeryNode}
|
|
|
|
vector={vector}
|
|
|
|
width={props.width}
|
|
|
|
onChange={props.onChange} />
|
2019-04-09 19:32:18 -06:00
|
|
|
<DefaultValueForm
|
2019-10-24 16:56:55 -06:00
|
|
|
key={props.locationDropdownKey}
|
2019-04-09 19:32:18 -06:00
|
|
|
variableNode={celeryNode}
|
|
|
|
resources={resources}
|
2019-06-06 17:54:48 -06:00
|
|
|
onChange={props.onChange} />
|
2019-04-09 19:32:18 -06:00
|
|
|
</div>}
|
2019-01-13 17:16:22 -07:00
|
|
|
</div>;
|
|
|
|
};
|