1+ import React from "react"
2+ import { useStaticQuery , graphql } from "gatsby"
3+ import { Tab , Tabs , TabList , TabPanel } from 'react-tabs' ;
4+ import 'react-tabs/style/react-tabs.css' ;
5+
6+ export default function ScannerExamples ( props ) {
7+
8+ const scanner = 'nmap' ;
9+ const query = graphql `
10+ query {
11+ examples: allFile(filter: {base: {regex: "/^(findings|scan).yaml/"}, extension: {eq: "yaml"}}) {
12+ edges {
13+ node {
14+ base
15+ relativeDirectory
16+ }
17+ }
18+ nodes {
19+ fields {
20+ content
21+ fileName
22+ scanTarget
23+ }
24+ }
25+ }
26+ }` ;
27+ const data = useStaticQuery ( query ) ;
28+ console . log ( "Results for query" ) ;
29+ console . log ( data ) ;
30+ const targets = [ ] ;
31+ const examples = [ ] ;
32+
33+ const length = data . examples . edges . length
34+ let i ;
35+ for ( i = 0 ; i < length ; i ++ ) {
36+ const edge = data . examples . edges [ i ] ;
37+ const node = data . examples . nodes [ i ] ;
38+ console . log ( edge . node . relativeDirectory )
39+ if ( edge . node . relativeDirectory . includes ( scanner ) ) {
40+ const target = data . examples . nodes [ i ] . fields . scanTarget
41+ if ( ! targets . includes ( target ) ) {
42+ targets . push ( target ) ;
43+ examples . push ( node ) ;
44+ }
45+ }
46+ }
47+
48+ console . log ( targets ) ;
49+ console . log ( examples ) ;
50+
51+ return (
52+ < div className = "container-fluid" >
53+ < h2 className = "title" > Examples</ h2 >
54+
55+ < Tabs >
56+ < TabList >
57+ { targets . map ( target => ( < Tab key = { target } > { target } </ Tab > ) ) }
58+ </ TabList >
59+ { targets . map ( target => ( < TabPanel key = { target } >
60+ < Tabs > < TabList >
61+ { examples . reverse ( ) . filter ( example => example . fields . scanTarget === target ) . map ( ( example , index ) => (
62+ < Tab key = { index } > { example . fields . fileName } </ Tab >
63+ ) ) }
64+ </ TabList >
65+
66+ { examples . filter ( example => example . fields . scanTarget === target ) . map ( ( example , index ) => (
67+ < TabPanel key = { index } >
68+ < pre > < code > { example . fields . content } </ code > </ pre >
69+ </ TabPanel >
70+ ) ) }
71+ </ Tabs >
72+ </ TabPanel > ) ) }
73+ </ Tabs >
74+ </ div >
75+ ) ;
76+ }
0 commit comments