Skip to content
Merged
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
@@ -1,7 +1,7 @@
'use client'

import { useCallback, useMemo } from 'react'
import { ChipCombobox, ChipTag, type ComboboxOption } from '@sim/emcn'
import { ChipTag, Combobox, type ComboboxOption } from '@sim/emcn'
import { X } from '@sim/emcn/icons'
import { useQueries } from '@tanstack/react-query'
import { useParams } from 'next/navigation'
Expand Down Expand Up @@ -211,7 +211,7 @@ export function KnowledgeBaseSelector({
</div>
)}

<ChipCombobox
<Combobox
options={options}
value={isMultiSelect ? undefined : (selectedIds[0] ?? '')}
multiSelect={isMultiSelect}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { ChipCombobox } from '@sim/emcn'
import { Combobox } from '@sim/emcn'
import { useParams } from 'next/navigation'
import { McpIcon } from '@/components/icons'
import { getMcpTargetOptions } from '@/components/mcp/target-options'
Expand Down Expand Up @@ -65,7 +65,7 @@ export function McpServerSelector({
})

return (
<ChipCombobox
<Combobox
options={comboboxOptions}
value={inputValue}
selectedValue={selectedServerId}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import { useMemo } from 'react'
import { ChipCombobox } from '@sim/emcn'
import { Combobox } from '@sim/emcn'
import { useParams } from 'next/navigation'
import { formatDisplayText } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/formatted-text'
import { getWorkflowSearchLabelHighlight } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/workflow-search-highlight'
Expand Down Expand Up @@ -86,7 +86,7 @@ export function McpToolSelector({
})

return (
<ChipCombobox
<Combobox
options={comboboxOptions}
value={inputValue}
selectedValue={selectedToolId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ vi.mock('next/navigation', () => ({
}))

vi.mock('@sim/emcn', () => ({
Button: ({ children, ...props }: React.ButtonHTMLAttributes<HTMLButtonElement>) => (
<button {...props}>{children}</button>
),
Chip: ({
children,
disabled,
Expand All @@ -43,7 +46,7 @@ vi.mock('@sim/emcn', () => ({
{children}
</button>
),
ChipCombobox: ({
Combobox: ({
options,
value,
placeholder,
Expand All @@ -60,21 +63,6 @@ vi.mock('@sim/emcn', () => ({
))}
</div>
),
ChipDropdown: ({
options,
value,
placeholder,
}: {
options: Array<{ value: string; label: string }>
value?: string
placeholder?: string
}) => (
<div data-combobox={placeholder} data-value={value}>
{options.map((option) => (
<span key={option.value}>{option.label}</span>
))}
</div>
),
Label: ({ children }: { children?: React.ReactNode }) => <span>{children}</span>,
Tooltip: {
Root: ({ children }: { children?: React.ReactNode }) => <>{children}</>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import { memo, useCallback, useEffect, useMemo, useRef } from 'react'
import { Chip, ChipCombobox, ChipDropdown, type ComboboxOption, Label, Tooltip } from '@sim/emcn'
import { Button, Chip, Combobox, type ComboboxOption, Label, Tooltip } from '@sim/emcn'
import { ChevronDown, ChevronUp, Plus, Trash } from '@sim/emcn/icons'
import { generateShortId } from '@sim/utils/id'
import { useParams } from 'next/navigation'
Expand Down Expand Up @@ -123,55 +123,64 @@ const FallbackRow = memo(function FallbackRow({
const apiKeyValue = isWholeEnvVarReference(row.apiKey) ? row.apiKey : ''

return (
<div
data-fallback-row-id={row.id}
className='space-y-3 rounded-lg border border-[var(--border)] p-3'
>
<div className='flex items-center justify-between'>
<span className='text-[var(--text-muted)] text-small'>{ordinalChoiceLabel(index)}</span>
<div className='flex items-center'>
<div data-fallback-row-id={row.id} className='min-w-0 rounded-sm border border-[var(--border)]'>
<div className='flex items-center justify-between gap-2 rounded-t-[4px] bg-[var(--surface-4)] px-2 py-1'>
<span className='text-[var(--text-secondary)] text-small'>{ordinalChoiceLabel(index)}</span>
<div className='flex shrink-0 items-center gap-1'>
{canMove && (
<>
<Tooltip.Root>
<Tooltip.Trigger asChild>
<Chip
leftIcon={ChevronUp}
<Button
type='button'
variant='ghost'
size='icon'
onClick={() => onMove(row.id, -1)}
disabled={readOnly || index === 0}
aria-label='Move up'
/>
>
<ChevronUp className='size-[14px]' />
</Button>
</Tooltip.Trigger>
<Tooltip.Content>Move up</Tooltip.Content>
</Tooltip.Root>
<Tooltip.Root>
<Tooltip.Trigger asChild>
<Chip
leftIcon={ChevronDown}
<Button
type='button'
variant='ghost'
size='icon'
onClick={() => onMove(row.id, 1)}
disabled={readOnly || isLast}
aria-label='Move down'
/>
>
<ChevronDown className='size-[14px]' />
</Button>
</Tooltip.Trigger>
<Tooltip.Content>Move down</Tooltip.Content>
</Tooltip.Root>
</>
)}
<Tooltip.Root>
<Tooltip.Trigger asChild>
<Chip
leftIcon={Trash}
<Button
type='button'
variant='ghost'
size='icon'
onClick={() => onRemove(row.id)}
disabled={readOnly}
aria-label='Remove fallback model'
/>
>
<Trash className='size-[14px]' />
</Button>
</Tooltip.Trigger>
<Tooltip.Content>Remove</Tooltip.Content>
</Tooltip.Root>
</div>
</div>

<div className='flex flex-col gap-3'>
<ChipCombobox
<div className='flex flex-col gap-2.5 rounded-b-[4px] border-[var(--border)] border-t bg-[var(--surface-2)] p-2'>
Comment thread
waleedlatif1 marked this conversation as resolved.
<Combobox
options={modelOptions}
value={row.model}
onChange={(model) => onChangeModel(row.id, model)}
Expand All @@ -184,9 +193,9 @@ const FallbackRow = memo(function FallbackRow({
emptyMessage='No models available'
/>
{needsApiKey && (
<div className='flex flex-col gap-1.5'>
<Label>API key</Label>
<ChipCombobox
<div className='flex flex-col gap-2.5'>
<Label className='pl-0.5'>API key</Label>
<Combobox
options={envVarOptions}
value={apiKeyValue}
onChange={(apiKey) => onChangeApiKey(row.id, apiKey)}
Expand All @@ -201,9 +210,9 @@ const FallbackRow = memo(function FallbackRow({
</div>
)}
{tuningFields.map(({ knob, options }) => (
<div key={knob} className='flex flex-col gap-1.5'>
<Label>{FALLBACK_TUNING_LABELS[knob]}</Label>
<ChipDropdown
<div key={knob} className='flex flex-col gap-2.5'>
<Label className='pl-0.5'>{FALLBACK_TUNING_LABELS[knob]}</Label>
<Combobox
options={options}
value={row[knob] ?? options[0]?.value ?? ''}
onChange={(value) => onChangeTuning(row.id, knob, value)}
Expand Down Expand Up @@ -387,7 +396,7 @@ export function ModelFallbackList({
)

return (
<div className='space-y-2'>
<div className='flex w-full min-w-0 flex-col gap-2.5'>
{rows.map((row, index) => (
<FallbackRow
key={row.id}
Expand All @@ -410,9 +419,8 @@ export function ModelFallbackList({
))}
{!readOnly && (
<Chip
variant='outline'
leftIcon={Plus}
fullWidth
className='self-start'
onClick={handleAdd}
disabled={rows.length >= MAX_FALLBACK_MODELS}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ vi.mock('next/navigation', () => ({
}))

vi.mock('@sim/emcn', () => ({
ChipCombobox: ({
Combobox: ({
options,
disabled,
isLoading,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import { useMemo } from 'react'
import { ChipCombobox } from '@sim/emcn'
import { Combobox } from '@sim/emcn'
import { useParams } from 'next/navigation'
import type { FolderResourceType } from '@/lib/api/contracts/folders'
import { parseFolderPath } from '@/lib/folders/paths'
Expand Down Expand Up @@ -58,7 +58,7 @@ export function WorkspaceFolderSelector({
}, [folders, isPlaceholderData, required, subBlock.multiSelect, subBlock.placeholder])

return (
<ChipCombobox
<Combobox
options={options}
value={subBlock.multiSelect ? undefined : selected}
onChange={(value) => {
Expand Down
6 changes: 3 additions & 3 deletions apps/sim/components/mcp/mcp-selectors.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/** @vitest-environment node */
import type { ComponentProps } from 'react'
import type { ChipCombobox } from '@sim/emcn'
import type { Combobox } from '@sim/emcn'
import { renderToStaticMarkup } from 'react-dom/server'
import { beforeEach, describe, expect, it, vi } from 'vitest'

const mocks = vi.hoisted(() => ({
combobox: vi.fn<(props: ComponentProps<typeof ChipCombobox>) => null>(() => null),
combobox: vi.fn<(props: ComponentProps<typeof Combobox>) => null>(() => null),
setValue: vi.fn(),
longInput: vi.fn(() => null),
shortInput: vi.fn(() => null),
Expand Down Expand Up @@ -38,7 +38,7 @@ vi.mock('@/stores/workflow-diff/store', () => ({
},
}),
}))
vi.mock('@sim/emcn', () => ({ ChipCombobox: mocks.combobox, Label: () => null }))
vi.mock('@sim/emcn', () => ({ Combobox: mocks.combobox, Label: () => null }))
vi.mock(
'@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/long-input/long-input',
() => ({ LongInput: mocks.longInput })
Expand Down
16 changes: 16 additions & 0 deletions packages/emcn/src/components/combobox/combobox.dom.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ afterEach(() => {
})

describe('Combobox onOpenChange', () => {
it('preserves trigger styling when an editable input adds padding for a clear button', () => {
render(
<Combobox
options={OPTIONS}
editable
className='min-w-0'
inputProps={{ className: 'pr-[60px]' }}
/>
)

const control = trigger()
expect(control.classList.contains('min-w-0')).toBe(true)
expect(control.classList.contains('pr-[60px]')).toBe(true)
expect(control.classList.contains('pr-10')).toBe(false)
})

it.each([false, true])(
'puts the field name and validation ARIA on the interactive control (editable=%s)',
(editable) => {
Expand Down
15 changes: 8 additions & 7 deletions packages/emcn/src/components/combobox/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -790,13 +790,6 @@ const Combobox = memo(
<div className='group relative'>
<Input
ref={inputRef}
className={cn(
'w-full pr-10 transition-colors',
(overlayContent || SelectedIcon) && 'text-transparent caret-foreground',
SelectedIcon && !overlayContent && 'pl-7',
open && 'focus-visible:border-[var(--border-1)]',
className
)}
placeholder={placeholder}
value={value ?? ''}
onChange={handleInputChange}
Expand All @@ -810,6 +803,14 @@ const Combobox = memo(
aria-required={ariaRequired}
aria-invalid={ariaInvalid}
{...inputProps}
className={cn(
'w-full pr-10 transition-colors',
(overlayContent || SelectedIcon) && 'text-transparent caret-foreground',
SelectedIcon && !overlayContent && 'pl-7',
open && 'focus-visible:border-[var(--border-1)]',
className,
inputProps?.className
)}
role='combobox'
aria-expanded={open}
aria-haspopup='listbox'
Expand Down
Loading