RocketChat/Rocket.Chat

View on GitHub
apps/meteor/client/views/omnichannel/currentChats/CurrentChatsPage.tsx

Summary

Maintainability
D
2 days
Test Coverage

File CurrentChatsPage.tsx has 339 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { Callout, Pagination } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import type { GETLivechatRoomsParams } from '@rocket.chat/rest-typings';
import { usePermission, useTranslation } from '@rocket.chat/ui-contexts';
import { hashQueryKey } from '@tanstack/react-query';

    Function currentChatQuery has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    const currentChatQuery: useQueryType = (
        { guest, servedBy, department, status, from, to, tags },
        customFields,
        [column, direction],
        current,

    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 CurrentChatsPage has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    const CurrentChatsPage = ({ id, onRowClick }: { id?: string; onRowClick: (_id: string) => void }): ReactElement => {
        const isWorkspaceOverMacLimit = useIsOverMacLimit();
        const { sortBy, sortDirection, setSort } = useSort<'fname' | 'departmentId' | 'servedBy' | 'priorityWeight' | 'ts' | 'lm' | 'open'>(
            'ts',
            'desc',

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

            (room) => {
                const { _id, fname, servedBy, ts, lm, department, open, onHold, priorityWeight } = room;
                const getStatusText = (open: boolean, onHold: boolean, servedBy: boolean): string => {
                    if (!open) return t('Closed');
                    if (open && !servedBy) return t('Queued');

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

                          {isSuccess && data?.rooms.length === 0 && !queryHasChanged && (
                              <GenericNoResults
                                  icon='discussion'
                                  title={t('No_chats_yet')}
                                  description={t('No_chats_yet_description')}
      apps/meteor/client/views/omnichannel/directory/calls/CallTable.tsx on lines 108..116
      apps/meteor/client/views/omnichannel/directory/chats/ChatTable.tsx on lines 147..155

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

                      <GenericTableHeaderCell
                          key='priorityWeight'
                          direction={sortDirection}
                          active={sortBy === 'priorityWeight'}
                          onClick={setSort}
      apps/meteor/client/views/omnichannel/currentChats/CurrentChatsPage.tsx on lines 278..288

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

      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

                  <GenericTableHeaderCell
                      key='open'
                      direction={sortDirection}
                      active={sortBy === 'open'}
                      onClick={setSort}
      apps/meteor/client/views/omnichannel/currentChats/CurrentChatsPage.tsx on lines 216..226

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

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

                          {isLoading && (
                              <GenericTable>
                                  <GenericTableHeader>{headers}</GenericTableHeader>
                                  <GenericTableBody>
                                      <GenericTableLoadingTable headerCells={6} />
      apps/meteor/client/omnichannel/businessHours/BusinessHoursTable.tsx on lines 51..58
      apps/meteor/client/omnichannel/cannedResponses/CannedResponsesTable.tsx on lines 128..135
      apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx on lines 148..155
      apps/meteor/client/omnichannel/priorities/PrioritiesTable.tsx on lines 38..45
      apps/meteor/client/omnichannel/slaPolicies/SlaTable.tsx on lines 88..95
      apps/meteor/client/omnichannel/tags/TagsTable.tsx on lines 74..81
      apps/meteor/client/views/admin/customEmoji/CustomEmoji.tsx on lines 70..77
      apps/meteor/client/views/admin/customSounds/CustomSoundsTable/CustomSoundsTable.tsx on lines 68..75
      apps/meteor/client/views/admin/invites/InvitesPage.tsx on lines 94..101
      apps/meteor/client/views/admin/oauthApps/OAuthAppsTable.tsx on lines 51..58
      apps/meteor/client/views/admin/permissions/UsersInRole/UsersInRoleTable/UsersInRoleTable.tsx on lines 91..98
      apps/meteor/client/views/admin/settings/groups/VoipGroupPage/VoipExtensionsPage.tsx on lines 70..77
      apps/meteor/client/views/audit/components/AuditLogTable.tsx on lines 63..70
      apps/meteor/client/views/directory/tabs/channels/ChannelsTable/ChannelsTable.tsx on lines 100..107
      apps/meteor/client/views/directory/tabs/teams/TeamsTable/TeamsTable.tsx on lines 77..84
      apps/meteor/client/views/directory/tabs/users/UsersTable/UsersTable.tsx on lines 99..106
      apps/meteor/client/views/omnichannel/customFields/CustomFieldsTable.tsx on lines 79..86
      apps/meteor/client/views/omnichannel/departments/DepartmentsTable/DepartmentsTable.tsx on lines 95..102
      apps/meteor/client/views/omnichannel/directory/calls/CallTable.tsx on lines 99..106
      apps/meteor/client/views/omnichannel/directory/chats/ChatTable.tsx on lines 138..145
      apps/meteor/client/views/omnichannel/directory/contacts/ContactTable.tsx on lines 115..122
      apps/meteor/client/views/omnichannel/queueList/QueueListTable.tsx on lines 117..124
      apps/meteor/client/views/omnichannel/triggers/TriggersTable.tsx on lines 48..55

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

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

                  const { _id, fname, servedBy, ts, lm, department, open, onHold, priorityWeight } = room;
      apps/meteor/app/api/server/lib/emailInbox.ts on lines 62..62
      apps/meteor/client/apps/orchestrator.ts on lines 65..65
      apps/meteor/client/views/admin/settings/Setting/Setting.tsx on lines 96..96
      apps/meteor/client/views/directory/tabs/channels/ChannelsTable/ChannelsTableRow.tsx on lines 20..20
      apps/meteor/client/views/marketplace/AppsList/AppRow.tsx on lines 15..15

      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

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

                                  <Pagination
                                      divider
                                      current={current}
                                      itemsPerPage={itemsPerPage}
                                      count={data.total}
      apps/meteor/client/views/omnichannel/departments/DepartmentAgentsTable/DepartmentAgentsTable.tsx on lines 45..53

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

      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

                  ...(from && {
                      start: moment(new Date(from)).set({ hour: 0, minutes: 0, seconds: 0 }).toISOString(),
                  }),
      apps/meteor/client/views/omnichannel/currentChats/CurrentChatsPage.tsx on lines 92..94

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

      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

                  ...(to && {
                      end: moment(new Date(to)).set({ hour: 23, minutes: 59, seconds: 59 }).toISOString(),
                  }),
      apps/meteor/client/views/omnichannel/currentChats/CurrentChatsPage.tsx on lines 89..91

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

      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

      const sortDir = (sortDir: 'asc' | 'desc'): 1 | -1 => (sortDir === 'asc' ? 1 : -1);
      apps/meteor/client/views/omnichannel/agents/hooks/useQuery.ts on lines 4..4

      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

      There are no issues that match your filters.

      Category
      Status