Skip to content

Commit

Permalink
Remove label identifier add button
Browse files Browse the repository at this point in the history
  • Loading branch information
thomtrp committed Oct 9, 2024
1 parent 402228d commit 98133c4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ export const RecordTable = ({
<RecordTableEmptyState />
) : (
<StyledTable className="entity-table-cell">
<RecordTableHeader />
<RecordTableHeader
objectMetadataNameSingular={objectNameSingular}
/>
<RecordTableBody />
</StyledTable>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ const StyledTableHead = styled.thead<{
}
`;

export const RecordTableHeader = () => {
export const RecordTableHeader = ({
objectMetadataNameSingular,
}: {
objectMetadataNameSingular: string;
}) => {
const { visibleTableColumnsSelector } = useRecordTableStates();

const visibleTableColumns = useRecoilValue(visibleTableColumnsSelector());
Expand All @@ -84,7 +88,11 @@ export const RecordTableHeader = () => {
<RecordTableHeaderDragDropColumn />
<RecordTableHeaderCheckboxColumn />
{visibleTableColumns.map((column) => (
<RecordTableHeaderCell key={column.fieldMetadataId} column={column} />
<RecordTableHeaderCell
key={column.fieldMetadataId}
column={column}
objectMetadataNameSingular={objectMetadataNameSingular}
/>
))}
<RecordTableHeaderLastColumn />
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { useCallback, useMemo, useState } from 'react';
import { useRecoilCallback, useRecoilState, useRecoilValue } from 'recoil';
import { IconPlus } from 'twenty-ui';

import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { isReadOnlyObject } from '@/object-metadata/utils/isReadOnlyObject';
import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';
import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates';
import { useCreateNewTableRecord } from '@/object-record/record-table/hooks/useCreateNewTableRecords';
Expand Down Expand Up @@ -91,11 +93,17 @@ const StyledHeaderIcon = styled.div`

export const RecordTableHeaderCell = ({
column,
objectMetadataNameSingular,
}: {
column: ColumnDefinition<FieldMetadata>;
objectMetadataNameSingular: string;
}) => {
const { resizeFieldOffsetState, tableColumnsState } = useRecordTableStates();

const { objectMetadataItem } = useObjectMetadataItem({
objectNameSingular: objectMetadataNameSingular,
});

const [resizeFieldOffset, setResizeFieldOffset] = useRecoilState(
resizeFieldOffsetState,
);
Expand Down Expand Up @@ -190,6 +198,8 @@ export const RecordTableHeaderCell = ({
createNewTableRecord();
};

const isReadOnly = isReadOnlyObject(objectMetadataItem);

return (
<StyledColumnHeaderCell
key={column.fieldMetadataId}
Expand All @@ -205,16 +215,18 @@ export const RecordTableHeaderCell = ({
>
<StyledColumnHeadContainer>
<RecordTableColumnHeadWithDropdown column={column} />
{(useIsMobile() || iconVisibility) && !!column.isLabelIdentifier && (
<StyledHeaderIcon>
<LightIconButton
Icon={IconPlus}
size="small"
accent="tertiary"
onClick={handlePlusButtonClick}
/>
</StyledHeaderIcon>
)}
{(useIsMobile() || iconVisibility) &&
!!column.isLabelIdentifier &&
!isReadOnly && (
<StyledHeaderIcon>
<LightIconButton
Icon={IconPlus}
size="small"
accent="tertiary"
onClick={handlePlusButtonClick}
/>
</StyledHeaderIcon>
)}
</StyledColumnHeadContainer>
{!disableColumnResize && (
<StyledResizeHandler
Expand Down

0 comments on commit 98133c4

Please sign in to comment.