Files
twenty/packages/twenty-front/src/modules/applications/hooks/useApplicationChipData.ts
T
Charles Bochet 8d24551e71 fix(settings): force display "Standard" and "Custom" for app chips (#19912)
## Summary
- Override the `AppChip` label so the Twenty standard application always
renders as `Standard` and the workspace custom application always
renders as `Custom`, instead of leaking each app's underlying name (e.g.
`Twenty Eng's custom application`).
- Detection mirrors the logic already used in
`useApplicationAvatarColors`, relying on
`TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER` /
`TWENTY_STANDARD_APPLICATION_NAME` and
`currentWorkspace.workspaceCustomApplication.id`.
- The `This app` label for the current application context and the
original `application.name` fallback for any other installed app are
preserved.

## Affected UI
- Settings → Data model → Existing objects (App column).
- Anywhere else `AppChip` / `useApplicationChipData` is used.
2026-04-21 08:26:26 +02:00

76 lines
2.2 KiB
TypeScript

import { CurrentApplicationContext } from '@/applications/contexts/CurrentApplicationContext';
import {
useApplicationAvatarColors,
type ApplicationAvatarColors,
} from '@/applications/hooks/useApplicationAvatarColors';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { t } from '@lingui/core/macro';
import { useContext } from 'react';
import { TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER } from 'twenty-shared/application';
import { isDefined } from 'twenty-shared/utils';
type UseApplicationChipDataArgs = {
applicationId: string;
};
type ApplicationChipData = {
name: string;
seed: string;
colors?: ApplicationAvatarColors;
};
type UseApplicationChipDataReturnType = {
applicationChipData: ApplicationChipData;
};
export const useApplicationChipData = ({
applicationId,
}: UseApplicationChipDataArgs): UseApplicationChipDataReturnType => {
const currentApplicationId = useContext(CurrentApplicationContext);
const currentWorkspace = useAtomStateValue(currentWorkspaceState);
const application = currentWorkspace?.installedApplications.find(
(installedApplication) => installedApplication.id === applicationId,
);
const colors = useApplicationAvatarColors(application);
if (!isDefined(application)) {
return {
applicationChipData: {
name: '',
seed: applicationId,
},
};
}
const isCurrent =
isDefined(currentApplicationId) && currentApplicationId === applicationId;
const isStandard =
isDefined(application.universalIdentifier) &&
application.universalIdentifier ===
TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER;
const isCustom =
isDefined(currentWorkspace?.workspaceCustomApplication?.id) &&
currentWorkspace.workspaceCustomApplication.id === application.id;
const displayName = isCurrent
? t`This app`
: isStandard
? t`Standard`
: isCustom
? t`Custom`
: application.name;
return {
applicationChipData: {
name: displayName,
seed: application.universalIdentifier ?? application.name,
colors,
},
};
};