34a903b4fa
## Summary Aligns **object metadata** icons with the **tinted tile** look everywhere we show a workspace object, and **retires** the navigation-only `NavigationMenuItemStyleIcon` wrapper in favor of **shared** UI primitives under `@/ui/display` and `@/object-metadata`. ## What changed ### Global tinted icon building blocks (`@/ui/display`) - **`TintedIconTile`** / **`StyledTintedIconTileContainer`** support optional **`size`** and **`stroke`**, and grow the tile when **`size`** is set so layouts match previous `theme.icon` usage. - Shared helpers and constants for theme color parsing and tinted backgrounds/borders/icon color (e.g. **`getTintedIconTileStyleFromColor`**, **`parseThemeColor`**, **`getColorFromTheme`**, related constants). ### Object metadata icon (`@/object-metadata`) - **`ObjectMetadataIcon`** composes **`TintedIconTile`** with **`getObjectColorWithFallback`**, forwards optional **`size`** / **`stroke`** for **visual parity** with old `getIcon` + explicit sizing. - **`getSelectOptionIconFromObjectMetadataItem`** returns an **`IconComponent`** for selects/menus that expect a component, not a React node. ### Navigation module cleanup - **Removed** **`NavigationMenuItemStyleIcon`**; call sites use **`ObjectMetadataIcon`**, **`TintedIconTile`**, and/or the shared **`getTintedIconTileStyleFromColor`** pipeline so the same treatment is **not** tied to the navigation package. - **`NavigationMenuItemIcon`**, view/link overlays, DnD handle, and sidebar editor flows updated to use the shared pattern where they render object (or tinted) icons. ### Product surfaces updated (non-exhaustive) - **Settings:** role object picker/rows, data model tables/graph/overview, object preview summary, webhooks entity list, morph relation multiselect. - **Workflows:** create/update/delete/upsert/find records, triggers, filters, variables dropdowns, AI agent object rows, object dropdowns. - **Shell:** side panel object filter / data sources / folder chrome where object icons appear. - **Records:** index header icon, show breadcrumb styling. - **Activity:** timeline event icon when linked object metadata applies. - **`NavigationDrawerItem`:** tinted branch aligned with shared **`TintedIconTile`** behavior. --------- Co-authored-by: Etienne <45695613+etiennejouan@users.noreply.github.com>
108 lines
3.9 KiB
TypeScript
108 lines
3.9 KiB
TypeScript
import { styled } from '@linaria/react';
|
|
import { useLingui } from '@lingui/react/macro';
|
|
import { NavigationMenuItemType } from 'twenty-shared/types';
|
|
import { TintedIconTile, useIcons } from 'twenty-ui/display';
|
|
|
|
import { FOLDER_ICON_DEFAULT } from '@/navigation-menu-item/common/constants/FolderIconDefault';
|
|
import { selectedNavigationMenuItemIdInEditModeState } from '@/navigation-menu-item/common/states/selectedNavigationMenuItemIdInEditModeState';
|
|
import { useNavigationMenuItemSectionItems } from '@/navigation-menu-item/display/hooks/useNavigationMenuItemSectionItems';
|
|
import { useUpdateFolderInDraft } from '@/navigation-menu-item/edit/folder/hooks/useUpdateFolderInDraft';
|
|
import { SidePanelPageInfoLayout } from '@/side-panel/components/SidePanelPageInfoLayout';
|
|
import { sidePanelPageInfoState } from '@/side-panel/states/sidePanelPageInfoState';
|
|
import { sidePanelShouldFocusTitleInputComponentState } from '@/side-panel/states/sidePanelShouldFocusTitleInputComponentState';
|
|
import { IconPicker } from '@/ui/input/components/IconPicker';
|
|
import { TitleInput } from '@/ui/input/components/TitleInput';
|
|
import { useAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentState';
|
|
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
|
|
|
|
const StyledClickableIconWrapper = styled.div`
|
|
cursor: pointer;
|
|
`;
|
|
|
|
export const SidePanelFolderInfo = () => {
|
|
const { t } = useLingui();
|
|
const { getIcon } = useIcons();
|
|
const sidePanelPageInfo = useAtomStateValue(sidePanelPageInfoState);
|
|
const [sidePanelShouldFocusTitleInput, setSidePanelShouldFocusTitleInput] =
|
|
useAtomComponentState(
|
|
sidePanelShouldFocusTitleInputComponentState,
|
|
sidePanelPageInfo.instanceId,
|
|
);
|
|
const selectedNavigationMenuItemIdInEditMode = useAtomStateValue(
|
|
selectedNavigationMenuItemIdInEditModeState,
|
|
);
|
|
const items = useNavigationMenuItemSectionItems();
|
|
const { updateFolderInDraft } = useUpdateFolderInDraft();
|
|
|
|
const defaultLabel = t`New folder`;
|
|
const placeholder = t`Folder name`;
|
|
|
|
const selectedItem = selectedNavigationMenuItemIdInEditMode
|
|
? items.find(
|
|
(item) =>
|
|
item.type === NavigationMenuItemType.FOLDER &&
|
|
item.id === selectedNavigationMenuItemIdInEditMode,
|
|
)
|
|
: undefined;
|
|
|
|
if (!selectedItem) return null;
|
|
|
|
const itemId = selectedItem.id;
|
|
const itemName = selectedItem.name ?? defaultLabel;
|
|
|
|
const handleChange = (text: string) => {
|
|
updateFolderInDraft(itemId, { name: text });
|
|
};
|
|
|
|
const handleSave = () => {
|
|
const trimmed = itemName.trim();
|
|
const finalName = trimmed.length > 0 ? trimmed : defaultLabel;
|
|
|
|
if (finalName !== itemName) {
|
|
updateFolderInDraft(itemId, { name: finalName });
|
|
}
|
|
};
|
|
|
|
const selectedIconKey = selectedItem.icon ?? FOLDER_ICON_DEFAULT;
|
|
const FolderIconComponent = getIcon(selectedIconKey);
|
|
|
|
return (
|
|
<SidePanelPageInfoLayout
|
|
icon={
|
|
<IconPicker
|
|
dropdownId="side-panel-folder-icon-picker"
|
|
selectedIconKey={selectedIconKey}
|
|
onChange={({ iconKey }) =>
|
|
updateFolderInDraft(itemId, { icon: iconKey })
|
|
}
|
|
clickableComponent={
|
|
<StyledClickableIconWrapper>
|
|
<TintedIconTile
|
|
Icon={FolderIconComponent}
|
|
color={selectedItem.color}
|
|
/>
|
|
</StyledClickableIconWrapper>
|
|
}
|
|
/>
|
|
}
|
|
title={
|
|
<TitleInput
|
|
instanceId={`folder-name-${itemId}`}
|
|
sizeVariant="sm"
|
|
value={itemName}
|
|
onChange={handleChange}
|
|
placeholder={placeholder}
|
|
onEnter={handleSave}
|
|
onEscape={handleSave}
|
|
onClickOutside={handleSave}
|
|
onTab={handleSave}
|
|
onShiftTab={handleSave}
|
|
shouldFocus={sidePanelShouldFocusTitleInput}
|
|
onFocus={() => setSidePanelShouldFocusTitleInput(false)}
|
|
/>
|
|
}
|
|
label={t`Folder`}
|
|
/>
|
|
);
|
|
};
|