Skip to content

The open alternative to Salesforce, designed for AI.

Slide the mobile record table's frozen column instead of resizing it (#24993)

Félix Malfait0109e4413c50
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/contexts/FieldContext.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/contexts/FieldContext.ts
index af3a3b58bb2..4684c853b3e 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/contexts/FieldContext.ts
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/contexts/FieldContext.ts
@@ -26,7 +26,6 @@ export type GenericFieldContextType = {
fieldDefinition: FieldDefinition<FieldMetadata>;
useUpdateRecord?: RecordUpdateHook;
isLabelIdentifier: boolean;
- isLabelIdentifierCompact?: boolean;
clearable?: boolean;
maxWidth?: number;
isCentered?: boolean;
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/display/components/ChipFieldDisplay.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/display/components/ChipFieldDisplay.tsx
index 304d4727627..8c0ffc089bc 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/display/components/ChipFieldDisplay.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/display/components/ChipFieldDisplay.tsx
@@ -12,7 +12,6 @@ export const ChipFieldDisplay = () => {
maxWidth,
triggerEvent,
onRecordChipClick,
- isLabelIdentifierCompact,
} = useChipFieldDisplay();
if (!isDefined(recordValue)) {
@@ -26,7 +25,6 @@ export const ChipFieldDisplay = () => {
record={recordValue}
size={ChipSize.Small}
to={labelIdentifierLink}
- isLabelHidden={isLabelIdentifierCompact ?? false}
forceDisableClick={disableChipClick}
triggerEvent={triggerEvent}
onClick={onRecordChipClick}
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/hooks/useChipFieldDisplay.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/hooks/useChipFieldDisplay.ts
index 4f1db7e2303..6ec66149ab2 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/hooks/useChipFieldDisplay.ts
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/hooks/useChipFieldDisplay.ts
@@ -22,7 +22,6 @@ export const useChipFieldDisplay = () => {
maxWidth,
triggerEvent,
onRecordChipClick,
- isLabelIdentifierCompact,
} = useContext(FieldContext);
const { indexIdentifierUrl, labelIdentifierFieldMetadataItem } =
@@ -65,6 +64,5 @@ export const useChipFieldDisplay = () => {
maxWidth,
triggerEvent,
onRecordChipClick,
- isLabelIdentifierCompact,
};
};
diff --git a/packages/twenty-front/src/modules/object-record/record-index/states/shouldCompactRecordIndexLabelIdentifierComponentState.ts b/packages/twenty-front/src/modules/object-record/record-index/states/shouldCompactRecordIndexLabelIdentifierComponentState.ts
deleted file mode 100644
index 3efec67fbee..00000000000
--- a/packages/twenty-front/src/modules/object-record/record-index/states/shouldCompactRecordIndexLabelIdentifierComponentState.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import { ContextStoreComponentInstanceContext } from '@/context-store/states/contexts/ContextStoreComponentInstanceContext';
-import { createAtomComponentState } from '@/ui/utilities/state/jotai/utils/createAtomComponentState';
-
-export const shouldCompactRecordIndexLabelIdentifierComponentState =
- createAtomComponentState<boolean>({
- key: 'shouldCompactRecordIndexLabelIdentifierComponentState',
- componentInstanceContext: ContextStoreComponentInstanceContext,
- defaultValue: false,
- });
diff --git a/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableColumnWidthEffect.tsx b/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableColumnWidthEffect.tsx
index 90fbbc4f502..44199a55022 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableColumnWidthEffect.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableColumnWidthEffect.tsx
@@ -2,15 +2,13 @@ import { RECORD_TABLE_COLUMN_ADD_COLUMN_BUTTON_WIDTH } from '@/object-record/rec
import { RECORD_TABLE_COLUMN_CHECKBOX_WIDTH } from '@/object-record/record-table/constants/RecordTableColumnCheckboxWidth';
import { RECORD_TABLE_COLUMN_DRAG_AND_DROP_WIDTH } from '@/object-record/record-table/constants/RecordTableColumnDragAndDropWidth';
import { RECORD_TABLE_COLUMN_LAST_EMPTY_COLUMN_WIDTH_VARIABLE_NAME } from '@/object-record/record-table/constants/RecordTableColumnLastEmptyColumnWidthVariableName';
-import { RECORD_TABLE_COLUMN_MIN_WIDTH } from '@/object-record/record-table/constants/RecordTableColumnMinWidth';
import { RECORD_TABLE_COLUMN_WITH_GROUP_LAST_EMPTY_COLUMN_WIDTH_VARIABLE_NAME } from '@/object-record/record-table/constants/RecordTableColumnWithGroupLastEmptyColumnWidthVariableName';
-import { RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE } from '@/object-record/record-table/constants/RecordTableLabelIdentifierColumnWidthOnMobile';
import { useRecordTableContextOrThrow } from '@/object-record/record-table/contexts/RecordTableContext';
import { useIsRecordTableCheckboxColumnHidden } from '@/object-record/record-table/hooks/useIsRecordTableCheckboxColumnHidden';
+import { useRecordTableFirstColumnWidthOverride } from '@/object-record/record-table/hooks/useRecordTableFirstColumnWidthOverride';
import { isRecordTableDragColumnHiddenComponentState } from '@/object-record/record-table/states/isRecordTableDragColumnHiddenComponentState';
import { recordTableWidthComponentState } from '@/object-record/record-table/states/recordTableWidthComponentState';
import { resizedFieldMetadataIdComponentState } from '@/object-record/record-table/states/resizedFieldMetadataIdComponentState';
-import { shouldCompactRecordTableFirstColumnComponentState } from '@/object-record/record-table/states/shouldCompactRecordTableFirstColumnComponentState';
import { computeLastRecordTableColumnWidth } from '@/object-record/record-table/utils/computeLastRecordTableColumnWidth';
import { computeVisibleRecordFieldsWidthOnTable } from '@/object-record/record-table/utils/computeVisibleRecordFieldsWidthOnTable';
import { getRecordTableColumnFieldWidthCSSVariableName } from '@/object-record/record-table/utils/getRecordTableColumnFieldWidthCSSVariableName';
@@ -29,9 +27,7 @@ export const RecordTableColumnWidthEffect = () => {
const { visibleRecordFields, recordTableId } = useRecordTableContextOrThrow();
- const shouldCompactRecordTableFirstColumn = useAtomComponentStateValue(
- shouldCompactRecordTableFirstColumnComponentState,
- );
+ const firstColumnWidthOverride = useRecordTableFirstColumnWidthOverride();
const recordTableWidth = useAtomComponentStateValue(
recordTableWidthComponentState,
@@ -51,7 +47,7 @@ export const RecordTableColumnWidthEffect = () => {
const { lastColumnWidth } = computeLastRecordTableColumnWidth({
recordFields: visibleRecordFields,
- shouldCompactFirstColumn: shouldCompactRecordTableFirstColumn,
+ firstColumnWidthOverride,
tableWidth: recordTableWidth,
isDragColumnHidden: isRecordTableDragColumnHidden,
isCheckboxColumnHidden: isRecordTableCheckboxColumnHidden,
@@ -59,7 +55,7 @@ export const RecordTableColumnWidthEffect = () => {
const { visibleRecordFieldsWidth } = computeVisibleRecordFieldsWidthOnTable(
{
- shouldCompactFirstColumn: shouldCompactRecordTableFirstColumn,
+ firstColumnWidthOverride,
visibleRecordFields,
},
);
@@ -100,34 +96,22 @@ export const RecordTableColumnWidthEffect = () => {
);
for (const [index, recordField] of visibleRecordFields.entries()) {
- updateRecordTableCSSVariable(
- recordTableId,
- getRecordTableColumnFieldWidthCSSVariableName(index),
- `${recordField.size}px`,
- );
- }
+ const columnWidth =
+ index === 0 && isDefined(firstColumnWidthOverride)
+ ? firstColumnWidthOverride
+ : recordField.size;
- if (shouldCompactRecordTableFirstColumn) {
updateRecordTableCSSVariable(
recordTableId,
- getRecordTableColumnFieldWidthCSSVariableName(0),
- `${RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE}px`,
- );
- } else {
- const firstColumnWidth =
- visibleRecordFields[0]?.size ?? RECORD_TABLE_COLUMN_MIN_WIDTH;
-
- updateRecordTableCSSVariable(
- recordTableId,
- getRecordTableColumnFieldWidthCSSVariableName(0),
- `${firstColumnWidth}px`,
+ getRecordTableColumnFieldWidthCSSVariableName(index),
+ `${columnWidth}px`,
);
}
}, [
resizedFieldMetadataId,
visibleRecordFields,
recordTableWidth,
- shouldCompactRecordTableFirstColumn,
+ firstColumnWidthOverride,
isRecordTableDragColumnHidden,
isRecordTableCheckboxColumnHidden,
recordTableId,
diff --git a/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableEmpty.tsx b/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableEmpty.tsx
index a2090ccbcb3..e075ba249f2 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableEmpty.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableEmpty.tsx
@@ -16,7 +16,7 @@ import { RecordTableHeader } from '@/object-record/record-table/record-table-hea
import { recordTableWidthComponentState } from '@/object-record/record-table/states/recordTableWidthComponentState';
import { resizedFieldMetadataIdComponentState } from '@/object-record/record-table/states/resizedFieldMetadataIdComponentState';
import { resizeFieldOffsetComponentState } from '@/object-record/record-table/states/resizeFieldOffsetComponentState';
-import { shouldCompactRecordTableFirstColumnComponentState } from '@/object-record/record-table/states/shouldCompactRecordTableFirstColumnComponentState';
+import { useRecordTableFirstColumnWidthOverride } from '@/object-record/record-table/hooks/useRecordTableFirstColumnWidthOverride';
import { computeVisibleRecordFieldsWidthOnTable } from '@/object-record/record-table/utils/computeVisibleRecordFieldsWidthOnTable';
import { RecordTableVirtualizedDataChangedEffect } from '@/object-record/record-table/virtualization/components/RecordTableVirtualizedDataChangedEffect';
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
@@ -66,9 +66,7 @@ export const RecordTableEmpty = ({ tableBodyRef }: RecordTableEmptyProps) => {
const isResizing = isDefined(resizedFieldMetadataId);
- const shouldCompactRecordTableFirstColumn = useAtomComponentStateValue(
- shouldCompactRecordTableFirstColumnComponentState,
- );
+ const firstColumnWidthOverride = useRecordTableFirstColumnWidthOverride();
const resizeOffsetToAddOnlyIfItMakesTableContainerGrow = isResizing
? resizeFieldOffset > 0
@@ -79,7 +77,7 @@ export const RecordTableEmpty = ({ tableBodyRef }: RecordTableEmptyProps) => {
const totalColumnsBorderWidth = visibleRecordFields.length;
const { visibleRecordFieldsWidth } = computeVisibleRecordFieldsWidthOnTable({
- shouldCompactFirstColumn: shouldCompactRecordTableFirstColumn,
+ firstColumnWidthOverride,
visibleRecordFields,
});
diff --git a/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableScrollAndZIndexEffect.tsx b/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableScrollAndZIndexEffect.tsx
index 3a342e74120..ad131676a22 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableScrollAndZIndexEffect.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableScrollAndZIndexEffect.tsx
@@ -1,37 +1,25 @@
-import { shouldCompactRecordIndexLabelIdentifierComponentState } from '@/object-record/record-index/states/shouldCompactRecordIndexLabelIdentifierComponentState';
import { RECORD_TABLE_HORIZONTAL_SCROLL_SHADOW_VISIBILITY_CSS_VARIABLE_NAME } from '@/object-record/record-table/constants/RecordTableHorizontalScrollShadowVisibilityCssVariableName';
import { RECORD_TABLE_VERTICAL_SCROLL_SHADOW_VISIBILITY_CSS_VARIABLE_NAME } from '@/object-record/record-table/constants/RecordTableVerticalScrollShadowVisibilityCssVariableName';
import { useRecordTableContextOrThrow } from '@/object-record/record-table/contexts/RecordTableContext';
import { isRecordTableScrolledHorizontallyComponentState } from '@/object-record/record-table/states/isRecordTableScrolledHorizontallyComponentState';
import { isRecordTableScrolledVerticallyComponentState } from '@/object-record/record-table/states/isRecordTableScrolledVerticallyComponentState';
-import { shouldCompactRecordTableFirstColumnComponentState } from '@/object-record/record-table/states/shouldCompactRecordTableFirstColumnComponentState';
import { updateRecordTableCSSVariable } from '@/object-record/record-table/utils/updateRecordTableCSSVariable';
import { useScrollWrapperHTMLElement } from '@/ui/utilities/scroll/hooks/useScrollWrapperHTMLElement';
import { useAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentState';
-import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';
import { useEffect } from 'react';
import { isDefined } from 'twenty-shared/utils';
-import { useIsMobile } from 'twenty-ui/utilities';
export const RecordTableScrollAndZIndexEffect = () => {
const { recordTableId } = useRecordTableContextOrThrow();
const { scrollWrapperHTMLElement } = useScrollWrapperHTMLElement();
- const isMobile = useIsMobile();
+
const [
isRecordTableScrolledHorizontally,
setIsRecordTableScrolledHorizontally,
] = useAtomComponentState(isRecordTableScrolledHorizontallyComponentState);
- const setShouldCompactRecordTableFirstColumn = useSetAtomComponentState(
- shouldCompactRecordTableFirstColumnComponentState,
- );
-
- const setShouldCompactRecordIndexLabelIdentifier = useSetAtomComponentState(
- shouldCompactRecordIndexLabelIdentifierComponentState,
- );
-
const [isRecordTableScrolledVertically, setIsRecordTableScrolledVertically] =
useAtomComponentState(isRecordTableScrolledVerticallyComponentState);
@@ -40,56 +28,38 @@ export const RecordTableScrollAndZIndexEffect = () => {
return;
}
- const handleScroll = (event: any) => {
- const target = event.currentTarget;
+ const handleScroll = (event: Event) => {
+ const target = event.currentTarget as HTMLElement;
- const newIsScrolledVertically = target?.scrollTop > 0;
+ const newIsScrolledVertically = target.scrollTop > 0;
if (newIsScrolledVertically !== isRecordTableScrolledVertically) {
setIsRecordTableScrolledVertically(newIsScrolledVertically);
- const newVisibilityOfShadows = newIsScrolledVertically
- ? 'visible'
- : 'hidden';
-
updateRecordTableCSSVariable(
recordTableId,
RECORD_TABLE_VERTICAL_SCROLL_SHADOW_VISIBILITY_CSS_VARIABLE_NAME,
- newVisibilityOfShadows,
+ newIsScrolledVertically ? 'visible' : 'hidden',
);
}
- const newIsScrolledHorizontally = target?.scrollLeft > 0;
+ const newIsScrolledHorizontally = target.scrollLeft > 0;
if (newIsScrolledHorizontally !== isRecordTableScrolledHorizontally) {
setIsRecordTableScrolledHorizontally(newIsScrolledHorizontally);
- const newVisibilityOfShadows = newIsScrolledHorizontally
- ? 'visible'
- : 'hidden';
-
updateRecordTableCSSVariable(
recordTableId,
RECORD_TABLE_HORIZONTAL_SCROLL_SHADOW_VISIBILITY_CSS_VARIABLE_NAME,
- newVisibilityOfShadows,
+ newIsScrolledHorizontally ? 'visible' : 'hidden',
);
-
- if (isMobile) {
- if (newIsScrolledHorizontally) {
- setShouldCompactRecordTableFirstColumn(true);
- setShouldCompactRecordIndexLabelIdentifier(true);
- } else {
- setShouldCompactRecordTableFirstColumn(false);
- setShouldCompactRecordIndexLabelIdentifier(false);
- }
- }
}
};
- scrollWrapperHTMLElement?.addEventListener('scroll', handleScroll);
+ scrollWrapperHTMLElement.addEventListener('scroll', handleScroll);
return () => {
- scrollWrapperHTMLElement?.removeEventListener('scroll', handleScroll);
+ scrollWrapperHTMLElement.removeEventListener('scroll', handleScroll);
};
}, [
recordTableId,
@@ -98,9 +68,6 @@ export const RecordTableScrollAndZIndexEffect = () => {
isRecordTableScrolledHorizontally,
setIsRecordTableScrolledVertically,
setIsRecordTableScrolledHorizontally,
- isMobile,
- setShouldCompactRecordTableFirstColumn,
- setShouldCompactRecordIndexLabelIdentifier,
]);
return <></>;
diff --git a/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableStyleWrapper.tsx b/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableStyleWrapper.tsx
index a7807796980..ecfe7f7a8af 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableStyleWrapper.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableStyleWrapper.tsx
@@ -1,6 +1,9 @@
import { type RecordField } from '@/object-record/record-field/types/RecordField';
import { HorizontalScrollBoxShadowCSS } from '@/object-record/record-table/components/HorizontalScrollBoxShadowCSS';
import { VerticalScrollBoxShadowCSS } from '@/object-record/record-table/components/VerticalScrollBoxShadowCSS';
+import { RECORD_TABLE_CELL_CONTENT_CLASS_NAME } from '@/object-record/record-table/constants/RecordTableCellContentClassName';
+import { RECORD_TABLE_CELL_DISPLAY_CLASS_NAME } from '@/object-record/record-table/constants/RecordTableCellDisplayClassName';
+import { RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_PINNED_WIDTH_ON_MOBILE } from '@/object-record/record-table/constants/RecordTableLabelIdentifierColumnPinnedWidthOnMobile';
import { RECORD_TABLE_COLUMN_ADD_COLUMN_BUTTON_WIDTH } from '@/object-record/record-table/constants/RecordTableColumnAddColumnButtonWidth';
import { RECORD_TABLE_COLUMN_ADD_COLUMN_BUTTON_WIDTH_CLASS_NAME } from '@/object-record/record-table/constants/RecordTableColumnAddColumnButtonWidthClassName';
import { RECORD_TABLE_COLUMN_CHECKBOX_WIDTH } from '@/object-record/record-table/constants/RecordTableColumnCheckboxWidth';
@@ -23,6 +26,8 @@ export const RECORD_TABLE_DRAG_DROP_WIDTH_CSS_VAR =
'--record-table-drag-drop-width';
export const RECORD_TABLE_CHECKBOX_WIDTH_CSS_VAR =
'--record-table-checkbox-width';
+export const RECORD_TABLE_FIRST_COLUMN_LEFT_CSS_VAR =
+ '--record-table-first-column-left';
const MAX_COLUMNS = 100;
@@ -77,6 +82,25 @@ const StyledTable = styled.div<{
width: 100%;
+ ${RECORD_TABLE_FIRST_COLUMN_LEFT_CSS_VAR}: calc(
+ var(${RECORD_TABLE_DRAG_DROP_WIDTH_CSS_VAR}) +
+ var(${RECORD_TABLE_CHECKBOX_WIDTH_CSS_VAR})
+ );
+
+ // On mobile the frozen column travels with the content instead of being
+ // resized, so the data columns keep pace with the finger exactly and nothing
+ // reflows mid-gesture. It pins once only the remnant is left.
+ @media (max-width: ${MOBILE_VIEWPORT}px) {
+ ${RECORD_TABLE_FIRST_COLUMN_LEFT_CSS_VAR}: calc(
+ var(${RECORD_TABLE_DRAG_DROP_WIDTH_CSS_VAR}) +
+ var(${RECORD_TABLE_CHECKBOX_WIDTH_CSS_VAR}) -
+ (
+ var(${getRecordTableColumnFieldWidthCSSVariableName(0)}) -
+ ${RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_PINNED_WIDTH_ON_MOBILE}px
+ )
+ );
+ }
+
// The mobile navigation bar floats over the page, so the table reserves its
// footprint to keep its last row reachable, grouped or not.
@media (max-width: ${MOBILE_VIEWPORT}px) {
@@ -104,10 +128,7 @@ const StyledTable = styled.div<{
div.header-cell.${getRecordTableColumnFieldWidthClassName(0)} {
background-color: ${themeCssVariables.background.primary};
- left: calc(
- var(${RECORD_TABLE_DRAG_DROP_WIDTH_CSS_VAR}) +
- var(${RECORD_TABLE_CHECKBOX_WIDTH_CSS_VAR})
- );
+ left: var(${RECORD_TABLE_FIRST_COLUMN_LEFT_CSS_VAR});
position: sticky;
right: 0;
z-index: ${TABLE_Z_INDEX.headerColumns.headerColumnsSticky};
@@ -128,20 +149,14 @@ const StyledTable = styled.div<{
}
div.table-cell-0-0 {
- left: calc(
- var(${RECORD_TABLE_DRAG_DROP_WIDTH_CSS_VAR}) +
- var(${RECORD_TABLE_CHECKBOX_WIDTH_CSS_VAR})
- );
+ left: var(${RECORD_TABLE_FIRST_COLUMN_LEFT_CSS_VAR});
position: sticky;
${HorizontalScrollBoxShadowCSS}
}
div.table-cell.${getRecordTableColumnFieldWidthClassName(0)} {
- left: calc(
- var(${RECORD_TABLE_DRAG_DROP_WIDTH_CSS_VAR}) +
- var(${RECORD_TABLE_CHECKBOX_WIDTH_CSS_VAR})
- );
+ left: var(${RECORD_TABLE_FIRST_COLUMN_LEFT_CSS_VAR});
position: sticky;
z-index: ${TABLE_Z_INDEX.cell.sticky};
@@ -189,6 +204,70 @@ const StyledTable = styled.div<{
${RECORD_TABLE_COLUMN_WITH_GROUP_LAST_EMPTY_COLUMN_WIDTH_VARIABLE_NAME}
);
}
+
+ @media (max-width: ${MOBILE_VIEWPORT}px) {
+ // clip, not hidden: hidden would make the cell its own scroll container and
+ // the anchor below would stick to it instead of the table. The margin keeps
+ // the scroll shadow, which paints outside the box.
+ div.header-cell.${getRecordTableColumnFieldWidthClassName(0)},
+ div.table-cell.${getRecordTableColumnFieldWidthClassName(0)},
+ div.footer-cell.${getRecordTableColumnFieldWidthClassName(0)},
+ div.table-cell-0-0 {
+ overflow: clip;
+ overflow-clip-margin: 4px;
+ }
+
+ // Re-pins the cell contents at the table's left edge while the cell slides
+ // under it, so the record name holds still and truncates from the right.
+ // The anchor has to stay zero-width or sticky's containing-block constraint
+ // drags it along with the cell once the cell is narrower than the name.
+ div.table-cell.${getRecordTableColumnFieldWidthClassName(0)}
+ > .${RECORD_TABLE_CELL_CONTENT_CLASS_NAME},
+ div.table-cell-0-0
+ > .${RECORD_TABLE_CELL_CONTENT_CLASS_NAME} {
+ left: calc(
+ var(${RECORD_TABLE_DRAG_DROP_WIDTH_CSS_VAR}) +
+ var(${RECORD_TABLE_CHECKBOX_WIDTH_CSS_VAR})
+ );
+ overflow: visible;
+ position: sticky;
+ width: 0;
+ }
+
+ // Absolute so it gives the chip its full layout width without adding any
+ // width back to the anchor.
+ div.table-cell.${getRecordTableColumnFieldWidthClassName(0)}
+ > .${RECORD_TABLE_CELL_CONTENT_CLASS_NAME}
+ > .${RECORD_TABLE_CELL_DISPLAY_CLASS_NAME},
+ div.table-cell-0-0
+ > .${RECORD_TABLE_CELL_CONTENT_CLASS_NAME}
+ > .${RECORD_TABLE_CELL_DISPLAY_CLASS_NAME} {
+ height: 100%;
+ left: 0;
+ position: absolute;
+ top: 0;
+ width: calc(
+ var(${getRecordTableColumnFieldWidthCSSVariableName(0)}) - var(
+ ${RECORD_TABLE_DRAG_DROP_WIDTH_CSS_VAR}
+ ) - var(${RECORD_TABLE_CHECKBOX_WIDTH_CSS_VAR})
+ );
+ }
+
+ // Shrink-wrapped so the label's and the aggregate's own boxes stay narrower
+ // than the pinned remnant; at full column width sticky's containing-block
+ // constraint would drag them off with the cell instead of holding them.
+ div.header-cell.${getRecordTableColumnFieldWidthClassName(0)}
+ .${RECORD_TABLE_CELL_CONTENT_CLASS_NAME},
+ div.footer-cell.${getRecordTableColumnFieldWidthClassName(0)}
+ .${RECORD_TABLE_CELL_CONTENT_CLASS_NAME} {
+ left: calc(
+ var(${RECORD_TABLE_DRAG_DROP_WIDTH_CSS_VAR}) +
+ var(${RECORD_TABLE_CHECKBOX_WIDTH_CSS_VAR})
+ );
+ position: sticky;
+ width: max-content;
+ }
+ }
`;
export const RecordTableStyleWrapper = StyledTable;
diff --git a/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableWithWrappers.tsx b/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableWithWrappers.tsx
index b16afa5acc2..fcebd7d1b57 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableWithWrappers.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableWithWrappers.tsx
@@ -16,6 +16,12 @@ import { styled } from '@linaria/react';
const StyledRecordTablePrintBoundary = styled.div`
display: contents;
+ // Without this, swiping the table back to its first column hands the gesture
+ // to the browser and navigates back on iOS.
+ .scroll-wrapper-x-enabled {
+ overscroll-behavior-x: contain;
+ }
+
@media print {
display: block;
max-height: calc(100vh / var(--t-zoom, 1));
diff --git a/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableCellContentClassName.ts b/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableCellContentClassName.ts
new file mode 100644
index 00000000000..32eca24c608
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableCellContentClassName.ts
@@ -0,0 +1 @@
+export const RECORD_TABLE_CELL_CONTENT_CLASS_NAME = 'record-table-cell-content';
diff --git a/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableCellDisplayClassName.ts b/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableCellDisplayClassName.ts
new file mode 100644
index 00000000000..98e16b3b9e3
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableCellDisplayClassName.ts
@@ -0,0 +1 @@
+export const RECORD_TABLE_CELL_DISPLAY_CLASS_NAME = 'record-table-cell-display';
diff --git a/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableLabelIdentifierColumnMaxWidthOnMobile.ts b/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableLabelIdentifierColumnMaxWidthOnMobile.ts
new file mode 100644
index 00000000000..c28ba2717c6
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableLabelIdentifierColumnMaxWidthOnMobile.ts
@@ -0,0 +1 @@
+export const RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_MAX_WIDTH_ON_MOBILE = 260;
diff --git a/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableLabelIdentifierColumnMinWidthOnMobile.ts b/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableLabelIdentifierColumnMinWidthOnMobile.ts
new file mode 100644
index 00000000000..ec059499be5
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableLabelIdentifierColumnMinWidthOnMobile.ts
@@ -0,0 +1 @@
+export const RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_MIN_WIDTH_ON_MOBILE = 180;
diff --git a/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableLabelIdentifierColumnPinnedWidthOnMobile.ts b/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableLabelIdentifierColumnPinnedWidthOnMobile.ts
new file mode 100644
index 00000000000..448307e43d8
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableLabelIdentifierColumnPinnedWidthOnMobile.ts
@@ -0,0 +1 @@
+export const RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_PINNED_WIDTH_ON_MOBILE = 72;
diff --git a/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableLabelIdentifierColumnWidthOnMobile.ts b/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableLabelIdentifierColumnWidthOnMobile.ts
deleted file mode 100644
index 425812b801b..00000000000
--- a/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableLabelIdentifierColumnWidthOnMobile.ts
+++ /dev/null
@@ -1 +0,0 @@
-export const RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE = 38;
diff --git a/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableLabelIdentifierColumnWidthRatioOnMobile.ts b/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableLabelIdentifierColumnWidthRatioOnMobile.ts
new file mode 100644
index 00000000000..9d84e5c0deb
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-table/constants/RecordTableLabelIdentifierColumnWidthRatioOnMobile.ts
@@ -0,0 +1 @@
+export const RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_RATIO_ON_MOBILE = 0.6;
diff --git a/packages/twenty-front/src/modules/object-record/record-table/hooks/useRecordTableFirstColumnWidthOverride.ts b/packages/twenty-front/src/modules/object-record/record-table/hooks/useRecordTableFirstColumnWidthOverride.ts
new file mode 100644
index 00000000000..d72f9ddfc5c
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-table/hooks/useRecordTableFirstColumnWidthOverride.ts
@@ -0,0 +1,21 @@
+import { recordTableWidthComponentState } from '@/object-record/record-table/states/recordTableWidthComponentState';
+import { computeRecordTableLabelIdentifierColumnWidthOnMobile } from '@/object-record/record-table/utils/computeRecordTableLabelIdentifierColumnWidthOnMobile';
+import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
+import { useIsMobile } from 'twenty-ui/utilities';
+
+export const useRecordTableFirstColumnWidthOverride = (
+ instanceId?: string,
+): number | undefined => {
+ const isMobile = useIsMobile();
+
+ const recordTableWidth = useAtomComponentStateValue(
+ recordTableWidthComponentState,
+ instanceId,
+ );
+
+ if (!isMobile) {
+ return undefined;
+ }
+
+ return computeRecordTableLabelIdentifierColumnWidthOnMobile(recordTableWidth);
+};
diff --git a/packages/twenty-front/src/modules/object-record/record-table/hooks/useRecordTableLastColumnWidthToFill.ts b/packages/twenty-front/src/modules/object-record/record-table/hooks/useRecordTableLastColumnWidthToFill.ts
index 6a796968673..ef9fe817a4b 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/hooks/useRecordTableLastColumnWidthToFill.ts
+++ b/packages/twenty-front/src/modules/object-record/record-table/hooks/useRecordTableLastColumnWidthToFill.ts
@@ -1,8 +1,8 @@
import { useRecordTableContextOrThrow } from '@/object-record/record-table/contexts/RecordTableContext';
import { useIsRecordTableCheckboxColumnHidden } from '@/object-record/record-table/hooks/useIsRecordTableCheckboxColumnHidden';
+import { useRecordTableFirstColumnWidthOverride } from '@/object-record/record-table/hooks/useRecordTableFirstColumnWidthOverride';
import { isRecordTableDragColumnHiddenComponentState } from '@/object-record/record-table/states/isRecordTableDragColumnHiddenComponentState';
import { recordTableWidthComponentState } from '@/object-record/record-table/states/recordTableWidthComponentState';
-import { shouldCompactRecordTableFirstColumnComponentState } from '@/object-record/record-table/states/shouldCompactRecordTableFirstColumnComponentState';
import { computeLastRecordTableColumnWidth } from '@/object-record/record-table/utils/computeLastRecordTableColumnWidth';
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
@@ -13,9 +13,7 @@ export const useRecordTableLastColumnWidthToFill = () => {
recordTableWidthComponentState,
);
- const shouldCompactRecordTableFirstColumn = useAtomComponentStateValue(
- shouldCompactRecordTableFirstColumnComponentState,
- );
+ const firstColumnWidthOverride = useRecordTableFirstColumnWidthOverride();
const isRecordTableDragColumnHidden = useAtomComponentStateValue(
isRecordTableDragColumnHiddenComponentState,
@@ -27,7 +25,7 @@ export const useRecordTableLastColumnWidthToFill = () => {
const { lastColumnWidth } = computeLastRecordTableColumnWidth({
recordFields: visibleRecordFields,
tableWidth: recordTableWidth,
- shouldCompactFirstColumn: shouldCompactRecordTableFirstColumn,
+ firstColumnWidthOverride,
isDragColumnHidden: isRecordTableDragColumnHidden,
isCheckboxColumnHidden: isRecordTableCheckboxColumnHidden,
});
diff --git a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellBaseContainer.tsx b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellBaseContainer.tsx
index bedce7657df..7b42fc6ee9f 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellBaseContainer.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellBaseContainer.tsx
@@ -4,6 +4,7 @@ import { useContext, type ReactNode } from 'react';
import { FieldContext } from '@/object-record/record-field/ui/contexts/FieldContext';
import { isFieldIdentifierDisplay } from '@/object-record/record-field/ui/meta-types/display/utils/isFieldIdentifierDisplay';
import { RECORD_CHIP_CLICK_OUTSIDE_ID } from '@/object-record/record-table/constants/RecordChipClickOutsideId';
+import { RECORD_TABLE_CELL_CONTENT_CLASS_NAME } from '@/object-record/record-table/constants/RecordTableCellContentClassName';
import { RecordTableCellContext } from '@/object-record/record-table/contexts/RecordTableCellContext';
import { useRecordTableContextOrThrow } from '@/object-record/record-table/contexts/RecordTableContext';
import { useOpenRecordTableCellFromCell } from '@/object-record/record-table/record-table-cell/hooks/useOpenRecordTableCellFromCell';
@@ -74,6 +75,7 @@ export const RecordTableCellBaseContainer = ({
return (
<StyledBaseContainer
+ className={RECORD_TABLE_CELL_CONTENT_CLASS_NAME}
onClick={handleContainerClick}
backgroundColorSecondary={theme.background.secondary}
fontColorSecondary={theme.font.color.secondary}
diff --git a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellDisplayContainer.tsx b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellDisplayContainer.tsx
index 3fe442e02d2..cc4889f8bdb 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellDisplayContainer.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellDisplayContainer.tsx
@@ -1,3 +1,4 @@
+import { RECORD_TABLE_CELL_DISPLAY_CLASS_NAME } from '@/object-record/record-table/constants/RecordTableCellDisplayClassName';
import { t } from '@lingui/core/macro';
import { styled } from '@linaria/react';
import { type Ref } from 'react';
@@ -44,6 +45,7 @@ export const RecordTableCellDisplayContainer = ({
placeholderForEmptyCell,
}: React.PropsWithChildren<EditableCellDisplayContainerProps>) => (
<StyledOuterContainer
+ className={RECORD_TABLE_CELL_DISPLAY_CLASS_NAME}
data-testid={
focus ? 'editable-cell-focus-mode' : 'editable-cell-display-mode'
}
diff --git a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellFieldContextLabelIdentifier.tsx b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellFieldContextLabelIdentifier.tsx
index 597d4018c5d..e72ace579f9 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellFieldContextLabelIdentifier.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellFieldContextLabelIdentifier.tsx
@@ -3,7 +3,6 @@ import { getObjectPermissionsForObject } from '@/object-metadata/utils/getObject
import { isRecordFieldReadOnly } from '@/object-record/read-only/utils/isRecordFieldReadOnly';
import { FieldContext } from '@/object-record/record-field/ui/contexts/FieldContext';
import { useRecordIndexContextOrThrow } from '@/object-record/record-index/contexts/RecordIndexContext';
-import { shouldCompactRecordIndexLabelIdentifierComponentState } from '@/object-record/record-index/states/shouldCompactRecordIndexLabelIdentifierComponentState';
import { RecordTableCellContext } from '@/object-record/record-table/contexts/RecordTableCellContext';
import { useRecordTableContextOrThrow } from '@/object-record/record-table/contexts/RecordTableContext';
import { useRecordTableRowContextOrThrow } from '@/object-record/record-table/contexts/RecordTableRowContext';
@@ -39,10 +38,6 @@ export const RecordTableCellFieldContextLabelIdentifier = ({
objectMetadataItem.id,
);
- const shouldCompactRecordIndexLabelIdentifier = useAtomComponentStateValue(
- shouldCompactRecordIndexLabelIdentifierComponentState,
- );
-
const hasObjectReadPermissions = objectPermissions.canReadObjectRecords;
const updateRecord = useContext(RecordTableUpdateContext);
@@ -63,7 +58,6 @@ export const RecordTableCellFieldContextLabelIdentifier = ({
fieldDefinition,
useUpdateRecord: updateRecord ? () => [updateRecord, {}] : undefined,
isLabelIdentifier: true,
- isLabelIdentifierCompact: shouldCompactRecordIndexLabelIdentifier,
displayedMaxRows: 1,
isRecordFieldReadOnly:
isRecordTableCellsNonEditable ||
diff --git a/packages/twenty-front/src/modules/object-record/record-table/record-table-footer/components/RecordTableAggregateFooterCell.tsx b/packages/twenty-front/src/modules/object-record/record-table/record-table-footer/components/RecordTableAggregateFooterCell.tsx
index 2e26bbb19e3..7aa6b872cab 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/record-table-footer/components/RecordTableAggregateFooterCell.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-table/record-table-footer/components/RecordTableAggregateFooterCell.tsx
@@ -2,11 +2,9 @@ import { styled } from '@linaria/react';
import { useContext } from 'react';
import { MOBILE_VIEWPORT, themeCssVariables } from 'twenty-ui/theme-constants';
-import {
- RECORD_TABLE_CHECKBOX_WIDTH_CSS_VAR,
- RECORD_TABLE_DRAG_DROP_WIDTH_CSS_VAR,
-} from '@/object-record/record-table/components/RecordTableStyleWrapper';
-import { RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE } from '@/object-record/record-table/constants/RecordTableLabelIdentifierColumnWidthOnMobile';
+import { RECORD_TABLE_FIRST_COLUMN_LEFT_CSS_VAR } from '@/object-record/record-table/components/RecordTableStyleWrapper';
+import { RECORD_TABLE_CELL_CONTENT_CLASS_NAME } from '@/object-record/record-table/constants/RecordTableCellContentClassName';
+import { getRecordTableColumnFieldWidthCSSVariableName } from '@/object-record/record-table/utils/getRecordTableColumnFieldWidthCSSVariableName';
import { RECORD_TABLE_ROW_HEIGHT } from '@/object-record/record-table/constants/RecordTableRowHeight';
import { TABLE_Z_INDEX } from '@/object-record/record-table/constants/TableZIndex';
import { useRecordTableContextOrThrow } from '@/object-record/record-table/contexts/RecordTableContext';
@@ -21,6 +19,8 @@ import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/use
import { cx } from '@linaria/core';
import { findByProperty, isDefined } from 'twenty-shared/utils';
+const FIRST_COLUMN_WIDTH_CSS_VAR = `var(${getRecordTableColumnFieldWidthCSSVariableName(0)})`;
+
const StyledColumnFooterCell = styled.div<{
columnWidth: number;
isFirstCell: boolean;
@@ -37,9 +37,7 @@ const StyledColumnFooterCell = styled.div<{
height: ${RECORD_TABLE_ROW_HEIGHT}px;
left: ${({ isFirstCell }) =>
- isFirstCell
- ? `calc(var(${RECORD_TABLE_DRAG_DROP_WIDTH_CSS_VAR}) + var(${RECORD_TABLE_CHECKBOX_WIDTH_CSS_VAR}))`
- : 'auto'};
+ isFirstCell ? `var(${RECORD_TABLE_FIRST_COLUMN_LEFT_CSS_VAR})` : 'auto'};
@media (hover: hover) {
&:hover {
@@ -68,17 +66,11 @@ const StyledColumnFooterCell = styled.div<{
@media (max-width: ${MOBILE_VIEWPORT}px) {
max-width: ${({ isFirstCell }) =>
- isFirstCell
- ? `${RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE}px`
- : 'none'};
+ isFirstCell ? FIRST_COLUMN_WIDTH_CSS_VAR : 'none'};
min-width: ${({ isFirstCell }) =>
- isFirstCell
- ? `${RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE}px`
- : '0'};
+ isFirstCell ? FIRST_COLUMN_WIDTH_CSS_VAR : '0'};
width: ${({ isFirstCell }) =>
- isFirstCell
- ? `${RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE}px`
- : 'auto'};
+ isFirstCell ? FIRST_COLUMN_WIDTH_CSS_VAR : 'auto'};
}
`;
@@ -132,7 +124,9 @@ export const RecordTableAggregateFooterCell = ({
getRecordTableColumnFieldWidthClassName(columnIndex),
)}
>
- <StyledColumnFootContainer>
+ <StyledColumnFootContainer
+ className={RECORD_TABLE_CELL_CONTENT_CLASS_NAME}
+ >
{isFooterReadOnly ? (
hasAggregateOperationForViewField ? (
<RecordTableColumnAggregateFooterValue
diff --git a/packages/twenty-front/src/modules/object-record/record-table/record-table-header/components/RecordTableColumnHead.tsx b/packages/twenty-front/src/modules/object-record/record-table/record-table-header/components/RecordTableColumnHead.tsx
index 4d8713fbe78..864fb9d4406 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/record-table-header/components/RecordTableColumnHead.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-table/record-table-header/components/RecordTableColumnHead.tsx
@@ -2,19 +2,13 @@ import { styled } from '@linaria/react';
import { useContext } from 'react';
import { fieldMetadataItemByIdSelector } from '@/object-metadata/states/fieldMetadataItemByIdSelector';
-import { isFieldMetadataItemLabelIdentifierSelector } from '@/object-metadata/states/isFieldMetadataItemLabelIdentifierSelector';
import { type RecordField } from '@/object-record/record-field/types/RecordField';
-import { shouldCompactRecordTableFirstColumnComponentState } from '@/object-record/record-table/states/shouldCompactRecordTableFirstColumnComponentState';
-import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
+import { RECORD_TABLE_CELL_CONTENT_CLASS_NAME } from '@/object-record/record-table/constants/RecordTableCellContentClassName';
import { useAtomFamilySelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilySelectorValue';
import { useIcons } from 'twenty-ui/icon';
-import {
- MOBILE_VIEWPORT,
- ThemeContext,
- themeCssVariables,
-} from 'twenty-ui/theme-constants';
+import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
-const StyledTitle = styled.div<{ hideTitle?: boolean }>`
+const StyledTitle = styled.div`
align-items: center;
display: flex;
flex-direction: row;
@@ -23,10 +17,6 @@ const StyledTitle = styled.div<{ hideTitle?: boolean }>`
height: ${themeCssVariables.spacing[8]};
padding-left: ${themeCssVariables.spacing[2]};
padding-right: ${themeCssVariables.spacing[2]};
-
- @media (max-width: ${MOBILE_VIEWPORT}px) {
- display: ${({ hideTitle }) => (hideTitle ? 'none' : 'flex')};
- }
`;
const StyledIcon = styled.div`
@@ -64,20 +54,8 @@ export const RecordTableColumnHead = ({
correspondingFieldMetadataItem.foundFieldMetadataItem?.icon,
);
- const isLabelIdentifier = useAtomFamilySelectorValue(
- isFieldMetadataItemLabelIdentifierSelector,
- { fieldMetadataItemId: recordField.fieldMetadataItemId },
- );
-
- const shouldCompactRecordTableFirstColumn = useAtomComponentStateValue(
- shouldCompactRecordTableFirstColumnComponentState,
- );
-
- const shouldHideTitle =
- shouldCompactRecordTableFirstColumn && isLabelIdentifier;
-
return (
- <StyledTitle hideTitle={shouldHideTitle}>
+ <StyledTitle className={RECORD_TABLE_CELL_CONTENT_CLASS_NAME}>
<StyledIcon>
<Icon size={theme.icon.size.md} />
</StyledIcon>
diff --git a/packages/twenty-front/src/modules/object-record/record-table/record-table-header/hooks/useResizeTableHeader.ts b/packages/twenty-front/src/modules/object-record/record-table/record-table-header/hooks/useResizeTableHeader.ts
index 50e46bef152..b4b52788e3c 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/record-table-header/hooks/useResizeTableHeader.ts
+++ b/packages/twenty-front/src/modules/object-record/record-table/record-table-header/hooks/useResizeTableHeader.ts
@@ -11,7 +11,7 @@ import { useIsRecordTableCheckboxColumnHidden } from '@/object-record/record-tab
import { isRecordTableDragColumnHiddenComponentState } from '@/object-record/record-table/states/isRecordTableDragColumnHiddenComponentState';
import { resizedFieldMetadataIdComponentState } from '@/object-record/record-table/states/resizedFieldMetadataIdComponentState';
import { resizeFieldOffsetComponentState } from '@/object-record/record-table/states/resizeFieldOffsetComponentState';
-import { shouldCompactRecordTableFirstColumnComponentState } from '@/object-record/record-table/states/shouldCompactRecordTableFirstColumnComponentState';
+import { useRecordTableFirstColumnWidthOverride } from '@/object-record/record-table/hooks/useRecordTableFirstColumnWidthOverride';
import { computeLastRecordTableColumnWidth } from '@/object-record/record-table/utils/computeLastRecordTableColumnWidth';
import { getRecordTableColumnFieldWidthCSSVariableName } from '@/object-record/record-table/utils/getRecordTableColumnFieldWidthCSSVariableName';
import { updateRecordTableCSSVariable } from '@/object-record/record-table/utils/updateRecordTableCSSVariable';
@@ -67,10 +67,8 @@ export const useResizeTableHeader = () => {
recordTableId,
);
- const shouldCompactRecordTableFirstColumn = useAtomComponentStateValue(
- shouldCompactRecordTableFirstColumnComponentState,
- recordTableId,
- );
+ const firstColumnWidthOverride =
+ useRecordTableFirstColumnWidthOverride(recordTableId);
const isRecordTableDragColumnHidden = useAtomComponentStateValue(
isRecordTableDragColumnHiddenComponentState,
@@ -121,7 +119,7 @@ export const useResizeTableHeader = () => {
const { lastColumnWidth } = computeLastRecordTableColumnWidth({
recordFields: visibleRecordFields,
- shouldCompactFirstColumn: shouldCompactRecordTableFirstColumn,
+ firstColumnWidthOverride,
tableWidth: recordTableWidth,
isDragColumnHidden: isRecordTableDragColumnHidden,
isCheckboxColumnHidden: isRecordTableCheckboxColumnHidden,
@@ -154,7 +152,7 @@ export const useResizeTableHeader = () => {
recordField,
recordTableId,
visibleRecordFields,
- shouldCompactRecordTableFirstColumn,
+ firstColumnWidthOverride,
recordTableWidth,
isRecordTableDragColumnHidden,
isRecordTableCheckboxColumnHidden,
diff --git a/packages/twenty-front/src/modules/object-record/record-table/record-table-row/components/RecordTableActionRow.tsx b/packages/twenty-front/src/modules/object-record/record-table/record-table-row/components/RecordTableActionRow.tsx
index 78330873705..184d556dfbf 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/record-table-row/components/RecordTableActionRow.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-table/record-table-row/components/RecordTableActionRow.tsx
@@ -4,7 +4,7 @@ import { useRecordIndexContextOrThrow } from '@/object-record/record-index/conte
import { RECORD_TABLE_COLUMN_CHECKBOX_WIDTH } from '@/object-record/record-table/constants/RecordTableColumnCheckboxWidth';
import { RECORD_TABLE_COLUMN_DRAG_AND_DROP_WIDTH } from '@/object-record/record-table/constants/RecordTableColumnDragAndDropWidth';
import { RECORD_TABLE_COLUMN_MIN_WIDTH } from '@/object-record/record-table/constants/RecordTableColumnMinWidth';
-import { RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE } from '@/object-record/record-table/constants/RecordTableLabelIdentifierColumnWidthOnMobile';
+import { useRecordTableFirstColumnWidthOverride } from '@/object-record/record-table/hooks/useRecordTableFirstColumnWidthOverride';
import { RECORD_TABLE_ROW_HEIGHT } from '@/object-record/record-table/constants/RecordTableRowHeight';
import { useRecordTableContextOrThrow } from '@/object-record/record-table/contexts/RecordTableContext';
import { RecordTableDragAndDropPlaceholderCell } from '@/object-record/record-table/record-table-cell/components/RecordTableDragAndDropPlaceholderCell';
@@ -18,7 +18,6 @@ import {
} from 'twenty-shared/utils';
import { type IconComponent } from 'twenty-ui/icon';
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
-import { useIsMobile } from 'twenty-ui/utilities';
const StyledFieldPlaceholderCell = styled.div<{ widthOfFields: number }>`
height: ${RECORD_TABLE_ROW_HEIGHT}px;
@@ -113,15 +112,16 @@ export const RecordTableActionRow = ({
),
);
- const isMobile = useIsMobile();
+ const firstColumnWidthOverride = useRecordTableFirstColumnWidthOverride();
const labelIdentifierRecordField = visibleRecordFields.find(
findByProperty('fieldMetadataItemId', labelIdentifierFieldMetadataItem?.id),
);
- const firstColumnWidth = isMobile
- ? RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE
- : (labelIdentifierRecordField?.size ?? RECORD_TABLE_COLUMN_MIN_WIDTH);
+ const firstColumnWidth =
+ firstColumnWidthOverride ??
+ labelIdentifierRecordField?.size ??
+ RECORD_TABLE_COLUMN_MIN_WIDTH;
const sumOfWidthOfVisibleRecordFieldsAfterLabelIdentifierField =
visibleRecordFieldsWithoutLabelIdentifier.reduce(sumByProperty('size'), 0);
diff --git a/packages/twenty-front/src/modules/object-record/record-table/record-table-row/components/RecordTableRowDragOverlayContent.tsx b/packages/twenty-front/src/modules/object-record/record-table/record-table-row/components/RecordTableRowDragOverlayContent.tsx
index f000b660d3d..530eb2c4e20 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/record-table-row/components/RecordTableRowDragOverlayContent.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-table/record-table-row/components/RecordTableRowDragOverlayContent.tsx
@@ -2,7 +2,7 @@ import { type Draggable } from '@dnd-kit/dom';
import { styled } from '@linaria/react';
import { useMemo } from 'react';
import { isDefined } from 'twenty-shared/utils';
-import { MOBILE_VIEWPORT, themeCssVariables } from 'twenty-ui/theme-constants';
+import { themeCssVariables } from 'twenty-ui/theme-constants';
import { HorizontalScrollBoxShadowCSS } from '@/object-record/record-table/components/HorizontalScrollBoxShadowCSS';
import {
@@ -17,7 +17,6 @@ import { RECORD_TABLE_COLUMN_DRAG_AND_DROP_WIDTH_CLASS_NAME } from '@/object-rec
import { RECORD_TABLE_COLUMN_LAST_EMPTY_COLUMN_WIDTH_CLASS_NAME } from '@/object-record/record-table/constants/RecordTableColumnLastEmptyColumnWidthClassName';
import { RECORD_TABLE_COLUMN_LAST_EMPTY_COLUMN_WIDTH_VARIABLE_NAME } from '@/object-record/record-table/constants/RecordTableColumnLastEmptyColumnWidthVariableName';
import { RECORD_TABLE_COLUMN_WITH_GROUP_LAST_EMPTY_COLUMN_WIDTH_VARIABLE_NAME } from '@/object-record/record-table/constants/RecordTableColumnWithGroupLastEmptyColumnWidthVariableName';
-import { RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE } from '@/object-record/record-table/constants/RecordTableLabelIdentifierColumnWidthOnMobile';
import { TABLE_Z_INDEX } from '@/object-record/record-table/constants/TableZIndex';
import { useRecordTableContextOrThrow } from '@/object-record/record-table/contexts/RecordTableContext';
import { RecordTableRowDraggableContextProvider } from '@/object-record/record-table/contexts/RecordTableRowDraggableContext';
@@ -43,24 +42,11 @@ const cloneColumnFieldWidthRules = Array.from(
(_, i) => {
const className = getRecordTableColumnFieldWidthClassName(i);
const cssVar = `var(--record-table-column-field-${i})`;
- const baseRule = `div.${className} {
+ return `div.${className} {
width: ${cssVar};
min-width: ${cssVar};
max-width: ${cssVar};
}`;
-
- if (i === 0) {
- return `${baseRule}
- div.${className} {
- @media (max-width: ${MOBILE_VIEWPORT}px) {
- width: ${RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE}px;
- max-width: ${RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE}px;
- min-width: ${RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE}px;
- }
- }`;
- }
-
- return baseRule;
},
).join('\n');
diff --git a/packages/twenty-front/src/modules/object-record/record-table/record-table-section/components/RecordTableRecordGroupSection.tsx b/packages/twenty-front/src/modules/object-record/record-table/record-table-section/components/RecordTableRecordGroupSection.tsx
index 0bff1ed6b4c..e47e338f596 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/record-table-section/components/RecordTableRecordGroupSection.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-table/record-table-section/components/RecordTableRecordGroupSection.tsx
@@ -18,7 +18,7 @@ import { RecordTableGroupSectionLastDynamicFillingCell } from '@/object-record/r
import { RECORD_TABLE_COLUMN_CHECKBOX_WIDTH } from '@/object-record/record-table/constants/RecordTableColumnCheckboxWidth';
import { RECORD_TABLE_COLUMN_MIN_WIDTH } from '@/object-record/record-table/constants/RecordTableColumnMinWidth';
-import { RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE } from '@/object-record/record-table/constants/RecordTableLabelIdentifierColumnWidthOnMobile';
+import { useRecordTableFirstColumnWidthOverride } from '@/object-record/record-table/hooks/useRecordTableFirstColumnWidthOverride';
import { recordIndexAggregateDisplayLabelComponentState } from '@/object-record/record-index/states/recordIndexAggregateDisplayLabelComponentState';
import { recordIndexAggregateDisplayValueForGroupValueComponentFamilyState } from '@/object-record/record-index/states/recordIndexAggregateDisplayValueForGroupValueComponentFamilyState';
@@ -35,7 +35,6 @@ import {
isDefined,
sumByProperty,
} from 'twenty-shared/utils';
-import { useIsMobile } from 'twenty-ui/utilities';
const StyledTrContainer = styled.div`
display: flex;
@@ -124,16 +123,17 @@ export const RecordTableRecordGroupSection = () => {
visibleRecordFieldsComponentSelector,
);
- const isMobile = useIsMobile();
-
- const widthOfLabelIdentifierRecordField = isMobile
- ? RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE
- : (visibleRecordFields.find(
- findByProperty(
- 'fieldMetadataItemId',
- labelIdentifierFieldMetadataItem?.id ?? '',
- ),
- )?.size ?? RECORD_TABLE_COLUMN_MIN_WIDTH);
+ const firstColumnWidthOverride = useRecordTableFirstColumnWidthOverride();
+
+ const widthOfLabelIdentifierRecordField =
+ firstColumnWidthOverride ??
+ visibleRecordFields.find(
+ findByProperty(
+ 'fieldMetadataItemId',
+ labelIdentifierFieldMetadataItem?.id ?? '',
+ ),
+ )?.size ??
+ RECORD_TABLE_COLUMN_MIN_WIDTH;
const [
isRecordGroupTableSectionToggled,
diff --git a/packages/twenty-front/src/modules/object-record/record-table/states/shouldCompactRecordTableFirstColumnComponentState.ts b/packages/twenty-front/src/modules/object-record/record-table/states/shouldCompactRecordTableFirstColumnComponentState.ts
deleted file mode 100644
index 63f556e5dfc..00000000000
--- a/packages/twenty-front/src/modules/object-record/record-table/states/shouldCompactRecordTableFirstColumnComponentState.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import { RecordTableComponentInstanceContext } from '@/object-record/record-table/states/context/RecordTableComponentInstanceContext';
-import { createAtomComponentState } from '@/ui/utilities/state/jotai/utils/createAtomComponentState';
-
-export const shouldCompactRecordTableFirstColumnComponentState =
- createAtomComponentState<boolean>({
- key: 'shouldCompactRecordTableFirstColumnComponentState',
- defaultValue: false,
- componentInstanceContext: RecordTableComponentInstanceContext,
- });
diff --git a/packages/twenty-front/src/modules/object-record/record-table/utils/__tests__/computeLastRecordTableColumnWidth.test.ts b/packages/twenty-front/src/modules/object-record/record-table/utils/__tests__/computeLastRecordTableColumnWidth.test.ts
index e868b24ea00..a9b81b36bcb 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/utils/__tests__/computeLastRecordTableColumnWidth.test.ts
+++ b/packages/twenty-front/src/modules/object-record/record-table/utils/__tests__/computeLastRecordTableColumnWidth.test.ts
@@ -7,7 +7,6 @@ describe('computeLastRecordTableColumnWidth', () => {
const { lastColumnWidth } = computeLastRecordTableColumnWidth({
recordFields,
tableWidth: 200,
- shouldCompactFirstColumn: false,
isDragColumnHidden: false,
isCheckboxColumnHidden: false,
});
@@ -21,7 +20,6 @@ describe('computeLastRecordTableColumnWidth', () => {
const { lastColumnWidth } = computeLastRecordTableColumnWidth({
recordFields,
tableWidth: 300,
- shouldCompactFirstColumn: false,
isDragColumnHidden: false,
isCheckboxColumnHidden: false,
});
@@ -35,7 +33,6 @@ describe('computeLastRecordTableColumnWidth', () => {
const { lastColumnWidth } = computeLastRecordTableColumnWidth({
recordFields,
tableWidth: 300,
- shouldCompactFirstColumn: false,
isDragColumnHidden: true,
isCheckboxColumnHidden: true,
});
@@ -43,28 +40,27 @@ describe('computeLastRecordTableColumnWidth', () => {
expect(lastColumnWidth).toBe(65);
});
- it('uses the compact first column width when shouldCompactFirstColumn is true', () => {
+ it('substitutes the first column width when an override is given', () => {
const recordFields = [{ size: 100 }, { size: 150 }];
- const { lastColumnWidth: lastColumnWidthWithCompact } =
+ const { lastColumnWidth: lastColumnWidthWithOverride } =
computeLastRecordTableColumnWidth({
recordFields,
tableWidth: 300,
- shouldCompactFirstColumn: true,
+ firstColumnWidthOverride: 72,
isDragColumnHidden: false,
isCheckboxColumnHidden: false,
});
- const { lastColumnWidth: lastColumnWidthWithoutCompact } =
+ const { lastColumnWidth: lastColumnWidthWithoutOverride } =
computeLastRecordTableColumnWidth({
recordFields,
tableWidth: 300,
- shouldCompactFirstColumn: false,
isDragColumnHidden: false,
isCheckboxColumnHidden: false,
});
- expect(lastColumnWidthWithCompact).toBe(37);
- expect(lastColumnWidthWithoutCompact).toBe(0);
+ expect(lastColumnWidthWithOverride).toBe(3);
+ expect(lastColumnWidthWithoutOverride).toBe(0);
});
});
diff --git a/packages/twenty-front/src/modules/object-record/record-table/utils/__tests__/computeRecordTableLabelIdentifierColumnWidthOnMobile.test.ts b/packages/twenty-front/src/modules/object-record/record-table/utils/__tests__/computeRecordTableLabelIdentifierColumnWidthOnMobile.test.ts
new file mode 100644
index 00000000000..f664a667357
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-table/utils/__tests__/computeRecordTableLabelIdentifierColumnWidthOnMobile.test.ts
@@ -0,0 +1,20 @@
+import { computeRecordTableLabelIdentifierColumnWidthOnMobile } from '@/object-record/record-table/utils/computeRecordTableLabelIdentifierColumnWidthOnMobile';
+
+describe('computeRecordTableLabelIdentifierColumnWidthOnMobile', () => {
+ it('takes a share of the table width', () => {
+ expect(computeRecordTableLabelIdentifierColumnWidthOnMobile(390)).toBe(234);
+ });
+
+ it('never goes below the width the column would have had on desktop', () => {
+ expect(computeRecordTableLabelIdentifierColumnWidthOnMobile(200)).toBe(180);
+ expect(computeRecordTableLabelIdentifierColumnWidthOnMobile(360)).toBe(216);
+ });
+
+ it('clamps to the maximum on the widest phones', () => {
+ expect(computeRecordTableLabelIdentifierColumnWidthOnMobile(800)).toBe(260);
+ });
+
+ it('falls back to the minimum before the table has been measured', () => {
+ expect(computeRecordTableLabelIdentifierColumnWidthOnMobile(0)).toBe(180);
+ });
+});
diff --git a/packages/twenty-front/src/modules/object-record/record-table/utils/__tests__/computeVisibleRecordFieldsWidthOnTable.test.ts b/packages/twenty-front/src/modules/object-record/record-table/utils/__tests__/computeVisibleRecordFieldsWidthOnTable.test.ts
new file mode 100644
index 00000000000..4e53b6525f8
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-table/utils/__tests__/computeVisibleRecordFieldsWidthOnTable.test.ts
@@ -0,0 +1,30 @@
+import { computeVisibleRecordFieldsWidthOnTable } from '@/object-record/record-table/utils/computeVisibleRecordFieldsWidthOnTable';
+
+describe('computeVisibleRecordFieldsWidthOnTable', () => {
+ it('sums every field size when no override is given', () => {
+ const { visibleRecordFieldsWidth } = computeVisibleRecordFieldsWidthOnTable(
+ { visibleRecordFields: [{ size: 100 }, { size: 150 }] },
+ );
+
+ expect(visibleRecordFieldsWidth).toBe(250);
+ });
+
+ it('replaces the first field size with the override', () => {
+ const { visibleRecordFieldsWidth } = computeVisibleRecordFieldsWidthOnTable(
+ {
+ visibleRecordFields: [{ size: 100 }, { size: 150 }],
+ firstColumnWidthOverride: 72,
+ },
+ );
+
+ expect(visibleRecordFieldsWidth).toBe(222);
+ });
+
+ it('ignores the override when there is no visible field to apply it to', () => {
+ const { visibleRecordFieldsWidth } = computeVisibleRecordFieldsWidthOnTable(
+ { visibleRecordFields: [], firstColumnWidthOverride: 72 },
+ );
+
+ expect(visibleRecordFieldsWidth).toBe(0);
+ });
+});
diff --git a/packages/twenty-front/src/modules/object-record/record-table/utils/computeLastRecordTableColumnWidth.ts b/packages/twenty-front/src/modules/object-record/record-table/utils/computeLastRecordTableColumnWidth.ts
index 1d7d28e13ef..068f9d7144d 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/utils/computeLastRecordTableColumnWidth.ts
+++ b/packages/twenty-front/src/modules/object-record/record-table/utils/computeLastRecordTableColumnWidth.ts
@@ -7,18 +7,18 @@ import { computeVisibleRecordFieldsWidthOnTable } from '@/object-record/record-t
export const computeLastRecordTableColumnWidth = ({
recordFields,
tableWidth,
- shouldCompactFirstColumn,
+ firstColumnWidthOverride,
isDragColumnHidden,
isCheckboxColumnHidden,
}: {
recordFields: Pick<RecordField, 'size'>[];
tableWidth: number;
- shouldCompactFirstColumn: boolean;
+ firstColumnWidthOverride?: number;
isDragColumnHidden?: boolean;
isCheckboxColumnHidden?: boolean;
}) => {
const { visibleRecordFieldsWidth } = computeVisibleRecordFieldsWidthOnTable({
- shouldCompactFirstColumn,
+ firstColumnWidthOverride,
visibleRecordFields: recordFields,
});
diff --git a/packages/twenty-front/src/modules/object-record/record-table/utils/computeRecordTableLabelIdentifierColumnWidthOnMobile.ts b/packages/twenty-front/src/modules/object-record/record-table/utils/computeRecordTableLabelIdentifierColumnWidthOnMobile.ts
new file mode 100644
index 00000000000..2e224b5b90e
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-table/utils/computeRecordTableLabelIdentifierColumnWidthOnMobile.ts
@@ -0,0 +1,20 @@
+import { RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_MAX_WIDTH_ON_MOBILE } from '@/object-record/record-table/constants/RecordTableLabelIdentifierColumnMaxWidthOnMobile';
+import { RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_MIN_WIDTH_ON_MOBILE } from '@/object-record/record-table/constants/RecordTableLabelIdentifierColumnMinWidthOnMobile';
+import { RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_RATIO_ON_MOBILE } from '@/object-record/record-table/constants/RecordTableLabelIdentifierColumnWidthRatioOnMobile';
+
+export const computeRecordTableLabelIdentifierColumnWidthOnMobile = (
+ tableWidth: number,
+) => {
+ const widthFromRatio =
+ tableWidth * RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_RATIO_ON_MOBILE;
+
+ return Math.round(
+ Math.min(
+ RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_MAX_WIDTH_ON_MOBILE,
+ Math.max(
+ RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_MIN_WIDTH_ON_MOBILE,
+ widthFromRatio,
+ ),
+ ),
+ );
+};
diff --git a/packages/twenty-front/src/modules/object-record/record-table/utils/computeVisibleRecordFieldsWidthOnTable.ts b/packages/twenty-front/src/modules/object-record/record-table/utils/computeVisibleRecordFieldsWidthOnTable.ts
index 401fec846e9..7631e12e7fe 100644
--- a/packages/twenty-front/src/modules/object-record/record-table/utils/computeVisibleRecordFieldsWidthOnTable.ts
+++ b/packages/twenty-front/src/modules/object-record/record-table/utils/computeVisibleRecordFieldsWidthOnTable.ts
@@ -1,33 +1,25 @@
import { type RecordField } from '@/object-record/record-field/types/RecordField';
-import { RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE } from '@/object-record/record-table/constants/RecordTableLabelIdentifierColumnWidthOnMobile';
-import { sumByProperty } from 'twenty-shared/utils';
+import { isDefined, sumByProperty } from 'twenty-shared/utils';
export const computeVisibleRecordFieldsWidthOnTable = ({
- shouldCompactFirstColumn,
+ firstColumnWidthOverride,
visibleRecordFields,
}: {
- shouldCompactFirstColumn: boolean;
+ firstColumnWidthOverride?: number;
visibleRecordFields: Pick<RecordField, 'size'>[];
}) => {
- const visibleRecordFieldsWithoutFirst = visibleRecordFields.slice(1);
+ const sumOfAllFields = visibleRecordFields.reduce(sumByProperty('size'), 0);
- const sumWithoutFirstField = visibleRecordFieldsWithoutFirst.reduce(
- sumByProperty('size'),
- 0,
- );
+ const firstRecordField = visibleRecordFields[0];
- const sumWithAllFields = visibleRecordFields.reduce(sumByProperty('size'), 0);
-
- const sumForCompactedFirstColumn =
- RECORD_TABLE_LABEL_IDENTIFIER_COLUMN_WIDTH_ON_MOBILE + sumWithoutFirstField;
-
- const sumForNoCompactColumn = sumWithAllFields;
-
- const visibleRecordFieldsWidth = shouldCompactFirstColumn
- ? sumForCompactedFirstColumn
- : sumForNoCompactColumn;
+ if (!isDefined(firstColumnWidthOverride) || !isDefined(firstRecordField)) {
+ return {
+ visibleRecordFieldsWidth: sumOfAllFields,
+ };
+ }
return {
- visibleRecordFieldsWidth,
+ visibleRecordFieldsWidth:
+ sumOfAllFields - firstRecordField.size + firstColumnWidthOverride,
};
};