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
Expand Up @@ -2,12 +2,16 @@

import { useCallback, useMemo } from 'react'
import { Tooltip } from '@/components/emcn'
import { buildCanonicalIndex, resolveDependencyValue } from '@/lib/workflows/subblocks/visibility'
import { SelectorCombobox } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/selector-combobox/selector-combobox'
import { useDependsOnGate } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-depends-on-gate'
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
import { resolvePreviewContextValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/utils'
import { getBlock } from '@/blocks/registry'
import type { SubBlockConfig } from '@/blocks/types'
import type { SelectorContext } from '@/hooks/selectors/types'
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
import { useWorkflowStore } from '@/stores/workflows/workflow/store'

interface DocumentSelectorProps {
blockId: string
Expand All @@ -28,15 +32,41 @@ export function DocumentSelector({
previewValue,
previewContextValues,
}: DocumentSelectorProps) {
const { activeWorkflowId } = useWorkflowRegistry()

const { finalDisabled } = useDependsOnGate(blockId, subBlock, {
disabled,
isPreview,
previewContextValues,
})
const [knowledgeBaseIdFromStore] = useSubBlockValue(blockId, 'knowledgeBaseId')
const knowledgeBaseIdValue = previewContextValues
? resolvePreviewContextValue(previewContextValues.knowledgeBaseId)
: knowledgeBaseIdFromStore

const blockState = useWorkflowStore((state) => state.blocks[blockId])
const blockConfig = blockState?.type ? getBlock(blockState.type) : null
const canonicalIndex = useMemo(
() => buildCanonicalIndex(blockConfig?.subBlocks || []),
[blockConfig?.subBlocks]
)
const canonicalModeOverrides = blockState?.data?.canonicalModes

const blockValues = useSubBlockStore((state) => {
if (!activeWorkflowId) return {}
const workflowValues = state.workflowValues[activeWorkflowId] || {}
return (workflowValues as Record<string, Record<string, unknown>>)[blockId] || {}
})

const knowledgeBaseIdValue = useMemo(
() =>
previewContextValues
? resolvePreviewContextValue(previewContextValues.knowledgeBaseId)
: resolveDependencyValue(
'knowledgeBaseId',
blockValues,
canonicalIndex,
canonicalModeOverrides
),
[previewContextValues, blockValues, canonicalIndex, canonicalModeOverrides]
)

const normalizedKnowledgeBaseId =
typeof knowledgeBaseIdValue === 'string' && knowledgeBaseIdValue.trim().length > 0
? knowledgeBaseIdValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ import {
} from '@/components/emcn'
import { cn } from '@/lib/core/utils/cn'
import { FIELD_TYPE_LABELS, getPlaceholderForFieldType } from '@/lib/knowledge/constants'
import { buildCanonicalIndex, resolveDependencyValue } from '@/lib/workflows/subblocks/visibility'
import { formatDisplayText } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/formatted-text'
import { TagDropdown } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tag-dropdown/tag-dropdown'
import { useSubBlockInput } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-input'
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
import { resolvePreviewContextValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/utils'
import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-accessible-reference-prefixes'
import { getBlock } from '@/blocks/registry'
import type { SubBlockConfig } from '@/blocks/types'
import { useKnowledgeBaseTagDefinitions } from '@/hooks/kb/use-knowledge-base-tag-definitions'
import { useTagSelection } from '@/hooks/kb/use-tag-selection'
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
import { useWorkflowStore } from '@/stores/workflows/workflow/store'

interface DocumentTag {
id: string
Expand Down Expand Up @@ -60,11 +65,26 @@ export function DocumentTagEntry({
previewValue,
previewContextValues,
}: DocumentTagEntryProps) {
const { activeWorkflowId } = useWorkflowRegistry()
const [storeValue, setStoreValue] = useSubBlockValue<string>(blockId, subBlock.id)
const accessiblePrefixes = useAccessibleReferencePrefixes(blockId)
const valueInputRefs = useRef<Record<string, HTMLInputElement>>({})
const overlayRefs = useRef<Record<string, HTMLDivElement>>({})

const blockState = useWorkflowStore((state) => state.blocks[blockId])
const blockConfig = blockState?.type ? getBlock(blockState.type) : null
const canonicalIndex = useMemo(
() => buildCanonicalIndex(blockConfig?.subBlocks || []),
[blockConfig?.subBlocks]
)
const canonicalModeOverrides = blockState?.data?.canonicalModes

const blockValues = useSubBlockStore((state) => {
if (!activeWorkflowId) return {}
const workflowValues = state.workflowValues[activeWorkflowId] || {}
return (workflowValues as Record<string, Record<string, unknown>>)[blockId] || {}
})

const inputController = useSubBlockInput({
blockId,
subBlockId: subBlock.id,
Expand All @@ -77,10 +97,18 @@ export function DocumentTagEntry({
disabled,
})

const [knowledgeBaseIdFromStore] = useSubBlockValue(blockId, 'knowledgeBaseId')
const knowledgeBaseIdValue = previewContextValues
? resolvePreviewContextValue(previewContextValues.knowledgeBaseId)
: knowledgeBaseIdFromStore
const knowledgeBaseIdValue = useMemo(
() =>
previewContextValues
? resolvePreviewContextValue(previewContextValues.knowledgeBaseId)
: resolveDependencyValue(
'knowledgeBaseId',
blockValues,
canonicalIndex,
canonicalModeOverrides
),
[previewContextValues, blockValues, canonicalIndex, canonicalModeOverrides]
)
const knowledgeBaseId =
typeof knowledgeBaseIdValue === 'string' && knowledgeBaseIdValue.trim().length > 0
? knowledgeBaseIdValue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { useRef } from 'react'
import { useMemo, useRef } from 'react'
import { Plus } from 'lucide-react'
import {
Badge,
Expand All @@ -14,14 +14,19 @@ import {
import { cn } from '@/lib/core/utils/cn'
import { FIELD_TYPE_LABELS, getPlaceholderForFieldType } from '@/lib/knowledge/constants'
import { type FilterFieldType, getOperatorsForFieldType } from '@/lib/knowledge/filters/types'
import { buildCanonicalIndex, resolveDependencyValue } from '@/lib/workflows/subblocks/visibility'
import { formatDisplayText } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/formatted-text'
import { TagDropdown } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tag-dropdown/tag-dropdown'
import { useSubBlockInput } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-input'
import { resolvePreviewContextValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/utils'
import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-accessible-reference-prefixes'
import { getBlock } from '@/blocks/registry'
import type { SubBlockConfig } from '@/blocks/types'
import { useKnowledgeBaseTagDefinitions } from '@/hooks/kb/use-knowledge-base-tag-definitions'
import { useTagSelection } from '@/hooks/kb/use-tag-selection'
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
import { useSubBlockValue } from '../../hooks/use-sub-block-value'

interface TagFilter {
Expand Down Expand Up @@ -64,15 +69,38 @@ export function KnowledgeTagFilters({
previewValue,
previewContextValues,
}: KnowledgeTagFiltersProps) {
const { activeWorkflowId } = useWorkflowRegistry()
const [storeValue, setStoreValue] = useSubBlockValue<string | null>(blockId, subBlock.id)
const emitTagSelection = useTagSelection(blockId, subBlock.id)
const valueInputRefs = useRef<Record<string, HTMLInputElement>>({})
const overlayRefs = useRef<Record<string, HTMLDivElement>>({})

const [knowledgeBaseIdFromStore] = useSubBlockValue(blockId, 'knowledgeBaseId')
const knowledgeBaseIdValue = previewContextValues
? resolvePreviewContextValue(previewContextValues.knowledgeBaseId)
: knowledgeBaseIdFromStore
const blockState = useWorkflowStore((state) => state.blocks[blockId])
const blockConfig = blockState?.type ? getBlock(blockState.type) : null
const canonicalIndex = useMemo(
() => buildCanonicalIndex(blockConfig?.subBlocks || []),
[blockConfig?.subBlocks]
)
const canonicalModeOverrides = blockState?.data?.canonicalModes

const blockValues = useSubBlockStore((state) => {
if (!activeWorkflowId) return {}
const workflowValues = state.workflowValues[activeWorkflowId] || {}
return (workflowValues as Record<string, Record<string, unknown>>)[blockId] || {}
})

const knowledgeBaseIdValue = useMemo(
() =>
previewContextValues
? resolvePreviewContextValue(previewContextValues.knowledgeBaseId)
: resolveDependencyValue(
'knowledgeBaseId',
blockValues,
canonicalIndex,
canonicalModeOverrides
),
[previewContextValues, blockValues, canonicalIndex, canonicalModeOverrides]
)
const knowledgeBaseId =
typeof knowledgeBaseIdValue === 'string' && knowledgeBaseIdValue.trim().length > 0
? knowledgeBaseIdValue
Expand Down
2 changes: 2 additions & 0 deletions apps/sim/blocks/blocks/confluence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const ConfluenceBlock: BlockConfig<ConfluenceResponse> = {
type: 'file-selector',
canonicalParamId: 'pageId',
serviceId: 'confluence',
selectorKey: 'confluence.pages',
placeholder: 'Select Confluence page',
dependsOn: ['credential', 'domain'],
mode: 'basic',
Expand Down Expand Up @@ -498,6 +499,7 @@ export const ConfluenceV2Block: BlockConfig<ConfluenceResponse> = {
type: 'file-selector',
canonicalParamId: 'pageId',
serviceId: 'confluence',
selectorKey: 'confluence.pages',
placeholder: 'Select Confluence page',
dependsOn: ['credential', 'domain'],
mode: 'basic',
Expand Down
4 changes: 4 additions & 0 deletions apps/sim/blocks/blocks/gmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ Return ONLY the email body - no explanations, no extra text.`,
type: 'folder-selector',
canonicalParamId: 'folder',
serviceId: 'gmail',
selectorKey: 'gmail.labels',
requiredScopes: ['https://www.googleapis.com/auth/gmail.labels'],
placeholder: 'Select Gmail label/folder',
dependsOn: ['credential'],
Expand Down Expand Up @@ -301,6 +302,7 @@ Return ONLY the search query - no explanations, no extra text.`,
type: 'folder-selector',
canonicalParamId: 'addLabelIds',
serviceId: 'gmail',
selectorKey: 'gmail.labels',
requiredScopes: ['https://www.googleapis.com/auth/gmail.labels'],
placeholder: 'Select destination label',
dependsOn: ['credential'],
Expand All @@ -326,6 +328,7 @@ Return ONLY the search query - no explanations, no extra text.`,
type: 'folder-selector',
canonicalParamId: 'removeLabelIds',
serviceId: 'gmail',
selectorKey: 'gmail.labels',
requiredScopes: ['https://www.googleapis.com/auth/gmail.labels'],
placeholder: 'Select label to remove',
dependsOn: ['credential'],
Expand Down Expand Up @@ -378,6 +381,7 @@ Return ONLY the search query - no explanations, no extra text.`,
type: 'folder-selector',
canonicalParamId: 'manageLabelId',
serviceId: 'gmail',
selectorKey: 'gmail.labels',
requiredScopes: ['https://www.googleapis.com/auth/gmail.labels'],
placeholder: 'Select label',
dependsOn: ['credential'],
Expand Down
4 changes: 4 additions & 0 deletions apps/sim/blocks/blocks/google_calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export const GoogleCalendarBlock: BlockConfig<GoogleCalendarResponse> = {
type: 'file-selector',
canonicalParamId: 'calendarId',
serviceId: 'google-calendar',
selectorKey: 'google.calendar',
selectorAllowSearch: false,
requiredScopes: ['https://www.googleapis.com/auth/calendar'],
placeholder: 'Select calendar',
dependsOn: ['credential'],
Expand Down Expand Up @@ -326,6 +328,8 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
type: 'file-selector',
canonicalParamId: 'destinationCalendarId',
serviceId: 'google-calendar',
selectorKey: 'google.calendar',
selectorAllowSearch: false,
requiredScopes: ['https://www.googleapis.com/auth/calendar'],
placeholder: 'Select destination calendar',
dependsOn: ['credential'],
Expand Down
2 changes: 2 additions & 0 deletions apps/sim/blocks/blocks/google_docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const GoogleDocsBlock: BlockConfig<GoogleDocsResponse> = {
type: 'file-selector',
canonicalParamId: 'documentId',
serviceId: 'google-docs',
selectorKey: 'google.drive',
requiredScopes: [],
mimeType: 'application/vnd.google-apps.document',
placeholder: 'Select a document',
Expand Down Expand Up @@ -100,6 +101,7 @@ Return ONLY the document title - no explanations, no extra text.`,
type: 'file-selector',
canonicalParamId: 'folderId',
serviceId: 'google-docs',
selectorKey: 'google.drive',
requiredScopes: [],
mimeType: 'application/vnd.google-apps.folder',
placeholder: 'Select a parent folder',
Expand Down
13 changes: 13 additions & 0 deletions apps/sim/blocks/blocks/google_drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Return ONLY the file content - no explanations, no markdown code blocks, no extr
type: 'file-selector',
canonicalParamId: 'uploadFolderId',
serviceId: 'google-drive',
selectorKey: 'google.drive',
requiredScopes: [
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive',
Expand Down Expand Up @@ -209,6 +210,7 @@ Return ONLY the file content - no explanations, no markdown code blocks, no extr
type: 'file-selector',
canonicalParamId: 'createFolderParentId',
serviceId: 'google-drive',
selectorKey: 'google.drive',
requiredScopes: [
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive',
Expand Down Expand Up @@ -236,6 +238,7 @@ Return ONLY the file content - no explanations, no markdown code blocks, no extr
type: 'file-selector',
canonicalParamId: 'listFolderId',
serviceId: 'google-drive',
selectorKey: 'google.drive',
requiredScopes: [
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive',
Expand Down Expand Up @@ -295,6 +298,7 @@ Return ONLY the query string - no explanations, no quotes around the whole thing
type: 'file-selector',
canonicalParamId: 'downloadFileId',
serviceId: 'google-drive',
selectorKey: 'google.drive',
requiredScopes: [
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive',
Expand Down Expand Up @@ -356,6 +360,7 @@ Return ONLY the query string - no explanations, no quotes around the whole thing
type: 'file-selector',
canonicalParamId: 'getFileId',
serviceId: 'google-drive',
selectorKey: 'google.drive',
requiredScopes: [
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive',
Expand Down Expand Up @@ -383,6 +388,7 @@ Return ONLY the query string - no explanations, no quotes around the whole thing
type: 'file-selector',
canonicalParamId: 'copyFileId',
serviceId: 'google-drive',
selectorKey: 'google.drive',
requiredScopes: [
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive',
Expand Down Expand Up @@ -416,6 +422,7 @@ Return ONLY the query string - no explanations, no quotes around the whole thing
type: 'file-selector',
canonicalParamId: 'copyDestFolderId',
serviceId: 'google-drive',
selectorKey: 'google.drive',
requiredScopes: [
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive',
Expand All @@ -442,6 +449,7 @@ Return ONLY the query string - no explanations, no quotes around the whole thing
type: 'file-selector',
canonicalParamId: 'updateFileId',
serviceId: 'google-drive',
selectorKey: 'google.drive',
requiredScopes: [
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive',
Expand Down Expand Up @@ -520,6 +528,7 @@ Return ONLY the description text - no explanations, no quotes, no extra text.`,
type: 'file-selector',
canonicalParamId: 'trashFileId',
serviceId: 'google-drive',
selectorKey: 'google.drive',
requiredScopes: [
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive',
Expand Down Expand Up @@ -547,6 +556,7 @@ Return ONLY the description text - no explanations, no quotes, no extra text.`,
type: 'file-selector',
canonicalParamId: 'deleteFileId',
serviceId: 'google-drive',
selectorKey: 'google.drive',
requiredScopes: [
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive',
Expand Down Expand Up @@ -574,6 +584,7 @@ Return ONLY the description text - no explanations, no quotes, no extra text.`,
type: 'file-selector',
canonicalParamId: 'shareFileId',
serviceId: 'google-drive',
selectorKey: 'google.drive',
requiredScopes: [
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive',
Expand Down Expand Up @@ -688,6 +699,7 @@ Return ONLY the message text - no subject line, no greetings/signatures, no extr
type: 'file-selector',
canonicalParamId: 'unshareFileId',
serviceId: 'google-drive',
selectorKey: 'google.drive',
requiredScopes: [
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive',
Expand Down Expand Up @@ -723,6 +735,7 @@ Return ONLY the message text - no subject line, no greetings/signatures, no extr
type: 'file-selector',
canonicalParamId: 'listPermissionsFileId',
serviceId: 'google-drive',
selectorKey: 'google.drive',
requiredScopes: [
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive',
Expand Down
1 change: 1 addition & 0 deletions apps/sim/blocks/blocks/google_forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const GoogleFormsBlock: BlockConfig = {
canonicalParamId: 'formId',
required: true,
serviceId: 'google-forms',
selectorKey: 'google.drive',
requiredScopes: [],
mimeType: 'application/vnd.google-apps.form',
placeholder: 'Select a form',
Expand Down
Loading