mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-03 07:14:38 +03:00
03b3c8a67a
This PR is the second part of https://github.com/twentyhq/twenty/pull/5693. It optimizes all remaining field types. The observed improvements are : - x2 loading time improvement on table rows - more consistent render time Here's a summary of measured improvements, what's given here is the average of hundreds of renders with a React Profiler component. (in our Storybook performance stories) | Component | Before (µs) | After (µs) | | ----- | ------------- | --- | | TextFieldDisplay | 127 | 83 | | EmailFieldDisplay | 117 | 83 | | NumberFieldDisplay | 97 | 56 | | DateFieldDisplay | 240 | 52 | | CurrencyFieldDisplay | 236 | 110 | | FullNameFieldDisplay | 131 | 85 | | AddressFieldDisplay | 118 | 81 | | BooleanFieldDisplay | 130 | 100 | | JSONFieldDisplay | 248 | 49 | | LinksFieldDisplay | 1180 | 140 | | LinkFieldDisplay | 140 | 78 | | MultiSelectFieldDisplay | 770 | 130 | | SelectFieldDisplay | 230 | 87 |
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { ThemeProvider } from '@emotion/react';
|
|
import { Preview } from '@storybook/react';
|
|
import { initialize, mswDecorator } from 'msw-storybook-addon';
|
|
import { useDarkMode } from 'storybook-dark-mode';
|
|
import { THEME_DARK, THEME_LIGHT, ThemeContextProvider } from 'twenty-ui';
|
|
|
|
import { RootDecorator } from '../src/testing/decorators/RootDecorator';
|
|
import { mockedUserJWT } from '../src/testing/mock-data/jwt';
|
|
|
|
import 'react-loading-skeleton/dist/skeleton.css';
|
|
|
|
initialize({
|
|
onUnhandledRequest: async (request: Request) => {
|
|
const fileExtensionsToIgnore =
|
|
/\.(ts|tsx|js|jsx|svg|css|png)(\?v=[a-zA-Z0-9]+)?/;
|
|
|
|
if (fileExtensionsToIgnore.test(request.url)) {
|
|
return;
|
|
}
|
|
|
|
const requestBody = await request.json();
|
|
// eslint-disable-next-line no-console
|
|
console.warn(`Unhandled ${request.method} request to ${request.url}
|
|
with payload ${JSON.stringify(requestBody)}\n
|
|
This request should be mocked with MSW`);
|
|
},
|
|
});
|
|
|
|
const preview: Preview = {
|
|
decorators: [
|
|
(Story) => {
|
|
const theme = useDarkMode() ? THEME_DARK : THEME_LIGHT;
|
|
|
|
useEffect(() => {
|
|
document.documentElement.className =
|
|
theme.name === 'dark' ? 'dark' : 'light';
|
|
}, [theme]);
|
|
|
|
return (
|
|
<ThemeProvider theme={theme}>
|
|
<ThemeContextProvider theme={theme}>
|
|
<Story />
|
|
</ThemeContextProvider>
|
|
</ThemeProvider>
|
|
);
|
|
},
|
|
RootDecorator,
|
|
mswDecorator,
|
|
],
|
|
parameters: {
|
|
actions: { argTypesRegex: '^on[A-Z].*' },
|
|
controls: {
|
|
matchers: {
|
|
color: /(background|color)$/i,
|
|
date: /Date$/,
|
|
},
|
|
},
|
|
options: {
|
|
storySort: {
|
|
order: ['UI', 'Modules', 'Pages'],
|
|
},
|
|
},
|
|
cookie: {
|
|
tokenPair: `{%22accessToken%22:{%22token%22:%22${mockedUserJWT}%22%2C%22expiresAt%22:%222023-07-18T15:06:40.704Z%22%2C%22__typename%22:%22AuthToken%22}%2C%22refreshToken%22:{%22token%22:%22${mockedUserJWT}%22%2C%22expiresAt%22:%222023-10-15T15:06:41.558Z%22%2C%22__typename%22:%22AuthToken%22}%2C%22__typename%22:%22AuthTokenPair%22}`,
|
|
},
|
|
},
|
|
};
|
|
|
|
export default preview;
|