GladysProject/Gladys

View on GitHub
front/src/components/boxs/chart/EditChart.jsx

Summary

Maintainability
F
1 wk
Test Coverage

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

  render(props, { selectedDeviceFeaturesOptions, deviceOptions, loading, displayPreview }) {
    const manyFeatures = selectedDeviceFeaturesOptions && selectedDeviceFeaturesOptions.length > 1;
    const colorOptions = DEFAULT_COLORS.map((colorValue, i) => ({
      value: colorValue,
      label: props.intl.dictionary.color[DEFAULT_COLORS_NAME[i]] || DEFAULT_COLORS_NAME[i]
Severity: Major
Found in front/src/components/boxs/chart/EditChart.jsx - About 6 hrs to fix

    File EditChart.jsx has 344 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import { Component } from 'preact';
    import { Localizer, Text } from 'preact-i18n';
    import { connect } from 'unistore/preact';
    import Select from 'react-select';
    import get from 'get-value';
    Severity: Minor
    Found in front/src/components/boxs/chart/EditChart.jsx - About 4 hrs to fix

      Function option has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        option: (styles, { data, isDisabled, isFocused, isSelected }) => {
          const { value: color } = data;
          return {
            ...styles,
            backgroundColor: isDisabled ? undefined : isSelected ? color : isFocused ? color : undefined,
      Severity: Minor
      Found in front/src/components/boxs/chart/EditChart.jsx - About 1 hr 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 6 (exceeds 5 allowed). Consider refactoring.
      Open

        render(props, { selectedDeviceFeaturesOptions, deviceOptions, loading, displayPreview }) {
          const manyFeatures = selectedDeviceFeaturesOptions && selectedDeviceFeaturesOptions.length > 1;
          const colorOptions = DEFAULT_COLORS.map((colorValue, i) => ({
            value: colorValue,
            label: props.intl.dictionary.color[DEFAULT_COLORS_NAME[i]] || DEFAULT_COLORS_NAME[i]
      Severity: Minor
      Found in front/src/components/boxs/chart/EditChart.jsx - About 25 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 class="form-group">
                    <label>
                      <Text id="dashboard.boxes.chart.displayAxes" />
                    </label>
                    <select
      Severity: Major
      Found in front/src/components/boxs/chart/EditChart.jsx and 1 other location - About 6 hrs to fix
      front/src/components/boxs/chart/EditChart.jsx on lines 301..317

      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 155.

      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 class="form-group">
                    <label>
                      <Text id="dashboard.boxes.chart.displayVariation" />
                    </label>
                    <select
      Severity: Major
      Found in front/src/components/boxs/chart/EditChart.jsx and 1 other location - About 6 hrs to fix
      front/src/components/boxs/chart/EditChart.jsx on lines 284..300

      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 155.

      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

        updateDisplayVariation = e => {
          if (e.target.value && e.target.value.length) {
            const valueBoolean = e.target.value === 'yes';
            this.props.updateBoxConfig(this.props.x, this.props.y, { display_variation: valueBoolean });
          } else {
      Severity: Major
      Found in front/src/components/boxs/chart/EditChart.jsx and 1 other location - About 5 hrs to fix
      front/src/components/boxs/chart/EditChart.jsx on lines 90..97

      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 143.

      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

        updateDisplayAxes = e => {
          if (e.target.value && e.target.value.length) {
            const valueBoolean = e.target.value === 'yes';
            this.props.updateBoxConfig(this.props.x, this.props.y, { display_axes: valueBoolean });
          } else {
      Severity: Major
      Found in front/src/components/boxs/chart/EditChart.jsx and 1 other location - About 5 hrs to fix
      front/src/components/boxs/chart/EditChart.jsx on lines 99..106

      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 143.

      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

        updateDefaultInterval = e => {
          if (e.target.value && e.target.value.length) {
            this.props.updateBoxConfig(this.props.x, this.props.y, { interval: e.target.value });
          } else {
            this.props.updateBoxConfig(this.props.x, this.props.y, { interval: undefined });
      Severity: Major
      Found in front/src/components/boxs/chart/EditChart.jsx and 1 other location - About 4 hrs to fix
      front/src/components/boxs/chart/EditChart.jsx on lines 71..77

      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 132.

      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

        updateChartType = e => {
          if (e.target.value && e.target.value.length) {
            this.props.updateBoxConfig(this.props.x, this.props.y, { chart_type: e.target.value });
          } else {
            this.props.updateBoxConfig(this.props.x, this.props.y, { chart_type: undefined });
      Severity: Major
      Found in front/src/components/boxs/chart/EditChart.jsx and 1 other location - About 4 hrs to fix
      front/src/components/boxs/chart/EditChart.jsx on lines 63..69

      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 132.

      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

                    <div class="form-group">
                      <label>
                        <Text id="dashboard.boxes.chart.editNameLabel" />
                      </label>
                      <Localizer>
      Severity: Major
      Found in front/src/components/boxs/chart/EditChart.jsx and 2 other locations - About 4 hrs to fix
      front/src/components/boxs/device-in-room/EditDevices.jsx on lines 174..187
      front/src/components/boxs/scene/EditSceneBox.jsx on lines 84..97

      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 118.

      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 4 locations. Consider refactoring.
      Open

              if (deviceFeaturesOptions.length > 0) {
                deviceFeaturesOptions.sort((a, b) => {
                  if (a.label < b.label) {
                    return -1;
                  } else if (a.label > b.label) {
      Severity: Major
      Found in front/src/components/boxs/chart/EditChart.jsx and 3 other locations - About 3 hrs to fix
      front/src/components/boxs/device-in-room/EditDeviceInRoom.jsx on lines 48..61
      front/src/components/boxs/device-in-room/EditDevices.jsx on lines 94..107
      front/src/components/device/SelectDeviceFeature.jsx on lines 37..50

      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 109.

      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

        componentDidUpdate(previousProps) {
          const deviceFeatureChanged = get(previousProps, 'box.device_feature') !== get(this.props, 'box.device_feature');
          const unitsChanged = get(previousProps, 'box.units') !== get(this.props, 'box.units');
          if (deviceFeatureChanged || unitsChanged) {
            this.getDeviceFeatures();
      Severity: Major
      Found in front/src/components/boxs/chart/EditChart.jsx and 1 other location - About 2 hrs to fix
      front/src/components/boxs/camera/Camera.jsx on lines 232..238

      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 80.

      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

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

                if (this.props.box.device_features && this.props.box.device_features.indexOf(feature.selector) !== -1) {
                  selectedDeviceFeaturesOptions.push(featureOption);
                }
      Severity: Major
      Found in front/src/components/boxs/chart/EditChart.jsx and 1 other location - About 1 hr to fix
      front/src/components/boxs/device-in-room/EditDeviceInRoom.jsx on lines 44..46

      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 64.

      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 12 locations. Consider refactoring.
      Open

        updateBoxTitle = e => {
          this.props.updateBoxConfig(this.props.x, this.props.y, { title: e.target.value });
        };
      Severity: Major
      Found in front/src/components/boxs/chart/EditChart.jsx and 11 other locations - About 1 hr to fix
      front/src/components/boxs/alarm/EditAlarm.jsx on lines 8..12
      front/src/components/boxs/alarm/EditAlarm.jsx on lines 14..18
      front/src/components/boxs/camera/EditCamera.jsx on lines 87..91
      front/src/components/boxs/camera/EditCamera.jsx on lines 93..97
      front/src/components/boxs/camera/EditCamera.jsx on lines 99..103
      front/src/components/boxs/clock/EditClock.jsx on lines 8..10
      front/src/components/boxs/device-in-room/EditDevices.jsx on lines 19..23
      front/src/components/boxs/room-humidity/EditRoomHumidityBox.jsx on lines 64..68
      front/src/components/boxs/room-temperature/EditRoomTemperatureBox.jsx on lines 72..76
      front/src/components/boxs/scene/EditSceneBox.jsx on lines 19..23
      front/src/components/boxs/weather/EditWeatherBox.jsx on lines 57..61

      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 58.

      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