Possible fix- `customFilterRule` prop.
parent
da5820f23b
commit
638821cf66
|
@ -39,6 +39,7 @@ describe("<LocalsList/>", () => {
|
|||
onChange: jest.fn(),
|
||||
shouldDisplay: jest.fn(),
|
||||
allowedVariableNodes: AllowedVariableNodes.parameter,
|
||||
customFilterRule: undefined
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ describe("<LocationForm/>", () => {
|
|||
onChange: jest.fn(),
|
||||
shouldDisplay: jest.fn(),
|
||||
allowedVariableNodes: AllowedVariableNodes.parameter,
|
||||
customFilterRule: undefined
|
||||
});
|
||||
|
||||
it("renders correct UI components", () => {
|
||||
|
@ -44,7 +45,7 @@ describe("<LocationForm/>", () => {
|
|||
|
||||
expect(selects.length).toBe(1);
|
||||
const select = selects.first().props();
|
||||
const choices = locationFormList(p.resources, [PARENT("")], true);
|
||||
const choices = locationFormList(p.resources, [PARENT("")]);
|
||||
const actualLabels = select.list.map(x => x.label).sort();
|
||||
const expectedLabels = choices.map(x => x.label).sort();
|
||||
const diff = difference(actualLabels, expectedLabels);
|
||||
|
@ -116,7 +117,6 @@ describe("<LocationForm/>", () => {
|
|||
it("shows groups in dropdown", () => {
|
||||
const p = fakeProps();
|
||||
p.shouldDisplay = () => true;
|
||||
p.hideGroups = false;
|
||||
const wrapper = shallow(<LocationForm {...p} />);
|
||||
expect(wrapper.find(FBSelect).first().props().list).toContainEqual({
|
||||
headingId: "Coordinate",
|
||||
|
|
|
@ -6,7 +6,7 @@ import { LocationForm } from "./location_form";
|
|||
import {
|
||||
SequenceMeta, determineVector, determineDropdown
|
||||
} from "../../resources/sequence_meta";
|
||||
import { Help } from "../../ui";
|
||||
import { Help, DropDownItem } from "../../ui";
|
||||
import { ToolTips } from "../../constants";
|
||||
import { t } from "../../i18next_wrapper";
|
||||
import { Position } from "@blueprintjs/core";
|
||||
|
@ -17,6 +17,14 @@ export interface DefaultValueFormProps {
|
|||
onChange: (v: ParameterDeclaration) => void;
|
||||
}
|
||||
|
||||
export const NO_GROUPS = (d: DropDownItem) => {
|
||||
console.log("QA THIS");
|
||||
if (d.headingId == "PointGroup") {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
export const DefaultValueForm = (props: DefaultValueFormProps) => {
|
||||
if (props.variableNode.kind === "parameter_declaration") {
|
||||
return <div className="default-value-form">
|
||||
|
@ -32,8 +40,8 @@ export const DefaultValueForm = (props: DefaultValueFormProps) => {
|
|||
shouldDisplay={() => true}
|
||||
allowedVariableNodes={AllowedVariableNodes.variable}
|
||||
hideTypeLabel={true}
|
||||
hideGroups={true}
|
||||
onChange={change(props.onChange, props.variableNode)} />
|
||||
onChange={change(props.onChange, props.variableNode)}
|
||||
customFilterRule={NO_GROUPS} />
|
||||
</div>;
|
||||
} else {
|
||||
return <div />;
|
||||
|
|
|
@ -46,21 +46,21 @@ export const LocalsList = (props: LocalsListProps) => {
|
|||
// Show default values for parameters as a fallback if not in Sequence header
|
||||
.map(v => v && props.bodyVariables && isParameterDeclaration(v.celeryNode)
|
||||
? convertFormVariable(v, props.resources) : v))
|
||||
.map(variable =>
|
||||
<LocationForm
|
||||
key={variable.celeryNode.args.label}
|
||||
locationDropdownKey={props.locationDropdownKey}
|
||||
bodyVariables={props.bodyVariables}
|
||||
variable={variable}
|
||||
sequenceUuid={props.sequenceUuid}
|
||||
resources={props.resources}
|
||||
shouldDisplay={props.shouldDisplay}
|
||||
hideVariableLabel={Object.values(props.variableData || {}).length < 2}
|
||||
allowedVariableNodes={props.allowedVariableNodes}
|
||||
collapsible={props.collapsible}
|
||||
collapsed={props.collapsed}
|
||||
toggleVarShow={props.toggleVarShow}
|
||||
onChange={props.onChange} />)}
|
||||
.map(variable => <LocationForm
|
||||
key={variable.celeryNode.args.label}
|
||||
locationDropdownKey={props.locationDropdownKey}
|
||||
bodyVariables={props.bodyVariables}
|
||||
variable={variable}
|
||||
sequenceUuid={props.sequenceUuid}
|
||||
resources={props.resources}
|
||||
shouldDisplay={props.shouldDisplay}
|
||||
hideVariableLabel={Object.values(props.variableData || {}).length < 2}
|
||||
allowedVariableNodes={props.allowedVariableNodes}
|
||||
collapsible={props.collapsible}
|
||||
collapsed={props.collapsed}
|
||||
toggleVarShow={props.toggleVarShow}
|
||||
onChange={props.onChange}
|
||||
customFilterRule={props.customFilterRule} />)}
|
||||
</div>;
|
||||
};
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
} from "../../resources/interfaces";
|
||||
import { SequenceMeta } from "../../resources/sequence_meta";
|
||||
import { ShouldDisplay } from "../../devices/interfaces";
|
||||
import { DropDownItem } from "../../ui";
|
||||
|
||||
export type VariableNode =
|
||||
ParameterDeclaration | VariableDeclaration | ParameterApplication;
|
||||
|
@ -49,13 +50,13 @@ interface CommonProps {
|
|||
* chooses between reassignment vs. creation for new variables,
|
||||
* and determines which variables to display in the form. */
|
||||
allowedVariableNodes: AllowedVariableNodes;
|
||||
/** Do not show `groups` as an option. Eg: Don't allow the user to pick
|
||||
* "group123" in the sequence editor header. */
|
||||
hideGroups?: boolean;
|
||||
/** Add ability to collapse the form content. */
|
||||
collapsible?: boolean;
|
||||
collapsed?: boolean;
|
||||
toggleVarShow?: () => void;
|
||||
/** Optional filter to allow removal of arbitrary dropdown items.
|
||||
* Return `false` to omit an item from display. */
|
||||
customFilterRule?: (ddi: DropDownItem) => boolean;
|
||||
}
|
||||
|
||||
export interface LocalsListProps extends CommonProps {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as React from "react";
|
||||
import { Row, Col, FBSelect, DropDownItem } from "../../ui";
|
||||
import { Row, Col, FBSelect } from "../../ui";
|
||||
import { locationFormList, NO_VALUE_SELECTED_DDI } from "./location_form_list";
|
||||
import { convertDDItoVariable } from "../locals_list/handle_select";
|
||||
import {
|
||||
|
@ -38,8 +38,6 @@ const maybeUseStepData = ({ resources, bodyVariables, variable, uuid }: {
|
|||
return variable;
|
||||
};
|
||||
|
||||
const hideGroups = (x: DropDownItem) => x.headingId !== "PointGroup";
|
||||
const allowAll = (_: unknown) => true;
|
||||
/**
|
||||
* Form with an "import from" dropdown and coordinate input boxes.
|
||||
* Can be used to set a specific value, import a value, or declare a variable.
|
||||
|
@ -57,8 +55,9 @@ export const LocationForm =
|
|||
const variableListItems = displayVariables ? [PARENT(determineVarDDILabel({
|
||||
label: "parent", resources, uuid: sequenceUuid, forceExternal: headerForm
|
||||
}))] : [];
|
||||
const list = locationFormList(resources, variableListItems)
|
||||
.filter(props.hideGroups ? hideGroups : allowAll);
|
||||
const unfiltered = locationFormList(resources, variableListItems);
|
||||
const list = props.customFilterRule ?
|
||||
unfiltered.filter(props.customFilterRule) : unfiltered;
|
||||
/** Variable name. */
|
||||
const { label } = celeryNode.args;
|
||||
if (variable.default) {
|
||||
|
|
|
@ -66,27 +66,22 @@ export const groups2Ddi = (groups: TaggedPointGroup[]): DropDownItem[] => {
|
|||
|
||||
/** Location selection menu items. */
|
||||
export function locationFormList(resources: ResourceIndex,
|
||||
additionalItems: DropDownItem[], displayGroups?: boolean): DropDownItem[] {
|
||||
additionalItems: DropDownItem[]): DropDownItem[] {
|
||||
const points = selectAllActivePoints(resources)
|
||||
.filter(x => x.body.pointer_type !== "ToolSlot");
|
||||
const plantDDI = points2ddi(points, "Plant");
|
||||
const genericPointerDDI = points2ddi(points, "GenericPointer");
|
||||
const toolDDI = activeToolDDIs(resources);
|
||||
const output = [COORDINATE_DDI()]
|
||||
return [COORDINATE_DDI()]
|
||||
.concat(additionalItems)
|
||||
.concat(heading("Tool"))
|
||||
.concat(toolDDI)
|
||||
.concat(heading("Plant"))
|
||||
.concat(plantDDI)
|
||||
.concat(heading("GenericPointer"))
|
||||
.concat(genericPointerDDI);
|
||||
if (displayGroups) {
|
||||
return output
|
||||
.concat(heading("PointGroup"))
|
||||
.concat(groups2Ddi(selectAllPointGroups(resources)));
|
||||
} else {
|
||||
return output;
|
||||
}
|
||||
.concat(genericPointerDDI)
|
||||
.concat(heading("PointGroup"))
|
||||
.concat(groups2Ddi(selectAllPointGroups(resources)));
|
||||
}
|
||||
|
||||
/** Create drop down item with label; i.e., "Point/Plant (1, 2, 3)" */
|
||||
|
|
|
@ -29,6 +29,7 @@ import {
|
|||
import { BooleanSetting } from "../session_keys";
|
||||
import { BooleanConfigKey } from "farmbot/dist/resources/configs/web_app";
|
||||
import { isUndefined } from "lodash";
|
||||
import { NO_GROUPS } from "./locals_list/default_value_form";
|
||||
|
||||
export const onDrop =
|
||||
(dispatch1: Function, sequence: TaggedSequence) =>
|
||||
|
@ -210,7 +211,8 @@ const SequenceHeader = (props: SequenceHeaderProps) => {
|
|||
collapsible={true}
|
||||
collapsed={props.variablesCollapsed}
|
||||
toggleVarShow={props.toggleVarShow}
|
||||
shouldDisplay={props.shouldDisplay} />
|
||||
shouldDisplay={props.shouldDisplay}
|
||||
customFilterRule={NO_GROUPS} />
|
||||
</div>;
|
||||
};
|
||||
|
||||
|
|
|
@ -118,8 +118,7 @@ export class RefactoredExecuteBlock
|
|||
onChange={assignVariable(this.props)(currentStep.body || [])}
|
||||
locationDropdownKey={JSON.stringify(currentSequence)}
|
||||
allowedVariableNodes={AllowedVariableNodes.identifier}
|
||||
shouldDisplay={this.props.shouldDisplay}
|
||||
hideGroups={false} />
|
||||
shouldDisplay={this.props.shouldDisplay} />
|
||||
</Col>}
|
||||
</Row>
|
||||
</StepContent>
|
||||
|
|
|
@ -22,6 +22,7 @@ import { MoveAbsoluteWarning } from "./tile_move_absolute_conflict_check";
|
|||
import { t } from "../../i18next_wrapper";
|
||||
import { Collapse } from "@blueprintjs/core";
|
||||
import { ExpandableHeader } from "../../ui/expandable_header";
|
||||
import { NO_GROUPS } from "../locals_list/default_value_form";
|
||||
|
||||
export class TileMoveAbsolute extends React.Component<StepParams, MoveAbsState> {
|
||||
state: MoveAbsState = {
|
||||
|
@ -96,8 +97,8 @@ export class TileMoveAbsolute extends React.Component<StepParams, MoveAbsState>
|
|||
hideHeader={true}
|
||||
locationDropdownKey={JSON.stringify(this.props.currentSequence)}
|
||||
allowedVariableNodes={AllowedVariableNodes.identifier}
|
||||
hideGroups={true}
|
||||
width={3} />
|
||||
width={3}
|
||||
customFilterRule={NO_GROUPS} />
|
||||
|
||||
SpeedInput = () =>
|
||||
<Col xs={3}>
|
||||
|
|
Loading…
Reference in New Issue