mirror of
https://github.com/twentyhq/twenty
synced 2026-04-21 21:47:38 +00:00
## Summary
Continues the Emotion → Linaria migration (PR 4-6 from the [migration
plan](docs/emotion-to-linaria-migration-plan.md)). Migrates **311
files** across four module groups:
| Module | Files |
|---|---|
| command-menu | 53 |
| workflow | 84 |
| page-layout | 84 |
| UI (partial - first ~80 files) | ~80 |
| twenty-ui (TEXT_INPUT_STYLE) | 1 |
| misc (hooks, keyboard-shortcut-menu, file-upload) | ~9 |
### Migration patterns applied
- `import styled from '@emotion/styled'` → `import { styled } from
'@linaria/react'`
- `import { useTheme } from '@emotion/react'` → `import { useContext }
from 'react'` + `import { ThemeContext } from 'twenty-ui/theme'`
- `${({ theme }) => theme.X.Y.Z}` → `${themeCssVariables.X.Y.Z}` (static
CSS variables)
- `theme.spacing(N)` → `themeCssVariables.spacing[N]`
- `styled(motion.div)` → `motion.create(StyledBase)` (11 components)
- `styled(Component)<TypeParams>` → wrapper div approach for non-HTML
elements
- Multi-declaration interpolations split into one CSS property per
interpolation
- Interpolation return types fixed (`&&` → ternary `? : ''`)
- `TEXT_INPUT_STYLE` converted from function to static string constant
(backward compatible)
- Emotion `<Global>` replaced with `useEffect` style injection
- Complex runtime-dependent styles use CSS custom properties via
`style={}` prop
### After this PR
- **Remaining files**: ~400 (object-record: ~160, settings: ~200, UI:
~44)
- **No breaking changes**: CSS variables resolve identically to the
previous Emotion theme values
151 lines
5.2 KiB
TypeScript
151 lines
5.2 KiB
TypeScript
import { styled } from '@linaria/react';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
import {
|
|
IconColumnInsertRight,
|
|
OverflowingTextWithTooltip,
|
|
} from 'twenty-ui/display';
|
|
|
|
import { CommandMenuAskAIInfo } from '@/command-menu/components/CommandMenuAskAIInfo';
|
|
import { CommandMenuFolderInfo } from '@/command-menu/components/CommandMenuFolderInfo';
|
|
import { CommandMenuLinkInfo } from '@/command-menu/components/CommandMenuLinkInfo';
|
|
import { CommandMenuMultipleRecordsInfo } from '@/command-menu/components/CommandMenuMultipleRecordsInfo';
|
|
import { CommandMenuObjectViewRecordInfo } from '@/command-menu/components/CommandMenuObjectViewRecordInfo';
|
|
import { CommandMenuPageInfoLayout } from '@/command-menu/components/CommandMenuPageInfoLayout';
|
|
import { CommandMenuPageLayoutInfo } from '@/command-menu/components/CommandMenuPageLayoutInfo';
|
|
import { CommandMenuRecordInfo } from '@/command-menu/components/CommandMenuRecordInfo';
|
|
import { CommandMenuWorkflowStepInfo } from '@/command-menu/components/CommandMenuWorkflowStepInfo';
|
|
import { NavigationMenuItemType } from '@/navigation-menu-item/constants/NavigationMenuItemType';
|
|
import { useWorkspaceSectionItems } from '@/navigation-menu-item/hooks/useWorkspaceSectionItems';
|
|
import { selectedNavigationMenuItemInEditModeState } from '@/navigation-menu-item/states/selectedNavigationMenuItemInEditModeState';
|
|
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
|
|
import { CommandMenuPages } from 'twenty-shared/types';
|
|
|
|
import { type CommandMenuContextChipProps } from './CommandMenuContextChip';
|
|
import { themeCssVariables } from 'twenty-ui/theme-constants';
|
|
import { useContext } from 'react';
|
|
import { ThemeContext } from 'twenty-ui/theme';
|
|
|
|
const StyledPageTitle = styled.div`
|
|
color: ${themeCssVariables.font.color.primary};
|
|
font-size: ${themeCssVariables.font.size.sm};
|
|
font-weight: ${themeCssVariables.font.weight.semiBold};
|
|
`;
|
|
|
|
type CommandMenuPageInfoProps = {
|
|
pageChip: CommandMenuContextChipProps | undefined;
|
|
};
|
|
|
|
export const CommandMenuPageInfo = ({ pageChip }: CommandMenuPageInfoProps) => {
|
|
const { theme } = useContext(ThemeContext);
|
|
const selectedNavigationMenuItemInEditMode = useAtomStateValue(
|
|
selectedNavigationMenuItemInEditModeState,
|
|
);
|
|
const items = useWorkspaceSectionItems();
|
|
|
|
if (!isDefined(pageChip)) {
|
|
return null;
|
|
}
|
|
|
|
const isNavigationMenuItemEditPage =
|
|
pageChip.page?.page === CommandMenuPages.NavigationMenuItemEdit;
|
|
const selectedNavItem = isNavigationMenuItemEditPage
|
|
? items.find((item) => item.id === selectedNavigationMenuItemInEditMode)
|
|
: undefined;
|
|
|
|
if (isNavigationMenuItemEditPage && isDefined(selectedNavItem)) {
|
|
const itemType = selectedNavItem.itemType;
|
|
|
|
if (itemType === NavigationMenuItemType.FOLDER) {
|
|
return <CommandMenuFolderInfo />;
|
|
}
|
|
|
|
if (itemType === NavigationMenuItemType.LINK) {
|
|
return <CommandMenuLinkInfo />;
|
|
}
|
|
|
|
if (
|
|
itemType === NavigationMenuItemType.VIEW ||
|
|
itemType === NavigationMenuItemType.RECORD
|
|
) {
|
|
return <CommandMenuObjectViewRecordInfo />;
|
|
}
|
|
}
|
|
|
|
const isRecordPage = pageChip.page?.page === CommandMenuPages.ViewRecord;
|
|
|
|
if (isRecordPage && isDefined(pageChip.page?.pageId)) {
|
|
return (
|
|
<CommandMenuRecordInfo commandMenuPageInstanceId={pageChip.page.pageId} />
|
|
);
|
|
}
|
|
|
|
const isWorkflowStepPage = pageChip.page?.page
|
|
? [
|
|
CommandMenuPages.WorkflowStepEdit,
|
|
CommandMenuPages.WorkflowStepView,
|
|
CommandMenuPages.WorkflowRunStepView,
|
|
].includes(pageChip.page?.page)
|
|
: false;
|
|
|
|
if (isWorkflowStepPage && isDefined(pageChip.page?.pageId)) {
|
|
return (
|
|
<CommandMenuWorkflowStepInfo
|
|
key={pageChip.page.pageId}
|
|
commandMenuPageInstanceId={pageChip.page.pageId}
|
|
/>
|
|
);
|
|
}
|
|
|
|
const isPageLayoutPage = pageChip.page?.page
|
|
? [
|
|
CommandMenuPages.PageLayoutWidgetTypeSelect,
|
|
CommandMenuPages.PageLayoutGraphTypeSelect,
|
|
CommandMenuPages.PageLayoutGraphFilter,
|
|
CommandMenuPages.PageLayoutIframeSettings,
|
|
CommandMenuPages.PageLayoutTabSettings,
|
|
CommandMenuPages.PageLayoutFieldsSettings,
|
|
CommandMenuPages.PageLayoutFieldsLayout,
|
|
].includes(pageChip.page?.page)
|
|
: false;
|
|
|
|
if (isPageLayoutPage) {
|
|
return <CommandMenuPageLayoutInfo />;
|
|
}
|
|
|
|
const isMultipleRecordsPage =
|
|
pageChip.page?.page === CommandMenuPages.UpdateRecords;
|
|
|
|
if (isMultipleRecordsPage && isDefined(pageChip.page?.pageId)) {
|
|
return (
|
|
<CommandMenuMultipleRecordsInfo
|
|
commandMenuPageInstanceId={pageChip.page.pageId}
|
|
/>
|
|
);
|
|
}
|
|
|
|
const isAskAIPage = pageChip.page?.page === CommandMenuPages.AskAI;
|
|
|
|
if (isAskAIPage) {
|
|
return <CommandMenuAskAIInfo />;
|
|
}
|
|
|
|
if (pageChip.page?.page === CommandMenuPages.NavigationMenuAddItem) {
|
|
return (
|
|
<CommandMenuPageInfoLayout
|
|
icon={
|
|
<IconColumnInsertRight
|
|
size={theme.icon.size.md}
|
|
color={theme.font.color.tertiary}
|
|
/>
|
|
}
|
|
title={<OverflowingTextWithTooltip text={pageChip.text ?? ''} />}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<StyledPageTitle>
|
|
<OverflowingTextWithTooltip text={pageChip.text ?? ''} />
|
|
</StyledPageTitle>
|
|
);
|
|
};
|