Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -22,9 +22,11 @@ vi.mock('../Toolbox', () => ({
onClose,
onItemSelect,
renderEmptyState,
searchPlaceholder,
}: ToolboxProps<NodeItemData>) => (
<div data-testid="toolbox-mock">
<div data-testid="toolbox-title">{title}</div>
<div data-testid="toolbox-search-placeholder">{searchPlaceholder}</div>
<div data-testid="toolbox-items">{JSON.stringify(initialItems)}</div>
<button type="button" data-testid="toolbox-close" onClick={onClose}>
Close
Expand Down Expand Up @@ -121,6 +123,26 @@ describe('AddNodePanel', () => {
expect(screen.getByTestId('toolbox-title')).toHaveTextContent('Add node');
});

it('should default the search placeholder to "Search nodes"', () => {
render(
<NodeRegistryProvider manifest={mockManifest}>
<AddNodePanel {...defaultProps} />
</NodeRegistryProvider>
);

expect(screen.getByTestId('toolbox-search-placeholder')).toHaveTextContent('Search nodes');
});

it('should forward a custom searchPlaceholder to Toolbox', () => {
render(
<NodeRegistryProvider manifest={mockManifest}>
<AddNodePanel {...defaultProps} searchPlaceholder="Search agents" />
</NodeRegistryProvider>
);

expect(screen.getByTestId('toolbox-search-placeholder')).toHaveTextContent('Search agents');
});

it('should transform empty registry into empty list items', () => {
render(
<NodeRegistryProvider manifest={{ version: '1.0.0', categories: [], nodes: [] }}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { memo, useCallback, useMemo } from 'react';
import { useSafeLingui } from '../../../i18n';
import { useOptionalNodeTypeRegistry } from '../../core';
import { usePreviewNode } from '../../hooks';
import { type ListItem, Toolbox } from '../Toolbox';
Expand All @@ -21,7 +22,9 @@ export const AddNodePanel = memo(function AddNodePanel({
title,
loading,
renderEmptyState,
searchPlaceholder,
}: AddNodePanelProps) {
const { _ } = useSafeLingui();
const registry = useOptionalNodeTypeRegistry();
const { previewNodeConnectionInfo } = usePreviewNode();

Expand Down Expand Up @@ -87,6 +90,9 @@ export const AddNodePanel = memo(function AddNodePanel({
onClose={onClose}
onItemHover={onNodeHover}
renderEmptyState={renderEmptyState}
searchPlaceholder={
searchPlaceholder ?? _({ id: 'add-node-panel.search-nodes', message: 'Search nodes' })
}
Comment thread
KodudulaAshishUiPath marked this conversation as resolved.
/>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ export interface AddNodePanelProps {
* When provided, replaces the built-in icon + message empty state.
*/
renderEmptyState?: ToolboxEmptyStateRenderer<NodeItemData>;
/**
* Placeholder for the search input. Should describe what will be searched,
* such as "Search agents". Defaults to "Search nodes".
*/
searchPlaceholder?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ describe('Toolbox', () => {
expect(screen.getByPlaceholderText('Search')).toBeInTheDocument();
});

it('should render a custom search placeholder when provided', () => {
render(<Toolbox {...defaultProps} searchPlaceholder="Search nodes" />);

expect(screen.getByPlaceholderText('Search nodes')).toBeInTheDocument();
expect(screen.queryByPlaceholderText('Search')).not.toBeInTheDocument();
});

it('should render all items in ListView', () => {
render(<Toolbox {...defaultProps} />);

Expand Down
13 changes: 11 additions & 2 deletions packages/apollo-react/src/canvas/components/Toolbox/Toolbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ export interface ToolboxProps<T> {
onItemHover?: (item: ListItem<T>) => void;
onBack?: () => void;
onSearch?: ToolboxSearchHandler<T>;
/**
* Placeholder for the search input. Should describe what will be searched,
* such as "Search nodes". Defaults to a generic "Search".
*/
searchPlaceholder?: string;
/**
* Optional row of icon shortcuts rendered above the title. Apollo controls
* the visuals so the strip stays consistent across consumers; pass the
Expand Down Expand Up @@ -155,9 +160,10 @@ export function Toolbox<T>({
fullHeight = false,
quickActions,
renderEmptyState,
searchPlaceholder: searchPlaceholderProp,
}: ToolboxProps<T>) {
const { _ } = useSafeLingui();
const searchPlaceholder = _({ id: 'toolbox.search', message: 'Search' });
const searchPlaceholder = searchPlaceholderProp ?? _({ id: 'toolbox.search', message: 'Search' });
Comment thread
KodudulaAshishUiPath marked this conversation as resolved.
Comment thread
KodudulaAshishUiPath marked this conversation as resolved.
const [items, setItems] = useState<ListItem<T>[]>(initialItems);
const [search, setSearch] = useState('');
const [searchLoading, setSearchLoading] = useState(false);
Expand Down Expand Up @@ -203,7 +209,10 @@ export function Toolbox<T>({
const wrappedRenderEmptyState = useMemo(
() =>
renderEmptyState && !isSearching
? () => renderEmptyState({ currentCategory: currentParentItem ?? undefined })
? () =>
renderEmptyState({
currentCategory: currentParentItem ?? undefined,
})
: undefined,
[renderEmptyState, isSearching, currentParentItem]
);
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-react/src/canvas/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"sticky-note.toolbar.color": "Color",
"sticky-note.toolbar.delete": "Delete",
"sticky-note.toolbar.edit": "Edit",
"add-node-panel.search-nodes": "Search nodes",
Comment thread
KodudulaAshishUiPath marked this conversation as resolved.
"toolbox.search": "Search",
"loop-node.add-node": "Add node to loop",
"loop-node.mode.parallel": "Parallel",
Expand Down
Loading