Skip to content

Commit 38f46bd

Browse files
author
priyanshu.solanki
committed
refactor: use EMCN components for KB UI
- Replace @/components/ui imports with @/components/emcn - Use Combobox instead of Select for dropdowns - Use EMCN Switch, Button, Input, Label components - Remove unsupported 'size' prop from EMCN Button
1 parent 030d8b6 commit 38f46bd

4 files changed

Lines changed: 44 additions & 66 deletions

File tree

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/[documentId]/components/document-tags-modal/document-tags-modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import {
1212
ModalContent,
1313
ModalFooter,
1414
ModalHeader,
15+
Switch,
1516
Trash,
1617
} from '@/components/emcn'
17-
import { Switch } from '@/components/ui/switch'
1818
import { cn } from '@/lib/core/utils/cn'
1919
import { ALL_TAG_SLOTS, type AllTagSlot } from '@/lib/knowledge/constants'
2020
import type { DocumentTag } from '@/lib/knowledge/tags/types'

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/components/base-tags-modal/base-tags-modal.tsx

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
'use client'
22

3-
import { useCallback, useEffect, useState } from 'react'
3+
import { useCallback, useEffect, useMemo, useState } from 'react'
44
import { Loader2 } from 'lucide-react'
55
import {
66
Button,
7+
Combobox,
8+
type ComboboxOption,
79
Input,
810
Label,
911
Modal,
@@ -13,13 +15,6 @@ import {
1315
ModalHeader,
1416
Trash,
1517
} from '@/components/emcn'
16-
import {
17-
Select,
18-
SelectContent,
19-
SelectItem,
20-
SelectTrigger,
21-
SelectValue,
22-
} from '@/components/ui/select'
2318
import { cn } from '@/lib/core/utils/cn'
2419
import { SUPPORTED_FIELD_TYPES, TAG_SLOT_CONFIG } from '@/lib/knowledge/constants'
2520
import { createLogger } from '@/lib/logs/console/logger'
@@ -203,6 +198,17 @@ export function BaseTagsModal({ open, onOpenChange, knowledgeBaseId }: BaseTagsM
203198
return used < max
204199
}
205200

201+
/** Field type options for Combobox */
202+
const fieldTypeOptions: ComboboxOption[] = useMemo(() => {
203+
return SUPPORTED_FIELD_TYPES.filter((type) => hasAvailableSlots(type)).map((type) => {
204+
const { used, max } = getSlotUsageByFieldType(type)
205+
return {
206+
value: type,
207+
label: `${FIELD_TYPE_LABELS[type]} (${used}/${max})`,
208+
}
209+
})
210+
}, [kbTagDefinitions])
211+
206212
const saveTagDefinition = async () => {
207213
if (!canSaveTag()) return
208214

@@ -403,32 +409,15 @@ export function BaseTagsModal({ open, onOpenChange, knowledgeBaseId }: BaseTagsM
403409

404410
<div className='flex flex-col gap-[8px]'>
405411
<Label htmlFor='tagType'>Type</Label>
406-
<Select
412+
<Combobox
413+
options={fieldTypeOptions}
407414
value={createTagForm.fieldType}
408-
onValueChange={(value) =>
415+
onChange={(value) =>
409416
setCreateTagForm({ ...createTagForm, fieldType: value })
410417
}
411-
>
412-
<SelectTrigger className='h-9'>
413-
<SelectValue placeholder='Select type' />
414-
</SelectTrigger>
415-
<SelectContent className='z-[9999]'>
416-
{SUPPORTED_FIELD_TYPES.map((type) => {
417-
const { used, max } = getSlotUsageByFieldType(type)
418-
const isDisabled = used >= max
419-
return (
420-
<SelectItem key={type} value={type} disabled={isDisabled}>
421-
<span className='flex items-center gap-2'>
422-
{FIELD_TYPE_LABELS[type]}
423-
<span className='text-[10px] text-[var(--text-muted)]'>
424-
({used}/{max})
425-
</span>
426-
</span>
427-
</SelectItem>
428-
)
429-
})}
430-
</SelectContent>
431-
</Select>
418+
placeholder='Select type'
419+
size='sm'
420+
/>
432421
{!hasAvailableSlots(createTagForm.fieldType) && (
433422
<span className='text-[11px] text-[var(--text-error)]'>
434423
No available slots for this type. Choose a different type.

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/document-tag-entry/document-tag-entry.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import { useMemo, useRef, useState } from 'react'
44
import { Plus } from 'lucide-react'
5-
import { Trash } from '@/components/emcn/icons/trash'
6-
import { Button } from '@/components/ui/button'
7-
import { Input } from '@/components/ui/input'
8-
import { Switch } from '@/components/ui/switch'
5+
import { Button, Input, Switch, Trash } from '@/components/emcn'
96
import { cn } from '@/lib/core/utils/cn'
107
import { SUPPORTED_FIELD_TYPES, TAG_SLOT_CONFIG } from '@/lib/knowledge/constants'
118
import { formatDisplayText } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/formatted-text'
@@ -608,8 +605,7 @@ export function DocumentTagEntry({
608605
<td className='w-0 p-0'>
609606
<Button
610607
variant='ghost'
611-
size='icon'
612-
className='-translate-y-1/2 absolute top-1/2 right-2 h-8 w-8 opacity-0 group-hover:opacity-100'
608+
className='-translate-y-1/2 absolute top-1/2 right-2 h-8 w-8 p-0 opacity-0 group-hover:opacity-100'
613609
onClick={() => handleDeleteRow(rowIndex)}
614610
>
615611
<Trash className='h-4 w-4 text-muted-foreground' />
@@ -631,7 +627,7 @@ export function DocumentTagEntry({
631627
<div className='relative'>
632628
{showPreFillButton && (
633629
<div className='mb-2'>
634-
<Button variant='outline' size='sm' onClick={handlePreFillTags}>
630+
<Button variant='outline' className='h-7 px-2 text-xs' onClick={handlePreFillTags}>
635631
Prefill Existing Tags
636632
</Button>
637633
</div>
@@ -657,7 +653,6 @@ export function DocumentTagEntry({
657653
<div className='mt-3 flex items-center justify-between'>
658654
<Button
659655
variant='outline'
660-
size='sm'
661656
onClick={handleAddRow}
662657
disabled={!canAddMoreTags}
663658
className='h-7 px-2 text-xs'

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/knowledge-tag-filters/knowledge-tag-filters.tsx

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
'use client'
22

3-
import { useState } from 'react'
3+
import { useMemo, useState } from 'react'
44
import { Plus } from 'lucide-react'
5-
import { Trash } from '@/components/emcn/icons/trash'
6-
import { Button } from '@/components/ui/button'
7-
import { Input } from '@/components/ui/input'
8-
import { Label } from '@/components/ui/label'
95
import {
10-
Select,
11-
SelectContent,
12-
SelectItem,
13-
SelectTrigger,
14-
SelectValue,
15-
} from '@/components/ui/select'
16-
import { Switch } from '@/components/ui/switch'
6+
Button,
7+
Combobox,
8+
type ComboboxOption,
9+
Input,
10+
Label,
11+
Switch,
12+
Trash,
13+
} from '@/components/emcn'
1714
import { formatDisplayText } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/formatted-text'
1815
import {
1916
checkTagTrigger,
@@ -369,24 +366,21 @@ export function KnowledgeTagFilters({
369366
const operator = row.cells.operator || 'eq'
370367
const operators = getOperatorsForFieldType(fieldType)
371368

369+
const operatorOptions: ComboboxOption[] = operators.map((op) => ({
370+
value: op.value,
371+
label: op.label,
372+
}))
373+
372374
return (
373375
<td className='border-r p-1'>
374-
<Select
376+
<Combobox
377+
options={operatorOptions}
375378
value={operator}
376-
onValueChange={(value) => handleCellChange(rowIndex, 'operator', value)}
379+
onChange={(value) => handleCellChange(rowIndex, 'operator', value)}
377380
disabled={disabled || !row.cells.tagName}
378-
>
379-
<SelectTrigger className='h-8 border-0 focus:ring-0 focus:ring-offset-0'>
380-
<SelectValue placeholder='Operator' />
381-
</SelectTrigger>
382-
<SelectContent>
383-
{operators.map((op) => (
384-
<SelectItem key={op.value} value={op.value}>
385-
{op.label}
386-
</SelectItem>
387-
))}
388-
</SelectContent>
389-
</Select>
381+
placeholder='Operator'
382+
size='sm'
383+
/>
390384
</td>
391385
)
392386
}

0 commit comments

Comments
 (0)