portainer/portainer

View on GitHub
app/react/kubernetes/ingresses/CreateIngressView/CreateIngressView.tsx

Summary

Maintainability
F
1 wk
Test Coverage

Function CreateIngressView has 726 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function CreateIngressView() {
  const environmentId = useEnvironmentId();
  const { params } = useCurrentStateAndParams();
  const { authorized: isAuthorizedToAddEdit } = useAuthorizations([
    'K8sIngressesW',
Severity: Major
Found in app/react/kubernetes/ingresses/CreateIngressView/CreateIngressView.tsx - About 3 days to fix

    File CreateIngressView.tsx has 765 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import { useState, useEffect, useMemo, useCallback, ReactNode } from 'react';
    import { useCurrentStateAndParams, useRouter } from '@uirouter/react';
    import { v4 as uuidv4 } from 'uuid';
    import { debounce } from 'lodash';
    
    

      Function CreateIngressView has a Cognitive Complexity of 71 (exceeds 5 allowed). Consider refactoring.
      Open

      export function CreateIngressView() {
        const environmentId = useEnvironmentId();
        const { params } = useCurrentStateAndParams();
        const { authorized: isAuthorizedToAddEdit } = useAuthorizations([
          'K8sIngressesW',

      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 validate has 151 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          (
            ingressRule: Rule,
            ingressNames: string[],
            groupedServiceOptions: GroupedServiceOptions,
            existingIngressClass?: IngressController

        Function handleCreateIngressRules has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          function handleCreateIngressRules() {
            const rule = { ...ingressRule };
        
            const classNameToSend =
              rule.IngressClassName === 'none' ? '' : rule.IngressClassName;

          Function ingressClassOptions has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            const ingressClassOptions: Option<string>[] = useMemo(() => {
              const allowedIngressClassOptions =
                ingressControllers
                  ?.filter((controller) => !!controller.Availability)
                  .map((cls) => ({

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

              const serviceOptions: GroupedServiceOptions = useMemo(() => {
                const groupedOptions: GroupedServiceOptions = (
                  allServices?.reduce<GroupedServiceOptions>(
                    (groupedOptions, service) => {
                      // add a new option to the group that matches the service type

              Consider simplifying this complex logical expression.
              Open

                  if (
                    !!params.name &&
                    ingressesResults.data &&
                    !ingressRule.IngressName &&
                    !ingressControllersQuery.isLoading &&
              Severity: Major
              Found in app/react/kubernetes/ingresses/CreateIngressView/CreateIngressView.tsx - About 40 mins to fix

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

                            if (key[0].length > 63) {
                              errors[`annotations.key[${i}]`] =
                                "Name (the segment after a slash (/), or only segment if no slash) can't exceed 63 characters.";
                            } else if (!re.test(key[0])) {
                              errors[`annotations.key[${i}]`] =
                app/react/kubernetes/ingresses/CreateIngressView/CreateIngressView.tsx on lines 430..436

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

                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

                            } else if (key[1].length > 63) {
                              errors[`annotations.key[${i}]`] =
                                "Name (after the slash) can't exceed 63 characters.";
                            } else if (!re.test(key[1])) {
                              errors[`annotations.key[${i}]`] =
                app/react/kubernetes/ingresses/CreateIngressView/CreateIngressView.tsx on lines 438..444

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

                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

                    if (isEdit) {
                      updateIngressMutation.mutate(
                        { environmentId, ingress },
                        {
                          onSuccess: () => {
                app/react/kubernetes/ingresses/CreateIngressView/CreateIngressView.tsx on lines 848..858

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

                    } else {
                      createIngressMutation.mutate(
                        { environmentId, ingress },
                        {
                          onSuccess: () => {
                app/react/kubernetes/ingresses/CreateIngressView/CreateIngressView.tsx on lines 838..848

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

                      Object.entries(namespaces || {})
                        .filter(([, nsValue]) => !nsValue.IsSystem)
                        .map(([nsKey]) => ({
                          label: nsKey,
                          value: nsKey,
                app/react/kubernetes/applications/components/NamespaceSelector/NamespaceSelector.tsx on lines 25..30

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

                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