Files
twenty/packages/twenty-front/src/modules/side-panel/components/SidePanelItemWithAddToNavigationDrag.tsx
T
Raphaël Bosi 8034c7725f Reorganize twenty-ui into best-practice component domains and per-component folders (#21745)
Reorganizes `twenty-ui`'s component organization to follow how the best
UI libraries (MUI, Mantine, Base UI, Polaris) structure their source,
now that the package has stabilized.

**Taxonomy** — dissolves the meaningless `components/` junk-drawer and
the 107-file `display/` mega-category. New domains/subpaths:
`data-display`, `typography`, `icon`, `surfaces`; `feedback` and
`layout` absorb the rest (banners/callout/info + placeholders →
feedback; modal/card → surfaces; motion + separators → layout).

**Per-component layout** — every component is now
`<domain>/<ComponentName>/<ComponentName>.tsx` with colocated
styles/stories/types, `internal/` for private helpers and `parts/` for
re-exported compound sub-parts. The redundant inner `/components/` is
gone. `icon` and `json-visualizer` are kept as cohesive subsystems.

**Also:** adds a tree-shakeable root barrel (`import { Button } from
'twenty-ui'`), the generator now owns `individual-entry.ts`, and a real
barrel-leak bug is fixed (private `internals/` parts were leaking into
the public API).

Consumer imports (~1.2k files) and the `twenty-sdk` UI aggregator were
updated by codemod. The change is **export-neutral** except 16
intentionally-removed private internals symbols (all verified
unconsumed). Gates green: typecheck, lint, build, size-limit, storybook.


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/21745?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
2026-06-18 10:31:29 +02:00

138 lines
4.2 KiB
TypeScript

import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
import { type ReactNode, lazy, Suspense, useState } from 'react';
import { isDefined } from 'twenty-shared/utils';
import { type IconComponent } from 'twenty-ui/icon';
import { CommandMenuItem } from '@/command-menu/components/CommandMenuItem';
import { addToNavPayloadRegistryState } from '@/navigation-menu-item/common/states/addToNavPayloadRegistryState';
import { navigationMenuItemEditSectionState } from '@/navigation-menu-item/common/states/navigationMenuItemEditSectionState';
import type { AddToNavigationDragPayload } from '@/navigation-menu-item/common/types/add-to-navigation-drag-payload';
import { AddToNavigationDragHandle } from '@/navigation-menu-item/display/dnd/components/AddToNavigationDragHandle';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
const CommandMenuItemWithAddToNavigationDragDndKit = lazy(() =>
import('@/command-menu/components/CommandMenuItemWithAddToNavigationDragDndKit').then(
(m) => ({
default: m.CommandMenuItemWithAddToNavigationDragDndKit,
}),
),
);
type SidePanelItemWithAddToNavigationDragProps = {
icon?: IconComponent;
customIconContent?: ReactNode;
label: string;
description?: string;
id: string;
onClick: () => void;
payload: AddToNavigationDragPayload;
dragIndex?: number;
disabled?: boolean;
disableDrag?: boolean;
};
const StyledDraggableMenuItem = styled.div<{
$disabled?: boolean;
$disableDrag?: boolean;
}>`
cursor: ${({ $disabled, $disableDrag }) =>
$disabled || $disableDrag ? 'default' : 'grab'};
pointer-events: ${({ $disabled }) => ($disabled ? 'none' : 'auto')};
width: 100%;
&:active {
cursor: ${({ $disabled, $disableDrag }) =>
$disabled || $disableDrag ? 'default' : 'grabbing'};
}
`;
export const SidePanelItemWithAddToNavigationDrag = ({
icon,
customIconContent,
label,
description,
id,
onClick,
payload,
dragIndex,
disabled = false,
disableDrag = false,
}: SidePanelItemWithAddToNavigationDragProps) => {
const { t } = useLingui();
const setAddToNavPayloadRegistry = useSetAtomState(
addToNavPayloadRegistryState,
);
const navigationMenuItemEditSection = useAtomStateValue(
navigationMenuItemEditSectionState,
);
const [isHovered, setIsHovered] = useState(false);
// Favorites are added by click only; drag-to-add targets the workspace
// sidebar and runs through layout-customization mode.
const effectiveDisableDrag =
disableDrag || navigationMenuItemEditSection === 'favorite';
const showDragAffordance = !disabled && !effectiveDisableDrag && isHovered;
const contextualDescription = showDragAffordance
? t`Drag to add to navbar`
: description;
const DragHandleIcon = () => (
<AddToNavigationDragHandle
icon={icon}
customIconContent={customIconContent}
payload={payload}
isHovered={showDragAffordance}
disabled={disabled}
disableDrag={effectiveDisableDrag}
/>
);
const registerPayload = () => {
if (!disabled && !effectiveDisableDrag && isDefined(dragIndex)) {
setAddToNavPayloadRegistry((prev) => new Map(prev).set(id, payload));
}
};
const menuItemContent = (
<StyledDraggableMenuItem
$disabled={disabled}
$disableDrag={effectiveDisableDrag}
onMouseEnter={() => {
if (!disabled && !effectiveDisableDrag) {
setIsHovered(true);
registerPayload();
}
}}
onMouseLeave={() => {
if (!disabled && !effectiveDisableDrag) setIsHovered(false);
}}
onMouseDown={registerPayload}
>
<CommandMenuItem
Icon={DragHandleIcon}
label={label}
description={contextualDescription}
id={id}
onClick={onClick}
disabled={disabled}
/>
</StyledDraggableMenuItem>
);
if (!isDefined(dragIndex) || effectiveDisableDrag) {
return menuItemContent;
}
return (
<Suspense fallback={menuItemContent}>
<CommandMenuItemWithAddToNavigationDragDndKit
id={id}
dragIndex={dragIndex}
menuItemContent={menuItemContent}
/>
</Suspense>
);
};