Skip to content

Commit

Permalink
chore: Make a twenty Eslint Rule to make sure that icons are imported…
Browse files Browse the repository at this point in the history
… from @/ui/icons (twentyhq#1370)

Fix the imports

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Mael FOSSO <fosso.mael.elvis@gmail.com>
  • Loading branch information
3 people authored Aug 29, 2023
1 parent f8df8b5 commit 96c4156
Show file tree
Hide file tree
Showing 30 changed files with 57 additions and 36 deletions.
13 changes: 12 additions & 1 deletion front/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ module.exports = {
"unused-imports/no-unused-vars": [
"warn",
{ "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" }
]
],
'no-restricted-imports': [
'error',
{
'patterns': [
{
'group': ['@tabler/icons-react'],
'message': 'Icon imports are only allowed for `@/ui/icon`',
},
],
},
],
}
};
2 changes: 1 addition & 1 deletion front/src/modules/activities/notes/components/Notes.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { IconNotes } from '@tabler/icons-react';

import { useOpenCreateActivityDrawer } from '@/activities/hooks/useOpenCreateActivityDrawer';
import { NoteList } from '@/activities/notes/components/NoteList';
import { useNotes } from '@/activities/notes/hooks/useNotes';
import { ActivityTargetableEntity } from '@/activities/types/ActivityTargetableEntity';
import { Button } from '@/ui/button/components/Button';
import { IconNotes } from '@/ui/icon';
import { ActivityType } from '~/generated/graphql';

