Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: content getting hide on drag and drop in stage view cards #7621

Merged
merged 16 commits into from
Nov 5, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { RecordBoardScrollWrapperContext } from '@/ui/utilities/scroll/contexts/
import { extractComponentState } from '@/ui/utilities/state/component-state/utils/extractComponentState';
import styled from '@emotion/styled';
import { ReactNode, useContext, useState } from 'react';
import { useInView } from 'react-intersection-observer';
import { InView, useInView } from 'react-intersection-observer';
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
import { AvatarChipVariant, IconEye, IconEyeOff } from 'twenty-ui';
import { useDebouncedCallback } from 'use-debounce';
Expand Down Expand Up @@ -141,10 +141,6 @@ const StyledCompactIconContainer = styled.div`
margin-left: ${({ theme }) => theme.spacing(1)};
`;

const StyledRecordInlineCellPlaceholder = styled.div`
height: 24px;
`;

export const RecordBoardCard = ({
isCreating = false,
onCreateSuccess,
Expand Down Expand Up @@ -234,7 +230,7 @@ export const RecordBoardCard = ({

const scrollWrapperRef = useContext(RecordBoardScrollWrapperContext);

const { ref: cardRef, inView } = useInView({
const { ref: cardRef } = useInView({
root: scrollWrapperRef?.ref.current,
rootMargin: '1000px',
});
Expand All @@ -250,125 +246,123 @@ export const RecordBoardCard = ({
return (
<StyledBoardCardWrapper onContextMenu={handleActionMenuDropdown}>
{!isCreating && <RecordValueSetterEffect recordId={recordId} />}
<StyledBoardCard
ref={cardRef}
selected={isCurrentCardSelected}
onMouseLeave={onMouseLeaveBoard}
onClick={() => {
if (!isCreating) {
setIsCurrentCardSelected(!isCurrentCardSelected);
}
}}
>
<StyledBoardCardHeader showCompactView={isCompactModeActive}>
{isCreating && position !== undefined ? (
<RecordInlineCellEditMode>
<StyledTextInput
autoFocus
value={newLabelValue}
onInputEnter={() =>
handleInputEnter(
labelIdentifierField?.label ?? '',
newLabelValue,
position,
onCreateSuccess,
)
}
onBlur={() =>
handleBlur(
labelIdentifierField?.label ?? '',
newLabelValue,
position,
onCreateSuccess,
)
}
onChange={(text: string) => setNewLabelValue(text)}
placeholder={labelIdentifierField?.label}
/>
</RecordInlineCellEditMode>
) : (
<RecordIdentifierChip
objectNameSingular={objectMetadataItem.nameSingular}
record={record as ObjectRecord}
variant={AvatarChipVariant.Transparent}
/>
)}

{!isCreating && (
<>
{isCompactModeActive && (
<StyledCompactIconContainer className="compact-icon-container">
<LightIconButton
Icon={isCardExpanded ? IconEyeOff : IconEye}
accent="tertiary"
onClick={(e) => {
e.stopPropagation();
setIsCardExpanded((prev) => !prev);
}}
/>
</StyledCompactIconContainer>
)}

<StyledCheckboxContainer className="checkbox-container">
<Checkbox
hoverable
checked={isCurrentCardSelected}
onChange={() =>
setIsCurrentCardSelected(!isCurrentCardSelected)
<InView>
<StyledBoardCard
ref={cardRef}
selected={isCurrentCardSelected}
onMouseLeave={onMouseLeaveBoard}
onClick={() => {
if (!isCreating) {
setIsCurrentCardSelected(!isCurrentCardSelected);
}
}}
>
<StyledBoardCardHeader showCompactView={isCompactModeActive}>
{isCreating && position !== undefined ? (
<RecordInlineCellEditMode>
<StyledTextInput
autoFocus
value={newLabelValue}
onInputEnter={() =>
handleInputEnter(
labelIdentifierField?.label ?? '',
newLabelValue,
position,
onCreateSuccess,
)
}
onBlur={() =>
handleBlur(
labelIdentifierField?.label ?? '',
newLabelValue,
position,
onCreateSuccess,
)
}
variant={CheckboxVariant.Secondary}
onChange={(text: string) => setNewLabelValue(text)}
placeholder={labelIdentifierField?.label}
/>
</StyledCheckboxContainer>
</>
)}
</StyledBoardCardHeader>

<AnimatedEaseInOut
isOpen={isCardExpanded || !isCompactModeActive}
initial={false}
>
<StyledBoardCardBody>
{visibleFieldDefinitionsFiltered.map((fieldDefinition) => (
<PreventSelectOnClickContainer
key={fieldDefinition.fieldMetadataId}
>
<FieldContext.Provider
value={{
recordId: isCreating ? '' : recordId,
maxWidth: 156,
recoilScopeId:
(isCreating ? 'new' : recordId) +
fieldDefinition.fieldMetadataId,
isLabelIdentifier: false,
fieldDefinition: {
disableTooltip: false,
fieldMetadataId: fieldDefinition.fieldMetadataId,
label: fieldDefinition.label,
iconName: fieldDefinition.iconName,
type: fieldDefinition.type,
metadata: fieldDefinition.metadata,
defaultValue: fieldDefinition.defaultValue,
editButtonIcon: getFieldButtonIcon({
metadata: fieldDefinition.metadata,
type: fieldDefinition.type,
}),
settings: fieldDefinition.settings,
},
useUpdateRecord: useUpdateOneRecordHook,
hotkeyScope: InlineCellHotkeyScope.InlineCell,
}}
</RecordInlineCellEditMode>
) : (
<RecordIdentifierChip
objectNameSingular={objectMetadataItem.nameSingular}
record={record as ObjectRecord}
variant={AvatarChipVariant.Transparent}
/>
)}

{!isCreating && (
<>
{isCompactModeActive && (
<StyledCompactIconContainer className="compact-icon-container">
<LightIconButton
Icon={isCardExpanded ? IconEyeOff : IconEye}
accent="tertiary"
onClick={(e) => {
e.stopPropagation();
setIsCardExpanded((prev) => !prev);
}}
/>
</StyledCompactIconContainer>
)}

<StyledCheckboxContainer className="checkbox-container">
<Checkbox
hoverable
checked={isCurrentCardSelected}
onChange={() =>
setIsCurrentCardSelected(!isCurrentCardSelected)
}
variant={CheckboxVariant.Secondary}
/>
</StyledCheckboxContainer>
</>
)}
</StyledBoardCardHeader>

<AnimatedEaseInOut
isOpen={isCardExpanded || !isCompactModeActive}
initial={false}
>
<StyledBoardCardBody>
{visibleFieldDefinitionsFiltered.map((fieldDefinition) => (
<PreventSelectOnClickContainer
key={fieldDefinition.fieldMetadataId}
>
{inView ? (
<FieldContext.Provider
value={{
recordId: isCreating ? '' : recordId,
maxWidth: 156,
recoilScopeId:
(isCreating ? 'new' : recordId) +
fieldDefinition.fieldMetadataId,
isLabelIdentifier: false,
fieldDefinition: {
disableTooltip: false,
fieldMetadataId: fieldDefinition.fieldMetadataId,
label: fieldDefinition.label,
iconName: fieldDefinition.iconName,
type: fieldDefinition.type,
metadata: fieldDefinition.metadata,
defaultValue: fieldDefinition.defaultValue,
editButtonIcon: getFieldButtonIcon({
metadata: fieldDefinition.metadata,
type: fieldDefinition.type,
}),
settings: fieldDefinition.settings,
},
useUpdateRecord: useUpdateOneRecordHook,
hotkeyScope: InlineCellHotkeyScope.InlineCell,
}}
>
<RecordInlineCell />
) : (
<StyledRecordInlineCellPlaceholder />
)}
</FieldContext.Provider>
</PreventSelectOnClickContainer>
))}
</StyledBoardCardBody>
</AnimatedEaseInOut>
</StyledBoardCard>
</FieldContext.Provider>
</PreventSelectOnClickContainer>
))}
</StyledBoardCardBody>
</AnimatedEaseInOut>
</StyledBoardCard>
</InView>
</StyledBoardCardWrapper>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const StyledContainer = styled.div`
`;

export const RecordTableCellCheckbox = () => {
const { isSelected } = useContext(RecordTableRowContext);
const { isSelected, isDragging } = useContext(RecordTableRowContext);

const { recordId } = useContext(RecordTableRowContext);
const { isRowSelectedFamilyState } = useRecordTableStates();
Expand All @@ -30,6 +30,10 @@ export const RecordTableCellCheckbox = () => {
setCurrentRowSelected(!currentRowSelected);
}, [currentRowSelected, setCurrentRowSelected]);

if (isDragging) {
return <></>;
}

return (
<RecordTableTd isSelected={isSelected} hasRightBorder={false}>
<StyledContainer onClick={handleClick}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { RecordTableCellWrapper } from '@/object-record/record-table/record-tabl
import { RecordTableTd } from '@/object-record/record-table/record-table-cell/components/RecordTableTd';

export const RecordTableCellsVisible = () => {
const { isDragging, isSelected } = useContext(RecordTableRowContext);
const { isSelected } = useContext(RecordTableRowContext);
const { visibleTableColumnsSelector } = useRecordTableStates();

const visibleTableColumns = useRecoilValue(visibleTableColumnsSelector());
Expand All @@ -22,18 +22,17 @@ export const RecordTableCellsVisible = () => {
<RecordTableCell />
</RecordTableTd>
</RecordTableCellWrapper>
{!isDragging &&
tableColumnsAfterFirst.map((column, columnIndex) => (
<RecordTableCellWrapper
key={column.fieldMetadataId}
column={column}
columnIndex={columnIndex + 1}
>
<RecordTableTd isSelected={isSelected}>
<RecordTableCell />
</RecordTableTd>
</RecordTableCellWrapper>
))}
{tableColumnsAfterFirst.map((column, columnIndex) => (
<RecordTableCellWrapper
key={column.fieldMetadataId}
column={column}
columnIndex={columnIndex + 1}
>
<RecordTableTd isSelected={isSelected}>
<RecordTableCell />
</RecordTableTd>
</RecordTableCellWrapper>
))}
</>
);
};
Loading