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+ const PREFIX = 23
7+ export default function ScannerExamples ( props ) {
8+
9+ console . log ( props . scanner ) ;
10+
11+ const scanner = props . scanner . substring ( PREFIX ) ;
12+ const query = graphql `
13+ query {
14+ examples: allFile(filter: {base: {regex: "/^(findings|scan).yaml/"}, extension: {eq: "yaml"}}) {
15+ edges {
16+ node {
17+ base
18+ relativeDirectory
19+ }
20+ }
21+ nodes {
22+ fields {
23+ content
24+ fileName
25+ scanTarget
26+ }
27+ }
28+ }
29+ }` ;
30+ const data = useStaticQuery ( query ) ;
31+ const targets = [ ] ;
32+ const examples = [ ] ;
33+
34+ const length = data . examples . edges . length
35+ let i ;
36+ for ( i = 0 ; i < length ; i ++ ) {
37+ const edge = data . examples . edges [ i ] ;
38+ const node = data . examples . nodes [ i ] ;
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+ return (
48+ < div className = "container-fluid" >
49+ < h2 className = "title" > Examples</ h2 >
50+ < Tabs >
51+ < TabList >
52+ { targets . map ( target => ( < Tab key = { target } > { target } </ Tab > ) ) }
53+ </ TabList >
54+ { targets . map ( target => ( < TabPanel key = { target } >
55+ < Tabs >
56+ < TabList >
57+ { /* We are reversing to ensure that the scan.yaml is shown before the findings.yaml */ }
58+ { examples . filter ( example => example . fields . scanTarget === target ) . reverse ( ) . map ( ( example , index ) => (
59+ < Tab key = { index } > { example . fields . fileName . split ( "." ) [ 0 ] } </ Tab >
60+ ) ) }
61+ </ TabList >
62+
63+ { /* We are reversing to ensure that the right text ist displayed for the right file */ }
64+ { examples . filter ( example => example . fields . scanTarget === target ) . reverse ( ) . map ( ( example , index ) => (
65+ < TabPanel key = { index } >
66+ < pre > < code > { example . fields . content } </ code > </ pre >
67+ </ TabPanel >
68+ ) ) }
69+ </ Tabs >
70+ </ TabPanel > ) ) }
71+ </ Tabs >
72+ </ div >
73+ ) ;
74+ }
0 commit comments