Skip to content

Commit

Permalink
feat: adds dependency graph page (#114)
Browse files Browse the repository at this point in the history
* dep graph

* working but not useful

* 3d dep graph

* imporve search / filter

imporve search / filter

imporve search / filter

* remove comments / gitignore bundle analysis

* remove dummy data file blocks.json

---------

Co-authored-by: Kris Stern <[email protected]>
  • Loading branch information
shlomomdahan and krisstern authored Jul 29, 2024
1 parent 9a38909 commit 9d85aad
Show file tree
Hide file tree
Showing 12 changed files with 2,229 additions and 437 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ dist-ssr

# infra-statistics
src/data/infra-statistics

# bundle analyzer
bundle-analysis.html
2 changes: 1 addition & 1 deletion bundle-analysis.html

Large diffs are not rendered by default.

2,144 changes: 1,710 additions & 434 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"@fontsource/roboto": "^5.0.13",
"@jenkinsci/jenkins-io-components": "^1.30.1",
"@mui/icons-material": "^5.15.18",
"@react-three/fiber": "^8.16.8",
"@tanstack/react-query": "^5.51.11",
"axios": "^1.7.2",
"cheerio": "^1.0.0-rc.12",
"dayjs": "^1.11.11",
Expand All @@ -27,17 +29,22 @@
"papaparse": "^5.4.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-force-graph": "^1.44.4",
"react-force-graph-2d": "^1.25.5",
"react-force-graph-3d": "^1.24.3",
"react-icons": "^5.2.1",
"react-responsive": "^10.0.0",
"react-router-dom": "^6.23.1",
"react-window": "^1.8.10"
"react-window": "^1.8.10",
"three": "^0.167.0"
},
"devDependencies": {
"@types/jsdom": "^21.1.7",
"@types/papaparse": "^5.3.14",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react-window": "^1.8.8",
"@types/three": "^0.167.1",
"@typescript-eslint/eslint-plugin": "^7.11.0",
"@typescript-eslint/parser": "^7.11.0",
"@vitejs/plugin-react": "^4.3.0",
Expand Down
21 changes: 21 additions & 0 deletions src/components/DependencyGraph/BackToHome.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react'
import { Button, Box } from '@mui/material'

const BackToHome: React.FC = () => (
<Box sx={{ width: '100%', marginBottom: '12px' }}>
<Button
size="small"
onClick={() => (window.location.href = '/')}
sx={{
color: 'white',
'&:hover': {
color: '#2196f3',
},
}}
>
&larr; Back to Home
</Button>
</Box>
)

export default BackToHome
90 changes: 90 additions & 0 deletions src/components/DependencyGraph/GraphTools.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import React from 'react'
import { Box, Button, TextField, Typography } from '@mui/material'
import BackToHome from './BackToHome'

interface GraphToolsProps {
searchTerm: string
// eslint-disable-next-line no-unused-vars
handleSearchChange: (event: React.ChangeEvent<HTMLInputElement>) => void
// eslint-disable-next-line no-unused-vars
setSearchTerm: (value: string) => void
}

const GraphTools: React.FC<GraphToolsProps> = ({ searchTerm, handleSearchChange, setSearchTerm }) => {
return (
<>
<BackToHome />
<Box
sx={{
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
}}
>
<TextField
label="Filter Plugins by Name / Maintainer"
variant="outlined"
value={searchTerm}
onChange={handleSearchChange}
sx={{
width: '300px',
marginRight: '10px',
'& .MuiOutlinedInput-root': {
'& fieldset': {
borderColor: 'rgba(255, 255, 255, 0.2)',
borderRadius: '8px',
},
'&:hover fieldset': {
borderColor: '#2196f3',
},
'&.Mui-focused fieldset': {
borderColor: '#2196f3',
},
backgroundColor: 'rgba(255, 255, 255, 0.1)',
},
'& .MuiInputLabel-root': {
color: 'white',
},
'& .MuiInputBase-input': {
color: 'white',
},
}}
InputLabelProps={{
style: { color: 'white' },
}}
InputProps={{
style: { color: 'white' },
}}
/>
<Button
onClick={() => setSearchTerm('')}
sx={{
backgroundColor: 'rgba(255, 255, 255, 0.1)',
color: 'white',
border: '1px solid rgba(255, 255, 255, 0.2)',
padding: '10px',
borderRadius: '8px',
cursor: 'pointer',
'&:hover': {
backgroundColor: 'rgba(255, 255, 255, 0.2)',
borderColor: '#2196f3',
},
}}
>
Clear
</Button>
</Box>
<Typography
sx={{
color: 'white',
marginTop: '10px',
marginLeft: '10px',
}}
>
drag / drop / hover / click any node...
</Typography>
</>
)
}

export default GraphTools
43 changes: 43 additions & 0 deletions src/hooks/useGetDependencyGraphData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { useState, useEffect } from 'react'
import { PluginData, PluginNode } from '../types/types'

const usePluginData = () => {
const [plugins, setPlugins] = useState<PluginNode[]>([])
const [loading, setLoading] = useState<boolean>(true)
const [error, setError] = useState<string | null>(null)

useEffect(() => {
const fetchPlugins = async () => {
try {
const fileUrl = new URL(`../data/infra-statistics/update-center.actual.json`, import.meta.url).href
const response = await fetch(fileUrl)
if (!response.ok) {
throw new Error('Network response was not ok')
}
const data: PluginData = (await response.json()) as PluginData

const pluginArray = Object.keys(data.plugins).map((key) => {
const plugin = data.plugins[key]
return {
...plugin,
defaultBranch: plugin.defaultBranch || 'N/A',
scm: plugin.scm || 'N/A',
issueTrackers: plugin.issueTrackers || [],
}
})

setPlugins(pluginArray)
} catch (error) {
setError((error as Error).message)
} finally {
setLoading(false)
}
}

fetchPlugins()
}, [])

return { plugins, loading, error }
}

export default usePluginData
5 changes: 5 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ThemeProvider } from '@mui/material/styles'
import theme from './theme/theme.ts'
import PluginTrends from './pages/plugin-trends/index.tsx'
import PluginVersions from './pages/plugin-versions/index.tsx'
import DependencyGraph from './pages/dep-graph/index.tsx'
import NavBar from './components/Layout/NavBar.tsx'
import { Stack } from '@mui/material'

Expand All @@ -28,6 +29,10 @@ const router = createBrowserRouter([
path: '/plugin-versions',
element: <PluginVersions />,
},
{
path: '/dep-graph',
element: <DependencyGraph />,
},
])

ReactDOM.createRoot(document.getElementById('root')!).render(
Expand Down
Loading

0 comments on commit 9d85aad

Please sign in to comment.