From b6468067860e6b5fbcb1b4212e7fd948be4924e7 Mon Sep 17 00:00:00 2001 From: Adam Gough <77861281+aadamgough@users.noreply.github.com> Date: Sun, 4 May 2025 12:39:16 -0700 Subject: [PATCH] fix(jira): jira project and issue auto loading (#324) Co-authored-by: Adam Gough --- sim/app/api/auth/oauth/jira/issue/route.ts | 1 + .../file-selector/components/jira-issue-selector.tsx | 11 ++++++++++- .../components/file-selector/file-selector-input.tsx | 8 ++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sim/app/api/auth/oauth/jira/issue/route.ts b/sim/app/api/auth/oauth/jira/issue/route.ts index 93a4049b12..f4a5ecae82 100644 --- a/sim/app/api/auth/oauth/jira/issue/route.ts +++ b/sim/app/api/auth/oauth/jira/issue/route.ts @@ -59,6 +59,7 @@ export async function POST(request: Request) { } const data = await response.json() + logger.info('Successfully fetched issue:', data.key) // Transform the Jira issue data into our expected format const issueInfo: any = { diff --git a/sim/app/w/[id]/components/workflow-block/components/sub-block/components/file-selector/components/jira-issue-selector.tsx b/sim/app/w/[id]/components/workflow-block/components/sub-block/components/file-selector/components/jira-issue-selector.tsx index 7f59de0a2a..91acd0e7dc 100644 --- a/sim/app/w/[id]/components/workflow-block/components/sub-block/components/file-selector/components/jira-issue-selector.tsx +++ b/sim/app/w/[id]/components/workflow-block/components/sub-block/components/file-selector/components/jira-issue-selector.tsx @@ -207,16 +207,24 @@ export function JiraIssueSelector({ if (!response.ok) { const errorData = await response.json() + logger.error('Failed to fetch issue info:', errorData) throw new Error(errorData.error || 'Failed to fetch issue info') } const data = await response.json() if (data.cloudId) { + logger.info('Using cloud ID:', data.cloudId) setCloudId(data.cloudId) } + if (data.issue) { + logger.info('Successfully fetched issue:', data.issue.name) setSelectedIssue(data.issue) onIssueInfoChange?.(data.issue) + } else { + logger.warn('No issue data received in response') + setSelectedIssue(null) + onIssueInfoChange?.(null) } } catch (error) { logger.error('Error fetching issue info:', error) @@ -363,6 +371,7 @@ export function JiraIssueSelector({ } }, [fetchCredentials]) + // Handle open change const handleOpenChange = (isOpen: boolean) => { setOpen(isOpen) @@ -375,7 +384,7 @@ export function JiraIssueSelector({ // Fetch selected issue metadata once credentials are ready or changed useEffect(() => { - if (value && selectedCredentialId && !selectedIssue && domain && domain.includes('.')) { + if (value && selectedCredentialId && domain && domain.includes('.') && (!selectedIssue || selectedIssue.id !== value)) { fetchIssueInfo(value) } }, [value, selectedCredentialId, selectedIssue, domain, fetchIssueInfo]) diff --git a/sim/app/w/[id]/components/workflow-block/components/sub-block/components/file-selector/file-selector-input.tsx b/sim/app/w/[id]/components/workflow-block/components/sub-block/components/file-selector/file-selector-input.tsx index 1c45125b18..c308b01f9b 100644 --- a/sim/app/w/[id]/components/workflow-block/components/sub-block/components/file-selector/file-selector-input.tsx +++ b/sim/app/w/[id]/components/workflow-block/components/sub-block/components/file-selector/file-selector-input.tsx @@ -33,9 +33,13 @@ export function FileSelectorInput({ blockId, subBlock, disabled = false }: FileS useEffect(() => { const value = getValue(blockId, subBlock.id) if (value && typeof value === 'string') { - setSelectedFileId(value) + if (isJira) { + setSelectedIssueId(value) + } else { + setSelectedFileId(value) + } } - }, [blockId, subBlock.id, getValue]) + }, [blockId, subBlock.id, getValue, isJira]) // Handle file selection const handleFileChange = (fileId: string, info?: any) => {