Files
twenty/packages/twenty-front/src/modules/ai/components/RoutingStatusDisplay.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

117 lines
3.6 KiB
TypeScript

import { RoutingDebugDisplay } from '@/ai/components/RoutingDebugDisplay';
import { ShimmeringText } from '@/ai/components/ShimmeringText';
import { styled } from '@linaria/react';
import { useContext, useState } from 'react';
import { type DataMessagePart } from 'twenty-shared/ai';
import { isDefined } from 'twenty-shared/utils';
import { IconChevronDown, IconChevronUp, IconCpu } from 'twenty-ui/icon';
import { AnimatedExpandableContainer } from 'twenty-ui/layout';
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
const StyledContainer = styled.div`
display: flex;
flex-direction: column;
gap: ${themeCssVariables.spacing[2]};
`;
const StyledToggleButton = styled.div<{ isExpandable: boolean }>`
align-items: center;
background: none;
border: none;
color: ${themeCssVariables.font.color.tertiary};
cursor: ${({ isExpandable }) => (isExpandable ? 'pointer' : 'auto')};
display: flex;
gap: ${themeCssVariables.spacing[1]};
padding: ${themeCssVariables.spacing[1]} 0;
transition: color calc(${themeCssVariables.animation.duration.normal} * 1s);
&:hover {
color: ${({ isExpandable }) =>
isExpandable
? themeCssVariables.font.color.secondary
: themeCssVariables.font.color.tertiary};
}
`;
const StyledDisplayMessage = styled.span`
color: ${themeCssVariables.font.color.tertiary};
font-size: ${themeCssVariables.font.size.md};
font-weight: ${themeCssVariables.font.weight.medium};
`;
const StyledIconTextContainer = styled.div`
align-items: center;
display: flex;
gap: ${themeCssVariables.spacing[1]};
svg {
min-width: calc(${themeCssVariables.icon.size.sm} * 1px);
}
`;
const StyledContentContainer = styled.div`
background: ${themeCssVariables.background.transparent.lighter};
border: 1px solid ${themeCssVariables.border.color.light};
border-radius: ${themeCssVariables.border.radius.sm};
min-width: 0;
padding: ${themeCssVariables.spacing[3]};
`;
export const RoutingStatusDisplay = ({
data,
}: {
data: DataMessagePart['routing-status'];
}) => {
const { theme } = useContext(ThemeContext);
const [isExpanded, setIsExpanded] = useState(false);
const isLoading = data.state === 'loading';
const isDebugMode = process.env.IS_DEBUG_MODE === 'true';
const isExpandable =
isDebugMode && data.state === 'routed' && isDefined(data.debug);
if (data.state === 'error') {
return null;
}
if (isLoading) {
return (
<StyledContainer>
<StyledIconTextContainer>
<IconCpu size={theme.icon.size.sm} />
<ShimmeringText>
<StyledDisplayMessage>{data.text}</StyledDisplayMessage>
</ShimmeringText>
</StyledIconTextContainer>
</StyledContainer>
);
}
return (
<StyledContainer>
<StyledToggleButton
onClick={() => isExpandable && setIsExpanded(!isExpanded)}
isExpandable={!!isExpandable}
>
<StyledIconTextContainer>
<IconCpu size={theme.icon.size.sm} />
<StyledDisplayMessage>{data.text}</StyledDisplayMessage>
</StyledIconTextContainer>
{isExpandable &&
(isExpanded ? (
<IconChevronUp size={theme.icon.size.sm} />
) : (
<IconChevronDown size={theme.icon.size.sm} />
))}
</StyledToggleButton>
{isExpandable && (
<AnimatedExpandableContainer isExpanded={isExpanded} mode="fit-content">
<StyledContentContainer>
<RoutingDebugDisplay debug={data.debug!} />
</StyledContentContainer>
</AnimatedExpandableContainer>
)}
</StyledContainer>
);
};