const StyledTaskGroupEmptyContainer = styled.div`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { IconCheckbox } from '@tabler/icons-react';

import { useOpenCreateActivityDrawer } from '@/activities/hooks/useOpenCreateActivityDrawer';
import { useTasks } from '@/activities/tasks/hooks/useTasks';
import { ActivityTargetableEntity } from '@/activities/types/ActivityTargetableEntity';
import { Button } from '@/ui/button/components/Button';
import { IconCheckbox } from '@/ui/icon';
import { ActivityType } from '~/generated/graphql';

import { AddTaskButton } from './AddTaskButton';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useState } from 'react';
import { getOperationName } from '@apollo/client/utilities';
import styled from '@emotion/styled';
import { flip, offset, useFloating } from '@floating-ui/react';
import { IconPlus } from '@tabler/icons-react';
import { v4 } from 'uuid';

import {
Expand All @@ -11,6 +10,7 @@ import {
} from '@/people/components/PeoplePicker';
import { GET_PEOPLE } from '@/people/graphql/queries/getPeople';
import { LightIconButton } from '@/ui/button/components/LightIconButton';
import { IconPlus } from '@/ui/icon';
import { RelationPickerHotkeyScope } from '@/ui/input/relation-picker/types/RelationPickerHotkeyScope';
import { TextInput } from '@/ui/input/text/components/TextInput';
import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousHotkeyScope';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IconCheckbox, IconNotes, IconTrash } from '@tabler/icons-react';
import { useSetRecoilState } from 'recoil';

import { useOpenCreateActivityDrawerForSelectedRowIds } from '@/activities/hooks/useOpenCreateActivityDrawerForSelectedRowIds';
import { ActivityTargetableEntityType } from '@/activities/types/ActivityTargetableEntity';
import { ContextMenuEntry } from '@/ui/context-menu/components/ContextMenuEntry';
import { contextMenuEntriesState } from '@/ui/context-menu/states/contextMenuEntriesState';
import { IconCheckbox, IconNotes, IconTrash } from '@/ui/icon';
import { ActivityType } from '~/generated/graphql';

import { useDeleteSelectedComapnies } from './useDeleteCompanies';
Expand Down
2 changes: 1 addition & 1 deletion front/src/modules/people/components/PeopleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { getOperationName } from '@apollo/client/utilities';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { autoUpdate, flip, offset, useFloating } from '@floating-ui/react';
import { IconDotsVertical, IconLinkOff, IconTrash } from '@tabler/icons-react';

import { FloatingIconButton } from '@/ui/button/components/FloatingIconButton';
import { DropdownMenuSelectableItem } from '@/ui/dropdown/components/DropdownMenuSelectableItem';
import { StyledDropdownMenu } from '@/ui/dropdown/components/StyledDropdownMenu';
import { StyledDropdownMenuItemsContainer } from '@/ui/dropdown/components/StyledDropdownMenuItemsContainer';
import { IconDotsVertical, IconLinkOff, IconTrash } from '@/ui/icon';
import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';
import { Avatar } from '@/users/components/Avatar';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getOperationName } from '@apollo/client/utilities';
import { IconCheckbox, IconNotes, IconTrash } from '@tabler/icons-react';
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';

import { useOpenCreateActivityDrawerForSelectedRowIds } from '@/activities/hooks/useOpenCreateActivityDrawerForSelectedRowIds';
import { ActivityTargetableEntityType } from '@/activities/types/ActivityTargetableEntity';
import { ContextMenuEntry } from '@/ui/context-menu/components/ContextMenuEntry';
import { contextMenuEntriesState } from '@/ui/context-menu/states/contextMenuEntriesState';
import { IconCheckbox, IconNotes, IconTrash } from '@/ui/icon';
import { useResetTableRowSelection } from '@/ui/table/hooks/useResetTableRowSelection';
import { selectedRowIdsSelector } from '@/ui/table/states/selectors/selectedRowIdsSelector';
import { tableRowIdsState } from '@/ui/table/states/tableRowIdsState';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
size,
useFloating,
} from '@floating-ui/react';
import { TablerIconsProps } from '@tabler/icons-react';
import debounce from 'lodash.debounce';
import { ReadonlyDeep } from 'type-fest';

Expand All @@ -20,7 +19,7 @@ import { DropdownMenuSelectableItem } from '@/ui/dropdown/components/DropdownMen
import { StyledDropdownMenu } from '@/ui/dropdown/components/StyledDropdownMenu';
import { StyledDropdownMenuItemsContainer } from '@/ui/dropdown/components/StyledDropdownMenuItemsContainer';
import { StyledDropdownMenuSeparator } from '@/ui/dropdown/components/StyledDropdownMenuSeparator';
import { IconChevronDown } from '@/ui/icon';
import { IconChevronDown, TablerIconsProps } from '@/ui/icon';
import { AppTooltip } from '@/ui/tooltip/AppTooltip';
import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';
import { useUpdateEffect } from '~/hooks/useUpdateEffect';
Expand Down
2 changes: 1 addition & 1 deletion front/src/modules/ui/board/components/EntityBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { getOperationName } from '@apollo/client/utilities';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { DragDropContext, OnDragEndResponder } from '@hello-pangea/dnd'; // Atlassian dnd does not support StrictMode from RN 18, so we use a fork @hello-pangea/dnd https://github.com/atlassian/react-beautiful-dnd/issues/2350
import { IconList } from '@tabler/icons-react';
import { useRecoilState } from 'recoil';

import { CompanyBoardRecoilScopeContext } from '@/companies/states/recoil-scope-contexts/CompanyBoardRecoilScopeContext';
Expand All @@ -12,6 +11,7 @@ import { BoardHeader } from '@/ui/board/components/BoardHeader';
import { StyledBoard } from '@/ui/board/components/StyledBoard';
import { BoardColumnIdContext } from '@/ui/board/contexts/BoardColumnIdContext';
import { SelectedSortType } from '@/ui/filter-n-sort/types/interface';
import { IconList } from '@/ui/icon';
import { DragSelect } from '@/ui/utilities/drag-select/components/DragSelect';
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
import { ScrollWrapper } from '@/ui/utilities/scroll/components/ScrollWrapper';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IconTrash } from '@tabler/icons-react';
import { useSetRecoilState } from 'recoil';

import { ContextMenuEntry } from '@/ui/context-menu/components/ContextMenuEntry';
import { contextMenuEntriesState } from '@/ui/context-menu/states/contextMenuEntriesState';
import { IconTrash } from '@/ui/icon';

import { useDeleteSelectedBoardCards } from './useDeleteSelectedBoardCards';

Expand Down
2 changes: 1 addition & 1 deletion front/src/modules/ui/button/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useMemo } from 'react';
import styled from '@emotion/styled';
import { TablerIconsProps } from '@tabler/icons-react';

import { TablerIconsProps } from '@/ui/icon';
import { SoonPill } from '@/ui/pill/components/SoonPill';

export type ButtonSize = 'medium' | 'small';
Expand Down
3 changes: 2 additions & 1 deletion front/src/modules/ui/button/components/FloatingButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useMemo } from 'react';
import styled from '@emotion/styled';
import { TablerIconsProps } from '@tabler/icons-react';

import { TablerIconsProps } from '@/ui/icon';

export type FloatingButtonSize = 'small' | 'medium';
export type FloatingButtonPosition = 'standalone' | 'left' | 'middle' | 'right';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useMemo } from 'react';
import styled from '@emotion/styled';
import { TablerIconsProps } from '@tabler/icons-react';

import { TablerIconsProps } from '@/ui/icon';

export type FloatingIconButtonSize = 'small' | 'medium';
export type FloatingIconButtonPosition =
Expand Down
3 changes: 2 additions & 1 deletion front/src/modules/ui/button/components/IconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useMemo } from 'react';
import styled from '@emotion/styled';
import { TablerIconsProps } from '@tabler/icons-react';

import { TablerIconsProps } from '@/ui/icon';

export type IconButtonSize = 'medium' | 'small';
export type IconButtonPosition = 'standalone' | 'left' | 'middle' | 'right';
Expand Down
3 changes: 2 additions & 1 deletion front/src/modules/ui/button/components/LightButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { MouseEvent, useMemo } from 'react';
import styled from '@emotion/styled';
import { TablerIconsProps } from '@tabler/icons-react';

import { TablerIconsProps } from '@/ui/icon';

export type LightButtonAccent = 'secondary' | 'tertiary';

Expand Down
3 changes: 2 additions & 1 deletion front/src/modules/ui/button/components/LightIconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { MouseEvent, useMemo } from 'react';
import styled from '@emotion/styled';
import { TablerIconsProps } from '@tabler/icons-react';

import { TablerIconsProps } from '@/ui/icon';

export type LightIconButtonAccent = 'secondary' | 'tertiary';
export type LightIconButtonSize = 'small' | 'medium';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta, StoryObj } from '@storybook/react';
import { IconCalendar } from '@tabler/icons-react';

import { IconCalendar } from '@/ui/icon';
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';

import { DateEditableField } from '../DateEditableField';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta, StoryObj } from '@storybook/react';
import { IconPhone } from '@tabler/icons-react';

import { IconPhone } from '@/ui/icon';
import { ComponentWithRouterDecorator } from '~/testing/decorators/ComponentWithRouterDecorator';

import { PhoneEditableField } from '../PhoneEditableField';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Context } from 'react';
import { useTheme } from '@emotion/react';
import { IconChevronDown } from '@tabler/icons-react';

import { DropdownMenuHeader } from '@/ui/dropdown/components/DropdownMenuHeader';
import { IconChevronDown } from '@/ui/icon';
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';

import { isFilterDropdownOperandSelectUnfoldedScopedState } from '../states/isFilterDropdownOperandSelectUnfoldedScopedState';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Context, useState } from 'react';
import React from 'react';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { IconChevronDown } from '@tabler/icons-react';

import { filterDefinitionUsedInDropdownScopedState } from '@/ui/filter-n-sort/states/filterDefinitionUsedInDropdownScopedState';
import { filterDropdownSearchInputScopedState } from '@/ui/filter-n-sort/states/filterDropdownSearchInputScopedState';
import { selectedOperandInDropdownScopedState } from '@/ui/filter-n-sort/states/selectedOperandInDropdownScopedState';
import { IconChevronDown } from '@/ui/icon';
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Context, useCallback, useState } from 'react';
import { useTheme } from '@emotion/react';
import { IconChevronDown } from '@tabler/icons-react';

import { DropdownMenuHeader } from '@/ui/dropdown/components/DropdownMenuHeader';
import { DropdownMenuSelectableItem } from '@/ui/dropdown/components/DropdownMenuSelectableItem';
import { StyledDropdownMenuItemsContainer } from '@/ui/dropdown/components/StyledDropdownMenuItemsContainer';
import { StyledDropdownMenuSeparator } from '@/ui/dropdown/components/StyledDropdownMenuSeparator';
import { IconChevronDown } from '@/ui/icon';
import { OverflowingTextWithTooltip } from '@/ui/tooltip/OverflowingTextWithTooltip';
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';

Expand Down
2 changes: 1 addition & 1 deletion front/src/modules/ui/icon/components/IconAddressBook.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TablerIconsProps } from '@tabler/icons-react';
import { TablerIconsProps } from '@/ui/icon';

import { ReactComponent as IconAddressBookRaw } from '../assets/address-book.svg';

Expand Down
5 changes: 5 additions & 0 deletions front/src/modules/ui/icon/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-restricted-imports */
export type { TablerIconsProps } from '@tabler/icons-react';
export {
IconAlertCircle,
IconAlertTriangle,
Expand Down Expand Up @@ -29,6 +31,7 @@ export {
IconCopy,
IconCross,
IconCurrencyDollar,
IconDotsVertical,
IconEye,
IconEyeOff,
IconFileImport,
Expand All @@ -39,7 +42,9 @@ export {
IconInbox,
IconLayoutSidebarLeftCollapse,
IconLayoutSidebarRightCollapse,
IconLayoutSidebarRightExpand,
IconLink,
IconLinkOff,
IconList,
IconLogout,
IconMail,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
IconLayoutSidebarRightCollapse,
IconLayoutSidebarRightExpand,
} from '@tabler/icons-react';
import { useRecoilState } from 'recoil';

import { LightIconButton } from '@/ui/button/components/LightIconButton';
import {
IconLayoutSidebarRightCollapse,
IconLayoutSidebarRightExpand,
} from '@/ui/icon';

import { isRightDrawerExpandedState } from '../states/isRightDrawerExpandedState';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta, StoryObj } from '@storybook/react';
import { IconCheckbox } from '@tabler/icons-react';

import { IconCheckbox } from '@/ui/icon';
import { CatalogDecorator } from '~/testing/decorators/CatalogDecorator';
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from '@storybook/jest';
import type { Meta, StoryObj } from '@storybook/react';
import { within } from '@storybook/testing-library';
import { IconCheckbox } from '@tabler/icons-react';

import { IconCheckbox } from '@/ui/icon';
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ReactElement, useState } from 'react';
import styled from '@emotion/styled';
import { IconPencil } from '@tabler/icons-react';
import { motion } from 'framer-motion';

import { FloatingIconButton } from '@/ui/button/components/FloatingIconButton';
import { IconPencil } from '@/ui/icon';
import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';

import { CellHotkeyScopeContext } from '../../contexts/CellHotkeyScopeContext';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import styled from '@emotion/styled';
import { IconCheck, IconX } from '@tabler/icons-react';
import { useRecoilState } from 'recoil';

import type { ViewFieldBooleanMetadata } from '@/ui/editable-field/types/ViewField';
import { IconCheck, IconX } from '@/ui/icon';
import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';
import { useUpdateEntityField } from '@/ui/table/hooks/useUpdateEntityField';
import { tableEntityFieldFamilySelector } from '@/ui/table/states/selectors/tableEntityFieldFamilySelector';
Expand Down
3 changes: 1 addition & 2 deletions front/src/pages/tasks/tasks-filters.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IconUser } from '@tabler/icons-react';

import { TasksRecoilScopeContext } from '@/activities/states/recoil-scope-contexts/TasksRecoilScopeContext';
import { FilterDefinitionByEntity } from '@/ui/filter-n-sort/types/FilterDefinitionByEntity';
import { IconUser } from '@/ui/icon';
import { FilterDropdownUserSearchSelect } from '@/users/components/FilterDropdownUserSearchSelect';
import { Activity } from '~/generated/graphql';

Expand Down
8 changes: 5 additions & 3 deletions front/src/sync-hooks/PageChangeEffect.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useEffect, useState } from 'react';
import { matchPath, useLocation, useNavigate } from 'react-router-dom';
import { IconCheckbox, IconNotes } from '@tabler/icons-react';

import { useOpenCreateActivityDrawer } from '@/activities/hooks/useOpenCreateActivityDrawer';
import { ActivityTargetableEntityType } from '@/activities/types/ActivityTargetableEntity';
Expand All @@ -13,11 +12,14 @@ import { AppBasePath } from '@/types/AppBasePath';
import { AppPath } from '@/types/AppPath';
import { PageHotkeyScope } from '@/types/PageHotkeyScope';
import { SettingsPath } from '@/types/SettingsPath';
import { IconCheckbox, IconNotes } from '@/ui/icon';
import { useSnackBar } from '@/ui/snack-bar/hooks/useSnackBar';
import { TableHotkeyScope } from '@/ui/table/types/TableHotkeyScope';
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
import { useGetWorkspaceFromInviteHashLazyQuery } from '~/generated/graphql';
import { ActivityType } from '~/generated/graphql';
import {
ActivityType,
useGetWorkspaceFromInviteHashLazyQuery,
} from '~/generated/graphql';

import { useIsMatchingLocation } from '../hooks/useIsMatchingLocation';

Expand Down

0 comments on commit 96c4156

Please sign in to comment.