Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Twenty Shared & Fix profile image rendering #8841

Merged
merged 24 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@
"packages/twenty-zapier",
"packages/twenty-website",
"packages/twenty-e2e-testing",
"packages/twenty-shared",
"tools/eslint-rules"
]
}
Expand Down
7 changes: 5 additions & 2 deletions packages/twenty-emails/src/emails/send-invite-link.email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { MainText } from 'src/components/MainText';
import { Title } from 'src/components/Title';
import { WhatIsTwenty } from 'src/components/WhatIsTwenty';
import { capitalize } from 'src/utils/capitalize';
import { getImageAbsoluteURI } from 'src/utils/getImageAbsoluteURI';
import { getImageAbsoluteURI } from 'twenty-shared';

type SendInviteLinkEmailProps = {
link: string;
Expand All @@ -29,7 +29,10 @@ export const SendInviteLinkEmail = ({
sender,
serverUrl,
}: SendInviteLinkEmailProps) => {
const workspaceLogo = getImageAbsoluteURI(workspace.logo, serverUrl);
const workspaceLogo = getImageAbsoluteURI(
workspace.logo ?? '',
serverUrl ?? '',
);

return (
<BaseEmail width={333}>
Expand Down
16 changes: 0 additions & 16 deletions packages/twenty-emails/src/utils/getImageAbsoluteURI.ts

This file was deleted.

5 changes: 4 additions & 1 deletion packages/twenty-emails/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"allowSyntheticDefaultImports": true,
"strict": true,
"types": ["vite/client"],
"baseUrl": "."
"baseUrl": ".",
"paths": {
"twenty-shared": ["packages/twenty-shared/dist"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"twenty-shared": ["packages/twenty-shared/dist"]
"twenty-shared": ["packages/twenty-shared/src/*"]

}
},
"files": [],
"include": [],
Expand Down
9 changes: 7 additions & 2 deletions packages/twenty-front/src/modules/auth/components/Logo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styled from '@emotion/styled';

import { getImageAbsoluteURI } from '~/utils/image/getImageAbsoluteURI';
import { getImageAbsoluteURI } from 'twenty-shared';
import { REACT_APP_SERVER_BASE_URL } from '~/config';

type LogoProps = {
primaryLogo?: string | null;
Expand Down Expand Up @@ -48,8 +49,12 @@ export const Logo = (props: LogoProps) => {

const primaryLogoUrl = getImageAbsoluteURI(
props.primaryLogo ?? defaultPrimaryLogoUrl,
REACT_APP_SERVER_BASE_URL,
);
const secondaryLogoUrl = getImageAbsoluteURI(
props.secondaryLogo ?? '',
REACT_APP_SERVER_BASE_URL,
);
const secondaryLogoUrl = getImageAbsoluteURI(props.secondaryLogo);

return (
<StyledContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
NavigationDrawerProps,
} from '@/ui/navigation/navigation-drawer/components/NavigationDrawer';
import { isAdvancedModeEnabledState } from '@/ui/navigation/navigation-drawer/states/isAdvancedModeEnabledState';
import { getImageAbsoluteURI } from '~/utils/image/getImageAbsoluteURI';
import { getImageAbsoluteURI } from 'twenty-shared';
import { REACT_APP_SERVER_BASE_URL } from '~/config';

import { useIsSettingsDrawer } from '@/navigation/hooks/useIsSettingsDrawer';

Expand Down Expand Up @@ -43,7 +44,10 @@ export const AppNavigationDrawer = ({
: {
logo:
(currentWorkspace?.logo &&
getImageAbsoluteURI(currentWorkspace.logo)) ??
getImageAbsoluteURI(
currentWorkspace.logo,
REACT_APP_SERVER_BASE_URL,
)) ??
undefined,
title: currentWorkspace?.displayName ?? undefined,
children: <MainNavigationDrawerItems />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSi
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
import { getLogoUrlFromDomainName } from '~/utils';
import { getImageAbsoluteURI } from '~/utils/image/getImageAbsoluteURI';
import { getImageAbsoluteURI } from 'twenty-shared';
import { isDefined } from '~/utils/isDefined';

import { REACT_APP_SERVER_BASE_URL } from '~/config';
import { Company } from '@/companies/types/Company';
import { getCompanyDomainName } from '@/object-metadata/utils/getCompanyDomainName';
import { getImageIdentifierFieldValue } from './getImageIdentifierFieldValue';
Expand All @@ -25,7 +25,9 @@ export const getAvatarUrl = (
}

if (objectNameSingular === CoreObjectNameSingular.Person) {
return getImageAbsoluteURI(record.avatarUrl) ?? '';
return (
getImageAbsoluteURI(record.avatarUrl, REACT_APP_SERVER_BASE_URL) ?? ''
);
}

const imageIdentifierFieldValue = getImageIdentifierFieldValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import React, { useMemo } from 'react';
import { Button, IconPhotoUp, IconTrash, IconUpload, IconX } from 'twenty-ui';
import { getImageAbsoluteURI } from '~/utils/image/getImageAbsoluteURI';
import { getImageAbsoluteURI } from 'twenty-shared';
import { isDefined } from '~/utils/isDefined';
import { REACT_APP_SERVER_BASE_URL } from '~/config';

const StyledContainer = styled.div`
display: flex;
Expand Down Expand Up @@ -109,7 +110,10 @@ export const ImageInput = ({
hiddenFileInput.current?.click();
};

const pictureURI = useMemo(() => getImageAbsoluteURI(picture), [picture]);
const pictureURI = useMemo(
() => getImageAbsoluteURI(picture ?? '', REACT_APP_SERVER_BASE_URL),
[picture],
);

return (
<StyledContainer className={className}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import {
MenuItemSelectAvatar,
UndecoratedLink,
} from 'twenty-ui';
import { getImageAbsoluteURI } from '~/utils/image/getImageAbsoluteURI';
import { getImageAbsoluteURI } from 'twenty-shared';
import { useBuildWorkspaceUrl } from '@/domain-manager/hooks/useBuildWorkspaceUrl';
import { REACT_APP_SERVER_BASE_URL } from '~/config';

const StyledLogo = styled.div<{ logo: string }>`
background: url(${({ logo }) => logo});
Expand Down Expand Up @@ -102,9 +103,12 @@ export const MultiWorkspaceDropdownButton = ({
isNavigationDrawerExpanded={isNavigationDrawerExpanded}
>
<StyledLogo
logo={getImageAbsoluteURI(
currentWorkspace?.logo ?? DEFAULT_WORKSPACE_LOGO,
)}
logo={
getImageAbsoluteURI(
currentWorkspace?.logo ?? '',
REACT_APP_SERVER_BASE_URL,
) ?? ''
}
/>
<NavigationDrawerAnimatedCollapseWrapper>
<StyledLabel>{currentWorkspace?.displayName ?? ''}</StyledLabel>
Expand Down Expand Up @@ -132,9 +136,12 @@ export const MultiWorkspaceDropdownButton = ({
text={workspace.displayName ?? ''}
avatar={
<StyledLogo
logo={getImageAbsoluteURI(
workspace.logo ?? DEFAULT_WORKSPACE_LOGO,
)}
logo={
getImageAbsoluteURI(
workspace.logo ?? DEFAULT_WORKSPACE_LOGO,
REACT_APP_SERVER_BASE_URL,
) ?? ''
}
/>
}
selected={currentWorkspace?.id === workspace.id}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Helmet } from 'react-helmet-async';
import { workspacePublicDataState } from '@/auth/states/workspacePublicDataState';
import { useRecoilValue } from 'recoil';
import { getImageAbsoluteURI } from '~/utils/image/getImageAbsoluteURI';
import { getImageAbsoluteURI } from 'twenty-shared';
import { REACT_APP_SERVER_BASE_URL } from '~/config';

export const PageFavicon = () => {
const workspacePublicData = useRecoilValue(workspacePublicDataState);
Expand All @@ -12,7 +13,10 @@ export const PageFavicon = () => {
<link
rel="icon"
type="image/x-icon"
href={getImageAbsoluteURI(workspacePublicData.logo)}
href={getImageAbsoluteURI(
workspacePublicData.logo,
REACT_APP_SERVER_BASE_URL,
)}
/>
)}
</Helmet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { useState } from 'react';
import { useRecoilValue } from 'recoil';
import {
Button,
getImageAbsoluteURI,
H1Title,
H1TitleFontColor,
H2Title,
Expand All @@ -26,6 +25,8 @@ import {
Section,
Toggle,
} from 'twenty-ui';
import { getImageAbsoluteURI } from 'twenty-shared';
import { REACT_APP_SERVER_BASE_URL } from '~/config';

const StyledLinkContainer = styled.div`
margin-right: ${({ theme }) => theme.spacing(2)};
Expand Down Expand Up @@ -107,7 +108,8 @@ export const SettingsAdminFeatureFlags = () => {
title: workspace.name,
logo:
getImageAbsoluteURI(
workspace.logo === null ? DEFAULT_WORKSPACE_LOGO : workspace.logo,
workspace.logo ?? DEFAULT_WORKSPACE_LOGO,
REACT_APP_SERVER_BASE_URL,
) ?? '',
})) ?? [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
PageDecoratorArgs,
} from '~/testing/decorators/PageDecorator';
import { graphqlMocks } from '~/testing/graphqlMocks';
import { getImageAbsoluteURI } from '~/utils/image/getImageAbsoluteURI';
import { getImageAbsoluteURI } from 'twenty-shared';
import { REACT_APP_SERVER_BASE_URL } from '~/config';
import { sleep } from '~/utils/sleep';

const SOURCE_CODE_FULL_PATH =
Expand Down Expand Up @@ -43,9 +44,15 @@ const meta: Meta<PageDecoratorArgs> = {
},
});
}),
http.get(getImageAbsoluteURI(SOURCE_CODE_FULL_PATH) || '', () => {
return HttpResponse.text('export const handler = () => {}');
}),
http.get(
getImageAbsoluteURI(
SOURCE_CODE_FULL_PATH,
REACT_APP_SERVER_BASE_URL,
) || '',
() => {
return HttpResponse.text('export const handler = () => {}');
},
),
],
},
},
Expand Down

This file was deleted.

26 changes: 0 additions & 26 deletions packages/twenty-front/src/utils/image/getImageAbsoluteURI.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/twenty-front/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"@/*": ["packages/twenty-front/src/modules/*"],
"~/*": ["packages/twenty-front/src/*"],
"twenty-ui": ["packages/twenty-ui/src/index.ts"],
"@ui/*": ["packages/twenty-ui/src/*"]
"@ui/*": ["packages/twenty-ui/src/*"],
"twenty-shared": ["packages/twenty-shared/src"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"twenty-shared": ["packages/twenty-shared/src"]
"twenty-shared": ["packages/twenty-shared/src/index.ts"]

}
},
"files": [],
Expand Down
15 changes: 15 additions & 0 deletions packages/twenty-shared/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
extends: ['../../.eslintrc.cjs', '../../.eslintrc.react.cjs'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
extends: ['../../.eslintrc.cjs', '../../.eslintrc.react.cjs'],
extends: ['../../.eslintrc.cjs'],

We will not use react in this package;

ignorePatterns: ['!**/*'],
overrides: [
{
files: ['*.ts', '*.tsx'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
files: ['*.ts', '*.tsx'],
files: ['*.ts'],

We will not have tsx in this package;

parserOptions: {
project: ['packages/twenty-shared/tsconfig.{json,*.json}'],
},
rules: {
'@nx/dependency-checks': 'error',
},
},
],
};
37 changes: 37 additions & 0 deletions packages/twenty-shared/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { JestConfigWithTsJest, pathsToModuleNameMapper } from 'ts-jest';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const tsConfig = require('./tsconfig.json');
process.env.TZ = 'GMT';

const jestConfig: JestConfigWithTsJest = {
silent: true,
displayName: 'twenty-shared',
preset: '../../jest.preset.js',
setupFilesAfterEnv: ['./setupTests.ts'],
testEnvironment: 'node',
transformIgnorePatterns: ['../../node_modules/'],
transform: {
'^.+\\.(ts|js)$': '@swc/jest',
},
moduleNameMapper: {
...pathsToModuleNameMapper(tsConfig.compilerOptions.paths, { prefix: '<rootDir>/' }),
},
moduleFileExtensions: ['ts', 'js'],
extensionsToTreatAsEsm: ['.ts'],
coverageThreshold: {
global: {
statements: 60,
lines: 60,
functions: 50,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
global: {
statements: 60,
lines: 60,
functions: 50,
},
global: {
statements: 95,
lines: 95,
functions: 95,
},

Since this package will be shared and should contain only easy-to-test functions we can have a high level of coverage.

},
collectCoverageFrom: ['<rootDir>/src/**/*.ts'],
coveragePathIgnorePatterns: [
'types/*',
'constants/*',
],
coverageDirectory: './coverage',
};

export default jestConfig;
Loading
Loading