Skip to content

The open alternative to Salesforce, designed for AI.

Pin the current workspace in admin and unify avatars (#29117)

Thomas des Francsb6203b6ed74b
diff --git a/packages/twenty-companion/src/renderer/components/WorkspaceIcon.tsx b/packages/twenty-companion/src/renderer/components/WorkspaceIcon.tsx
index d0a3590ae0e..3fbe6bdcb89 100644
--- a/packages/twenty-companion/src/renderer/components/WorkspaceIcon.tsx
+++ b/packages/twenty-companion/src/renderer/components/WorkspaceIcon.tsx
@@ -1,17 +1,23 @@
import { Avatar } from 'twenty-ui/primitives/data-display';
+import { getAvatarInitial } from 'twenty-ui/utilities';
import { type Agenda } from '../../shared/types/Agenda';
export const WorkspaceIcon = ({
workspace,
}: {
workspace: Agenda['workspace'] | null;
-}) => (
- <span aria-hidden="true" className="workspace-avatar">
- <Avatar
- src={workspace?.logoUrl || './twenty.svg'}
- name={workspace?.name ?? 'Twenty'}
- size="lg"
- shape="square"
- />
- </span>
-);
+}) => {
+ const workspaceName = workspace?.name ?? 'Twenty';
+
+ return (
+ <span aria-hidden="true" className="workspace-avatar">
+ <Avatar
+ src={workspace?.logoUrl || './twenty.svg'}
+ name={workspaceName}
+ colorSeed={getAvatarInitial(workspaceName)}
+ size="lg"
+ shape="square"
+ />
+ </span>
+ );
+};
diff --git a/packages/twenty-front/src/modules/settings/admin-panel/apps/components/SettingsAdminApplicationMonitoringWorkspacesTable.tsx b/packages/twenty-front/src/modules/settings/admin-panel/apps/components/SettingsAdminApplicationMonitoringWorkspacesTable.tsx
index 7721d7ac4de..605e9ec16eb 100644
--- a/packages/twenty-front/src/modules/settings/admin-panel/apps/components/SettingsAdminApplicationMonitoringWorkspacesTable.tsx
+++ b/packages/twenty-front/src/modules/settings/admin-panel/apps/components/SettingsAdminApplicationMonitoringWorkspacesTable.tsx
@@ -6,7 +6,7 @@ import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';
import { themeCssVariables } from 'twenty-ui/theme';
import { type AdminApplicationMonitoringData } from '@/settings/admin-panel/apps/types/AdminApplicationMonitoringData';
-import { getAdminApplicationMonitoringWorkspaceLabel } from '@/settings/admin-panel/apps/utils/getAdminApplicationMonitoringWorkspaceLabel';
+import { getAdminWorkspaceLabel } from '@/settings/admin-panel/utils/getAdminWorkspaceLabel';
import { APPLICATION_MONITORING_TABLE_METRIC_COLUMNS } from '@/settings/application-monitoring/constants/ApplicationMonitoringTableMetricColumns';
import { SettingsEmptyPlaceholder } from '@/settings/components/SettingsEmptyPlaceholder';
import { Table } from '@/ui/layout/table/components/Table';
@@ -14,6 +14,7 @@ import { TableBody } from '@/ui/layout/table/components/TableBody';
import { TableCell } from '@/ui/layout/table/components/TableCell';
import { TableHeader } from '@/ui/layout/table/components/TableHeader';
import { TableRow } from '@/ui/layout/table/components/TableRow';
+import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
import { beautifyPastDateRelativeToNow } from '~/utils/date-utils';
import { getAbsoluteImageUrl } from '~/utils/image/getAbsoluteImageUrl';
@@ -60,12 +61,15 @@ export const SettingsAdminApplicationMonitoringWorkspacesTable = ({
>
<Avatar
src={getAbsoluteImageUrl(workspace.workspaceLogoUrl)}
- name={getAdminApplicationMonitoringWorkspaceLabel(workspace)}
- colorSeed={workspace.workspaceId}
+ name={workspace.workspaceName ?? ''}
+ colorSeed={getWorkspaceAvatarColorSeed(workspace.workspaceName)}
size="md"
/>
<OverflowingTextWithTooltip
- text={getAdminApplicationMonitoringWorkspaceLabel(workspace)}
+ text={getAdminWorkspaceLabel({
+ id: workspace.workspaceId,
+ name: workspace.workspaceName,
+ })}
/>
</TableCell>
<TableCell color={themeCssVariables.font.color.tertiary}>
diff --git a/packages/twenty-front/src/modules/settings/admin-panel/apps/utils/buildAdminApplicationMonitoringWorkspaceOptions.ts b/packages/twenty-front/src/modules/settings/admin-panel/apps/utils/buildAdminApplicationMonitoringWorkspaceOptions.ts
index 24aa30d2897..1d2a22d48ba 100644
--- a/packages/twenty-front/src/modules/settings/admin-panel/apps/utils/buildAdminApplicationMonitoringWorkspaceOptions.ts
+++ b/packages/twenty-front/src/modules/settings/admin-panel/apps/utils/buildAdminApplicationMonitoringWorkspaceOptions.ts
@@ -2,7 +2,7 @@ import { isDefined } from 'twenty-shared/utils';
import { type SelectOption } from 'twenty-ui/primitives/input';
import { type AdminApplicationMonitoringWorkspace } from '@/settings/admin-panel/apps/types/AdminApplicationMonitoringWorkspace';
-import { getAdminApplicationMonitoringWorkspaceLabel } from '@/settings/admin-panel/apps/utils/getAdminApplicationMonitoringWorkspaceLabel';
+import { getAdminWorkspaceLabel } from '@/settings/admin-panel/utils/getAdminWorkspaceLabel';
export const buildAdminApplicationMonitoringWorkspaceOptions = ({
allWorkspacesLabel,
@@ -26,7 +26,10 @@ export const buildAdminApplicationMonitoringWorkspaceOptions = ({
{ value: '', label: allWorkspacesLabel },
...listedWorkspaces.map((workspace) => ({
value: workspace.workspaceId,
- label: getAdminApplicationMonitoringWorkspaceLabel(workspace),
+ label: getAdminWorkspaceLabel({
+ id: workspace.workspaceId,
+ name: workspace.workspaceName,
+ }),
})),
];
};
diff --git a/packages/twenty-front/src/modules/settings/admin-panel/apps/utils/getAdminApplicationMonitoringWorkspaceLabel.ts b/packages/twenty-front/src/modules/settings/admin-panel/apps/utils/getAdminApplicationMonitoringWorkspaceLabel.ts
deleted file mode 100644
index 5ee583383ae..00000000000
--- a/packages/twenty-front/src/modules/settings/admin-panel/apps/utils/getAdminApplicationMonitoringWorkspaceLabel.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import { isNonEmptyString } from '@sniptt/guards';
-
-import { type AdminApplicationMonitoringWorkspace } from '@/settings/admin-panel/apps/types/AdminApplicationMonitoringWorkspace';
-
-export const getAdminApplicationMonitoringWorkspaceLabel = ({
- workspaceId,
- workspaceName,
-}: AdminApplicationMonitoringWorkspace): string =>
- isNonEmptyString(workspaceName) ? workspaceName : workspaceId;
diff --git a/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminGeneral.tsx b/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminGeneral.tsx
index 518fe6b08a5..6c4a71e77a6 100644
--- a/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminGeneral.tsx
+++ b/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminGeneral.tsx
@@ -1,8 +1,11 @@
+import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { canManageFeatureFlagsState } from '@/client-config/states/canManageFeatureFlagsState';
import { useNumberFormat } from '@/localization/hooks/useNumberFormat';
import { useApolloAdminClient } from '@/settings/admin-panel/apollo/hooks/useApolloAdminClient';
import { SettingsAdminServerAdmins } from '@/settings/admin-panel/components/SettingsAdminServerAdmins';
import { SettingsAdminVersionContainer } from '@/settings/admin-panel/components/SettingsAdminVersionContainer';
+import { getAdminPanelTopWorkspaceGroups } from '@/settings/admin-panel/utils/getAdminPanelTopWorkspaceGroups';
+import { getAdminWorkspaceLabel } from '@/settings/admin-panel/utils/getAdminWorkspaceLabel';
import { SettingsSectionSkeletonLoader } from '@/settings/components/SettingsSectionSkeletonLoader';
import { SettingsTextInput } from '@/ui/input/components/SettingsTextInput';
import { Table } from '@/ui/layout/table/components/Table';
@@ -11,6 +14,7 @@ import { TableCell } from '@/ui/layout/table/components/TableCell';
import { TableHeader } from '@/ui/layout/table/components/TableHeader';
import { TableRow } from '@/ui/layout/table/components/TableRow';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
import { useQuery } from '@apollo/client/react';
import { styled } from '@linaria/react';
import { t } from '@lingui/core/macro';
@@ -54,6 +58,7 @@ export const SettingsAdminGeneral = () => {
const [debouncedWorkspaceSearchTerm] = useDebounce(workspaceSearchTerm, 300);
const currentUser = useAtomStateValue(currentUserState);
+ const currentWorkspace = useAtomStateValue(currentWorkspaceState);
const canAccessFullAdminPanel = currentUser?.canAccessFullAdminPanel;
const canImpersonate = currentUser?.canImpersonate;
const canManageFeatureFlags = useAtomStateValue(canManageFeatureFlagsState);
@@ -77,7 +82,11 @@ export const SettingsAdminGeneral = () => {
);
const recentUsers = recentUsersData?.adminPanelRecentUsers ?? [];
- const topWorkspaces = topWorkspacesData?.adminPanelTopWorkspaces ?? [];
+ const workspaceGroups = getAdminPanelTopWorkspaceGroups({
+ topWorkspaces: topWorkspacesData?.adminPanelTopWorkspaces ?? [],
+ currentWorkspace,
+ searchTerm: debouncedWorkspaceSearchTerm,
+ });
return (
<>
@@ -170,7 +179,9 @@ export const SettingsAdminGeneral = () => {
<Avatar
src={getAbsoluteImageUrl(user.workspaceLogo)}
name={user.workspaceName || ''}
- colorSeed={user.workspaceId}
+ colorSeed={getWorkspaceAvatarColorSeed(
+ user.workspaceName,
+ )}
size="sm"
/>
<OverflowingTextWithTooltip
@@ -213,7 +224,7 @@ export const SettingsAdminGeneral = () => {
</StyledSearchInputContainer>
{isLoadingWorkspaces ? (
<SettingsSectionSkeletonLoader />
- ) : topWorkspaces.length === 0 ? (
+ ) : workspaceGroups.length === 0 ? (
<StyledEmptyState>
{t`No workspaces found matching your search criteria.`}
</StyledEmptyState>
@@ -226,44 +237,52 @@ export const SettingsAdminGeneral = () => {
<TableHeader align="right">{t`Users`}</TableHeader>
<TableHeader />
</TableRow>
- <TableBody>
- {topWorkspaces.map((workspace) => (
- <TableRow
- key={workspace.id}
- gridTemplateColumns={TOP_WORKSPACES_GRID_TEMPLATE_COLUMNS}
- to={getSettingsPath(
- SettingsPath.AdminPanelWorkspaceDetail,
- { workspaceId: workspace.id },
- )}
- >
- <TableCell
- color={themeCssVariables.font.color.primary}
- gap={themeCssVariables.spacing[2]}
- overflow="hidden"
+ {workspaceGroups.map((workspaces, groupIndex) => (
+ <TableBody
+ key={workspaces[0].id}
+ padding={`${themeCssVariables.spacing[1]} 0`}
+ hasTopBorder={groupIndex > 0}
+ >
+ {workspaces.map((workspace) => (
+ <TableRow
+ key={workspace.id}
+ gridTemplateColumns={TOP_WORKSPACES_GRID_TEMPLATE_COLUMNS}
+ to={getSettingsPath(
+ SettingsPath.AdminPanelWorkspaceDetail,
+ { workspaceId: workspace.id },
+ )}
>
- <Avatar
- src={getAbsoluteImageUrl(workspace.logoUrl)}
- name={workspace.name || ''}
- colorSeed={workspace.id}
- size="md"
- />
- <OverflowingTextWithTooltip
- text={workspace.name || '\u2014'}
- />
- </TableCell>
- <TableCell align="right">
- {formatNumber(workspace.totalUsers)}
- </TableCell>
- <TableCell align="center">
- <IconChevronRight
- size={theme.icon.size.md}
- stroke={theme.icon.stroke.sm}
- color={theme.font.color.tertiary}
- />
- </TableCell>
- </TableRow>
- ))}
- </TableBody>
+ <TableCell
+ color={themeCssVariables.font.color.primary}
+ gap={themeCssVariables.spacing[2]}
+ overflow="hidden"
+ >
+ <Avatar
+ src={getAbsoluteImageUrl(workspace.logoUrl)}
+ name={workspace.name || ''}
+ colorSeed={getWorkspaceAvatarColorSeed(
+ workspace.name,
+ )}
+ size="md"
+ />
+ <OverflowingTextWithTooltip
+ text={getAdminWorkspaceLabel(workspace)}
+ />
+ </TableCell>
+ <TableCell align="right">
+ {formatNumber(workspace.totalUsers)}
+ </TableCell>
+ <TableCell align="center">
+ <IconChevronRight
+ size={theme.icon.size.md}
+ stroke={theme.icon.stroke.sm}
+ color={theme.font.color.tertiary}
+ />
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ ))}
</Table>
)}
</Section.Root>
diff --git a/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminWorkspaceContent.tsx b/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminWorkspaceContent.tsx
index 04f102929a6..921d2db9f27 100644
--- a/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminWorkspaceContent.tsx
+++ b/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminWorkspaceContent.tsx
@@ -1,7 +1,7 @@
-import { getChipLabel } from '@/ui/field/display/utils/getChipLabel';
import { useNumberFormat } from '@/localization/hooks/useNumberFormat';
import { type WorkspaceInfo } from '@/settings/admin-panel/types/WorkspaceInfo';
import { getUpgradeHealthStatusBadge } from '@/settings/admin-panel/utils/getUpgradeHealthStatusBadge';
+import { getAdminWorkspaceLabel } from '@/settings/admin-panel/utils/getAdminWorkspaceLabel';
import { getWorkspaceSchemaName } from '@/settings/admin-panel/utils/getWorkspaceSchemaName';
import { SettingsAdminWorkspaceDataExportSection } from '@/settings/admin-panel/components/SettingsAdminWorkspaceDataExportSection';
import { SettingsTableCard } from '@/settings/components/SettingsTableCard';
@@ -10,6 +10,7 @@ import { LinkChip } from '@/ui/navigation/link/components/LinkChip/LinkChip';
import { DEFAULT_WORKSPACE_LOGO } from '@/ui/navigation/navigation-drawer/constants/DefaultWorkspaceLogo';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { UserContext } from '@/users/contexts/UserContext';
+import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
import { isNonEmptyString } from '@sniptt/guards';
@@ -89,6 +90,8 @@ export const SettingsAdminWorkspaceContent = ({
})}
startElement={
<AvatarOrIcon
+ name={activeWorkspace.name}
+ colorSeed={getWorkspaceAvatarColorSeed(activeWorkspace.name)}
src={getAbsoluteImageUrl(
isNonEmptyString(activeWorkspace?.logo)
? activeWorkspace?.logo
@@ -97,7 +100,7 @@ export const SettingsAdminWorkspaceContent = ({
/>
}
>
- {getChipLabel(activeWorkspace.name).content}
+ {getAdminWorkspaceLabel(activeWorkspace)}
</LinkChip>
) : (
(activeWorkspace?.name ?? '')
diff --git a/packages/twenty-front/src/modules/settings/admin-panel/utils/__tests__/getAdminPanelTopWorkspaceGroups.test.ts b/packages/twenty-front/src/modules/settings/admin-panel/utils/__tests__/getAdminPanelTopWorkspaceGroups.test.ts
new file mode 100644
index 00000000000..80da65cd008
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/admin-panel/utils/__tests__/getAdminPanelTopWorkspaceGroups.test.ts
@@ -0,0 +1,81 @@
+import { getAdminPanelTopWorkspaceGroups } from '@/settings/admin-panel/utils/getAdminPanelTopWorkspaceGroups';
+
+const APPLE = {
+ id: 'workspace-apple',
+ name: 'Apple',
+ logoUrl: null,
+ subdomain: 'apple',
+ totalUsers: 12,
+};
+const YCOMBINATOR = {
+ id: 'workspace-ycombinator',
+ name: 'YCombinator',
+ logoUrl: null,
+ subdomain: 'yc',
+ totalUsers: 4,
+};
+const YCOMBINATOR_CURRENT_WORKSPACE = {
+ id: 'workspace-ycombinator',
+ displayName: 'YCombinator',
+ logo: null,
+ subdomain: 'yc',
+ workspaceMembersCount: 3,
+};
+const ACME_CURRENT_WORKSPACE = {
+ id: 'workspace-acme',
+ displayName: 'Acme',
+ logo: 'acme-logo.png',
+ subdomain: 'acme',
+ workspaceMembersCount: 2,
+};
+
+describe('getAdminPanelTopWorkspaceGroups', () => {
+ it('should move the listed current workspace into its own first group', () => {
+ expect(
+ getAdminPanelTopWorkspaceGroups({
+ topWorkspaces: [APPLE, YCOMBINATOR],
+ currentWorkspace: YCOMBINATOR_CURRENT_WORKSPACE,
+ searchTerm: '',
+ }),
+ ).toEqual([[YCOMBINATOR], [APPLE]]);
+ });
+
+ it('should pin the current workspace when it is outside the top workspaces', () => {
+ expect(
+ getAdminPanelTopWorkspaceGroups({
+ topWorkspaces: [APPLE, YCOMBINATOR],
+ currentWorkspace: ACME_CURRENT_WORKSPACE,
+ searchTerm: '',
+ }),
+ ).toEqual([
+ [
+ {
+ id: 'workspace-acme',
+ name: 'Acme',
+ logoUrl: 'acme-logo.png',
+ subdomain: 'acme',
+ totalUsers: 2,
+ },
+ ],
+ [APPLE, YCOMBINATOR],
+ ]);
+ });
+
+ it('should only show search results when the current workspace does not match', () => {
+ expect(
+ getAdminPanelTopWorkspaceGroups({
+ topWorkspaces: [APPLE],
+ currentWorkspace: ACME_CURRENT_WORKSPACE,
+ searchTerm: 'app',
+ }),
+ ).toEqual([[APPLE]]);
+
+ expect(
+ getAdminPanelTopWorkspaceGroups({
+ topWorkspaces: [],
+ currentWorkspace: ACME_CURRENT_WORKSPACE,
+ searchTerm: 'zzz',
+ }),
+ ).toEqual([]);
+ });
+});
diff --git a/packages/twenty-front/src/modules/settings/admin-panel/utils/__tests__/getAdminWorkspaceLabel.test.ts b/packages/twenty-front/src/modules/settings/admin-panel/utils/__tests__/getAdminWorkspaceLabel.test.ts
new file mode 100644
index 00000000000..1cdf3c67768
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/admin-panel/utils/__tests__/getAdminWorkspaceLabel.test.ts
@@ -0,0 +1,19 @@
+import { getAdminWorkspaceLabel } from '@/settings/admin-panel/utils/getAdminWorkspaceLabel';
+
+describe('getAdminWorkspaceLabel', () => {
+ it('should return the workspace name when it is set', () => {
+ expect(getAdminWorkspaceLabel({ id: 'workspace-id', name: 'Apple' })).toBe(
+ 'Apple',
+ );
+ });
+
+ it('should fall back to the workspace id when the name is missing', () => {
+ expect(getAdminWorkspaceLabel({ id: 'workspace-id', name: '' })).toBe(
+ 'workspace-id',
+ );
+ expect(getAdminWorkspaceLabel({ id: 'workspace-id', name: null })).toBe(
+ 'workspace-id',
+ );
+ expect(getAdminWorkspaceLabel({ id: 'workspace-id' })).toBe('workspace-id');
+ });
+});
diff --git a/packages/twenty-front/src/modules/settings/admin-panel/utils/getAdminPanelTopWorkspaceGroups.ts b/packages/twenty-front/src/modules/settings/admin-panel/utils/getAdminPanelTopWorkspaceGroups.ts
new file mode 100644
index 00000000000..1eca15fb38a
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/admin-panel/utils/getAdminPanelTopWorkspaceGroups.ts
@@ -0,0 +1,50 @@
+import { isNonEmptyString } from '@sniptt/guards';
+import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';
+
+import { type CurrentWorkspace } from '@/auth/states/currentWorkspaceState';
+import { type AdminPanelTopWorkspace } from '~/generated-admin/graphql';
+
+type GetAdminPanelTopWorkspaceGroupsArgs = {
+ topWorkspaces: AdminPanelTopWorkspace[];
+ currentWorkspace: Pick<
+ CurrentWorkspace,
+ 'id' | 'displayName' | 'logo' | 'subdomain' | 'workspaceMembersCount'
+ > | null;
+ searchTerm: string;
+};
+
+export const getAdminPanelTopWorkspaceGroups = ({
+ topWorkspaces,
+ currentWorkspace,
+ searchTerm,
+}: GetAdminPanelTopWorkspaceGroupsArgs): AdminPanelTopWorkspace[][] => {
+ const listedCurrentWorkspace = topWorkspaces.find(
+ (workspace) => workspace.id === currentWorkspace?.id,
+ );
+
+ if (isDefined(listedCurrentWorkspace)) {
+ return [
+ [listedCurrentWorkspace],
+ topWorkspaces.filter(
+ (workspace) => workspace.id !== listedCurrentWorkspace.id,
+ ),
+ ].filter(isNonEmptyArray);
+ }
+
+ if (!isDefined(currentWorkspace) || isNonEmptyString(searchTerm.trim())) {
+ return [topWorkspaces].filter(isNonEmptyArray);
+ }
+
+ return [
+ [
+ {
+ id: currentWorkspace.id,
+ name: currentWorkspace.displayName ?? '',
+ logoUrl: currentWorkspace.logo,
+ subdomain: currentWorkspace.subdomain,
+ totalUsers: currentWorkspace.workspaceMembersCount ?? 0,
+ },
+ ],
+ topWorkspaces,
+ ].filter(isNonEmptyArray);
+};
diff --git a/packages/twenty-front/src/modules/settings/admin-panel/utils/getAdminWorkspaceLabel.ts b/packages/twenty-front/src/modules/settings/admin-panel/utils/getAdminWorkspaceLabel.ts
new file mode 100644
index 00000000000..1ea91941bec
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/admin-panel/utils/getAdminWorkspaceLabel.ts
@@ -0,0 +1,11 @@
+import { isNonEmptyString } from '@sniptt/guards';
+
+type GetAdminWorkspaceLabelArgs = {
+ id: string;
+ name?: string | null;
+};
+
+export const getAdminWorkspaceLabel = ({
+ id,
+ name,
+}: GetAdminWorkspaceLabelArgs): string => (isNonEmptyString(name) ? name : id);
diff --git a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderCell.tsx b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderCell.tsx
index cdb85ebae31..96e7b184b13 100644
--- a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderCell.tsx
+++ b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderCell.tsx
@@ -54,8 +54,8 @@ export const SettingsBillingLimitSpenderCell = ({
if (isWorkspaceWide) {
return (
<Avatar
- name={name}
- colorSeed={getWorkspaceAvatarColorSeed(name)}
+ name={currentWorkspace?.displayName ?? ''}
+ colorSeed={getWorkspaceAvatarColorSeed(currentWorkspace?.displayName)}
src={getAbsoluteImageUrl(
currentWorkspace?.logo ?? DEFAULT_WORKSPACE_LOGO,
)}
diff --git a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderSelect.tsx b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderSelect.tsx
index 80c4897f47a..5505e36fe24 100644
--- a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderSelect.tsx
+++ b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderSelect.tsx
@@ -62,7 +62,9 @@ export const SettingsBillingLimitSpenderSelect = ({
const workspaceAvatarUrl = getAbsoluteImageUrl(
currentWorkspace?.logo ?? DEFAULT_WORKSPACE_LOGO,
);
- const workspaceAvatarColorSeed = getWorkspaceAvatarColorSeed(workspaceName);
+ const workspaceAvatarColorSeed = getWorkspaceAvatarColorSeed(
+ currentWorkspace?.displayName,
+ );
const handleSelect = (
nextSpenderType: UsageLimitSpenderType,
@@ -94,7 +96,7 @@ export const SettingsBillingLimitSpenderSelect = ({
if (spenderType === 'workspace') {
return (
<Avatar
- name={workspaceName}
+ name={currentWorkspace?.displayName ?? ''}
colorSeed={workspaceAvatarColorSeed}
src={workspaceAvatarUrl}
shape="square"
@@ -155,7 +157,7 @@ export const SettingsBillingLimitSpenderSelect = ({
description={t`Workspace`}
startIcon={
<Avatar
- name={workspaceName}
+ name={currentWorkspace?.displayName ?? ''}
colorSeed={workspaceAvatarColorSeed}
src={workspaceAvatarUrl}
shape="square"
diff --git a/packages/twenty-front/src/modules/ui/layout/tab-list/components/TabAvatar.tsx b/packages/twenty-front/src/modules/ui/layout/tab-list/components/TabAvatar.tsx
index ef37cf57636..42399418f41 100644
--- a/packages/twenty-front/src/modules/ui/layout/tab-list/components/TabAvatar.tsx
+++ b/packages/twenty-front/src/modules/ui/layout/tab-list/components/TabAvatar.tsx
@@ -9,7 +9,12 @@ export const TabAvatar = ({ tab }: { tab: SingleTabProps }) => {
if (isDefined(tab.logo)) {
return (
- <Avatar src={getAbsoluteImageUrl(tab.logo)} size="md" name={tab.title} />
+ <Avatar
+ src={getAbsoluteImageUrl(tab.logo)}
+ size="md"
+ name={tab.title}
+ colorSeed={tab.colorSeed}
+ />
);
}
return (
diff --git a/packages/twenty-front/src/modules/ui/layout/tab-list/types/SingleTabProps.ts b/packages/twenty-front/src/modules/ui/layout/tab-list/types/SingleTabProps.ts
index 2119c12da5c..54c6158898d 100644
--- a/packages/twenty-front/src/modules/ui/layout/tab-list/types/SingleTabProps.ts
+++ b/packages/twenty-front/src/modules/ui/layout/tab-list/types/SingleTabProps.ts
@@ -8,5 +8,6 @@ export type SingleTabProps<T extends string = string> = {
disabled?: boolean;
pill?: string | React.ReactElement;
logo?: string;
+ colorSeed?: string;
tooltipContent?: string;
};
diff --git a/packages/twenty-front/src/modules/ui/layout/tab-list/utils/getTabListItemContent.tsx b/packages/twenty-front/src/modules/ui/layout/tab-list/utils/getTabListItemContent.tsx
index f8132a1bd68..427e7a40bac 100644
--- a/packages/twenty-front/src/modules/ui/layout/tab-list/utils/getTabListItemContent.tsx
+++ b/packages/twenty-front/src/modules/ui/layout/tab-list/utils/getTabListItemContent.tsx
@@ -8,6 +8,7 @@ export const getTabListItemContent = ({
Icon,
logo,
title,
+ colorSeed,
pill,
}: SingleTabProps) => ({
startIcon:
@@ -15,7 +16,13 @@ export const getTabListItemContent = ({
<>
{isDefined(Icon) && <Icon />}
{isNonEmptyString(logo) && (
- <Avatar src={logo} size="md" name={title} aria-hidden />
+ <Avatar
+ src={logo}
+ size="md"
+ name={title}
+ colorSeed={colorSeed}
+ aria-hidden
+ />
)}
</>
) : undefined,
diff --git a/packages/twenty-front/src/modules/ui/layout/table/components/TableBody.tsx b/packages/twenty-front/src/modules/ui/layout/table/components/TableBody.tsx
index 2e0becd2b40..f32857d1fc4 100644
--- a/packages/twenty-front/src/modules/ui/layout/table/components/TableBody.tsx
+++ b/packages/twenty-front/src/modules/ui/layout/table/components/TableBody.tsx
@@ -1,11 +1,20 @@
import { styled } from '@linaria/react';
import { themeCssVariables } from 'twenty-ui/theme';
-const StyledTableBody = styled.div`
+type TableBodyProps = {
+ padding?: string;
+ hasTopBorder?: boolean;
+};
+
+const StyledTableBody = styled.div<TableBodyProps>`
+ border-top: ${({ hasTopBorder }) =>
+ hasTopBorder
+ ? `1px solid ${themeCssVariables.border.color.light}`
+ : 'none'};
display: flex;
flex-direction: column;
gap: 2px;
- padding: ${themeCssVariables.spacing[2]} 0;
+ padding: ${({ padding }) => padding ?? `${themeCssVariables.spacing[2]} 0`};
`;
export { StyledTableBody as TableBody };
diff --git a/packages/twenty-front/src/modules/workspace/utils/__tests__/getWorkspaceAvatarColorSeed.test.ts b/packages/twenty-front/src/modules/workspace/utils/__tests__/getWorkspaceAvatarColorSeed.test.ts
deleted file mode 100644
index 1b89d1fce95..00000000000
--- a/packages/twenty-front/src/modules/workspace/utils/__tests__/getWorkspaceAvatarColorSeed.test.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
-
-describe('getWorkspaceAvatarColorSeed', () => {
- it('should keep the same seed while the name is being typed', () => {
- expect(getWorkspaceAvatarColorSeed('w')).toBe('W');
- expect(getWorkspaceAvatarColorSeed('worksp')).toBe('W');
- expect(getWorkspaceAvatarColorSeed(' Workspace')).toBe('W');
- });
-
- it('should return an empty seed when there is no name', () => {
- expect(getWorkspaceAvatarColorSeed('')).toBe('');
- expect(getWorkspaceAvatarColorSeed(null)).toBe('');
- expect(getWorkspaceAvatarColorSeed(undefined)).toBe('');
- });
-});
diff --git a/packages/twenty-front/src/modules/workspace/utils/getWorkspaceAvatarColorSeed.ts b/packages/twenty-front/src/modules/workspace/utils/getWorkspaceAvatarColorSeed.ts
index f81f770110a..06942a44f5d 100644
--- a/packages/twenty-front/src/modules/workspace/utils/getWorkspaceAvatarColorSeed.ts
+++ b/packages/twenty-front/src/modules/workspace/utils/getWorkspaceAvatarColorSeed.ts
@@ -1,5 +1 @@
-export const getWorkspaceAvatarColorSeed = (
- workspaceDisplayName: string | null | undefined,
-): string => {
- return (workspaceDisplayName ?? '').trim().charAt(0).toUpperCase();
-};
+export { getAvatarInitial as getWorkspaceAvatarColorSeed } from 'twenty-ui/utilities';
diff --git a/packages/twenty-front/src/pages/settings/admin-panel/SettingsAdminUserDetail.tsx b/packages/twenty-front/src/pages/settings/admin-panel/SettingsAdminUserDetail.tsx
index ff660b79449..6d0c0bce559 100644
--- a/packages/twenty-front/src/pages/settings/admin-panel/SettingsAdminUserDetail.tsx
+++ b/packages/twenty-front/src/pages/settings/admin-panel/SettingsAdminUserDetail.tsx
@@ -28,6 +28,8 @@ import { activeTabIdComponentState } from '@/ui/layout/tab-list/states/activeTab
import { DEFAULT_WORKSPACE_LOGO } from '@/ui/navigation/navigation-drawer/constants/DefaultWorkspaceLogo';
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { getAdminWorkspaceLabel } from '@/settings/admin-panel/utils/getAdminWorkspaceLabel';
+import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
import { Section } from 'twenty-ui/components/layout';
import {
IconCalendar,
@@ -77,7 +79,8 @@ export const SettingsAdminUserDetail = () => {
const tabs =
userLookupResult?.workspaces.map((workspace) => ({
id: workspace.id,
- title: workspace.name,
+ title: getAdminWorkspaceLabel(workspace),
+ colorSeed: getWorkspaceAvatarColorSeed(workspace.name),
logo:
getImageAbsoluteURI({
imageUrl: isNonEmptyString(workspace.logo)
diff --git a/packages/twenty-front/src/pages/settings/admin-panel/SettingsAdminWorkspaceDetail.tsx b/packages/twenty-front/src/pages/settings/admin-panel/SettingsAdminWorkspaceDetail.tsx
index 79a74ade14f..04f2e79157b 100644
--- a/packages/twenty-front/src/pages/settings/admin-panel/SettingsAdminWorkspaceDetail.tsx
+++ b/packages/twenty-front/src/pages/settings/admin-panel/SettingsAdminWorkspaceDetail.tsx
@@ -31,6 +31,8 @@ import { TableRow } from '@/ui/layout/table/components/TableRow';
import { DEFAULT_WORKSPACE_LOGO } from '@/ui/navigation/navigation-drawer/constants/DefaultWorkspaceLogo';
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { getAdminWorkspaceLabel } from '@/settings/admin-panel/utils/getAdminWorkspaceLabel';
+import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
import { useMutation, useQuery } from '@apollo/client/react';
import { styled } from '@linaria/react';
import { t } from '@lingui/core/macro';
@@ -210,7 +212,10 @@ export const SettingsAdminWorkspaceDetail = () => {
: []),
];
- const workspaceName = workspace?.name || workspaceId || '';
+ const workspaceName = getAdminWorkspaceLabel({
+ id: workspaceId ?? '',
+ name: workspace?.name,
+ });
const workspaceLogo = isNonEmptyString(workspace?.logo)
? workspace.logo
: DEFAULT_WORKSPACE_LOGO;
@@ -302,8 +307,8 @@ export const SettingsAdminWorkspaceDetail = () => {
icon={
<Avatar
src={getAbsoluteImageUrl(workspaceLogo)}
- name={workspaceName}
- colorSeed={workspace?.id}
+ name={workspace?.name ?? ''}
+ colorSeed={getWorkspaceAvatarColorSeed(workspace?.name)}
size="md"
/>
}
diff --git a/packages/twenty-front/src/pages/settings/applications/components/SettingsApplicationRegistrationGeneralInfo.tsx b/packages/twenty-front/src/pages/settings/applications/components/SettingsApplicationRegistrationGeneralInfo.tsx
index b188ead6bc9..8df23ab1e5c 100644
--- a/packages/twenty-front/src/pages/settings/applications/components/SettingsApplicationRegistrationGeneralInfo.tsx
+++ b/packages/twenty-front/src/pages/settings/applications/components/SettingsApplicationRegistrationGeneralInfo.tsx
@@ -7,6 +7,8 @@ import {
} from '@/settings/components/SettingsTableCard';
import { AvatarOrIcon } from '@/ui/field/display/components/internal/AvatarOrIcon/AvatarOrIcon';
import { LinkChip } from '@/ui/navigation/link/components/LinkChip/LinkChip';
+import { getAdminWorkspaceLabel } from '@/settings/admin-panel/utils/getAdminWorkspaceLabel';
+import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
import { useQuery } from '@apollo/client/react';
import { styled } from '@linaria/react';
import { Trans, useLingui } from '@lingui/react/macro';
@@ -90,6 +92,15 @@ export const SettingsApplicationRegistrationGeneralInfo = ({
const ownerWorkspace = ownerWorkspaceData?.getPublicWorkspaceDataById;
+ const ownerWorkspaceAvatar = (
+ <AvatarOrIcon
+ shape="circle"
+ name={ownerWorkspace?.displayName ?? ''}
+ colorSeed={getWorkspaceAvatarColorSeed(ownerWorkspace?.displayName)}
+ src={getAbsoluteImageUrl(ownerWorkspace?.logo ?? undefined)}
+ />
+ );
+
const generateItems = () => {
const items: TableItem[] = [
{
@@ -111,26 +122,15 @@ export const SettingsApplicationRegistrationGeneralInfo = ({
to={getSettingsPath(SettingsPath.AdminPanelWorkspaceDetail, {
workspaceId: registration.ownerWorkspaceId,
})}
- startElement={
- <AvatarOrIcon
- shape="circle"
- src={getAbsoluteImageUrl(ownerWorkspace?.logo ?? undefined)}
- />
- }
+ startElement={ownerWorkspaceAvatar}
>
- {getChipLabel(ownerWorkspace.displayName).content}
+ {getAdminWorkspaceLabel({
+ id: registration.ownerWorkspaceId,
+ name: ownerWorkspace.displayName,
+ })}
</LinkChip>
) : (
- <Chip
- size="md"
- variant="soft"
- startElement={
- <AvatarOrIcon
- shape="circle"
- src={getAbsoluteImageUrl(ownerWorkspace?.logo ?? undefined)}
- />
- }
- >
+ <Chip size="md" variant="soft" startElement={ownerWorkspaceAvatar}>
{getChipLabel(ownerWorkspace.displayName).content}
</Chip>
),
diff --git a/packages/twenty-front/src/pages/settings/applications/components/SettingsApplicationRegistrationInstalledWorkspaces.tsx b/packages/twenty-front/src/pages/settings/applications/components/SettingsApplicationRegistrationInstalledWorkspaces.tsx
index 1a00a2b060c..a0b7703a092 100644
--- a/packages/twenty-front/src/pages/settings/applications/components/SettingsApplicationRegistrationInstalledWorkspaces.tsx
+++ b/packages/twenty-front/src/pages/settings/applications/components/SettingsApplicationRegistrationInstalledWorkspaces.tsx
@@ -19,6 +19,8 @@ import { TableBody } from '@/ui/layout/table/components/TableBody';
import { TableCell } from '@/ui/layout/table/components/TableCell';
import { TableHeader } from '@/ui/layout/table/components/TableHeader';
import { TableRow } from '@/ui/layout/table/components/TableRow';
+import { getAdminWorkspaceLabel } from '@/settings/admin-panel/utils/getAdminWorkspaceLabel';
+import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
import { SettingsPath } from 'twenty-shared/types';
import { FindAdminApplicationRegistrationInstalledWorkspacesDocument } from '~/generated-admin/graphql';
import { type ApplicationRegistration } from '~/generated-metadata/graphql';
@@ -170,12 +172,17 @@ export const SettingsApplicationRegistrationInstalledWorkspaces = ({
>
<Avatar
src={getAbsoluteImageUrl(workspace.logo ?? undefined)}
- name={workspace.displayName ?? '—'}
- colorSeed={workspace.id}
+ name={workspace.displayName ?? ''}
+ colorSeed={getWorkspaceAvatarColorSeed(
+ workspace.displayName,
+ )}
size="md"
/>
<OverflowingTextWithTooltip
- text={workspace.displayName ?? '—'}
+ text={getAdminWorkspaceLabel({
+ id: workspace.id,
+ name: workspace.displayName,
+ })}
/>
</TableCell>
<TableCell
diff --git a/packages/twenty-ui/docs/public-exports.json b/packages/twenty-ui/docs/public-exports.json
index 416180f9128..bbd24416496 100644
--- a/packages/twenty-ui/docs/public-exports.json
+++ b/packages/twenty-ui/docs/public-exports.json
@@ -1260,6 +1260,7 @@
"utilities": {
"reExports": [],
"values": {
+ "getAvatarInitial": "utilities/utils/getAvatarInitial",
"getMainColorNameFromPaletteColorName": "utilities/color/utils/getMainColorNameFromPaletteColorName",
"getOsControlSymbol": "utilities/device/getOsControlSymbol",
"getSafeUrl": "utilities/utils/getSafeUrl",
diff --git a/packages/twenty-ui/src/primitives/data-display/Avatar/Avatar.tsx b/packages/twenty-ui/src/primitives/data-display/Avatar/Avatar.tsx
index 21df087b022..2c10e3141d9 100644
--- a/packages/twenty-ui/src/primitives/data-display/Avatar/Avatar.tsx
+++ b/packages/twenty-ui/src/primitives/data-display/Avatar/Avatar.tsx
@@ -1,11 +1,11 @@
import { isBoolean, isNonEmptyString } from '@sniptt/guards';
+import { getAvatarInitial } from '@ui/utilities/utils/getAvatarInitial';
import { isDefined } from '@ui/utilities/utils/isDefined';
import { AvatarFallback } from './internal/AvatarFallback';
import { AvatarImage } from './internal/AvatarImage';
import { AvatarRoot } from './internal/AvatarRoot';
-import { getAvatarInitial } from './internal/getAvatarInitial';
import { type AvatarProps } from './types/AvatarProps';
const AvatarAssembly = ({
diff --git a/packages/twenty-ui/src/primitives/data-display/Avatar/internal/AvatarRoot.tsx b/packages/twenty-ui/src/primitives/data-display/Avatar/internal/AvatarRoot.tsx
index 4482c18e0ac..1df3b4fea16 100644
--- a/packages/twenty-ui/src/primitives/data-display/Avatar/internal/AvatarRoot.tsx
+++ b/packages/twenty-ui/src/primitives/data-display/Avatar/internal/AvatarRoot.tsx
@@ -5,11 +5,11 @@ import { type CSSProperties } from 'react';
import { useTheme } from '@ui/theme';
import { mergeClassNames } from '@ui/utilities/internal/mergeClassNames';
import { stringToThemeColorP3String } from '@ui/utilities';
+import { getAvatarInitial } from '@ui/utilities/utils/getAvatarInitial';
import styles from '../Avatar.module.scss';
import { type AvatarRootProps } from '../types/AvatarRootProps';
-import { getAvatarInitial } from './getAvatarInitial';
import { doNotTranslate } from '@ui/utilities/internal/doNotTranslate';
export const AvatarRoot = ({
diff --git a/packages/twenty-ui/src/primitives/data-display/Avatar/internal/getAvatarInitial.ts b/packages/twenty-ui/src/primitives/data-display/Avatar/internal/getAvatarInitial.ts
deleted file mode 100644
index b6737af25b4..00000000000
--- a/packages/twenty-ui/src/primitives/data-display/Avatar/internal/getAvatarInitial.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export const getAvatarInitial = (name?: string) =>
- name?.trim().charAt(0).toUpperCase();
diff --git a/packages/twenty-ui/src/utilities/index.ts b/packages/twenty-ui/src/utilities/index.ts
index 676e54f8e58..17439c0e626 100644
--- a/packages/twenty-ui/src/utilities/index.ts
+++ b/packages/twenty-ui/src/utilities/index.ts
@@ -22,6 +22,7 @@ export { useIsMobile } from './responsive/hooks/useIsMobile';
export { useIsTouchDevice } from './responsive/hooks/useIsTouchDevice';
export { useMediaQuery } from './responsive/hooks/useMediaQuery';
export type { Nullable } from './types/Nullable';
+export { getAvatarInitial } from './utils/getAvatarInitial';
export { getSafeUrl } from './utils/getSafeUrl';
export { isDefined } from './utils/isDefined';
export { normalizeSearchText } from './utils/normalizeSearchText';
diff --git a/packages/twenty-ui/src/utilities/utils/__tests__/getAvatarInitial.test.ts b/packages/twenty-ui/src/utilities/utils/__tests__/getAvatarInitial.test.ts
new file mode 100644
index 00000000000..28ea633eed5
--- /dev/null
+++ b/packages/twenty-ui/src/utilities/utils/__tests__/getAvatarInitial.test.ts
@@ -0,0 +1,15 @@
+import { getAvatarInitial } from '../getAvatarInitial';
+
+describe('getAvatarInitial', () => {
+ it('keeps the same initial while the name is being typed', () => {
+ expect(getAvatarInitial('w')).toBe('W');
+ expect(getAvatarInitial('worksp')).toBe('W');
+ expect(getAvatarInitial(' Workspace')).toBe('W');
+ });
+
+ it('returns an empty initial when there is no name', () => {
+ expect(getAvatarInitial('')).toBe('');
+ expect(getAvatarInitial(null)).toBe('');
+ expect(getAvatarInitial(undefined)).toBe('');
+ });
+});
diff --git a/packages/twenty-ui/src/utilities/utils/getAvatarInitial.ts b/packages/twenty-ui/src/utilities/utils/getAvatarInitial.ts
new file mode 100644
index 00000000000..52de0e3d185
--- /dev/null
+++ b/packages/twenty-ui/src/utilities/utils/getAvatarInitial.ts
@@ -0,0 +1,2 @@
+export const getAvatarInitial = (name?: string | null): string =>
+ (name ?? '').trim().charAt(0).toUpperCase();