7a2e397ad1
## Summary
Completes the migration of the frontend styling system from **Emotion**
(`@emotion/styled`, `@emotion/react`) to **Linaria** (`@linaria/react`,
`@linaria/core`), a zero-runtime CSS-in-JS library where styles are
extracted at build time.
This is the final step of the migration — all ~494 files across
`twenty-front`, `twenty-ui`, `twenty-website`, and `twenty-sdk` are now
fully converted.
## Changes
### Styling Migration (across ~480 component files)
- Replaced all `@emotion/styled` imports with `@linaria/react`
- Converted runtime theme access patterns (`({ theme }) => theme.x.y`)
to build-time `themeCssVariables` CSS custom properties
- Replaced `useTheme()` hook (from Emotion) with
`useContext(ThemeContext)` where runtime theme values are still needed
(e.g., passing colors to non-CSS props like icon components)
- Removed `@emotion/react` `css` helper usages in favor of Linaria
template literals
### Dependency & Configuration Changes
- **Removed**: `@emotion/react`, `@emotion/styled` from root
`package.json`
- **Added**: `@wyw-in-js/babel-preset`, `next-with-linaria` (for
twenty-website SSR support)
- Updated Nx generator defaults from `@emotion/styled` to
`@linaria/react` in `nx.json`
- Simplified `vite.config.ts` (removed Emotion-specific configuration)
- Updated `twenty-website/next.config.js` to use `next-with-linaria` for
SSR Linaria support
### Storybook & Testing
- Removed `ThemeProvider` from Emotion in Storybook previews
(`twenty-front`, `twenty-sdk`)
- Now relies solely on `ThemeContextProvider` for theme injection
### Documentation
- Removed the temporary `docs/emotion-to-linaria-migration-plan.md`
(migration complete)
- Updated `CLAUDE.md` and `README.md` to reflect Linaria as the styling
stack
- Updated frontend style guide docs across all locales
## How it works
Linaria extracts styles at build time via the `@wyw-in-js/vite` plugin.
All expressions in `styled` template literals must be **statically
evaluable** — no runtime theme objects or closures over component state.
- **Static styles** use `themeCssVariables` which map to CSS custom
properties (`var(--theme-color-x)`)
- **Runtime theme access** (for non-CSS use cases like icon `color`
props) uses `useContext(ThemeContext)` instead of Emotion's `useTheme()`
148 lines
4.7 KiB
TypeScript
148 lines
4.7 KiB
TypeScript
import { FormTextFieldInput } from '@/object-record/record-field/ui/form-types/components/FormTextFieldInput';
|
|
import { SettingsDatabaseEventsForm } from '@/settings/components/SettingsDatabaseEventsForm';
|
|
import { Table } from '@/ui/layout/table/components/Table';
|
|
import { TableHeader } from '@/ui/layout/table/components/TableHeader';
|
|
import { TableRow } from '@/ui/layout/table/components/TableRow';
|
|
import { styled } from '@linaria/react';
|
|
import { useLingui } from '@lingui/react/macro';
|
|
import { H2Title, OverflowingTextWithTooltip } from 'twenty-ui/display';
|
|
import { Section } from 'twenty-ui/layout';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
import { TableCell } from '@/ui/layout/table/components/TableCell';
|
|
import { REACT_APP_SERVER_BASE_URL } from '~/config';
|
|
import { Tag } from 'twenty-ui/components';
|
|
import { type LogicFunction } from '~/generated-metadata/graphql';
|
|
import { themeCssVariables } from 'twenty-ui/theme-constants';
|
|
|
|
export const StyledRouteTriggerTableRow = styled(TableRow)`
|
|
grid-template-columns: 1fr 120px 120px;
|
|
`;
|
|
|
|
const StyledTableCell = styled(TableCell)`
|
|
color: ${themeCssVariables.font.color.tertiary};
|
|
gap: ${themeCssVariables.spacing[2]};
|
|
min-width: 0;
|
|
overflow: hidden;
|
|
`;
|
|
|
|
const StyledRouteTriggerTableHeaderRow = styled(StyledRouteTriggerTableRow)`
|
|
margin-bottom: ${themeCssVariables.spacing[2]};
|
|
`;
|
|
|
|
const StyledEmptyState = styled.div`
|
|
align-items: center;
|
|
color: ${themeCssVariables.font.color.tertiary};
|
|
display: flex;
|
|
font-size: ${themeCssVariables.font.size.md};
|
|
height: 160px;
|
|
justify-content: center;
|
|
text-align: center;
|
|
`;
|
|
|
|
export const SettingsLogicFunctionTriggersTab = ({
|
|
logicFunction,
|
|
}: {
|
|
logicFunction: LogicFunction;
|
|
}) => {
|
|
const { t } = useLingui();
|
|
|
|
const cronTrigger = logicFunction.cronTriggerSettings;
|
|
|
|
const routeTrigger = logicFunction.httpRouteTriggerSettings;
|
|
|
|
const databaseEventTriggerSettings =
|
|
logicFunction.databaseEventTriggerSettings;
|
|
|
|
let databaseEventTrigger = undefined;
|
|
|
|
if (isDefined(databaseEventTriggerSettings)) {
|
|
const [object, action]: [string, string] =
|
|
databaseEventTriggerSettings.eventName.split('.');
|
|
databaseEventTrigger = {
|
|
object,
|
|
action,
|
|
updatedFields: databaseEventTriggerSettings.updatedFields,
|
|
};
|
|
}
|
|
const hasNoTriggers = !cronTrigger && !routeTrigger && !databaseEventTrigger;
|
|
|
|
if (hasNoTriggers) {
|
|
return (
|
|
<Section>
|
|
<H2Title
|
|
title={t`Triggers`}
|
|
description={t`Configure when this function should be executed`}
|
|
/>
|
|
<StyledEmptyState>
|
|
{t`No triggers configured for this function.`}
|
|
</StyledEmptyState>
|
|
</Section>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{isDefined(databaseEventTrigger) && (
|
|
<Section>
|
|
<H2Title
|
|
title={t`Database event`}
|
|
description={t`Select the events that should trigger the function`}
|
|
/>
|
|
<SettingsDatabaseEventsForm
|
|
events={[databaseEventTrigger]}
|
|
disabled
|
|
/>
|
|
</Section>
|
|
)}
|
|
|
|
{isDefined(cronTrigger) && (
|
|
<Section>
|
|
<H2Title
|
|
title={t`Cron`}
|
|
description={t`Triggers the function at regular intervals`}
|
|
/>
|
|
<FormTextFieldInput
|
|
label={t`Expression`}
|
|
placeholder="0 */1 * * *"
|
|
hint={t`Format: [Minute] [Hour] [Day of Month] [Month] [Day of Week]`}
|
|
onChange={() => {}}
|
|
readonly
|
|
defaultValue={cronTrigger.pattern}
|
|
/>
|
|
</Section>
|
|
)}
|
|
|
|
{isDefined(routeTrigger) && (
|
|
<Section>
|
|
<H2Title
|
|
title={t`Http`}
|
|
description={t`Triggers the function with Http request`}
|
|
/>
|
|
<Table>
|
|
<StyledRouteTriggerTableHeaderRow>
|
|
<TableHeader>{t`Path`}</TableHeader>
|
|
<TableHeader>{t`Method`}</TableHeader>
|
|
<TableHeader>{t`Auth Required`}</TableHeader>
|
|
</StyledRouteTriggerTableHeaderRow>
|
|
<StyledRouteTriggerTableRow>
|
|
<StyledTableCell>
|
|
<OverflowingTextWithTooltip
|
|
text={`${REACT_APP_SERVER_BASE_URL}/s${routeTrigger.path}`}
|
|
/>
|
|
</StyledTableCell>
|
|
<StyledTableCell>{routeTrigger.httpMethod}</StyledTableCell>
|
|
<StyledTableCell>
|
|
<Tag
|
|
text={routeTrigger.isAuthRequired ? t`True` : t`False`}
|
|
color={routeTrigger.isAuthRequired ? 'green' : 'orange'}
|
|
weight="medium"
|
|
/>
|
|
</StyledTableCell>
|
|
</StyledRouteTriggerTableRow>
|
|
</Table>
|
|
</Section>
|
|
)}
|
|
</>
|
|
);
|
|
};
|