Skip to content

The open alternative to Salesforce, designed for AI.

Unify record and side-panel header identifiers (#24935)

Thomas des Francs732fb8e7fc33
diff --git a/packages/twenty-front/src/modules/object-record/record-show/components/RecordIdentifierBarCreatedAt.tsx b/packages/twenty-front/src/modules/object-record/record-show/components/RecordIdentifierBarCreatedAt.tsx
new file mode 100644
index 00000000000..0ff1d14b185
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-show/components/RecordIdentifierBarCreatedAt.tsx
@@ -0,0 +1,58 @@
+import { recordStoreFamilySelector } from '@/object-record/record-store/states/selectors/recordStoreFamilySelector';
+import { StyledHeaderIdentifierLabel } from '@/ui/layout/page/components/StyledHeaderIdentifierLabel';
+import { useAtomFamilySelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilySelectorValue';
+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { styled } from '@linaria/react';
+import { Trans } from '@lingui/react/macro';
+import { isNonEmptyString } from '@sniptt/guards';
+import { useId } from 'react';
+import { AppTooltip } from 'twenty-ui/surfaces';
+import { dateLocaleState } from '~/localization/states/dateLocaleState';
+import {
+ beautifyExactDateTime,
+ beautifyPastDateRelativeToNow,
+} from '~/utils/date-utils';
+
+const StyledCreatedAt = styled(StyledHeaderIdentifierLabel)`
+ cursor: pointer;
+`;
+
+type RecordIdentifierBarCreatedAtProps = {
+ objectRecordId: string;
+};
+
+export const RecordIdentifierBarCreatedAt = ({
+ objectRecordId,
+}: RecordIdentifierBarCreatedAtProps) => {
+ const recordCreatedAt = useAtomFamilySelectorValue(
+ recordStoreFamilySelector,
+ { recordId: objectRecordId, fieldName: 'createdAt' },
+ );
+ const { localeCatalog } = useAtomStateValue(dateLocaleState);
+ const instanceId = useId().replace(/:/g, '');
+
+ if (!isNonEmptyString(recordCreatedAt)) {
+ return null;
+ }
+
+ const createdAtElementId = `record-identifier-bar-created-at-${instanceId}`;
+ const beautifiedCreatedAt = beautifyPastDateRelativeToNow(
+ recordCreatedAt,
+ localeCatalog,
+ );
+
+ return (
+ <>
+ <StyledCreatedAt id={createdAtElementId}>
+ <Trans>Created {beautifiedCreatedAt}</Trans>
+ </StyledCreatedAt>
+ <AppTooltip
+ anchorSelect={`#${createdAtElementId}`}
+ content={beautifyExactDateTime(recordCreatedAt)}
+ clickable
+ noArrow
+ place="left"
+ />
+ </>
+ );
+};
diff --git a/packages/twenty-front/src/modules/object-record/record-show/components/RecordIdentifierBarTitle.tsx b/packages/twenty-front/src/modules/object-record/record-show/components/RecordIdentifierBarTitle.tsx
new file mode 100644
index 00000000000..9fab7089ff8
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-show/components/RecordIdentifierBarTitle.tsx
@@ -0,0 +1,87 @@
+import { FieldContext } from '@/object-record/record-field/ui/contexts/FieldContext';
+import { useRecordIdentifierTitle } from '@/object-record/record-show/hooks/useRecordIdentifierTitle';
+import { RecordTitleCell } from '@/object-record/record-title-cell/components/RecordTitleCell';
+import { RecordTitleCellContainerType } from '@/object-record/record-title-cell/types/RecordTitleCellContainerType';
+import { HeaderIdentifier } from '@/ui/layout/page/components/HeaderIdentifier';
+import { styled } from '@linaria/react';
+import { useRef, type ChangeEvent } from 'react';
+import { AppPath } from 'twenty-shared/types';
+import { getAppPath, isDefined } from 'twenty-shared/utils';
+import { UndecoratedLink } from 'twenty-ui/navigation';
+import { getAbsoluteImageUrl } from '~/utils/image/getAbsoluteImageUrl';
+
+const StyledFileInput = styled.input`
+ display: none;
+`;
+
+type RecordIdentifierBarTitleProps = {
+ objectNameSingular: string;
+ objectRecordId: string;
+};
+
+export const RecordIdentifierBarTitle = ({
+ objectNameSingular,
+ objectRecordId,
+}: RecordIdentifierBarTitleProps) => {
+ const { recordIdentifier, onUploadPicture, titleFieldContextValue } =
+ useRecordIdentifierTitle({
+ objectNameSingular,
+ objectRecordId,
+ });
+
+ const inputFileRef = useRef<HTMLInputElement>(null);
+
+ const handleFileChange = (event: ChangeEvent<HTMLInputElement>) => {
+ if (isDefined(event.target.files)) {
+ onUploadPicture?.(event.target.files[0]);
+ }
+ };
+
+ const isAvatarEditable = isDefined(onUploadPicture);
+
+ const title = (
+ <FieldContext.Provider value={titleFieldContextValue}>
+ <RecordTitleCell
+ sizeVariant="sm"
+ containerType={RecordTitleCellContainerType.PageHeader}
+ />
+ </FieldContext.Provider>
+ );
+
+ return (
+ <>
+ <HeaderIdentifier
+ avatar={{
+ avatarUrl: getAbsoluteImageUrl(recordIdentifier?.avatarUrl ?? ''),
+ onClick: isAvatarEditable
+ ? () => inputFileRef.current?.click?.()
+ : undefined,
+ placeholderColorSeed: objectRecordId,
+ placeholder: recordIdentifier?.name ?? '',
+ type: recordIdentifier?.avatarType ?? 'rounded',
+ }}
+ title={
+ // A writable title has to stay click-to-edit, so only a read-only one
+ // can double as a link to the record page.
+ titleFieldContextValue.isRecordFieldReadOnly ? (
+ <UndecoratedLink
+ to={getAppPath(AppPath.RecordShowPage, {
+ objectNameSingular,
+ objectRecordId,
+ })}
+ >
+ {title}
+ </UndecoratedLink>
+ ) : (
+ title
+ )
+ }
+ />
+ <StyledFileInput
+ ref={inputFileRef}
+ onChange={handleFileChange}
+ type="file"
+ />
+ </>
+ );
+};
diff --git a/packages/twenty-front/src/modules/object-record/record-show/hooks/useRecordIdentifierTitle.ts b/packages/twenty-front/src/modules/object-record/record-show/hooks/useRecordIdentifierTitle.ts
new file mode 100644
index 00000000000..03412211086
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-show/hooks/useRecordIdentifierTitle.ts
@@ -0,0 +1,79 @@
+import { allowRequestsToTwentyIconsState } from '@/client-config/states/allowRequestsToTwentyIcons';
+import { useLabelIdentifierFieldMetadataItem } from '@/object-metadata/hooks/useLabelIdentifierFieldMetadataItem';
+import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
+import { useIsRecordFieldReadOnly } from '@/object-record/read-only/hooks/useIsRecordFieldReadOnly';
+import { type GenericFieldContextType } from '@/object-record/record-field/ui/contexts/FieldContext';
+import { useRecordImageIdentifierUpload } from '@/object-record/record-show/hooks/useRecordImageIdentifierUpload';
+import { useRecordShowContainerActions } from '@/object-record/record-show/hooks/useRecordShowContainerActions';
+import { recordStoreIdentifierFamilySelector } from '@/object-record/record-store/states/selectors/recordStoreIdentifierFamilySelector';
+import { useAtomFamilySelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilySelectorValue';
+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { FieldMetadataType } from '~/generated-metadata/graphql';
+
+type UseRecordIdentifierTitleParams = {
+ objectNameSingular: string;
+ objectRecordId: string;
+};
+
+export const useRecordIdentifierTitle = ({
+ objectNameSingular,
+ objectRecordId,
+}: UseRecordIdentifierTitleParams) => {
+ const allowRequestsToTwentyIcons = useAtomStateValue(
+ allowRequestsToTwentyIconsState,
+ );
+
+ const recordIdentifier = useAtomFamilySelectorValue(
+ recordStoreIdentifierFamilySelector,
+ {
+ recordId: objectRecordId,
+ allowRequestsToTwentyIcons,
+ },
+ );
+
+ const { useUpdateOneObjectRecordMutation } = useRecordShowContainerActions({
+ objectNameSingular,
+ });
+
+ const { onUploadPicture } = useRecordImageIdentifierUpload({
+ objectNameSingular,
+ recordId: objectRecordId,
+ });
+
+ const { objectMetadataItem } = useObjectMetadataItem({ objectNameSingular });
+
+ const { labelIdentifierFieldMetadataItem } =
+ useLabelIdentifierFieldMetadataItem({ objectNameSingular });
+
+ const isTitleReadOnly = useIsRecordFieldReadOnly({
+ recordId: objectRecordId,
+ fieldMetadataId: labelIdentifierFieldMetadataItem?.id ?? '',
+ objectMetadataId: objectMetadataItem.id,
+ });
+
+ const titleFieldContextValue: GenericFieldContextType = {
+ recordId: objectRecordId,
+ isLabelIdentifier: false,
+ fieldDefinition: {
+ type: labelIdentifierFieldMetadataItem?.type || FieldMetadataType.TEXT,
+ iconName: '',
+ fieldMetadataId: labelIdentifierFieldMetadataItem?.id ?? '',
+ label: labelIdentifierFieldMetadataItem?.label || '',
+ metadata: {
+ fieldName: labelIdentifierFieldMetadataItem?.name || '',
+ objectMetadataNameSingular: objectNameSingular,
+ },
+ defaultValue: labelIdentifierFieldMetadataItem?.defaultValue,
+ },
+ useUpdateRecord: useUpdateOneObjectRecordMutation,
+ isCentered: false,
+ isDisplayModeFixHeight: true,
+ isRecordFieldReadOnly: isTitleReadOnly,
+ };
+
+ return {
+ recordIdentifier,
+ onUploadPicture,
+ titleFieldContextValue,
+ };
+};
diff --git a/packages/twenty-front/src/modules/side-panel/components/SidePanelAskAiInfo.tsx b/packages/twenty-front/src/modules/side-panel/components/SidePanelAskAiInfo.tsx
index 8494caf278a..e1d218d8d35 100644
--- a/packages/twenty-front/src/modules/side-panel/components/SidePanelAskAiInfo.tsx
+++ b/packages/twenty-front/src/modules/side-panel/components/SidePanelAskAiInfo.tsx
@@ -1,17 +1,9 @@
import { currentAiChatThreadState } from '@/ai/states/currentAiChatThreadState';
import { currentAiChatThreadTitleComponentFamilyState } from '@/ai/states/currentAiChatThreadTitleComponentFamilyState';
+import { HeaderIdentifier } from '@/ui/layout/page/components/HeaderIdentifier';
import { useAtomComponentFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentFamilyStateValue';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
-import { styled } from '@linaria/react';
import { t } from '@lingui/core/macro';
-import { OverflowingTextWithTooltip } from 'twenty-ui/surfaces';
-import { themeCssVariables } from 'twenty-ui/theme-constants';
-
-const StyledPageTitle = styled.div`
- color: ${themeCssVariables.font.color.primary};
- font-size: ${themeCssVariables.font.size.sm};
- font-weight: ${themeCssVariables.font.weight.semiBold};
-`;
export const SidePanelAskAiInfo = () => {
const currentAiChatThread = useAtomStateValue(currentAiChatThreadState);
@@ -20,11 +12,5 @@ export const SidePanelAskAiInfo = () => {
{ threadId: currentAiChatThread },
);
- return (
- <StyledPageTitle>
- <OverflowingTextWithTooltip
- text={currentAiChatThreadTitle ?? t`Ask AI`}
- />
- </StyledPageTitle>
- );
+ return <HeaderIdentifier title={currentAiChatThreadTitle ?? t`Ask AI`} />;
};
diff --git a/packages/twenty-front/src/modules/side-panel/components/SidePanelFolderInfo.tsx b/packages/twenty-front/src/modules/side-panel/components/SidePanelFolderInfo.tsx
index 9b9022980ed..3cf9db251fe 100644
--- a/packages/twenty-front/src/modules/side-panel/components/SidePanelFolderInfo.tsx
+++ b/packages/twenty-front/src/modules/side-panel/components/SidePanelFolderInfo.tsx
@@ -10,7 +10,7 @@ import { selectedNavigationMenuItemIdInEditModeState } from '@/navigation-menu-i
import { useNavigationMenuItemEditController } from '@/navigation-menu-item/edit/hooks/useNavigationMenuItemEditController';
import { useNavigationMenuItemEditSectionItems } from '@/navigation-menu-item/edit/hooks/useNavigationMenuItemEditSectionItems';
import { useNavigationMenuItemTitleEdit } from '@/navigation-menu-item/edit/hooks/useNavigationMenuItemTitleEdit';
-import { SidePanelPageInfoLayout } from '@/side-panel/components/SidePanelPageInfoLayout';
+import { HeaderIdentifier } from '@/ui/layout/page/components/HeaderIdentifier';
import { sidePanelPageInfoState } from '@/side-panel/states/sidePanelPageInfoState';
import { sidePanelShouldFocusTitleInputComponentState } from '@/side-panel/states/sidePanelShouldFocusTitleInputComponentState';
import { IconPicker } from '@/ui/input/components/IconPicker';
@@ -65,7 +65,7 @@ export const SidePanelFolderInfo = () => {
const FolderIconComponent = getIcon(selectedIconKey);
return (
- <SidePanelPageInfoLayout
+ <HeaderIdentifier
icon={
<IconPicker
dropdownId="side-panel-folder-icon-picker"
diff --git a/packages/twenty-front/src/modules/side-panel/components/SidePanelLinkInfo.tsx b/packages/twenty-front/src/modules/side-panel/components/SidePanelLinkInfo.tsx
index e5dff4c5ff1..b701433b892 100644
--- a/packages/twenty-front/src/modules/side-panel/components/SidePanelLinkInfo.tsx
+++ b/packages/twenty-front/src/modules/side-panel/components/SidePanelLinkInfo.tsx
@@ -8,7 +8,7 @@ import { LinkIconWithLinkOverlay } from '@/navigation-menu-item/display/link/com
import { useNavigationMenuItemEditSectionItems } from '@/navigation-menu-item/edit/hooks/useNavigationMenuItemEditSectionItems';
import { useNavigationMenuItemTitleEdit } from '@/navigation-menu-item/edit/hooks/useNavigationMenuItemTitleEdit';
import { useNavigationMenuItemEditController } from '@/navigation-menu-item/edit/hooks/useNavigationMenuItemEditController';
-import { SidePanelPageInfoLayout } from '@/side-panel/components/SidePanelPageInfoLayout';
+import { HeaderIdentifier } from '@/ui/layout/page/components/HeaderIdentifier';
import { sidePanelPageInfoState } from '@/side-panel/states/sidePanelPageInfoState';
import { sidePanelShouldFocusTitleInputComponentState } from '@/side-panel/states/sidePanelShouldFocusTitleInputComponentState';
import { TitleInput } from '@/ui/input/components/TitleInput';
@@ -54,7 +54,7 @@ export const SidePanelLinkInfo = () => {
if (!isDefined(selectedItem)) return null;
return (
- <SidePanelPageInfoLayout
+ <HeaderIdentifier
icon={
<LinkIconWithLinkOverlay
link={selectedItem.link}
diff --git a/packages/twenty-front/src/modules/side-panel/components/SidePanelMultipleRecordsInfo.tsx b/packages/twenty-front/src/modules/side-panel/components/SidePanelMultipleRecordsInfo.tsx
index 2b9cb62aead..6b0497617ff 100644
--- a/packages/twenty-front/src/modules/side-panel/components/SidePanelMultipleRecordsInfo.tsx
+++ b/packages/twenty-front/src/modules/side-panel/components/SidePanelMultipleRecordsInfo.tsx
@@ -1,4 +1,4 @@
-import { SidePanelPageInfoLayout } from '@/side-panel/components/SidePanelPageInfoLayout';
+import { HeaderIdentifier } from '@/ui/layout/page/components/HeaderIdentifier';
import { useFindManyRecordsSelectedInContextStore } from '@/context-store/hooks/useFindManyRecordsSelectedInContextStore';
import { useNumberFormat } from '@/localization/hooks/useNumberFormat';
import { t } from '@lingui/core/macro';
@@ -21,7 +21,7 @@ export const SidePanelMultipleRecordsInfo = ({
});
return (
- <SidePanelPageInfoLayout
+ <HeaderIdentifier
icon={
<IconPencil size={theme.icon.size.md} stroke={theme.icon.stroke.sm} />
}
diff --git a/packages/twenty-front/src/modules/side-panel/components/SidePanelObjectViewRecordInfo.tsx b/packages/twenty-front/src/modules/side-panel/components/SidePanelObjectViewRecordInfo.tsx
index 0bc33682359..ebfcb2dc407 100644
--- a/packages/twenty-front/src/modules/side-panel/components/SidePanelObjectViewRecordInfo.tsx
+++ b/packages/twenty-front/src/modules/side-panel/components/SidePanelObjectViewRecordInfo.tsx
@@ -1,7 +1,6 @@
import { useLingui } from '@lingui/react/macro';
-import { OverflowingTextWithTooltip } from 'twenty-ui/surfaces';
-import { SidePanelPageInfoLayout } from '@/side-panel/components/SidePanelPageInfoLayout';
+import { HeaderIdentifier } from '@/ui/layout/page/components/HeaderIdentifier';
import { NavigationMenuItemIcon } from '@/navigation-menu-item/display/components/NavigationMenuItemIcon';
import { NavigationMenuItemType } from 'twenty-shared/types';
import { useSelectedNavigationMenuItemEditItem } from '@/navigation-menu-item/edit/hooks/useSelectedNavigationMenuItemEditItem';
@@ -42,9 +41,9 @@ export const SidePanelObjectViewRecordInfo = () => {
: t`View`;
return (
- <SidePanelPageInfoLayout
+ <HeaderIdentifier
icon={<NavigationMenuItemIcon navigationMenuItem={navItem} />}
- title={<OverflowingTextWithTooltip text={selectedItemLabel} />}
+ title={selectedItemLabel}
label={label}
/>
);
diff --git a/packages/twenty-front/src/modules/side-panel/components/SidePanelPageInfo.tsx b/packages/twenty-front/src/modules/side-panel/components/SidePanelPageInfo.tsx
index 22d15032184..e8110ef277e 100644
--- a/packages/twenty-front/src/modules/side-panel/components/SidePanelPageInfo.tsx
+++ b/packages/twenty-front/src/modules/side-panel/components/SidePanelPageInfo.tsx
@@ -1,7 +1,5 @@
-import { styled } from '@linaria/react';
import { isDefined } from 'twenty-shared/utils';
import { IconColumnInsertRight } from 'twenty-ui/icon';
-import { OverflowingTextWithTooltip } from 'twenty-ui/surfaces';
import { selectedNavigationMenuItemIdInEditModeState } from '@/navigation-menu-item/common/states/selectedNavigationMenuItemIdInEditModeState';
import { useNavigationMenuItemEditSectionItems } from '@/navigation-menu-item/edit/hooks/useNavigationMenuItemEditSectionItems';
@@ -10,7 +8,7 @@ import { SidePanelFolderInfo } from '@/side-panel/components/SidePanelFolderInfo
import { SidePanelLinkInfo } from '@/side-panel/components/SidePanelLinkInfo';
import { SidePanelMultipleRecordsInfo } from '@/side-panel/components/SidePanelMultipleRecordsInfo';
import { SidePanelObjectViewRecordInfo } from '@/side-panel/components/SidePanelObjectViewRecordInfo';
-import { SidePanelPageInfoLayout } from '@/side-panel/components/SidePanelPageInfoLayout';
+import { HeaderIdentifier } from '@/ui/layout/page/components/HeaderIdentifier';
import { SidePanelPageLayoutInfo } from '@/side-panel/components/SidePanelPageLayoutInfo';
import { SidePanelRecordInfo } from '@/side-panel/components/SidePanelRecordInfo';
import { SidePanelWorkflowStepInfo } from '@/side-panel/components/SidePanelWorkflowStepInfo';
@@ -20,12 +18,7 @@ import { NavigationMenuItemType, SidePanelPages } from 'twenty-shared/types';
import { type SidePanelContextChipProps } from '@/side-panel/components/SidePanelContextChip';
import { useContext } from 'react';
-import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
-const StyledPageTitle = styled.div`
- color: ${themeCssVariables.font.color.primary};
- font-size: ${themeCssVariables.font.size.sm};
- font-weight: ${themeCssVariables.font.weight.semiBold};
-`;
+import { ThemeContext } from 'twenty-ui/theme-constants';
type SidePanelPageInfoProps = {
pageChip: SidePanelContextChipProps | undefined;
@@ -120,21 +113,17 @@ export const SidePanelPageInfo = ({ pageChip }: SidePanelPageInfoProps) => {
if (pageChip.page?.page === SidePanelPages.NavigationMenuAddItem) {
return (
- <SidePanelPageInfoLayout
+ <HeaderIdentifier
icon={
<IconColumnInsertRight
size={theme.icon.size.md}
color={theme.font.color.tertiary}
/>
}
- title={<OverflowingTextWithTooltip text={pageChip.text ?? ''} />}
+ title={pageChip.text ?? ''}
/>
);
}
- return (
- <StyledPageTitle>
- <OverflowingTextWithTooltip text={pageChip.text ?? ''} />
- </StyledPageTitle>
- );
+ return <HeaderIdentifier title={pageChip.text ?? ''} />;
};
diff --git a/packages/twenty-front/src/modules/side-panel/components/SidePanelPageInfoLayout.tsx b/packages/twenty-front/src/modules/side-panel/components/SidePanelPageInfoLayout.tsx
deleted file mode 100644
index 14038d76601..00000000000
--- a/packages/twenty-front/src/modules/side-panel/components/SidePanelPageInfoLayout.tsx
+++ /dev/null
@@ -1,71 +0,0 @@
-import { styled } from '@linaria/react';
-import { type ReactNode } from 'react';
-import { isDefined } from 'twenty-shared/utils';
-import { themeCssVariables } from 'twenty-ui/theme-constants';
-
-export const StyledPageInfoContainer = styled.div`
- align-items: center;
- display: flex;
- gap: ${themeCssVariables.spacing[0.5]};
-`;
-
-export const StyledPageInfoIcon = styled.div<{ iconColor?: string }>`
- align-items: center;
- background: ${themeCssVariables.background.transparent.light};
- border-radius: ${themeCssVariables.border.radius.sm};
- color: ${({ iconColor }) => iconColor ?? ''};
- display: flex;
- flex-shrink: 0;
- justify-content: center;
- padding: ${themeCssVariables.spacing[1]};
-`;
-
-export const StyledPageInfoTextContainer = styled.div`
- align-items: center;
- display: flex;
- flex: 1;
- gap: ${themeCssVariables.spacing[0.5]};
- min-width: 0;
-`;
-
-export const StyledPageInfoTitleContainer = styled.div`
- color: ${themeCssVariables.font.color.primary};
- font-size: ${themeCssVariables.font.size.md};
- font-weight: ${themeCssVariables.font.weight.semiBold};
- max-width: 150px;
- min-width: 0;
- padding-inline: ${themeCssVariables.spacing[1]};
-`;
-
-export const StyledPageInfoLabel = styled.div`
- color: ${themeCssVariables.font.color.tertiary};
- flex-shrink: 0;
- font-size: ${themeCssVariables.font.size.sm};
- white-space: nowrap;
-`;
-
-type SidePanelPageInfoLayoutProps = {
- icon?: ReactNode;
- iconColor?: string;
- title: ReactNode;
- label?: ReactNode;
-};
-
-export const SidePanelPageInfoLayout = ({
- icon,
- iconColor,
- title,
- label,
-}: SidePanelPageInfoLayoutProps) => {
- return (
- <StyledPageInfoContainer>
- {isDefined(icon) && (
- <StyledPageInfoIcon iconColor={iconColor}>{icon}</StyledPageInfoIcon>
- )}
- <StyledPageInfoTextContainer>
- <StyledPageInfoTitleContainer>{title}</StyledPageInfoTitleContainer>
- {isDefined(label) && <StyledPageInfoLabel>{label}</StyledPageInfoLabel>}
- </StyledPageInfoTextContainer>
- </StyledPageInfoContainer>
- );
-};
diff --git a/packages/twenty-front/src/modules/side-panel/components/SidePanelPageLayoutInfoContent.tsx b/packages/twenty-front/src/modules/side-panel/components/SidePanelPageLayoutInfoContent.tsx
index 92bc031d84b..4a98a0472d6 100644
--- a/packages/twenty-front/src/modules/side-panel/components/SidePanelPageLayoutInfoContent.tsx
+++ b/packages/twenty-front/src/modules/side-panel/components/SidePanelPageLayoutInfoContent.tsx
@@ -21,7 +21,7 @@ import { SidePanelPages } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { useIcons } from 'twenty-ui/icon';
import { ThemeContext } from 'twenty-ui/theme-constants';
-import { SidePanelPageInfoLayout } from './SidePanelPageInfoLayout';
+import { HeaderIdentifier } from '@/ui/layout/page/components/HeaderIdentifier';
const StyledClickableIconWrapper = styled.div`
cursor: pointer;
@@ -161,7 +161,7 @@ export const SidePanelPageLayoutInfoContent = ({
);
return (
- <SidePanelPageInfoLayout
+ <HeaderIdentifier
icon={iconElement}
iconColor={headerIconColor}
title={
diff --git a/packages/twenty-front/src/modules/side-panel/components/SidePanelRecordInfo.tsx b/packages/twenty-front/src/modules/side-panel/components/SidePanelRecordInfo.tsx
index 91d79ccdea6..37363b9da7d 100644
--- a/packages/twenty-front/src/modules/side-panel/components/SidePanelRecordInfo.tsx
+++ b/packages/twenty-front/src/modules/side-panel/components/SidePanelRecordInfo.tsx
@@ -1,55 +1,30 @@
-import { allowRequestsToTwentyIconsState } from '@/client-config/states/allowRequestsToTwentyIcons';
+import { RecordIdentifierBarCreatedAt } from '@/object-record/record-show/components/RecordIdentifierBarCreatedAt';
+import { RecordIdentifierBarTitle } from '@/object-record/record-show/components/RecordIdentifierBarTitle';
+import { useRecordShowPage } from '@/object-record/record-show/hooks/useRecordShowPage';
import { viewableRecordIdComponentState } from '@/side-panel/pages/record-page/states/viewableRecordIdComponentState';
import { viewableRecordNameSingularComponentState } from '@/side-panel/pages/record-page/states/viewableRecordNameSingularComponentState';
-import { useLabelIdentifierFieldMetadataItem } from '@/object-metadata/hooks/useLabelIdentifierFieldMetadataItem';
-import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
-import { useIsRecordFieldReadOnly } from '@/object-record/read-only/hooks/useIsRecordFieldReadOnly';
-import { FieldContext } from '@/object-record/record-field/ui/contexts/FieldContext';
-import { useRecordShowContainerActions } from '@/object-record/record-show/hooks/useRecordShowContainerActions';
-import { useRecordShowPage } from '@/object-record/record-show/hooks/useRecordShowPage';
-import { recordStoreFamilySelector } from '@/object-record/record-store/states/selectors/recordStoreFamilySelector';
-import { recordStoreIdentifierFamilySelector } from '@/object-record/record-store/states/selectors/recordStoreIdentifierFamilySelector';
-import { RecordTitleCell } from '@/object-record/record-title-cell/components/RecordTitleCell';
-import { RecordTitleCellContainerType } from '@/object-record/record-title-cell/types/RecordTitleCellContainerType';
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
-import { Trans } from '@lingui/react/macro';
-import { isNonEmptyString } from '@sniptt/guards';
import { styled } from '@linaria/react';
-import { useAtomFamilySelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilySelectorValue';
-import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
-import { AppPath } from 'twenty-shared/types';
-import { getAppPath } from 'twenty-shared/utils';
-import { Avatar } from 'twenty-ui/data-display';
-import { UndecoratedLink } from 'twenty-ui/navigation';
-import { FieldMetadataType } from '~/generated-metadata/graphql';
-import { dateLocaleState } from '~/localization/states/dateLocaleState';
-
-import { beautifyPastDateRelativeToNow } from '~/utils/date-utils';
-import { getAbsoluteImageUrl } from '~/utils/image/getAbsoluteImageUrl';
-import { SidePanelPageInfoLayout } from './SidePanelPageInfoLayout';
+import { themeCssVariables } from 'twenty-ui/theme-constants';
-const StyledClickableTitle = styled.div`
- cursor: pointer;
-
- a {
- color: inherit;
- text-decoration: none;
- }
+const StyledRecordInfo = styled.div`
+ align-items: center;
+ display: flex;
+ gap: ${themeCssVariables.spacing[2]};
+ min-width: 0;
`;
+type SidePanelRecordInfoProps = {
+ sidePanelPageInstanceId: string;
+};
+
export const SidePanelRecordInfo = ({
sidePanelPageInstanceId,
-}: {
- sidePanelPageInstanceId: string;
-}) => {
+}: SidePanelRecordInfoProps) => {
const viewableRecordNameSingular = useAtomComponentStateValue(
viewableRecordNameSingularComponentState,
sidePanelPageInstanceId,
);
- const allowRequestsToTwentyIcons = useAtomStateValue(
- allowRequestsToTwentyIconsState,
- );
-
const viewableRecordId = useAtomComponentStateValue(
viewableRecordIdComponentState,
sidePanelPageInstanceId,
@@ -60,111 +35,13 @@ export const SidePanelRecordInfo = ({
viewableRecordId!,
);
- const recordCreatedAt = useAtomFamilySelectorValue(
- recordStoreFamilySelector,
- {
- recordId: objectRecordId,
- fieldName: 'createdAt',
- },
- ) as string | null;
-
- const recordIdentifier = useAtomFamilySelectorValue(
- recordStoreIdentifierFamilySelector,
- {
- recordId: objectRecordId,
- allowRequestsToTwentyIcons,
- },
- );
-
- const { localeCatalog } = useAtomStateValue(dateLocaleState);
- const beautifiedCreatedAt = isNonEmptyString(recordCreatedAt)
- ? beautifyPastDateRelativeToNow(recordCreatedAt, localeCatalog)
- : '';
-
- const { objectMetadataItem } = useObjectMetadataItem({
- objectNameSingular,
- });
-
- const { labelIdentifierFieldMetadataItem } =
- useLabelIdentifierFieldMetadataItem({
- objectNameSingular,
- });
-
- const isTitleReadOnly = useIsRecordFieldReadOnly({
- recordId: objectRecordId,
- fieldMetadataId: labelIdentifierFieldMetadataItem?.id ?? '',
- objectMetadataId: objectMetadataItem.id,
- });
-
- const { useUpdateOneObjectRecordMutation } = useRecordShowContainerActions({
- objectNameSingular,
- });
-
- const recordShowPagePath = getAppPath(AppPath.RecordShowPage, {
- objectNameSingular,
- objectRecordId,
- });
-
- const fieldDefinition = {
- type: labelIdentifierFieldMetadataItem?.type ?? FieldMetadataType.TEXT,
- iconName: '',
- fieldMetadataId: labelIdentifierFieldMetadataItem?.id ?? '',
- label: labelIdentifierFieldMetadataItem?.label ?? '',
- metadata: {
- fieldName: labelIdentifierFieldMetadataItem?.name ?? '',
- objectMetadataNameSingular: objectNameSingular,
- },
- defaultValue: labelIdentifierFieldMetadataItem?.defaultValue,
- };
-
- const titleContent = (
- <FieldContext.Provider
- value={{
- recordId: objectRecordId,
- isLabelIdentifier: false,
- fieldDefinition,
- useUpdateRecord: useUpdateOneObjectRecordMutation,
- isCentered: false,
- isDisplayModeFixHeight: true,
- isRecordFieldReadOnly: isTitleReadOnly,
- }}
- >
- <RecordTitleCell
- sizeVariant="sm"
- containerType={RecordTitleCellContainerType.PageHeader}
- />
- </FieldContext.Provider>
- );
-
return (
- <SidePanelPageInfoLayout
- icon={
- recordIdentifier ? (
- <Avatar
- avatarUrl={getAbsoluteImageUrl(recordIdentifier.avatarUrl)}
- placeholder={recordIdentifier.name}
- placeholderColorSeed={objectRecordId}
- size="md"
- type={recordIdentifier.avatarType}
- />
- ) : undefined
- }
- title={
- isTitleReadOnly ? (
- <StyledClickableTitle>
- <UndecoratedLink to={recordShowPagePath}>
- {titleContent}
- </UndecoratedLink>
- </StyledClickableTitle>
- ) : (
- titleContent
- )
- }
- label={
- beautifiedCreatedAt ? (
- <Trans>Created {beautifiedCreatedAt}</Trans>
- ) : undefined
- }
- />
+ <StyledRecordInfo>
+ <RecordIdentifierBarTitle
+ objectNameSingular={objectNameSingular}
+ objectRecordId={objectRecordId}
+ />
+ <RecordIdentifierBarCreatedAt objectRecordId={objectRecordId} />
+ </StyledRecordInfo>
);
};
diff --git a/packages/twenty-front/src/modules/side-panel/components/SidePanelWorkflowStepInfo.tsx b/packages/twenty-front/src/modules/side-panel/components/SidePanelWorkflowStepInfo.tsx
index 2f5e9a4acb9..644e2f88b02 100644
--- a/packages/twenty-front/src/modules/side-panel/components/SidePanelWorkflowStepInfo.tsx
+++ b/packages/twenty-front/src/modules/side-panel/components/SidePanelWorkflowStepInfo.tsx
@@ -27,7 +27,7 @@ import { SidePanelPages } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { TRIGGER_STEP_ID } from 'twenty-shared/workflow';
import { useIcons } from 'twenty-ui/icon';
-import { SidePanelPageInfoLayout } from './SidePanelPageInfoLayout';
+import { HeaderIdentifier } from '@/ui/layout/page/components/HeaderIdentifier';
import { ThemeContext } from 'twenty-ui/theme-constants';
export const SidePanelWorkflowStepInfo = ({
@@ -177,7 +177,7 @@ export const SidePanelWorkflowStepInfo = ({
};
return (
- <SidePanelPageInfoLayout
+ <HeaderIdentifier
icon={
isDefined(thirdPartyApplicationInformation) ? (
<AppChip
diff --git a/packages/twenty-front/src/modules/side-panel/components/__stories__/SidePanelRecordInfo.stories.tsx b/packages/twenty-front/src/modules/side-panel/components/__stories__/SidePanelRecordInfo.stories.tsx
new file mode 100644
index 00000000000..9785a45f877
--- /dev/null
+++ b/packages/twenty-front/src/modules/side-panel/components/__stories__/SidePanelRecordInfo.stories.tsx
@@ -0,0 +1,107 @@
+import { isLayoutCustomizationModeEnabledState } from '@/layout-customization/states/isLayoutCustomizationModeEnabledState';
+import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
+import { SidePanelRecordInfo } from '@/side-panel/components/SidePanelRecordInfo';
+import { viewableRecordIdComponentState } from '@/side-panel/pages/record-page/states/viewableRecordIdComponentState';
+import { viewableRecordNameSingularComponentState } from '@/side-panel/pages/record-page/states/viewableRecordNameSingularComponentState';
+import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { act } from 'react';
+import { expect, userEvent, within } from 'storybook/test';
+import { ComponentWithRouterDecorator } from '~/testing/decorators/ComponentWithRouterDecorator';
+import { ObjectMetadataItemsDecorator } from '~/testing/decorators/ObjectMetadataItemsDecorator';
+import { mockedCompanyRecords } from '~/testing/mock-data/generated/data/companies/mock-companies-data';
+import {
+ beautifyExactDateTime,
+ beautifyPastDateRelativeToNow,
+} from '~/utils/date-utils';
+
+const SIDE_PANEL_PAGE_INSTANCE_ID = 'side-panel-record-info';
+const CREATED_AT = '2026-08-25T12:00:00.000Z';
+const COMPANY = {
+ ...mockedCompanyRecords[0],
+ name: 'Acme',
+ createdAt: CREATED_AT,
+};
+
+const meta: Meta<typeof SidePanelRecordInfo> = {
+ title: 'Modules/SidePanel/SidePanelRecordInfo',
+ component: SidePanelRecordInfo,
+ args: { sidePanelPageInstanceId: SIDE_PANEL_PAGE_INSTANCE_ID },
+ parameters: {
+ mockingDate: new Date('2026-08-27T12:00:00.000Z'),
+ },
+ beforeEach: () => {
+ jotaiStore.set(recordStoreFamilyState.atomFamily(COMPANY.id), COMPANY);
+ jotaiStore.set(
+ viewableRecordIdComponentState.atomFamily({
+ instanceId: SIDE_PANEL_PAGE_INSTANCE_ID,
+ }),
+ COMPANY.id,
+ );
+ jotaiStore.set(
+ viewableRecordNameSingularComponentState.atomFamily({
+ instanceId: SIDE_PANEL_PAGE_INSTANCE_ID,
+ }),
+ 'company',
+ );
+ },
+ decorators: [ObjectMetadataItemsDecorator, ComponentWithRouterDecorator],
+};
+
+export default meta;
+type Story = StoryObj<typeof SidePanelRecordInfo>;
+
+export const Editable: Story = {
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const createdAtLabel = `Created ${beautifyPastDateRelativeToNow(CREATED_AT)}`;
+
+ expect(
+ await canvas.findByRole('heading', { level: 3, name: 'Acme' }),
+ ).toBeVisible();
+ expect(
+ canvas.queryByRole('link', { name: 'Acme' }),
+ ).not.toBeInTheDocument();
+
+ // The tooltip attaches its native hover listeners in effects after mount.
+ await act(async () => {
+ await canvas.findByText(createdAtLabel);
+ });
+ await userEvent.hover(canvas.getByText(createdAtLabel));
+ expect(
+ await within(canvasElement.ownerDocument.body).findByRole('tooltip'),
+ ).toHaveTextContent(beautifyExactDateTime(CREATED_AT));
+ await userEvent.unhover(canvas.getByText(createdAtLabel));
+ },
+};
+
+export const ReadOnly: Story = {
+ beforeEach: () => {
+ jotaiStore.set(isLayoutCustomizationModeEnabledState.atom, true);
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ expect(await canvas.findByRole('link', { name: 'Acme' })).toHaveAttribute(
+ 'href',
+ `/object/company/${COMPANY.id}`,
+ );
+ },
+};
+
+export const WithoutCreationDate: Story = {
+ beforeEach: () => {
+ jotaiStore.set(recordStoreFamilyState.atomFamily(COMPANY.id), {
+ ...COMPANY,
+ createdAt: null,
+ });
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ expect(
+ await canvas.findByRole('heading', { level: 3, name: 'Acme' }),
+ ).toBeVisible();
+ expect(canvas.queryByText(/^Created /)).not.toBeInTheDocument();
+ },
+};
diff --git a/packages/twenty-front/src/modules/side-panel/pages/search/components/SidePanelSearchRecordPreviewCard.tsx b/packages/twenty-front/src/modules/side-panel/pages/search/components/SidePanelSearchRecordPreviewCard.tsx
index d96f0507b9b..259cdfe8143 100644
--- a/packages/twenty-front/src/modules/side-panel/pages/search/components/SidePanelSearchRecordPreviewCard.tsx
+++ b/packages/twenty-front/src/modules/side-panel/pages/search/components/SidePanelSearchRecordPreviewCard.tsx
@@ -9,7 +9,7 @@ import { recordStoreFamilySelector } from '@/object-record/record-store/states/s
import { recordStoreIdentifierFamilySelector } from '@/object-record/record-store/states/selectors/recordStoreIdentifierFamilySelector';
import { getRecordFieldInputInstanceId } from '@/object-record/utils/getRecordFieldInputId';
import { FieldWidgetShowMoreButton } from '@/page-layout/widgets/field/components/FieldWidgetShowMoreButton';
-import { SidePanelPageInfoLayout } from '@/side-panel/components/SidePanelPageInfoLayout';
+import { HeaderIdentifier } from '@/ui/layout/page/components/HeaderIdentifier';
import { SIDE_PANEL_SEARCH_RECORD_PREVIEW_MAX_COLLAPSED_FIELDS } from '@/side-panel/pages/search/constants/SidePanelSearchRecordPreviewMaxCollapsedFields';
import { SIDE_PANEL_SEARCH_RECORD_PREVIEW_WIDTH } from '@/side-panel/pages/search/constants/SidePanelSearchRecordPreviewWidth';
import { useSidePanelSearchRecordPreviewFields } from '@/side-panel/pages/search/hooks/useSidePanelSearchRecordPreviewFields';
@@ -22,7 +22,6 @@ import { Trans } from '@lingui/react/macro';
import { isNonEmptyString } from '@sniptt/guards';
import { useContext, useState } from 'react';
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton';
-import { Avatar } from 'twenty-ui/data-display';
import { useIcons } from 'twenty-ui/icon';
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
@@ -231,16 +230,13 @@ export const SidePanelSearchRecordPreviewCard = ({
>
<StyledCard>
<StyledHeader>
- <SidePanelPageInfoLayout
- icon={
- <Avatar
- avatarUrl={getAbsoluteImageUrl(recordIdentifier?.avatarUrl)}
- placeholder={recordIdentifier?.name ?? label}
- placeholderColorSeed={recordId}
- size="md"
- type={recordIdentifier?.avatarType ?? 'rounded'}
- />
- }
+ <HeaderIdentifier
+ avatar={{
+ avatarUrl: getAbsoluteImageUrl(recordIdentifier?.avatarUrl),
+ placeholder: recordIdentifier?.name ?? label,
+ placeholderColorSeed: recordId,
+ type: recordIdentifier?.avatarType ?? 'rounded',
+ }}
title={
<StyledTitleText>
{recordIdentifier?.name ?? label}
diff --git a/packages/twenty-front/src/modules/ui/layout/page/components/HeaderIdentifier.tsx b/packages/twenty-front/src/modules/ui/layout/page/components/HeaderIdentifier.tsx
new file mode 100644
index 00000000000..cf2ac6b2109
--- /dev/null
+++ b/packages/twenty-front/src/modules/ui/layout/page/components/HeaderIdentifier.tsx
@@ -0,0 +1,102 @@
+import { StyledHeaderIdentifierLabel } from '@/ui/layout/page/components/StyledHeaderIdentifierLabel';
+import { styled } from '@linaria/react';
+import { type ReactNode } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+import {
+ AVATAR_PROPERTIES_BY_SIZE,
+ Avatar,
+ type AvatarProps,
+} from 'twenty-ui/data-display';
+import { OverflowingTextWithTooltip } from 'twenty-ui/surfaces';
+import { themeCssVariables } from 'twenty-ui/theme-constants';
+
+const HEADER_IDENTIFIER_TILE_SIZE = AVATAR_PROPERTIES_BY_SIZE.lg.width;
+
+const StyledContainer = styled.div`
+ align-items: center;
+ display: flex;
+ gap: ${themeCssVariables.spacing[1]};
+ min-width: 0;
+`;
+
+const StyledIcon = styled.div<{ iconColor?: string }>`
+ align-items: center;
+ background: ${themeCssVariables.background.transparent.light};
+ border-radius: ${themeCssVariables.border.radius.sm};
+ box-sizing: border-box;
+ color: ${({ iconColor }) => iconColor ?? ''};
+ display: flex;
+ flex-shrink: 0;
+ height: ${HEADER_IDENTIFIER_TILE_SIZE};
+ justify-content: center;
+ width: ${HEADER_IDENTIFIER_TILE_SIZE};
+`;
+
+const StyledTextContainer = styled.div`
+ align-items: center;
+ display: flex;
+ flex: 1;
+ gap: ${themeCssVariables.spacing[2]};
+ min-width: 0;
+`;
+
+const StyledTitle = styled.h3`
+ color: ${themeCssVariables.font.color.primary};
+ font-size: ${themeCssVariables.font.size.md};
+ font-weight: ${themeCssVariables.font.weight.semiBold};
+ margin: 0;
+ min-width: 0;
+ overflow: hidden;
+`;
+
+type HeaderIdentifierProps = {
+ avatar?: Pick<
+ AvatarProps,
+ 'avatarUrl' | 'onClick' | 'placeholder' | 'placeholderColorSeed' | 'type'
+ >;
+ icon?: ReactNode;
+ iconColor?: string;
+ title: ReactNode;
+ label?: ReactNode;
+};
+
+export const HeaderIdentifier = ({
+ avatar,
+ icon,
+ iconColor,
+ title,
+ label,
+}: HeaderIdentifierProps) => {
+ const identifierIcon = isDefined(avatar) ? (
+ <Avatar
+ avatarUrl={avatar.avatarUrl}
+ onClick={avatar.onClick}
+ placeholder={avatar.placeholder}
+ placeholderColorSeed={avatar.placeholderColorSeed}
+ type={avatar.type}
+ size="md"
+ />
+ ) : (
+ icon
+ );
+
+ return (
+ <StyledContainer>
+ {isDefined(identifierIcon) && (
+ <StyledIcon iconColor={iconColor}>{identifierIcon}</StyledIcon>
+ )}
+ <StyledTextContainer>
+ <StyledTitle>
+ {typeof title === 'string' ? (
+ <OverflowingTextWithTooltip text={title} />
+ ) : (
+ title
+ )}
+ </StyledTitle>
+ {isDefined(label) && (
+ <StyledHeaderIdentifierLabel>{label}</StyledHeaderIdentifierLabel>
+ )}
+ </StyledTextContainer>
+ </StyledContainer>
+ );
+};
diff --git a/packages/twenty-front/src/modules/ui/layout/page/components/StyledHeaderIdentifierLabel.tsx b/packages/twenty-front/src/modules/ui/layout/page/components/StyledHeaderIdentifierLabel.tsx
new file mode 100644
index 00000000000..5ce365f82f6
--- /dev/null
+++ b/packages/twenty-front/src/modules/ui/layout/page/components/StyledHeaderIdentifierLabel.tsx
@@ -0,0 +1,9 @@
+import { styled } from '@linaria/react';
+import { themeCssVariables } from 'twenty-ui/theme-constants';
+
+export const StyledHeaderIdentifierLabel = styled.span`
+ color: ${themeCssVariables.font.color.tertiary};
+ flex-shrink: 0;
+ font-size: ${themeCssVariables.font.size.md};
+ white-space: nowrap;
+`;
diff --git a/packages/twenty-front/src/modules/ui/layout/page/components/__stories__/HeaderIdentifier.stories.tsx b/packages/twenty-front/src/modules/ui/layout/page/components/__stories__/HeaderIdentifier.stories.tsx
new file mode 100644
index 00000000000..59b34e0b31f
--- /dev/null
+++ b/packages/twenty-front/src/modules/ui/layout/page/components/__stories__/HeaderIdentifier.stories.tsx
@@ -0,0 +1,165 @@
+import { TitleInput } from '@/ui/input/components/TitleInput';
+import { HeaderIdentifier } from '@/ui/layout/page/components/HeaderIdentifier';
+import { styled } from '@linaria/react';
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { expect, fn, userEvent, within } from 'storybook/test';
+import { IconChartBar } from 'twenty-ui/icon';
+import { ComponentDecorator } from 'twenty-ui/testing';
+
+const StyledContainer = styled.div`
+ display: flex;
+ width: 280px;
+`;
+
+const onIconClick = fn();
+const onTitleChange = fn();
+const onTitleEnter = fn();
+
+const meta: Meta<typeof HeaderIdentifier> = {
+ title: 'UI/Layout/Page/HeaderIdentifier',
+ component: HeaderIdentifier,
+ decorators: [
+ ComponentDecorator,
+ (Story) => (
+ <StyledContainer>
+ <Story />
+ </StyledContainer>
+ ),
+ ],
+};
+
+export default meta;
+type Story = StoryObj<typeof HeaderIdentifier>;
+
+export const Record: Story = {
+ args: {
+ avatar: { placeholder: 'Acme', type: 'rounded', onClick: fn() },
+ title: 'Acme',
+ label: 'Created 2 days ago',
+ },
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+
+ expect(
+ await canvas.findByRole('heading', { name: 'Acme', level: 3 }),
+ ).toBeVisible();
+ expect(canvas.getByText('Created 2 days ago')).toBeVisible();
+
+ await userEvent.click(canvas.getByRole('button', { name: 'Acme' }));
+
+ expect(args.avatar?.onClick).toHaveBeenCalledTimes(1);
+ },
+};
+
+export const Chart: Story = {
+ args: {
+ icon: <IconChartBar size={16} />,
+ title: 'Revenue forecast',
+ label: 'Chart',
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ expect(
+ await canvas.findByRole('heading', {
+ name: 'Revenue forecast',
+ level: 3,
+ }),
+ ).toBeVisible();
+ expect(canvas.getByText('Chart')).toBeVisible();
+ },
+};
+
+export const LongTitle: Story = {
+ args: {
+ ...Chart.args,
+ title: 'Rocket Count (Object Permission Test)',
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ expect(
+ await canvas.findByRole('heading', {
+ name: 'Rocket Count (Object Permission Test)',
+ level: 3,
+ }),
+ ).toBeVisible();
+ expect(canvas.getByText('Chart')).toBeVisible();
+ },
+};
+
+export const TitleOnly: Story = {
+ args: {
+ title: 'Update records',
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ expect(
+ await canvas.findByRole('heading', { name: 'Update records', level: 3 }),
+ ).toBeVisible();
+ expect(canvas.queryByText('Chart')).not.toBeInTheDocument();
+ },
+};
+
+export const InteractiveIcon: Story = {
+ args: {
+ ...Chart.args,
+ icon: (
+ <button aria-label="Change chart icon" onClick={onIconClick}>
+ <IconChartBar size={16} />
+ </button>
+ ),
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ await userEvent.click(
+ await canvas.findByRole('button', { name: 'Change chart icon' }),
+ );
+
+ expect(onIconClick).toHaveBeenCalledTimes(1);
+ },
+};
+
+export const EditableTitle: Story = {
+ args: { label: 'Chart' },
+ render: (args) => (
+ <HeaderIdentifier
+ {...args}
+ title={
+ <TitleInput
+ instanceId="header-identifier-title"
+ sizeVariant="sm"
+ value="Revenue forecast"
+ onChange={onTitleChange}
+ onEnter={onTitleEnter}
+ />
+ }
+ />
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ await userEvent.click(await canvas.findByText('Revenue forecast'));
+ const titleInput = await canvas.findByRole('textbox');
+ await userEvent.clear(titleInput);
+ await userEvent.type(titleInput, 'Updated forecast{Enter}');
+
+ expect(onTitleChange).toHaveBeenLastCalledWith('Updated forecast');
+ expect(onTitleEnter).toHaveBeenCalledTimes(1);
+ expect(canvas.queryByRole('textbox')).not.toBeInTheDocument();
+ },
+};
+
+export const LinkedTitle: Story = {
+ args: { title: <a href="/record/acme">Acme</a> },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ expect(await canvas.findByRole('link', { name: 'Acme' })).toHaveAttribute(
+ 'href',
+ '/record/acme',
+ );
+ },
+};