FarmBot/Farmbot-Web-App

View on GitHub
frontend/curves/edit_curve.tsx

Summary

Maintainability
F
5 days
Test Coverage

File edit_curve.tsx has 392 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import React from "react";
import { t } from "../i18next_wrapper";
import { connect } from "react-redux";
import { push } from "../history";
import { SpecialStatus, TaggedCurve } from "farmbot";
Severity: Minor
Found in frontend/curves/edit_curve.tsx - About 5 hrs to fix

    Function render has 80 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      render() {
        const { curve, setHovered } = this;
        const { dispatch } = this.props;
        const { hovered } = this.state;
        const curvesPath = Path.curves();
    Severity: Major
    Found in frontend/curves/edit_curve.tsx - About 3 hrs to fix

      Function TemplatesMenu has 60 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export const TemplatesMenu = (props: ActionMenuProps) => {
        const { type } = props.curve.body;
        const [shapeCache, setShapeCache] = templateShape(type);
        const [shape, setShapeState] = React.useState(shapeCache);
        const [maxDayCache, setMaxDayCache] = templateScale(type, TemplateOption.day);
      Severity: Major
      Found in frontend/curves/edit_curve.tsx - About 2 hrs to fix

        Function curveDataTableRow has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        export const curveDataTableRow = (props: CurveDataTableRowProps) =>
          ([day, value]: [string, number], index: number) => {
            const { dispatch, curve, hovered, setHovered } = props;
            const active = inData(curve.body.data, day);
            return <tr key={day} className={hovered == day ? "hovered" : ""}
        Severity: Minor
        Found in frontend/curves/edit_curve.tsx - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function ScaleMenu has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export const ScaleMenu = (props: ActionMenuProps) => {
          const { data } = props.curve.body;
          const [maxDayNum, setMaxDay] = React.useState(maxDay(data));
          const [maxValueNum, setMaxValue] = React.useState(maxValue(data));
          return <div className={"curve-action-menu"}>
        Severity: Minor
        Found in frontend/curves/edit_curve.tsx - About 1 hr to fix

          Function curveDataTableRow has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            ([day, value]: [string, number], index: number) => {
              const { dispatch, curve, hovered, setHovered } = props;
              const active = inData(curve.body.data, day);
              return <tr key={day} className={hovered == day ? "hovered" : ""}
                onMouseEnter={() => setHovered(day)}
          Severity: Minor
          Found in frontend/curves/edit_curve.tsx - About 1 hr to fix

            Function PercentChange has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            const PercentChange = (props: PercentChangeProps) => {
              const exactData = populatedData(props.curve.body.data, true);
              const prev = exactData[props.index] || 0;
              const value = exactData[props.index + 1];
              if (prev == 0) { return <p>-</p>; }
            Severity: Minor
            Found in frontend/curves/edit_curve.tsx - About 45 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function render has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              render() {
                const { curve, setHovered } = this;
                const { dispatch } = this.props;
                const { hovered } = this.state;
                const curvesPath = Path.curves();
            Severity: Minor
            Found in frontend/curves/edit_curve.tsx - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                <div className={"curve-menu-row"}>
                  <label>{t("days")}</label>
                  <input type={"number"}
                    defaultValue={maxDayNum}
                    min={1} max={200}
            Severity: Major
            Found in frontend/curves/edit_curve.tsx and 1 other location - About 5 hrs to fix
            frontend/curves/edit_curve.tsx on lines 294..303

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 137.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                <div className={"curve-menu-row"}>
                  <label>{t("days")}</label>
                  <input type={"number"}
                    defaultValue={maxDay}
                    min={1} max={200}
            Severity: Major
            Found in frontend/curves/edit_curve.tsx and 1 other location - About 5 hrs to fix
            frontend/curves/edit_curve.tsx on lines 232..241

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 137.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                        <Popover
                          isOpen={this.state.templates}
                          popoverClassName={"curve-action-popover"}
                          target={<button className={"transparent-button"}
                            onClick={this.toggle("templates")}>
            Severity: Major
            Found in frontend/curves/edit_curve.tsx and 1 other location - About 4 hrs to fix
            frontend/curves/edit_curve.tsx on lines 165..173

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 119.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                        <Popover
                          isOpen={this.state.scale}
                          popoverClassName={"curve-action-popover"}
                          target={<button className={"transparent-button"}
                            onClick={this.toggle("scale")}>
            Severity: Major
            Found in frontend/curves/edit_curve.tsx and 1 other location - About 4 hrs to fix
            frontend/curves/edit_curve.tsx on lines 174..182

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 119.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                <div className={"curve-menu-row"}>
                  <label>{t("max value")}</label>
                  <input type={"number"}
                    defaultValue={maxValue}
                    onChange={e => {
            Severity: Major
            Found in frontend/curves/edit_curve.tsx and 1 other location - About 4 hrs to fix
            frontend/curves/edit_curve.tsx on lines 223..231

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 115.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                <div className={"curve-menu-row"}>
                  <label>{t("max value")}</label>
                  <input type={"number"}
                    defaultValue={maxValueNum}
                    onChange={e => {
            Severity: Major
            Found in frontend/curves/edit_curve.tsx and 1 other location - About 4 hrs to fix
            frontend/curves/edit_curve.tsx on lines 285..293

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 115.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

                    titleElement={<ResourceTitle
                      key={curve?.body.name}
                      resource={curve}
                      save={true}
                      fallback={t("No Curve selected")}
            Severity: Major
            Found in frontend/curves/edit_curve.tsx and 2 other locations - About 1 hr to fix
            frontend/points/point_info.tsx on lines 69..74
            frontend/weeds/weeds_edit.tsx on lines 69..74

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 60.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 5 locations. Consider refactoring.
            Open

              toggle = (key: keyof EditCurveState) => () =>
                this.setState({ ...this.state, [key]: !this.state[key] });
            Severity: Major
            Found in frontend/curves/edit_curve.tsx and 4 other locations - About 50 mins to fix
            frontend/farm_designer/move_to.tsx on lines 164..165
            frontend/sequences/panel/preview.tsx on lines 40..41
            frontend/sequences/sequence_editor_middle_active.tsx on lines 458..459
            frontend/tools/index.tsx on lines 159..160

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 51.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            There are no issues that match your filters.

            Category
            Status