@@ -10,7 +10,6 @@ import EllipticLoader from "../../components/EllipticLoader";
1010interface ScanData {
1111 totalFiles : number | null ;
1212 totalDirectories : number | null ;
13- totalUniqueCopyrightHolders : number | null ;
1413}
1514import { NO_VALUE_DETECTED_LABEL } from "../../constants/data" ;
1615
@@ -20,12 +19,11 @@ const FileInfoDash = () => {
2019 const workbenchDB = useWorkbenchDB ( ) ;
2120
2221 const [ progLangsData , setProgLangsData ] = useState ( null ) ;
22+ const [ mimeTypesData , setMimeTypesData ] = useState ( null ) ;
2323 const [ fileTypesData , setFileTypesData ] = useState ( null ) ;
24- const [ copyrightHoldersData , setCopyrightHoldersData ] = useState ( null ) ;
2524 const [ scanData , setScanData ] = useState < ScanData > ( {
2625 totalFiles : null ,
2726 totalDirectories : null ,
28- totalUniqueCopyrightHolders : null ,
2927 } ) ;
3028
3129 useEffect ( ( ) => {
@@ -45,78 +43,51 @@ const FileInfoDash = () => {
4543 ? root . getDataValue ( "dirs_count" ) || 0
4644 : 0 ;
4745
48- setScanData ( ( oldScanData ) => ( {
49- ...oldScanData ,
46+ setScanData ( {
5047 totalFiles : Number ( filesCount ) ,
5148 totalDirectories : Number ( dirsCount ) ,
52- } ) ) ;
53-
54- return db . sync . then ( ( db ) =>
55- db . File . findAll ( {
56- where : {
57- type : {
58- [ Op . eq ] : "file" ,
59- } ,
60- path : {
61- [ Op . or ] : [
62- { [ Op . like ] : `${ currentPath } ` } , // Matches self
63- { [ Op . like ] : `${ currentPath } /%` } , // Matches all its children (if any).
64- ] ,
65- } ,
66- } ,
67- attributes : [ "id" , "mime_type" , "programming_language" ] ,
68- } )
69- ) ;
49+ } ) ;
50+ return db . sync ;
7051 } )
52+ . then ( ( db ) =>
53+ db . File . findAll ( {
54+ where : {
55+ type : {
56+ [ Op . eq ] : "file" ,
57+ } ,
58+ path : {
59+ [ Op . or ] : [
60+ { [ Op . like ] : `${ currentPath } ` } , // Matches self
61+ { [ Op . like ] : `${ currentPath } /%` } , // Matches all its children (if any).
62+ ] ,
63+ } ,
64+ } ,
65+ attributes : [ "id" , "file_type" , "mime_type" , "programming_language" ] ,
66+ } )
67+ )
7168 . then ( ( files ) => {
72- // Prepare chart for file types
73- const fileMimeTypes = files . map (
74- ( file ) => file . getDataValue ( "mime_type" ) || NO_VALUE_DETECTED_LABEL
75- ) ;
76- const { chartData : fileTypesChartData } = formatChartData (
77- fileMimeTypes ,
78- "file-types"
79- ) ;
80- setFileTypesData ( fileTypesChartData ) ;
81-
8269 // Prepare chart for programming languages
8370 const langs = files . map (
8471 ( file ) =>
8572 file . getDataValue ( "programming_language" ) || NO_VALUE_DETECTED_LABEL
8673 ) ;
87- const { chartData : langsChartData } = formatChartData (
88- langs ,
89- "programming-langs"
90- ) ;
74+ const { chartData : langsChartData } = formatChartData ( langs ) ;
9175 setProgLangsData ( langsChartData ) ;
9276
93- return files ;
94- } )
95- . then ( ( files ) => {
96- const fileIDs = files . map ( ( file ) => file . getDataValue ( "id" ) ) ;
97-
98- // Query data for copyright holders chart
99- db . sync
100- . then ( ( db ) => db . Copyright . findAll ( { where : { fileId : fileIDs } } ) )
101- . then ( ( copyrights ) =>
102- copyrights . map (
103- ( copyright ) =>
104- copyright . getDataValue ( "holders" ) || NO_VALUE_DETECTED_LABEL
105- )
106- )
107- . then ( ( copyrightHolders ) => {
108- setScanData ( ( oldScanData ) => ( {
109- ...oldScanData ,
110- totalUniqueCopyrightHolders : new Set ( copyrightHolders ) . size ,
111- } ) ) ;
77+ // Prepare chart for file types
78+ const fileTypes = files . map (
79+ ( file ) => file . getDataValue ( "file_type" ) || NO_VALUE_DETECTED_LABEL
80+ ) ;
81+ const { chartData : fileTypesChartData } = formatChartData ( fileTypes ) ;
82+ setFileTypesData ( fileTypesChartData ) ;
11283
113- // Prepare chart for copyright holders
114- const { chartData : copyrightHoldersChartData } = formatChartData (
115- copyrightHolders ,
116- "policy"
117- ) ;
118- setCopyrightHoldersData ( copyrightHoldersChartData ) ;
119- } ) ;
84+ // Prepare chart for mime types
85+ const fileMimeTypes = files . map (
86+ ( file ) => file . getDataValue ( "mime_type" ) || NO_VALUE_DETECTED_LABEL
87+ ) ;
88+ const { chartData : mimeTypesChartData } =
89+ formatChartData ( fileMimeTypes ) ;
90+ setMimeTypesData ( mimeTypesChartData ) ;
12091 } ) ;
12192 } , [ workbenchDB ] ) ;
12293
@@ -147,16 +118,6 @@ const FileInfoDash = () => {
147118 < h5 className = "title" > Total Number of Directories</ h5 >
148119 </ Card >
149120 </ Col >
150- < Col sm = { 6 } md = { 4 } >
151- < Card className = "info-card" >
152- { scanData . totalUniqueCopyrightHolders === null ? (
153- < EllipticLoader wrapperClass = "value" />
154- ) : (
155- < h4 className = "value" > { scanData . totalUniqueCopyrightHolders } </ h4 >
156- ) }
157- < h5 className = "title" > Unique Copyright Holders Detected</ h5 >
158- </ Card >
159- </ Col >
160121 </ Row >
161122 < br />
162123 < br />
@@ -183,11 +144,11 @@ const FileInfoDash = () => {
183144 </ Col >
184145 < Col sm = { 6 } md = { 4 } >
185146 < Card className = "chart-card" >
186- < h5 className = "title" > Copyright holders </ h5 >
147+ < h5 className = "title" > Mime types </ h5 >
187148 < PieChart
188- chartData = { copyrightHoldersData }
189- noDataText = "Use --copyright CLI option for copyright data "
190- noDataLink = "https://scancode-toolkit.readthedocs.io/en/latest/cli-reference/basic-options.html#copyright -option"
149+ chartData = { mimeTypesData }
150+ noDataText = "Use --info CLI option for mime types "
151+ noDataLink = "https://scancode-toolkit.readthedocs.io/en/latest/cli-reference/basic-options.html#info -option"
191152 />
192153 </ Card >
193154 </ Col >
0 commit comments