o2xp/react-datatable

View on GitHub
src/redux/reducers/datatableReducer.js

Summary

Maintainability
A
2 hrs
Test Coverage

File datatableReducer.js has 1169 lines of code (exceeds 250 allowed). Consider refactoring.
Wontfix

import deepmerge from "deepmerge";
import arrayMove from "array-move";
import {
  chunk,
  cloneDeep,
Severity: Major
Found in src/redux/reducers/datatableReducer.js - About 3 days to fix

    Function saveAllRowsEdited has 73 lines of code (exceeds 25 allowed). Consider refactoring.
    Wontfix

    const saveAllRowsEdited = state => {
      const {
        data,
        keyColumn,
        rowsGlobalEdited,
    Severity: Major
    Found in src/redux/reducers/datatableReducer.js - About 2 hrs to fix

      Function setRowEdited has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Wontfix

      const setRowEdited = (state, { columnId, rowId, newValue, error }) => {
        const { rowsEdited, keyColumn, rowsGlobalEdited, features } = state;
        let newRowsGlobalEdited = [...rowsGlobalEdited];
        const rowsEditedUpdate = rowsEdited.map(row => {
          if (row[keyColumn] === rowId) {
      Severity: Minor
      Found in src/redux/reducers/datatableReducer.js - 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 updateRowSizeMultiplier has 66 lines of code (exceeds 25 allowed). Consider refactoring.
      Wontfix

      const updateRowSizeMultiplier = state => {
        const { canEdit, canDelete, canSelectRow, canDuplicate } = state.features;
        const numberOfActions = [
          canEdit,
          canDelete,
      Severity: Major
      Found in src/redux/reducers/datatableReducer.js - About 2 hrs to fix

        Function datatableReducer has 59 lines of code (exceeds 25 allowed). Consider refactoring.
        Wontfix

        const datatableReducer = (state = defaultState, action) => {
          const { payload, type } = action;
        
          switch (type) {
            case "INITIALIZE_OPTIONS":
        Severity: Major
        Found in src/redux/reducers/datatableReducer.js - About 2 hrs to fix

          Function setPagination has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Wontfix

          const setPagination = ({
            state,
            newPageSelected = null,
            newRowsPerPageSelected = null
          }) => {
          Severity: Minor
          Found in src/redux/reducers/datatableReducer.js - 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 updateRowSizeMultiplier has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Wontfix

          const updateRowSizeMultiplier = state => {
            const { canEdit, canDelete, canSelectRow, canDuplicate } = state.features;
            const numberOfActions = [
              canEdit,
              canDelete,
          Severity: Minor
          Found in src/redux/reducers/datatableReducer.js - 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 initializeOptions has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Wontfix

          const initializeOptions = (
            state,
            {
              optionsInit,
              forceRerender = false,
          Severity: Minor
          Found in src/redux/reducers/datatableReducer.js - 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 addNewRow has 47 lines of code (exceeds 25 allowed). Consider refactoring.
          Wontfix

          const addNewRow = (state, payload) => {
            const {
              keyColumn,
              data,
              pagination,
          Severity: Minor
          Found in src/redux/reducers/datatableReducer.js - About 1 hr to fix

            Function setColumnVisibilty has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Wontfix

            const setColumnVisibilty = (state, payload) => {
              const { columns } = state.data;
              const { columnsOrder } = state.features.userConfiguration;
              const orderDisplayed = columns.filter(
                col => columnsOrder.includes(col.id) || col.id === payload.id
            Severity: Minor
            Found in src/redux/reducers/datatableReducer.js - About 1 hr to fix

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

              const saveRowEdited = (state, payload) => {
                const row = payload;
                delete row.idOfColumnErr;
                delete row.hasBeenEdited;
                const { data, rowsEdited, keyColumn, pagination, actions } = state;
              Severity: Minor
              Found in src/redux/reducers/datatableReducer.js - About 1 hr to fix

                Function rowsEditedUpdate has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                Wontfix

                  const rowsEditedUpdate = rowsEdited.map(row => {
                    if (row[keyColumn] === rowId) {
                      let idOfColumnErrUpdate = row.idOfColumnErr;
                      if (error) {
                        if (!idOfColumnErrUpdate.includes(columnId)) {
                Severity: Minor
                Found in src/redux/reducers/datatableReducer.js - About 1 hr to fix

                  Function addToDeleteRow has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                  Wontfix

                  const addToDeleteRow = (state, payload) => {
                    const row = payload;
                    const {
                      data,
                      keyColumn,
                  Severity: Minor
                  Found in src/redux/reducers/datatableReducer.js - About 1 hr to fix

                    Function revertAllRowsToEdited has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    const revertAllRowsToEdited = state => {
                      const { newRows, data, keyColumn, pagination, rowsDeleted, actions } = state;
                      const newRowsId = newRows.map(r => r[keyColumn]);
                      const { rows } = data;
                    
                    
                    Severity: Minor
                    Found in src/redux/reducers/datatableReducer.js - About 1 hr to fix

                      Function convertSizeToNumber has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Wontfix

                      const convertSizeToNumber = (val, height) => {
                        const splitSize = val.match(/[0-9]+|(px|%|vw|vh)/gi);
                        let valSize = splitSize[0];
                        const unitSize = splitSize[1];
                        if (unitSize === "px") {
                      Severity: Minor
                      Found in src/redux/reducers/datatableReducer.js - 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

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

                        let newState = {
                          ...state,
                          rowsEdited: [...rowsEdited.filter(r => r[keyColumn] !== row[keyColumn])],
                          rowsGlobalEdited: [
                            ...rowsGlobalEdited.filter(r => r[keyColumn] !== row[keyColumn])
                      Severity: Major
                      Found in src/redux/reducers/datatableReducer.js and 1 other location - About 4 hrs to fix
                      src/redux/reducers/datatableReducer.js on lines 1006..1016

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

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

                        let newState = {
                          ...state,
                          rowsEdited: [...rowsEdited.filter(r => r[keyColumn] !== row[keyColumn])],
                          rowsGlobalEdited: [
                            ...rowsGlobalEdited.filter(r => r[keyColumn] !== row[keyColumn])
                      Severity: Major
                      Found in src/redux/reducers/datatableReducer.js and 1 other location - About 4 hrs to fix
                      src/redux/reducers/datatableReducer.js on lines 977..987

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

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

                        const hasHeader =
                          canGlobalEdit ||
                          canPrint ||
                          canDownload ||
                          canSearch ||
                      Severity: Major
                      Found in src/redux/reducers/datatableReducer.js and 1 other location - About 1 hr to fix
                      src/components/DatatableContainer.js on lines 44..54

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

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

                        const {
                          canGlobalEdit,
                          canPrint,
                          canDownload,
                          canSearch,
                      Severity: Minor
                      Found in src/redux/reducers/datatableReducer.js and 1 other location - About 55 mins to fix
                      src/components/DatatableContainer.js on lines 33..43

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

                      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