Skip to content

Commit

Permalink
update data format
Browse files Browse the repository at this point in the history
  • Loading branch information
iethree committed Jan 8, 2025
1 parent 6c35e5b commit 5bc6f1c
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 98 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "next dev -p 3001",
"build": "next build",
"start": "next start",
"lint": "next lint",
Expand Down
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function Home({
const fileId = searchParams.fileId as string | undefined

const handleFileUpload = (data: DiagnosticData) => {
if (data.url && Array.isArray(data.frontendErrors) && Array.isArray(data.backendErrors)) {
if (data.basicInfo.url && Array.isArray(data.frontendErrors) && Array.isArray(data.backendErrors)) {
setDiagnosticData(data)
} else {
throw new Error('Invalid file structure: missing required data')
Expand Down
18 changes: 13 additions & 5 deletions src/components/CreateGithubIssue.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import { render, screen, fireEvent } from '../test/test-utils'

describe('CreateGithubIssue', () => {
const mockDiagnosticData = {
url: 'https://test.metabase.com',
description: 'Test description',
entityName: 'Test Entity',
basicInfo: {
url: 'https://test.metabase.com',
description: 'Test description',
},
entityInfo: {
entityName: 'Test Entity',
}
}

beforeEach(() => {
Expand Down Expand Up @@ -71,8 +75,12 @@ describe('CreateGithubIssue', () => {

it('handles missing optional data gracefully', () => {
const minimalData = {
url: '',
entityName: '',
basicInfo: {
url: '',
},
entityInfo: {
entityName: '',
}
}

render(<CreateGithubIssue diagnosticData={minimalData} />)
Expand Down
17 changes: 7 additions & 10 deletions src/components/CreateGithubIssue.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { GithubIcon } from 'lucide-react'

import { Button } from './ui/button'
import type { DiagnosticData } from '@/types/DiagnosticData'

import { Button } from './ui/button'
interface CreateGithubIssueProps {
diagnosticData: {
url: string
description?: string
entityName: string
}
diagnosticData: DiagnosticData
slackFileId?: string
}

Expand All @@ -18,16 +15,16 @@ export function CreateGithubIssue({ diagnosticData, slackFileId }: CreateGithubI
? `https://metaboat.slack.com/files/U02T6V8MXN2/${slackFileId}/diagnostic-info.json`
: null

const issueTitle = `[Bug Report] ${diagnosticData.entityName || 'Issue'} - ${
diagnosticData.url || 'No URL'
const issueTitle = `[Bug Report] ${diagnosticData.entityInfo.entityName || 'Issue'} - ${
diagnosticData.basicInfo.url || 'No URL'
}`

const issueBody = `
### Description
${diagnosticData.description || 'No description provided'}
${diagnosticData.basicInfo.description || 'No description provided'}
### Links
- Original URL: ${diagnosticData.url || 'N/A'}
- Original URL: ${diagnosticData.basicInfo.url || 'N/A'}
${slackFileUrl ? `- Slack File: ${slackFileUrl}` : ''}
- Bug Report Debugger: ${debuggerUrl}
`
Expand Down
64 changes: 36 additions & 28 deletions src/components/DevToolsUi.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@ import { render, screen } from '../test/test-utils'

describe('DevToolsUI', () => {
const sampleDiagnosticData: DiagnosticData = {
entityName: 'Test Entity',
bugReportDetails: {},
url: 'https://test.com',
description: 'Test description',
browserInfo: {
browserName: 'Chrome',
browserVersion: '100.0.0',
os: 'Windows',
osVersion: '10',
platform: 'Desktop',
language: 'en-US',
},
entityInfo: {
basicInfo: {
url: 'https://test.com',
description: 'Test description',
bugReportDetails: {},
browserInfo: {
browserName: 'Chrome',
browserVersion: '100.0.0',
os: 'Windows',
osVersion: '10',
platform: 'Desktop',
language: 'en-US',
},
'metabase-info': {},
'system-info': {},
},
entityInfo: {
entityName: 'question',
name: "Test Question's Name",
},
frontendErrors: [
'"[webpack-dev-server] ERROR in ./components/ErrorPages/utils.ts\\n × Module not found: Error message 1"',
'"[webpack-dev-server] ERROR in ./components/ErrorPages/tab.ts\\n × Module not found: Error message 1"',
Expand Down Expand Up @@ -72,7 +74,7 @@ describe('DevToolsUI', () => {
const openCall = vi.mocked(window.open).mock.calls[0][0] as string
const url = new URL(openCall)

expect(url.searchParams.get('title')).toBe('[Bug Report] Test Entity - https://test.com')
expect(url.searchParams.get('title')).toBe('[Bug Report] question - https://test.com')
expect(url.searchParams.get('body')).toContain('Test description')
expect(url.searchParams.get('body')).toContain(
'https://metaboat.slack.com/files/U02T6V8MXN2/TEST123/diagnostic-info.json'
Expand All @@ -83,16 +85,17 @@ describe('DevToolsUI', () => {
render(<DevToolsUI diagnosticData={sampleDiagnosticData} />)

// Check URL and description
expect(screen.getByText('URL:')).toBeInTheDocument()
expect(screen.getByText('url')).toBeInTheDocument()
expect(screen.getByText('https://test.com')).toBeInTheDocument()
expect(screen.getByText('Description:')).toBeInTheDocument()
expect(screen.getByText('description')).toBeInTheDocument()
expect(screen.getByText('Test description')).toBeInTheDocument()

// Check browser info
expect(screen.getByText('Browser:')).toBeInTheDocument()
expect(screen.getByText('Chrome 100.0.0')).toBeInTheDocument()
expect(screen.getByText('OS:')).toBeInTheDocument()
expect(screen.getByText('Windows 10')).toBeInTheDocument()
expect(screen.getByText('browserInfo')).toBeInTheDocument()
expect(screen.getByText('Chrome')).toBeInTheDocument()
expect(screen.getByText('100.0.0')).toBeInTheDocument()
expect(screen.getByText('os')).toBeInTheDocument()
expect(screen.getByText('Windows')).toBeInTheDocument()
})

it('switches tabs correctly', async () => {
Expand Down Expand Up @@ -129,12 +132,16 @@ describe('DevToolsUI', () => {

it('handles empty diagnostic data', () => {
const emptyData: DiagnosticData = {
entityName: '',
bugReportDetails: {},
url: '',
description: '',
browserInfo: {},
entityInfo: {},
basicInfo: {
url: '',
bugReportDetails: {},
description: '',
browserInfo: {},
},
entityInfo: {
entityName: '',
name: '',
},
frontendErrors: [],
backendErrors: [],
userLogs: [],
Expand All @@ -144,8 +151,9 @@ describe('DevToolsUI', () => {
render(<DevToolsUI diagnosticData={emptyData} />)

// Should still render without errors
expect(screen.getByText('Unknown URL')).toBeInTheDocument()
expect(screen.queryByText('Unknown browser')).not.toBeInTheDocument()
expect(screen.getByText('url')).toBeInTheDocument()
expect(screen.getByText('browserInfo')).toBeInTheDocument()
expect(screen.getByText('description')).toBeInTheDocument()
})

it('updates frontend error count', async () => {
Expand Down
30 changes: 1 addition & 29 deletions src/components/DevToolsUi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,7 @@ export const DevToolsUI = ({ diagnosticData, slackFileId }: DevToolsUIProps) =>
</div>

<TabsContent value="basicInfo" className="h-[calc(100%-3rem)]">
<div className="space-y-2">
<p>
<strong>URL:</strong> {diagnosticData.url || 'Unknown URL'}
</p>
<p>
<strong>Description:</strong> {diagnosticData.description}
</p>
{diagnosticData.browserInfo && (
<>
<p>
<strong>Browser:</strong>{' '}
{diagnosticData.browserInfo.browserName || 'Unknown browser'}{' '}
{diagnosticData.browserInfo.browserVersion || 'Unknown version'}
</p>
<p>
<strong>OS:</strong> {diagnosticData.browserInfo.os || 'Unknown OS'}{' '}
{diagnosticData.browserInfo.osVersion || 'Unknown version'}
</p>
<p>
<strong>Platform:</strong>{' '}
{diagnosticData.browserInfo.platform || 'Unknown platform'}
</p>
<p>
<strong>Language:</strong>{' '}
{diagnosticData.browserInfo.language || 'Unknown language'}
</p>
</>
)}
</div>
<MetadataTable metadata={diagnosticData.basicInfo} />
</TabsContent>
<TabsContent value="entityInfo" className="h-[calc(100%-3rem)]">
<MetadataTable metadata={diagnosticData.entityInfo} />
Expand Down
1 change: 1 addition & 0 deletions src/components/MetadataTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('MetadataTable', () => {
it('handles empty metadata object', () => {
render(<MetadataTable metadata={{}} />)
expect(screen.queryByRole('table')).not.toBeInTheDocument()
expect(screen.getByText('No data 🙁')).toBeInTheDocument()
})

it('renders nested objects correctly', () => {
Expand Down
8 changes: 5 additions & 3 deletions src/components/MetadataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ const MetadataTable: React.FC<MetadataTableProps> = ({ metadata }) => {
</div>
)

if (!metadata || !Object.keys(metadata).length) {
return <p className="text-center">No data 🙁</p>
}

return (
<ScrollArea className="h-[calc(100vh-12rem)] w-full">
{metadata.bugReportDetails && renderTable(metadata.bugReportDetails)}
{metadata['metabase-info'] && renderTable(metadata['metabase-info'])}
{metadata['system-info'] && renderTable(metadata['system-info'])}
{renderTable(metadata)}
</ScrollArea>
)
}
Expand Down
9 changes: 5 additions & 4 deletions src/components/UploadDropzone.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ describe('UploadDropzone', () => {
url: 'https://test.com',
description: 'Test description',
entityInfo: {
'metabase-info': {},
'system-info': {},
},

browserInfo: { browserName: 'Chrome' },
frontendErrors: [],
backendErrors: [],
Expand All @@ -49,8 +48,10 @@ describe('UploadDropzone', () => {
expect(mockOnFileUpload).toHaveBeenCalledTimes(1)
expect(mockOnFileUpload).toHaveBeenCalledWith(
expect.objectContaining({
url: 'https://test.com',
description: 'Test description',
basicInfo: expect.objectContaining({
url: 'https://test.com',
description: 'Test description',
})
})
)
})
Expand Down
14 changes: 7 additions & 7 deletions src/components/UploadDropzone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ const UploadDropzone: React.FC<UploadDropzoneProps> = ({ onFileUpload }) => {
const parsedData = JSON.parse(result)

const diagnosticData: DiagnosticData = {
entityName: parsedData.entityName || '',
bugReportDetails: parsedData.bugReportDetails || {},
url: parsedData.url || '',
basicInfo: {
description: parsedData.description || 'No description provided',
url: parsedData.url || 'Unknown URL',
bugReportDetails: parsedData.bugReportDetails || {},
browserInfo: parsedData.browserInfo || {},
},
entityInfo: {
entityName: parsedData.entityName || '',
...parsedData.entityInfo,
bugReportDetails: parsedData.bugReportDetails,
},
frontendErrors: Array.isArray(parsedData.frontendErrors)
? parsedData.frontendErrors
Expand All @@ -35,11 +38,8 @@ const UploadDropzone: React.FC<UploadDropzoneProps> = ({ onFileUpload }) => {
: [],
userLogs: Array.isArray(parsedData.userLogs) ? parsedData.userLogs : [],
logs: Array.isArray(parsedData.logs) ? parsedData.logs : [],
description: parsedData.description || 'No description provided',
browserInfo: parsedData.browserInfo || {},
queryResults: parsedData.queryResults || {},
}

onFileUpload(diagnosticData)
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const TableCell = React.forwardRef<
>(({ className, ...props }, ref) => (
<td
ref={ref}
className={cn('p-2 align-middle [&:has([role=checkbox])]:pr-0', className)}
className={cn('p-2 align-middle max-w-6 overflow-x-auto [&:has([role=checkbox])]:pr-0', className)}
{...props}
/>
))
Expand Down
19 changes: 10 additions & 9 deletions src/types/DiagnosticData.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
export interface DiagnosticData {
entityName: string
url: string
basicInfo: {
url: string
description?: string
bugReportDetails: Record<string, any>
browserInfo: Record<string, any>
},
entityInfo: {
bugReportDetails?: Record<string, any>
'metabase-info'?: Record<string, any>
'system-info'?: Record<string, any>
}
entityName: string
name: string
[key: string]: any
},
frontendErrors: any[]
backendErrors: any[]
userLogs: any[]
logs: any[]
bugReportDetails: Record<string, any>
description: string
browserInfo: Record<string, any>
queryResults?: {
cached: boolean | null
database_id: number
Expand Down

0 comments on commit 5bc6f1c

Please sign in to comment.