ui/src/modules/segments/components/form/Form.tsx

Summary

Maintainability
F
4 days
Test Coverage

File Form.tsx has 721 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { IBoard } from 'modules/boards/types';
import Button from 'modules/common/components/Button';
import FormControl from 'modules/common/components/form/Control';
import CommonForm from 'modules/common/components/form/Form';
import FormGroup from 'modules/common/components/form/Group';
Severity: Major
Found in ui/src/modules/segments/components/form/Form.tsx - About 1 day to fix

    SegmentFormAutomations has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class SegmentFormAutomations extends React.Component<Props, State> {
      constructor(props) {
        super(props);
    
        let state = 'propertyForm';
    Severity: Minor
    Found in ui/src/modules/segments/components/form/Form.tsx - About 2 hrs to fix

      Function constructor has 51 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        constructor(props) {
          super(props);
      
          let state = 'propertyForm';
          let showAddGroup = true;
      Severity: Major
      Found in ui/src/modules/segments/components/form/Form.tsx - About 2 hrs to fix

        Function constructor has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

          constructor(props) {
            super(props);
        
            let state = 'propertyForm';
            let showAddGroup = true;
        Severity: Minor
        Found in ui/src/modules/segments/components/form/Form.tsx - 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

        Avoid too many return statements within this function.
        Open

            return <></>;
        Severity: Major
        Found in ui/src/modules/segments/components/form/Form.tsx - About 30 mins to fix

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

            generatePipelineOptions = () => {
              const { boardId } = this.state;
          
              const board = (this.props.boards || []).find(b => b._id === boardId);
          
          
          Severity: Major
          Found in ui/src/modules/segments/components/form/Form.tsx and 1 other location - About 4 hrs to fix
          ui/src/modules/segments/components/form/PropertyCondition.tsx on lines 79..92

          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

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

            addNewProperty = (segmentKey: string) => {
              const segments = [...this.state.segments];
          
              const foundedSegment = segments.find(segment => segment.key === segmentKey);
          
          
          Severity: Major
          Found in ui/src/modules/segments/components/form/Form.tsx and 1 other location - About 2 hrs to fix
          ui/src/modules/segments/components/form/Form.tsx on lines 440..446

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

          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

            addNewEvent = (segmentKey: string) => {
              const segments = [...this.state.segments];
          
              const foundedSegment = segments.find(segment => segment.key === segmentKey);
          
          
          Severity: Major
          Found in ui/src/modules/segments/components/form/Form.tsx and 1 other location - About 2 hrs to fix
          ui/src/modules/segments/components/form/Form.tsx on lines 432..438

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

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

            handleChange = <T extends keyof State>(name: T, value: State[T]) => {
              this.setState(({ [name]: value } as unknown) as Pick<State, keyof State>);
            };
          Severity: Major
          Found in ui/src/modules/segments/components/form/Form.tsx and 8 other locations - About 2 hrs to fix
          ui/src/modules/automations/components/forms/actions/placeHolder/SelectBoard.tsx on lines 66..68
          ui/src/modules/engage/components/AutoAndManualForm.tsx on lines 106..108
          ui/src/modules/engage/components/VisitorForm.tsx on lines 78..80
          ui/src/modules/engage/components/WidgetForm.tsx on lines 96..98
          ui/src/modules/inbox/containers/conversationDetail/responseTemplate/PopoverContent.tsx on lines 125..130
          ui/src/modules/settings/calendars/components/scheduler/PageForm.tsx on lines 166..168
          ui/src/modules/settings/growthHacks/components/PipelineForm.tsx on lines 103..105
          ui/src/modules/settings/integrations/components/messenger/Form.tsx on lines 170..172

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

          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

                    {this.props.headSegments.map(segment => (
                      <option value={segment._id} key={segment._id}>
                        {segment.name}
                      </option>
                    ))}
          Severity: Major
          Found in ui/src/modules/segments/components/form/Form.tsx and 3 other locations - About 1 hr to fix
          ui/src/modules/engage/components/MessengerForm.tsx on lines 172..176
          ui/src/modules/settings/brands/components/ChooseBrand.tsx on lines 69..73
          ui/src/modules/settings/email/components/Signature.tsx on lines 133..137

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

              const {
                segments,
                state,
                chosenSegment,
                conditionsConjunction,
          Severity: Major
          Found in ui/src/modules/segments/components/form/Form.tsx and 6 other locations - About 1 hr to fix
          ui/src/modules/boards/containers/ArchivedItems.tsx on lines 128..138
          ui/src/modules/boards/containers/Stage.tsx on lines 192..202
          ui/src/modules/boards/containers/label/Form.tsx on lines 44..54
          ui/src/modules/forms/containers/EditForm.tsx on lines 61..71
          ui/src/modules/inbox/components/conversationDetail/sidebar/Sidebar.tsx on lines 186..196
          ui/src/modules/leads/components/step/preview/FormPreview.tsx on lines 25..35

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

          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

                        <Link to={`/segments/${contentType}`}>
                          <Button btnStyle="simple" icon="times-circle">
                            Cancel
                          </Button>
                        </Link>
          Severity: Major
          Found in ui/src/modules/segments/components/form/Form.tsx and 3 other locations - About 50 mins to fix
          ui/src/modules/dashboard/components/DashboardDetail.tsx on lines 87..91
          ui/src/modules/dashboard/components/DashboardDetail.tsx on lines 93..97
          ui/src/modules/dashboard/components/InitialData.tsx on lines 42..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 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

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

              const {
                renderButton,
                segment,
                afterSave,
                closeModal,
          Severity: Major
          Found in ui/src/modules/segments/components/form/Form.tsx and 22 other locations - About 35 mins to fix
          dashboard-ui/src/modules/dashboard/components/QueryBuilder/ExploreQueryBuilder.tsx on lines 59..67
          ui/src/modules/boards/components/MainActionBar.tsx on lines 123..131
          ui/src/modules/boards/components/MainActionBar.tsx on lines 311..319
          ui/src/modules/boards/components/stage/ItemList.tsx on lines 196..204
          ui/src/modules/boards/containers/ListGroupBy.tsx on lines 122..130
          ui/src/modules/boards/containers/MainActionBar.tsx on lines 104..112
          ui/src/modules/boards/containers/ViewGroupBy.tsx on lines 36..44
          ui/src/modules/calendar/components/Detail.tsx on lines 67..75
          ui/src/modules/customers/components/list/CustomersList.tsx on lines 151..159
          ui/src/modules/engage/components/AutoAndManualForm.tsx on lines 246..254
          ui/src/modules/engage/components/VisitorForm.tsx on lines 154..162
          ui/src/modules/engage/containers/withFormMutations.tsx on lines 42..50
          ui/src/modules/inbox/components/conversationDetail/workarea/WorkArea.tsx on lines 158..166
          ui/src/modules/inbox/components/leftSidebar/ConversationList.tsx on lines 23..31
          ui/src/modules/knowledgeBase/components/knowledge/KnowledgeList.tsx on lines 25..33
          ui/src/modules/leads/components/List.tsx on lines 46..54
          ui/src/modules/leads/components/step/preview/SuccessPreview.tsx on lines 17..25
          ui/src/modules/segments/containers/form/SegmentsForm.tsx on lines 160..168
          ui/src/modules/settings/boards/containers/Pipelines.tsx on lines 46..54
          ui/src/modules/settings/productService/containers/product/ProductList.tsx on lines 43..51
          ui/src/modules/settings/templates/components/product/ProductList.tsx on lines 130..138
          widgets/client/messenger/components/ConversationHeadContent.tsx on lines 37..37

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

          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

              segments.forEach((cond: ISegmentMap) => {
                conditionsForPreview.push({
                  type: 'subSegment',
                  subSegmentForPreview: cond
                });
          Severity: Minor
          Found in ui/src/modules/segments/components/form/Form.tsx and 1 other location - About 30 mins to fix
          ui/src/modules/segments/components/form/Form.tsx on lines 689..694

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

          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

                segments.forEach((cond: ISegmentMap) => {
                  conditionsForPreview.push({
                    type: 'subSegment',
                    subSegmentForPreview: cond
                  });
          Severity: Minor
          Found in ui/src/modules/segments/components/form/Form.tsx and 1 other location - About 30 mins to fix
          ui/src/modules/segments/components/form/Form.tsx on lines 151..156

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

          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