Add new feature flags
parent
c1c2bbf250
commit
26a98f486a
|
@ -9,7 +9,8 @@ import {
|
|||
} from "../resources/selectors";
|
||||
import { Props } from "./interfaces";
|
||||
import {
|
||||
validFwConfig, shouldDisplay as shouldDisplayFunc,
|
||||
validFwConfig,
|
||||
createShouldDisplayFn as shouldDisplayFunc,
|
||||
determineInstalledOsVersion
|
||||
} from "../util";
|
||||
import { getWebAppConfigValue } from "../config_storage/actions";
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as React from "react";
|
||||
import axios from "axios";
|
||||
import { t } from "../../i18next_wrapper";
|
||||
import { FarmbotOsProps, FarmbotOsState } from "../interfaces";
|
||||
import { FarmbotOsProps, FarmbotOsState, Feature } from "../interfaces";
|
||||
import { Widget, WidgetHeader, WidgetBody, Row, Col } from "../../ui";
|
||||
import { save, edit } from "../../api/crud";
|
||||
import { MustBeOnline, isBotOnline } from "../must_be_online";
|
||||
|
@ -157,7 +157,7 @@ export class FarmbotOsSettings
|
|||
</label>
|
||||
</Col>
|
||||
<Col xs={7}>
|
||||
<BootSequenceSelector />
|
||||
{this.props.shouldDisplay(Feature.boot_sequence) && <BootSequenceSelector />}
|
||||
</Col>
|
||||
</Row>
|
||||
<PowerAndReset
|
||||
|
|
|
@ -65,29 +65,31 @@ export type SourceFwConfig = (config: McuParamName) =>
|
|||
export type ShouldDisplay = (x: Feature) => boolean;
|
||||
/** Names of features that use minimum FBOS version checking. */
|
||||
export enum Feature {
|
||||
assertion_block = "assertion_block",
|
||||
named_pins = "named_pins",
|
||||
sensors = "sensors",
|
||||
change_ownership = "change_ownership",
|
||||
variables = "variables",
|
||||
loops = "loops",
|
||||
api_pin_bindings = "api_pin_bindings",
|
||||
farmduino_k14 = "farmduino_k14",
|
||||
jest_feature = "jest_feature", // for tests
|
||||
backscheduled_regimens = "backscheduled_regimens",
|
||||
endstop_invert = "endstop_invert",
|
||||
diagnostic_dumps = "diagnostic_dumps",
|
||||
rpi_led_control = "rpi_led_control",
|
||||
mark_as_step = "mark_as_step",
|
||||
firmware_restart = "firmware_restart",
|
||||
api_farmware_installations = "api_farmware_installations",
|
||||
api_farmware_env = "api_farmware_env",
|
||||
use_update_channel = "use_update_channel",
|
||||
long_scaling_factor = "long_scaling_factor",
|
||||
flash_firmware = "flash_firmware",
|
||||
api_farmware_installations = "api_farmware_installations",
|
||||
api_pin_bindings = "api_pin_bindings",
|
||||
assertion_block = "assertion_block",
|
||||
backscheduled_regimens = "backscheduled_regimens",
|
||||
boot_sequence = "boot_sequence",
|
||||
change_ownership = "change_ownership",
|
||||
diagnostic_dumps = "diagnostic_dumps",
|
||||
endstop_invert = "endstop_invert",
|
||||
express_k10 = "express_k10",
|
||||
farmduino_k14 = "farmduino_k14",
|
||||
firmware_restart = "firmware_restart",
|
||||
flash_firmware = "flash_firmware",
|
||||
groups = "groups",
|
||||
jest_feature = "jest_feature",
|
||||
long_scaling_factor = "long_scaling_factor",
|
||||
mark_as_step = "mark_as_step",
|
||||
named_pins = "named_pins",
|
||||
none_firmware = "none_firmware",
|
||||
rpi_led_control = "rpi_led_control",
|
||||
sensors = "sensors",
|
||||
use_update_channel = "use_update_channel",
|
||||
variables = "variables"
|
||||
}
|
||||
|
||||
/** Object fetched from FEATURE_MIN_VERSIONS_URL. */
|
||||
export type MinOsFeatureLookup = Partial<Record<Feature, string>>;
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import {
|
|||
} from "./components/source_config_value";
|
||||
import {
|
||||
determineInstalledOsVersion, validFwConfig, validFbosConfig,
|
||||
shouldDisplay as shouldDisplayFunc
|
||||
createShouldDisplayFn as shouldDisplayFunc
|
||||
} from "../util";
|
||||
import {
|
||||
saveOrEditFarmwareEnv, reduceFarmwareEnv
|
||||
|
@ -27,8 +27,9 @@ export function mapStateToProps(props: Everything): Props {
|
|||
const installedOsVersion = determineInstalledOsVersion(
|
||||
props.bot, maybeGetDevice(props.resources.index));
|
||||
const fbosVersionOverride = DevSettings.overriddenFbosVersion();
|
||||
const shouldDisplay = shouldDisplayFunc(
|
||||
installedOsVersion, props.bot.minOsFeatureData, fbosVersionOverride);
|
||||
const shouldDisplay = shouldDisplayFunc(installedOsVersion,
|
||||
props.bot.minOsFeatureData,
|
||||
fbosVersionOverride);
|
||||
const env = shouldDisplay(Feature.api_farmware_env)
|
||||
? reduceFarmwareEnv(props.resources.index)
|
||||
: props.bot.hardware.user_env;
|
||||
|
|
|
@ -24,7 +24,7 @@ import {
|
|||
import { DropDownItem } from "../../ui/index";
|
||||
import {
|
||||
validFbosConfig,
|
||||
shouldDisplay as shouldDisplayFunc,
|
||||
createShouldDisplayFn as shouldDisplayFunc,
|
||||
determineInstalledOsVersion
|
||||
} from "../../util";
|
||||
import {
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
} from "../resources/selectors";
|
||||
import {
|
||||
validBotLocationData, validFwConfig, unpackUUID,
|
||||
shouldDisplay as shouldDisplayFunc,
|
||||
createShouldDisplayFn as shouldDisplayFunc,
|
||||
determineInstalledOsVersion
|
||||
} from "../util";
|
||||
import { getWebAppConfigValue } from "../config_storage/actions";
|
||||
|
|
|
@ -11,7 +11,7 @@ import {
|
|||
} from "../resources/selectors_by_kind";
|
||||
import {
|
||||
determineInstalledOsVersion,
|
||||
shouldDisplay as shouldDisplayFunc,
|
||||
createShouldDisplayFn as shouldDisplayFunc,
|
||||
betterCompact
|
||||
} from "../util";
|
||||
import { ResourceIndex } from "../resources/interfaces";
|
||||
|
|
|
@ -8,7 +8,7 @@ import {
|
|||
} from "../devices/components/source_config_value";
|
||||
import {
|
||||
validFbosConfig, determineInstalledOsVersion,
|
||||
shouldDisplay as shouldDisplayFunc
|
||||
createShouldDisplayFn as shouldDisplayFunc
|
||||
} from "../util";
|
||||
import { ResourceIndex } from "../resources/interfaces";
|
||||
import { TaggedLog } from "farmbot";
|
||||
|
|
|
@ -18,7 +18,7 @@ import moment from "moment";
|
|||
import { ResourceIndex, UUID, VariableNameSet } from "../resources/interfaces";
|
||||
import {
|
||||
randomColor, determineInstalledOsVersion,
|
||||
shouldDisplay as shouldDisplayFunc,
|
||||
createShouldDisplayFn as shouldDisplayFunc,
|
||||
timeFormatString
|
||||
} from "../util";
|
||||
import { resourceUsageList } from "../resources/in_use";
|
||||
|
|
|
@ -55,7 +55,7 @@ export const LocationForm =
|
|||
const variableListItems = displayVariables ? [PARENT(determineVarDDILabel({
|
||||
label: "parent", resources, uuid: sequenceUuid, forceExternal: headerForm
|
||||
}))] : [];
|
||||
const displayGroups = props.shouldDisplay(Feature.loops) && !disallowGroups;
|
||||
const displayGroups = props.shouldDisplay(Feature.groups) && !disallowGroups;
|
||||
const list = locationFormList(resources, variableListItems, displayGroups);
|
||||
/** Variable name. */
|
||||
const { label } = celeryNode.args;
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
import { getStepTag } from "../resources/sequence_tagging";
|
||||
import { enabledAxisMap } from "../devices/components/axis_tracking_status";
|
||||
import {
|
||||
shouldDisplay as shouldDisplayFunc,
|
||||
createShouldDisplayFn as shouldDisplayFunc,
|
||||
determineInstalledOsVersion, validFwConfig
|
||||
} from "../util";
|
||||
import { BooleanSetting } from "../session_keys";
|
||||
|
|
|
@ -2,7 +2,7 @@ import {
|
|||
semverCompare,
|
||||
SemverResult,
|
||||
minFwVersionCheck,
|
||||
shouldDisplay,
|
||||
createShouldDisplayFn,
|
||||
determineInstalledOsVersion,
|
||||
versionOK,
|
||||
} from "../version";
|
||||
|
@ -121,34 +121,34 @@ describe("shouldDisplay()", () => {
|
|||
const fakeMinOsData = { jest_feature: "1.0.0" };
|
||||
|
||||
it("should display", () => {
|
||||
expect(shouldDisplay("1.0.0", fakeMinOsData, undefined)(
|
||||
expect(createShouldDisplayFn("1.0.0", fakeMinOsData, undefined)(
|
||||
Feature.jest_feature)).toBeTruthy();
|
||||
expect(shouldDisplay("10.0.0", fakeMinOsData, undefined)(
|
||||
expect(createShouldDisplayFn("10.0.0", fakeMinOsData, undefined)(
|
||||
Feature.jest_feature)).toBeTruthy();
|
||||
expect(shouldDisplay("10.0.0",
|
||||
expect(createShouldDisplayFn("10.0.0",
|
||||
{ jest_feature: "1.0.0" }, undefined)(
|
||||
Feature.jest_feature)).toBeTruthy();
|
||||
});
|
||||
|
||||
it("shouldn't display", () => {
|
||||
expect(shouldDisplay("0.9.0", fakeMinOsData, undefined)(
|
||||
expect(createShouldDisplayFn("0.9.0", fakeMinOsData, undefined)(
|
||||
Feature.jest_feature)).toBeFalsy();
|
||||
expect(shouldDisplay(undefined, fakeMinOsData, undefined)(
|
||||
expect(createShouldDisplayFn(undefined, fakeMinOsData, undefined)(
|
||||
Feature.jest_feature)).toBeFalsy();
|
||||
// tslint:disable-next-line:no-any
|
||||
const unknown_feature = "unknown_feature" as any;
|
||||
expect(shouldDisplay("1.0.0", fakeMinOsData, undefined)(
|
||||
expect(createShouldDisplayFn("1.0.0", fakeMinOsData, undefined)(
|
||||
unknown_feature)).toBeFalsy();
|
||||
expect(shouldDisplay("1.0.0", undefined, undefined)(
|
||||
expect(createShouldDisplayFn("1.0.0", undefined, undefined)(
|
||||
unknown_feature)).toBeFalsy();
|
||||
// tslint:disable-next-line:no-any
|
||||
expect(shouldDisplay("1.0.0", "" as any, undefined)(
|
||||
expect(createShouldDisplayFn("1.0.0", "" as any, undefined)(
|
||||
unknown_feature)).toBeFalsy();
|
||||
// tslint:disable-next-line:no-any
|
||||
expect(shouldDisplay("1.0.0", "{}" as any, undefined)(
|
||||
expect(createShouldDisplayFn("1.0.0", "{}" as any, undefined)(
|
||||
unknown_feature)).toBeFalsy();
|
||||
// tslint:disable-next-line:no-any
|
||||
expect(shouldDisplay("1.0.0", "bad" as any, undefined)(
|
||||
expect(createShouldDisplayFn("1.0.0", "bad" as any, undefined)(
|
||||
unknown_feature)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -109,14 +109,15 @@ export enum MinVersionOverride {
|
|||
* @param current installed OS version string to compare against data ("0.0.0")
|
||||
* @param lookupData min req versions data, for example {"feature": "1.0.0"}
|
||||
*/
|
||||
export function shouldDisplay(
|
||||
export function createShouldDisplayFn(
|
||||
current: string | undefined,
|
||||
lookupData: MinOsFeatureLookup | undefined,
|
||||
override: string | undefined) {
|
||||
return function (feature: Feature): boolean {
|
||||
const target = override || current;
|
||||
if (isString(target)) {
|
||||
const min = (lookupData || {})[feature] || MinVersionOverride.NEVER;
|
||||
const table = lookupData || {};
|
||||
const min = table[feature] || MinVersionOverride.NEVER;
|
||||
switch (semverCompare(target, min)) {
|
||||
case SemverResult.LEFT_IS_GREATER:
|
||||
case SemverResult.EQUAL:
|
||||
|
|
Loading…
Reference in New Issue