RocketChat/Rocket.Chat

View on GitHub
apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx

Summary

Maintainability
D
2 days
Test Coverage

Function MonitorsTable has 150 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const MonitorsTable = () => {
    const t = useTranslation();
    const setModal = useSetModal();

    const [text, setText] = useState('');
Severity: Major
Found in apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx - About 6 hrs to fix

    Function MonitorsTable has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    const MonitorsTable = () => {
        const t = useTranslation();
        const setModal = useSetModal();
    
        const [text, setText] = useState('');
    Severity: Minor
    Found in apps/meteor/client/omnichannel/monitors/MonitorsTable.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

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

                {isError && (
                    <States>
                        <StatesIcon name='warning' variation='danger' />
                        <StatesTitle>{t('Something_went_wrong')}</StatesTitle>
                        <StatesActions>
    Severity: Major
    Found in apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx and 11 other locations - About 3 hrs to fix
    apps/meteor/client/omnichannel/businessHours/BusinessHoursTable.tsx on lines 81..89
    apps/meteor/client/views/admin/customEmoji/CustomEmoji.tsx on lines 116..124
    apps/meteor/client/views/admin/customSounds/CustomSoundsTable/CustomSoundsTable.tsx on lines 98..106
    apps/meteor/client/views/admin/integrations/IntegrationsTable.tsx on lines 131..139
    apps/meteor/client/views/admin/invites/InvitesPage.tsx on lines 114..122
    apps/meteor/client/views/admin/moderation/UserReports/ModConsoleUsersTable.tsx on lines 136..144
    apps/meteor/client/views/admin/rooms/RoomsTable.tsx on lines 153..161
    apps/meteor/client/views/directory/tabs/channels/ChannelsTable/ChannelsTable.tsx on lines 130..138
    apps/meteor/client/views/directory/tabs/teams/TeamsTable/TeamsTable.tsx on lines 112..120
    apps/meteor/client/views/directory/tabs/users/UsersTable/UsersTable.tsx on lines 136..144
    apps/meteor/client/views/omnichannel/directory/chats/ChatTable.tsx on lines 173..181

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

    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 query = useMemo(
            () => ({
                text: debouncedText,
                sort: `{ "${sortBy}": ${sortDirection === 'asc' ? 1 : -1} }`,
                ...(itemsPerPage && { count: itemsPerPage }),
    Severity: Major
    Found in apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx and 1 other location - About 2 hrs to fix
    apps/meteor/client/views/omnichannel/customFields/CustomFieldsTable.tsx on lines 36..44

    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

                {isSuccess && data.monitors.length === 0 && !queryHasChanged && (
                    <GenericNoResults
                        icon='shield-blank'
                        title={t('No_monitors_yet')}
                        description={t('No_monitors_yet_description')}
    Severity: Major
    Found in apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx and 1 other location - About 2 hrs to fix
    apps/meteor/client/views/omnichannel/agents/AgentsTable/AgentsTable.tsx on lines 86..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 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

                try {
                    await removeMonitor(username);
                    dispatchToastMessage({ type: 'success', message: t('Monitor_removed') });
                } catch (error) {
                    dispatchToastMessage({ type: 'error', message: error });
    Severity: Major
    Found in apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx and 1 other location - About 1 hr to fix
    apps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx on lines 79..84

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

    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={4} />
    Severity: Major
    Found in apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx and 23 other locations - About 1 hr to fix
    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/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/currentChats/CurrentChatsPage.tsx on lines 331..338
    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 19 locations. Consider refactoring.
    Open

                        <Pagination
                            divider
                            current={current}
                            itemsPerPage={itemsPerPage}
                            count={data?.total || 0}
    Severity: Major
    Found in apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx and 18 other locations - About 1 hr to fix
    apps/meteor/client/components/deviceManagement/DeviceManagementTable/DeviceManagementTable.tsx on lines 69..77
    apps/meteor/client/omnichannel/cannedResponses/CannedResponsesTable.tsx on lines 188..196
    apps/meteor/client/omnichannel/slaPolicies/SlaTable.tsx on lines 125..133
    apps/meteor/client/omnichannel/tags/TagsTable.tsx on lines 118..126
    apps/meteor/client/omnichannel/units/UnitsTable.tsx on lines 118..126
    apps/meteor/client/views/admin/customEmoji/CustomEmoji.tsx on lines 104..112
    apps/meteor/client/views/admin/integrations/IntegrationsTable.tsx on lines 119..127
    apps/meteor/client/views/admin/rooms/RoomsTable.tsx on lines 142..150
    apps/meteor/client/views/admin/settings/groups/VoipGroupPage/VoipExtensionsPage.tsx on lines 126..134
    apps/meteor/client/views/directory/tabs/channels/ChannelsTable/ChannelsTable.tsx on lines 118..126
    apps/meteor/client/views/directory/tabs/teams/TeamsTable/TeamsTable.tsx on lines 100..108
    apps/meteor/client/views/directory/tabs/users/UsersTable/UsersTable.tsx on lines 124..132
    apps/meteor/client/views/omnichannel/agents/AgentsTable/AgentsTable.tsx on lines 105..113
    apps/meteor/client/views/omnichannel/departments/DepartmentsTable/DepartmentsTable.tsx on lines 134..142
    apps/meteor/client/views/omnichannel/directory/calls/CallTable.tsx on lines 127..135
    apps/meteor/client/views/omnichannel/directory/chats/ChatTable.tsx on lines 162..170
    apps/meteor/client/views/omnichannel/queueList/QueueListTable.tsx on lines 148..156
    apps/meteor/client/views/omnichannel/triggers/TriggersTable.tsx on lines 78..86

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

    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

            setModal(
                <GenericModal
                    variant='danger'
                    data-qa-id='manage-monitors-confirm-remove'
                    onConfirm={onDeleteMonitor}
    Severity: Major
    Found in apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx and 2 other locations - About 55 mins to fix
    apps/meteor/client/omnichannel/units/useRemoveUnit.tsx on lines 31..39
    apps/meteor/client/views/omnichannel/agents/hooks/useRemoveAgent.tsx on lines 32..40

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

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

                <GenericTableHeaderCell key='name' direction={sortDirection} active={sortBy === 'name'} onClick={setSort}>
                    {t('Name')}
                </GenericTableHeaderCell>,
    Severity: Major
    Found in apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx and 7 other locations - About 45 mins to fix
    apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx on lines 123..125
    apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx on lines 126..128
    apps/meteor/client/omnichannel/reports/components/AgentsTable.tsx on lines 34..36
    apps/meteor/client/omnichannel/reports/components/AgentsTable.tsx on lines 37..39
    apps/meteor/client/views/admin/emailInbox/EmailInboxTable.tsx on lines 49..51
    apps/meteor/client/views/admin/emailInbox/EmailInboxTable.tsx on lines 52..54
    apps/meteor/client/views/admin/emailInbox/EmailInboxTable.tsx on lines 55..57

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

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

                <GenericTableHeaderCell key='username' direction={sortDirection} active={sortBy === 'username'} onClick={setSort}>
                    {t('Username')}
                </GenericTableHeaderCell>,
    Severity: Major
    Found in apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx and 7 other locations - About 45 mins to fix
    apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx on lines 120..122
    apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx on lines 126..128
    apps/meteor/client/omnichannel/reports/components/AgentsTable.tsx on lines 34..36
    apps/meteor/client/omnichannel/reports/components/AgentsTable.tsx on lines 37..39
    apps/meteor/client/views/admin/emailInbox/EmailInboxTable.tsx on lines 49..51
    apps/meteor/client/views/admin/emailInbox/EmailInboxTable.tsx on lines 52..54
    apps/meteor/client/views/admin/emailInbox/EmailInboxTable.tsx on lines 55..57

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

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

                <GenericTableHeaderCell key='email' direction={sortDirection} active={sortBy === 'email'} onClick={setSort}>
                    {t('Email')}
                </GenericTableHeaderCell>,
    Severity: Major
    Found in apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx and 7 other locations - About 45 mins to fix
    apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx on lines 120..122
    apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx on lines 123..125
    apps/meteor/client/omnichannel/reports/components/AgentsTable.tsx on lines 34..36
    apps/meteor/client/omnichannel/reports/components/AgentsTable.tsx on lines 37..39
    apps/meteor/client/views/admin/emailInbox/EmailInboxTable.tsx on lines 49..51
    apps/meteor/client/views/admin/emailInbox/EmailInboxTable.tsx on lines 52..54
    apps/meteor/client/views/admin/emailInbox/EmailInboxTable.tsx on lines 55..57

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

    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