Skip to content

Commit fa8ed0c

Browse files
author
waleed
committed
removed route, consolidated utils
1 parent 4c70b8e commit fa8ed0c

6 files changed

Lines changed: 46 additions & 239 deletions

File tree

apps/sim/app/api/knowledge/field-types/route.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

apps/sim/app/workspace/[workspaceId]/knowledge/components/document-tag-entry/document-tag-entry.tsx

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

3-
import { useEffect, useState } from 'react'
3+
import { useState } from 'react'
44
import { ChevronDown, Info, Plus, X } from 'lucide-react'
55
import {
66
Badge,
@@ -25,7 +25,12 @@ import {
2525
TooltipProvider,
2626
TooltipTrigger,
2727
} from '@/components/ui'
28-
import { MAX_TAG_SLOTS, type TagSlot } from '@/lib/knowledge/consts'
28+
import {
29+
FIELD_TYPE_METADATA,
30+
MAX_TAG_SLOTS,
31+
SUPPORTED_FIELD_TYPES,
32+
type TagSlot,
33+
} from '@/lib/knowledge/consts'
2934
import { createLogger } from '@/lib/logs/console/logger'
3035
import { useKnowledgeBaseTagDefinitions } from '@/hooks/use-knowledge-base-tag-definitions'
3136
import { useNextAvailableSlot } from '@/hooks/use-next-available-slot'
@@ -67,44 +72,13 @@ export function DocumentTagEntry({
6772
const { saveTagDefinitions } = documentTagHook
6873
const { tagDefinitions: kbTagDefinitions, fetchTagDefinitions: refreshTagDefinitions } = kbTagHook
6974

70-
// State for field types
71-
const [fieldTypes, setFieldTypes] = useState<
72-
Array<{
73-
value: string
74-
label: string
75-
description: string
76-
placeholder: string
77-
}>
78-
>([
79-
{
80-
value: 'text',
81-
label: 'Text',
82-
description: 'Free-form text content',
83-
placeholder: 'Enter text',
84-
},
85-
])
86-
87-
// Fetch field types on component mount
88-
useEffect(() => {
89-
const fetchFieldTypes = async () => {
90-
try {
91-
const response = await fetch('/api/knowledge/field-types')
92-
if (response.ok) {
93-
const result = await response.json()
94-
if (result.success) {
95-
setFieldTypes(result.data.fieldTypes)
96-
}
97-
}
98-
} catch (error) {
99-
logger.error('Error fetching field types:', error)
100-
// Keep the default fallback
101-
}
102-
}
103-
104-
fetchFieldTypes()
105-
}, [])
75+
const fieldTypes = SUPPORTED_FIELD_TYPES.map((fieldType) => ({
76+
value: fieldType,
77+
label: FIELD_TYPE_METADATA[fieldType].label,
78+
description: FIELD_TYPE_METADATA[fieldType].description,
79+
placeholder: FIELD_TYPE_METADATA[fieldType].placeholder,
80+
}))
10681

107-
// Modal state for tag editing
10882
const [editingTagIndex, setEditingTagIndex] = useState<number | null>(null)
10983
const [modalOpen, setModalOpen] = useState(false)
11084
const [editForm, setEditForm] = useState({
@@ -117,18 +91,13 @@ export function DocumentTagEntry({
11791
const updatedTags = tags.filter((_, i) => i !== index)
11892
onTagsChange(updatedTags)
11993

120-
// Persist the changes if onSave is provided
12194
if (onSave) {
12295
try {
12396
await onSave(updatedTags)
124-
} catch (error) {
125-
// Handle error silently - the UI will show the optimistic update
126-
// but the user can retry if needed
127-
}
97+
} catch (error) {}
12898
}
12999
}
130100

131-
// Open modal to edit tag
132101
const openTagModal = (index: number) => {
133102
const tag = tags[index]
134103
setEditingTagIndex(index)
@@ -140,7 +109,6 @@ export function DocumentTagEntry({
140109
setModalOpen(true)
141110
}
142111

143-
// Open modal to create new tag
144112
const openNewTagModal = () => {
145113
setEditingTagIndex(null)
146114
setEditForm({
@@ -151,7 +119,6 @@ export function DocumentTagEntry({
151119
setModalOpen(true)
152120
}
153121

154-
// Save tag from modal
155122
const saveTagFromModal = async () => {
156123
if (!editForm.displayName.trim() || !editForm.value.trim()) return
157124

@@ -450,12 +417,12 @@ export function DocumentTagEntry({
450417
value={editForm.fieldType}
451418
onValueChange={(value) => setEditForm({ ...editForm, fieldType: value })}
452419
disabled={
453-
editingTagIndex !== null || // Disable in edit mode
420+
editingTagIndex !== null ||
454421
(editingTagIndex === null &&
455422
kbTagDefinitions.some(
456423
(def) => def.displayName.toLowerCase() === editForm.displayName.toLowerCase()
457424
))
458-
} // Also disable when using existing definition in create mode
425+
}
459426
>
460427
<SelectTrigger className='h-8 w-full justify-between rounded-[10px] border-[#E5E5E5] bg-[#FFFFFF] text-sm dark:border-[#414141] dark:bg-[var(--surface-elevated)]'>
461428
<SelectValue placeholder='Select type' />
@@ -483,11 +450,7 @@ export function DocumentTagEntry({
483450
}
484451
showInlineError={true}
485452
onValidityChange={(valid) => {
486-
// Disable save when invalid
487-
// We just store validity in state via a refactor-free approach by toggling a hidden flag on form
488-
// Use a no-op set to trigger re-render when invalid so button disabled reflects it
489453
if (!valid) {
490-
// noop – re-render by updating same state value
491454
setEditForm((prev) => ({ ...prev }))
492455
}
493456
}}
@@ -517,18 +480,14 @@ export function DocumentTagEntry({
517480
disabled={(() => {
518481
if (!editForm.displayName.trim()) return true
519482

520-
// In edit mode, always allow
521483
if (editingTagIndex !== null) return false
522484

523-
// In create mode, check if we're creating a new definition at max slots
524485
const existingDefinition = kbTagDefinitions.find(
525486
(def) => def.displayName.toLowerCase() === editForm.displayName.toLowerCase()
526487
)
527488

528-
// If using existing definition, allow
529489
if (existingDefinition) return false
530490

531-
// If creating new definition and at max slots, disable
532491
return kbTagDefinitions.length >= MAX_TAG_SLOTS
533492
})()}
534493
>

apps/sim/app/workspace/[workspaceId]/knowledge/components/tag-input/typed-tag-input.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,13 @@ export function TypedTagInput({
3636
const [isValid, setIsValid] = useState(true)
3737
const [error, setError] = useState<string | undefined>()
3838

39-
// Update internal state when value prop changes
4039
useEffect(() => {
4140
setInputValue(value || '')
4241
}, [value])
4342

44-
// Clear validation errors when field type changes
4543
useEffect(() => {
4644
setIsValid(true)
4745
setError(undefined)
48-
// Re-validate the current value for the new field type if there is a value
4946
if (inputValue.trim()) {
5047
validateAndUpdate(inputValue)
5148
}
@@ -54,7 +51,6 @@ export function TypedTagInput({
5451
const validateAndUpdate = (newValue: string) => {
5552
setInputValue(newValue)
5653

57-
// Simple client-side validation
5854
let valid = true
5955
let errorMessage: string | undefined
6056

@@ -96,9 +92,6 @@ export function TypedTagInput({
9692
}
9793
}
9894

99-
// Minimal UI: we don't show validation messages, only subtle border changes.
100-
101-
// Render different input types based on field type
10295
switch (fieldType) {
10396
case 'boolean':
10497
return (
@@ -169,7 +162,6 @@ export function TypedTagInput({
169162
)
170163

171164
default:
172-
// text, select, or unknown types use regular input
173165
return (
174166
<div className={className}>
175167
<Input

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

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use client'
22

3-
import { useEffect, useMemo, useState } from 'react'
3+
import { useMemo, useState } from 'react'
44
import { Calendar, Hash, Plus, ToggleLeft, Trash2, Type as TypeIcon } from 'lucide-react'
55
import { Button } from '@/components/ui/button'
66
import { formatDisplayText } from '@/components/ui/formatted-text'
77
import { Input } from '@/components/ui/input'
88
import { TagDropdown } from '@/components/ui/tag-dropdown'
9-
import { MAX_TAG_SLOTS } from '@/lib/knowledge/consts'
9+
import { FIELD_TYPE_METADATA, MAX_TAG_SLOTS, SUPPORTED_FIELD_TYPES } from '@/lib/knowledge/consts'
1010
import { cn } from '@/lib/utils'
1111
import { TypedTagInput } from '@/app/workspace/[workspaceId]/knowledge/components/tag-input/typed-tag-input'
1212
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/hooks/use-sub-block-value'
@@ -51,41 +51,15 @@ export function DocumentTagEntry({
5151

5252
const emitTagSelection = useTagSelection(blockId, subBlock.id)
5353

54-
// State for field types
55-
const [fieldTypes, setFieldTypes] = useState<
56-
Array<{
57-
value: string
58-
label: string
59-
description: string
60-
}>
61-
>([{ value: 'text', label: 'Text', description: 'Free-form text content' }])
62-
63-
// Fetch field types on component mount
64-
useEffect(() => {
65-
const fetchFieldTypes = async () => {
66-
try {
67-
const response = await fetch('/api/knowledge/field-types')
68-
if (response.ok) {
69-
const result = await response.json()
70-
if (result.success) {
71-
setFieldTypes(result.data.fieldTypes)
72-
}
73-
}
74-
} catch (error) {
75-
console.error('Error fetching field types:', error)
76-
// Keep the default fallback
77-
}
78-
}
79-
80-
fetchFieldTypes()
81-
}, [])
54+
const fieldTypes = SUPPORTED_FIELD_TYPES.map((fieldType) => ({
55+
value: fieldType,
56+
label: FIELD_TYPE_METADATA[fieldType].label,
57+
description: FIELD_TYPE_METADATA[fieldType].description,
58+
}))
8259

83-
// State for dropdown visibility - one for each row
8460
const [dropdownStates, setDropdownStates] = useState<Record<number, boolean>>({})
85-
// State for type dropdown visibility - one for each row
8661
const [typeDropdownStates, setTypeDropdownStates] = useState<Record<number, boolean>>({})
8762

88-
// State for managing tag dropdown
8963
const [activeTagDropdown, setActiveTagDropdown] = useState<{
9064
rowIndex: number
9165
showTags: boolean
@@ -94,12 +68,9 @@ export function DocumentTagEntry({
9468
element?: HTMLElement | null
9569
} | null>(null)
9670

97-
// Use preview value when in preview mode, otherwise use store value
9871
const currentValue = isPreview ? previewValue : storeValue
9972

100-
// Transform stored JSON string to table format for display
10173
const rows = useMemo(() => {
102-
// If we have stored data, use it
10374
if (currentValue) {
10475
try {
10576
const tagData = JSON.parse(currentValue)
@@ -113,12 +84,9 @@ export function DocumentTagEntry({
11384
},
11485
}))
11586
}
116-
} catch {
117-
// If parsing fails, fall through to default
118-
}
87+
} catch {}
11988
}
12089

121-
// Default: just one empty row
12290
return [
12391
{
12492
id: 'empty-row-0',

0 commit comments

Comments
 (0)