Skip to content

Commit

Permalink
Possible fix- customFilterRule prop.
Browse files Browse the repository at this point in the history
  • Loading branch information
RickCarlino committed Oct 21, 2019
1 parent da5820f commit 638821c
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 43 deletions.
Expand Up @@ -39,6 +39,7 @@ describe("<LocalsList/>", () => {
onChange: jest.fn(),
shouldDisplay: jest.fn(),
allowedVariableNodes: AllowedVariableNodes.parameter,
customFilterRule: undefined
};
};

Expand Down
Expand Up @@ -34,6 +34,7 @@ describe("<LocationForm/>", () => {
onChange: jest.fn(),
shouldDisplay: jest.fn(),
allowedVariableNodes: AllowedVariableNodes.parameter,
customFilterRule: undefined
});

it("renders correct UI components", () => {
Expand All @@ -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);
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 11 additions & 3 deletions frontend/sequences/locals_list/default_value_form.tsx
Expand Up @@ -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";
Expand All @@ -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">
Expand All @@ -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 />;
Expand Down
30 changes: 15 additions & 15 deletions frontend/sequences/locals_list/locals_list.tsx
Expand Up @@ -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>;
};

Expand Down
7 changes: 4 additions & 3 deletions frontend/sequences/locals_list/locals_list_support.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 4 additions & 5 deletions frontend/sequences/locals_list/location_form.tsx
@@ -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 {
Expand Down Expand Up @@ -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.
Expand All @@ -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) {
Expand Down
15 changes: 5 additions & 10 deletions frontend/sequences/locals_list/location_form_list.ts
Expand Up @@ -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)" */
Expand Down
4 changes: 3 additions & 1 deletion frontend/sequences/sequence_editor_middle_active.tsx
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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>;
};

Expand Down
3 changes: 1 addition & 2 deletions frontend/sequences/step_tiles/tile_execute.tsx
Expand Up @@ -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>
Expand Down
5 changes: 3 additions & 2 deletions frontend/sequences/step_tiles/tile_move_absolute.tsx
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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}>
Expand Down

0 comments on commit 638821c

Please sign in to comment.