Skip to content

Commit

Permalink
fix: content getting hide on drag and drop in stage view cards (#7621)
Browse files Browse the repository at this point in the history
## ISSUE

-  Closes #7388 

## Demo



https://github.com/user-attachments/assets/193813aa-def9-406b-9fe7-397627bb1242

- [ ] Table Row Drag WIP

---------

Co-authored-by: Lucas Bordeau <[email protected]>
  • Loading branch information
Nabhag8848 and lucasbordeau authored Nov 5, 2024
1 parent 84b0b78 commit 3793f6c
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ 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 {
AnimatedEaseInOut,
AvatarChipVariant,
Checkbox,
CheckboxVariant,
ChipSize,
IconEye,
IconEyeOff,
LightIconButton,
Expand Down Expand Up @@ -147,10 +146,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 @@ -240,7 +235,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 @@ -256,126 +251,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}
size={ChipSize.Large}
/>
)}

{!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
@@ -1,5 +1,5 @@
import { createContext } from 'react';
import { DraggableProvidedDragHandleProps } from '@hello-pangea/dnd';
import { createContext } from 'react';

export type RecordTableRowContextProps = {
pathToShowPage: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import { Checkbox } from 'twenty-ui';
const StyledContainer = styled.div`
align-items: center;
cursor: pointer;
display: flex;
height: 32px;
justify-content: center;
min-width: 24px;
`;

export const RecordTableCellCheckbox = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const StyledTd = styled.td<{
left?: number;
hasRightBorder?: boolean;
hasBottomBorder?: boolean;
width?: number;
}>`
border-bottom: 1px solid
${({ borderColor, hasBottomBorder }) =>
Expand All @@ -32,13 +33,12 @@ const StyledTd = styled.td<{
background: ${({ backgroundColor }) => backgroundColor};
z-index: ${({ zIndex }) => (isDefined(zIndex) ? zIndex : 'auto')};
${({ isDragging }) =>
isDragging
? `
background-color: transparent;
border-color: transparent;
`
`
: ''}
${({ freezeFirstColumns }) =>
Expand All @@ -60,6 +60,7 @@ export const RecordTableTd = ({
left,
hasRightBorder = true,
hasBottomBorder = true,
width,
...dragHandleProps
}: {
className?: string;
Expand All @@ -72,6 +73,7 @@ export const RecordTableTd = ({
hasRightBorder?: boolean;
hasBottomBorder?: boolean;
left?: number;
width?: number;
} & (Partial<DraggableProvidedDragHandleProps> | null)) => {
const { theme } = useContext(ThemeContext);

Expand All @@ -94,6 +96,7 @@ export const RecordTableTd = ({
left={left}
hasRightBorder={hasRightBorder}
hasBottomBorder={hasBottomBorder}
width={width}
// eslint-disable-next-line react/jsx-props-no-spreading
{...dragHandleProps}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export const RecordTableHeaderCell = ({
resizedFieldKey,
resizeFieldOffsetState,
tableColumnsByKey,
setResizedFieldKey,
tableColumns,
handleColumnsChange,
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useContext } from 'react';

import { RecordTableRowContext } from '@/object-record/record-table/contexts/RecordTableRowContext';
import { RecordTableTd } from '@/object-record/record-table/record-table-cell/components/RecordTableTd';
import { visibleTableColumnsComponentSelector } from '@/object-record/record-table/states/selectors/visibleTableColumnsComponentSelector';
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
import { useContext } from 'react';

export const RecordTableCellsEmpty = () => {
const { isSelected } = useContext(RecordTableRowContext);
Expand Down
Loading

0 comments on commit 3793f6c

Please sign in to comment.