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

Fixed dropdown bugs on 0.34 #9000

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ type StyledContainerProps = {

const StyledContainerActionMenuDropdown = styled.div<StyledContainerProps>`
align-items: flex-start;
background: ${({ theme }) => theme.background.secondary};
border: 1px solid ${({ theme }) => theme.border.color.light};
border-radius: ${({ theme }) => theme.border.radius.md};
box-shadow: ${({ theme }) => theme.boxShadow.strong};
display: flex;
flex-direction: column;

Expand All @@ -33,7 +29,8 @@ const StyledContainerActionMenuDropdown = styled.div<StyledContainerProps>`
top: ${(props) => `${props.position.y}px`};

transform: translateX(-50%);
width: auto;
width: 0;
height: 0;
`;

export const RecordIndexActionMenuDropdown = () => {
Expand Down Expand Up @@ -84,6 +81,7 @@ export const RecordIndexActionMenuDropdown = () => {
))}
</DropdownMenuItemsContainer>
}
avoidPortal
/>
</StyledContainerActionMenuDropdown>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useFieldFocus } from '@/object-record/record-field/hooks/useFieldFocus'
import { CellHotkeyScopeContext } from '@/object-record/record-table/contexts/CellHotkeyScopeContext';
import { RecordTableCellContext } from '@/object-record/record-table/contexts/RecordTableCellContext';
import { RecordTableContext } from '@/object-record/record-table/contexts/RecordTableContext';
import { RecordTableRowContext } from '@/object-record/record-table/contexts/RecordTableRowContext';
import {
DEFAULT_CELL_SCOPE,
useOpenRecordTableCellFromCell,
Expand Down Expand Up @@ -44,7 +43,6 @@ export const RecordTableCellBaseContainer = ({
const { setIsFocused } = useFieldFocus();
const { openTableCell } = useOpenRecordTableCellFromCell();
const { theme } = useContext(ThemeContext);
const { recordId } = useContext(RecordTableRowContext);

const { hasSoftFocus, cellPosition } = useContext(RecordTableCellContext);

Expand All @@ -71,12 +69,6 @@ export const RecordTableCellBaseContainer = ({
}
};

const { onActionMenuDropdownOpened } = useContext(RecordTableContext);

const handleActionMenuDropdown = (event: React.MouseEvent) => {
onActionMenuDropdownOpened(event, recordId);
};

const { hotkeyScope } = useContext(FieldContext);

const editHotkeyScope = { scope: hotkeyScope ?? DEFAULT_CELL_SCOPE };
Expand All @@ -87,7 +79,6 @@ export const RecordTableCellBaseContainer = ({
onMouseLeave={handleContainerMouseLeave}
onMouseMove={handleContainerMouseMove}
onClick={handleContainerClick}
onContextMenu={handleActionMenuDropdown}
backgroundColorTransparentSecondary={
theme.background.transparent.secondary
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ export type EditableCellDisplayContainerProps = {
onClick?: () => void;
scrollRef?: Ref<HTMLDivElement>;
isHovered?: boolean;
onContextMenu?: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
};

export const RecordTableCellDisplayContainer = ({
children,
softFocus,
onClick,
scrollRef,
onContextMenu,
}: React.PropsWithChildren<EditableCellDisplayContainerProps>) => (
<StyledOuterContainer
data-testid={
Expand All @@ -41,6 +43,7 @@ export const RecordTableCellDisplayContainer = ({
onClick={onClick}
ref={scrollRef}
hasSoftFocus={softFocus}
onContextMenu={onContextMenu}
>
<StyledInnerContainer>{children}</StyledInnerContainer>
</StyledOuterContainer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { useIsFieldEmpty } from '@/object-record/record-field/hooks/useIsFieldEmpty';

import { FieldContext } from '@/object-record/record-field/contexts/FieldContext';
import { RecordTableContext } from '@/object-record/record-table/contexts/RecordTableContext';
import { useContext } from 'react';
import { RecordTableCellDisplayContainer } from './RecordTableCellDisplayContainer';

export const RecordTableCellDisplayMode = ({
children,
softFocus,
}: React.PropsWithChildren<{ softFocus?: boolean }>) => {
const isEmpty = useIsFieldEmpty();
const { onActionMenuDropdownOpened } = useContext(RecordTableContext);
const { recordId } = useContext(FieldContext);

if (isEmpty) {
return <></>;
}
const handleActionMenuDropdown = (event: React.MouseEvent) => {
onActionMenuDropdownOpened(event, recordId);
};

Comment on lines +13 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: event.preventDefault() should be called to prevent the default browser context menu from appearing

return (
<RecordTableCellDisplayContainer softFocus={softFocus}>
<RecordTableCellDisplayContainer
softFocus={softFocus}
onContextMenu={handleActionMenuDropdown}
>
{children}
</RecordTableCellDisplayContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import { isDefined } from '~/utils/isDefined';

import { TableHotkeyScope } from '../../types/TableHotkeyScope';

import { FieldContext } from '@/object-record/record-field/contexts/FieldContext';
import { useIsFieldValueReadOnly } from '@/object-record/record-field/hooks/useIsFieldValueReadOnly';
import { RecordTableContext } from '@/object-record/record-table/contexts/RecordTableContext';
import { RecordTableCellDisplayContainer } from './RecordTableCellDisplayContainer';

type RecordTableCellSoftFocusModeProps = {
Expand All @@ -32,6 +34,7 @@ export const RecordTableCellSoftFocusMode = ({
nonEditModeContent,
}: RecordTableCellSoftFocusModeProps) => {
const { columnIndex } = useContext(RecordTableCellContext);
const { recordId } = useContext(FieldContext);

const isFieldReadOnly = useIsFieldValueReadOnly();

Expand Down Expand Up @@ -132,6 +135,12 @@ export const RecordTableCellSoftFocusMode = ({
*/
};

const { onActionMenuDropdownOpened } = useContext(RecordTableContext);

const handleActionMenuDropdown = (event: React.MouseEvent) => {
onActionMenuDropdownOpened(event, recordId);
};

const isFirstColumn = columnIndex === 0;
const customButtonIcon = useGetButtonIcon();
const buttonIcon = isFirstColumn
Expand All @@ -152,6 +161,7 @@ export const RecordTableCellSoftFocusMode = ({
onClick={handleClick}
scrollRef={scrollRef}
softFocus
onContextMenu={handleActionMenuDropdown}
>
{dontShowContent ? (
<></>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getActionBarIdFromActionMenuId } from '@/action-menu/utils/getActionBar
import { getActionMenuDropdownIdFromActionMenuId } from '@/action-menu/utils/getActionMenuDropdownIdFromActionMenuId';
import { isRowSelectedComponentFamilyState } from '@/object-record/record-table/record-table-row/states/isRowSelectedComponentFamilyState';
import { isBottomBarOpenedComponentState } from '@/ui/layout/bottom-bar/states/isBottomBarOpenedComponentState';
import { useSetActiveDropdownFocusIdAndMemorizePrevious } from '@/ui/layout/dropdown/hooks/useSetFocusedDropdownIdAndMemorizePrevious';
import { isDropdownOpenComponentState } from '@/ui/layout/dropdown/states/isDropdownOpenComponentState';
import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotValue';
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
Expand Down Expand Up @@ -40,6 +41,9 @@ export const useTriggerActionMenuDropdown = ({
instanceId: getActionBarIdFromActionMenuId(actionMenuInstanceId),
});

const { setActiveDropdownFocusIdAndMemorizePrevious } =
useSetActiveDropdownFocusIdAndMemorizePrevious();

const triggerActionMenuDropdown = useRecoilCallback(
({ set, snapshot }) =>
(event: React.MouseEvent, recordId: string) => {
Expand All @@ -61,12 +65,19 @@ export const useTriggerActionMenuDropdown = ({

set(isActionBarOpenState, false);
set(isActionMenuDropdownOpenState, true);

const actionMenuDropdownId =
getActionMenuDropdownIdFromActionMenuId(actionMenuInstanceId);

setActiveDropdownFocusIdAndMemorizePrevious(actionMenuDropdownId);
},
[
isActionBarOpenState,
isActionMenuDropdownOpenState,
isRowSelectedFamilyState,
recordIndexActionMenuDropdownPositionState,
setActiveDropdownFocusIdAndMemorizePrevious,
actionMenuInstanceId,
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ type DropdownProps = {
dropdownStrategy?: 'fixed' | 'absolute';
disableBlur?: boolean;
onClickOutside?: () => void;
usePortal?: boolean;
onClose?: () => void;
onOpen?: () => void;
avoidPortal?: boolean;
};

export const Dropdown = ({
Expand All @@ -59,6 +59,7 @@ export const Dropdown = ({
onClickOutside,
onClose,
onOpen,
avoidPortal,
}: DropdownProps) => {
const { isDropdownOpen, toggleDropdown } = useDropdown(dropdownId);

Expand Down Expand Up @@ -132,6 +133,7 @@ export const Dropdown = ({
hotkey={hotkey}
onClickOutside={onClickOutside}
onHotkeyTriggered={toggleDropdown}
avoidPortal={avoidPortal}
/>
)}
<DropdownOnToggleEffect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type DropdownContentProps = {
dropdownMenuWidth?: `${string}px` | `${number}%` | 'auto' | number;
dropdownComponents: React.ReactNode;
parentDropdownId?: string;
avoidPortal?: boolean;
};

export const DropdownContent = ({
Expand All @@ -51,6 +52,7 @@ export const DropdownContent = ({
disableBlur,
dropdownMenuWidth,
dropdownComponents,
avoidPortal,
}: DropdownContentProps) => {
const { isDropdownOpen, closeDropdown, dropdownWidth, setDropdownPlacement } =
useDropdown(dropdownId);
Expand Down Expand Up @@ -111,7 +113,7 @@ export const DropdownContent = ({
{hotkey && onHotkeyTriggered && (
<HotkeyEffect hotkey={hotkey} onHotkeyTriggered={onHotkeyTriggered} />
)}
<FloatingPortal>
{avoidPortal ? (
<DropdownMenu
className={className}
disableBlur={disableBlur}
Expand All @@ -122,7 +124,20 @@ export const DropdownContent = ({
>
{dropdownComponents}
</DropdownMenu>
</FloatingPortal>
) : (
<FloatingPortal>
<DropdownMenu
className={className}
disableBlur={disableBlur}
width={dropdownMenuWidth ?? dropdownWidth}
data-select-disable
ref={floatingUiRefs.setFloating}
style={dropdownMenuStyles}
>
{dropdownComponents}
</DropdownMenu>
</FloatingPortal>
)}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export const ShowPageAddButton = ({
}: {
activityTargetObject: ActivityTargetableObject;
}) => {
const { closeDropdown } = useDropdown('add-show-page');
const { closeDropdown } = useDropdown(SHOW_PAGE_ADD_BUTTON_DROPDOWN_ID);

const openNote = useOpenCreateActivityDrawer({
activityObjectNameSingular: CoreObjectNameSingular.Note,
});
Expand All @@ -35,8 +36,7 @@ export const ShowPageAddButton = ({
openNote({
targetableObjects: [activityTargetObject],
});
}
if (objectNameSingular === CoreObjectNameSingular.Task) {
} else if (objectNameSingular === CoreObjectNameSingular.Task) {
openTask({
targetableObjects: [activityTargetObject],
});
Expand Down
Loading