1
- import React , { useState } from 'react' ;
1
+ import React , { useEffect } from 'react' ;
2
2
import TableCell from '@material-ui/core/TableCell' ;
3
3
import TableRow from '@material-ui/core/TableRow' ;
4
4
import GridContainer from '../../../components/Grid/GridContainer' ;
5
5
import GridItem from '../../../components/Grid/GridItem' ;
6
6
import { CodeReviewIcon , LawIcon , PeopleIcon } from '@primer/octicons-react' ;
7
7
8
8
9
-
10
-
11
9
const colors = {
12
10
'1C Enterprise' : '#814CCC' ,
13
11
'2-Dimensional Array' : '#38761D' ,
@@ -568,149 +566,110 @@ const colors = {
568
566
Zimpl : '#d67711' ,
569
567
} ;
570
568
571
- // import axios from 'axios';
569
+ import axios from 'axios' ;
572
570
import moment from 'moment' ;
573
571
import CodeActionButton from '../../../components/CustomButtons/CodeActionButton' ;
574
- import Pagination from '../../../components/Pagination/Pagination' ;
575
- import Search from '../../../components/Search/Search' ;
576
572
577
573
export default function Repositories ( props ) {
578
- // const [github, setGitHub] = React.useState({});
579
- // const [repositories, setRepositories] = useState([]); // To hold all repositories
580
- const [ currentPage , setCurrentPage ] = useState ( 1 ) ;
581
- const [ searchQuery , setSearchQuery ] = useState ( '' ) ;
582
- const itemsPerPage = 5 ;
583
-
584
-
585
- // Dummy repository data```````````
586
- const dummyRepositories = [
587
- { project : 'Org1' , name : 'Repo1' , description : 'Description for Repo 1' } ,
588
- { project : 'Org2' , name : 'Repo2' , description : 'Description for Repo 2' } ,
589
- { project : 'Org3' , name : 'Repo3' , description : 'Description for Repo 3' } ,
590
- { project : 'Org4' , name : 'Repo4' , description : 'Description for Repo 4' } ,
591
- { project : 'Org5' , name : 'Repo5' , description : 'Description for Repo 5' } ,
592
- { project : 'Org6' , name : 'Repo6' , description : 'Description for Repo 6' } ,
593
- // Add more dummy repositories as needed
594
- ] ;
595
-
596
-
597
- // useEffect(() => {
598
- // getGitHubRepository();
599
- // }, [props.data.project, props.data.name]);
600
-
601
- // const getGitHubRepository = async () => {
602
- // try {
603
- // const res = await axios.get(
604
- // `https://api.github.com/repos/${props.data.project}/${props.data.name}`
605
- // );
606
- // setRepositories([res.data]); // Store the single repository in an array
607
- // } catch (error) {
608
- // console.error("Failed to fetch repository", error);
609
- // }
610
- // };
611
-
612
-
613
- // Handle search functionality
614
- const handleSearch = ( query ) => {
615
- setSearchQuery ( query ) ;
616
- setCurrentPage ( 1 ) ; // Reset to first page when searching
617
- } ;
618
-
619
- // Filter repositories based on search query
620
- const filteredRepositories = dummyRepositories . filter ( repo =>
621
- repo . name . toLowerCase ( ) . includes ( searchQuery . toLowerCase ( ) )
622
- ) ;
623
-
574
+ const [ github , setGitHub ] = React . useState ( { } ) ;
624
575
576
+ useEffect ( ( ) => {
577
+ getGitHubRepository ( ) ;
578
+ } , [ props . data . project , props . data . name ] ) ;
625
579
626
- // Pagination logic to get current items for the page
627
- const indexOfLastItem = currentPage * itemsPerPage ;
628
- const indexOfFirstItem = indexOfLastItem - itemsPerPage ;
629
- const currentItems = filteredRepositories . slice ( indexOfFirstItem , indexOfLastItem ) ;
630
-
631
- const handlePageChange = ( page ) => {
632
- setCurrentPage ( page ) ;
580
+ const getGitHubRepository = async ( ) => {
581
+ await axios
582
+ . get ( `https://api.github.com/repos/${ props . data . project } /${ props . data . name } ` )
583
+ . then ( ( res ) => {
584
+ setGitHub ( res . data ) ;
585
+ } ) ;
633
586
} ;
634
587
635
588
const { project : org , name } = props ?. data || { } ;
636
589
const cloneURL = `${ window . location . origin . toString ( ) } /${ org } /${ name } .git` ;
637
590
638
591
return (
639
- < >
640
-
641
- < Search onSearch = { handleSearch } placeholder = "Search repositories..." />
642
-
643
-
644
- { currentItems . map ( ( repo , index ) => (
645
- < TableRow key = { index } >
646
- < TableCell >
647
- < div style = { { padding : '15px' } } >
648
- < a href = { `/admin/repo/${ props . data . name } ` } >
649
- < span style = { { fontSize : '17px' } } >
650
- { repo . project } /{ repo . name }
651
- </ span >
592
+ < TableRow >
593
+ < TableCell >
594
+ < div style = { { padding : '15px' } } >
595
+ < a href = { `/admin/repo/${ props . data . name } ` } >
596
+ < span style = { { fontSize : '17px' } } >
597
+ { props . data . project } /{ props . data . name }
598
+ </ span >
599
+ </ a >
600
+ { github . parent && (
601
+ < span
602
+ style = { {
603
+ fontSize : '11.5px' ,
604
+ display : 'block' ,
605
+ opacity : 0.8 ,
606
+ } }
607
+ >
608
+ Forked from{ ' ' }
609
+ < a
610
+ style = { {
611
+ fontWeight : 'normal' ,
612
+ color : 'inherit' ,
613
+ } }
614
+ href = { github . parent . html_url }
615
+ >
616
+ { github . parent . full_name }
652
617
</ a >
653
- { repo . parent && (
654
- < span style = { { fontSize : '11.5px' , display : 'block' , opacity : 0.8 } } >
655
- Forked from{ ' ' }
656
- < a style = { { fontWeight : 'normal' , color : 'inherit' } } href = { repo . parent . html_url } >
657
- { repo . parent . full_name }
658
- </ a >
659
- </ span >
660
- ) }
661
- { repo . description && < p style = { { maxWidth : '80%' } } > { repo . description } </ p > }
662
- < GridContainer >
663
- { repo . language && (
664
- < GridItem >
665
- < span
666
- style = { {
667
- height : '12px' ,
668
- width : '12px' ,
669
- backgroundColor : `${ colors [ repo . language ] } ` ,
670
- borderRadius : '50px' ,
671
- display : 'inline-block' ,
672
- marginRight : '5px' ,
673
- } }
674
- > </ span >
675
- { repo . language }
676
- </ GridItem >
677
- ) }
678
- { repo . license && (
679
- < GridItem >
680
- < LawIcon size = "small" /> < span style = { { marginLeft : '5px' } } > { repo . license . spdx_id } </ span >
681
- </ GridItem >
682
- ) }
683
- < GridItem >
684
- < PeopleIcon size = "small" /> < span style = { { marginLeft : '5px' } } > { props . data . users ?. canPush ?. length || 0 } </ span >
685
- </ GridItem >
686
- < GridItem >
687
- < CodeReviewIcon size = "small" /> < span style = { { marginLeft : '5px' } } > { props . data . users ?. canAuthorise ?. length || 0 } </ span >
688
- </ GridItem >
689
- { ( repo . created_at || repo . updated_at || repo . pushed_at ) && (
690
- < GridItem >
691
- Last updated { moment . max ( [ moment ( repo . created_at ) , moment ( repo . updated_at ) , moment ( repo . pushed_at ) ] ) . fromNow ( ) }
692
- </ GridItem >
693
- ) }
694
- </ GridContainer >
695
- </ div >
696
- </ TableCell >
697
- < TableCell align = "right" >
698
- < div style = { { padding : '15px' } } >
699
- < CodeActionButton cloneURL = { cloneURL } />
700
- </ div >
701
- </ TableCell >
702
- </ TableRow >
703
- ) ) }
704
-
705
- { /* Render the Pagination component */ }
706
- < Pagination
707
- currentPage = { currentPage }
708
- totalItems = { filteredRepositories . length } // Use filtered repositories for pagination
709
- itemsPerPage = { itemsPerPage }
710
- onPageChange = { handlePageChange }
711
- />
712
-
713
- </ >
714
-
618
+ </ span >
619
+ ) }
620
+ { github . description && < p style = { { maxWidth : '80%' } } > { github . description } </ p > }
621
+ < GridContainer >
622
+ { github . language && (
623
+ < GridItem >
624
+ < span
625
+ style = { {
626
+ height : '12px' ,
627
+ width : '12px' ,
628
+ backgroundColor : `${ colors [ github . language ] } ` ,
629
+ borderRadius : '50px' ,
630
+ display : 'inline-block' ,
631
+ marginRight : '5px' ,
632
+ } }
633
+ > </ span >
634
+ { github . language }
635
+ </ GridItem >
636
+ ) }
637
+ { github . license && (
638
+ < GridItem >
639
+ < LawIcon size = 'small' /> { ' ' }
640
+ < span style = { { marginLeft : '5px' } } > { github . license . spdx_id } </ span >
641
+ </ GridItem >
642
+ ) }
643
+ < GridItem >
644
+ < PeopleIcon size = 'small' /> { ' ' }
645
+ < span style = { { marginLeft : '5px' } } > { props . data . users ?. canPush ?. length || 0 } </ span >
646
+ </ GridItem >
647
+ < GridItem >
648
+ < CodeReviewIcon size = 'small' /> { ' ' }
649
+ < span style = { { marginLeft : '5px' } } >
650
+ { props . data . users ?. canAuthorise ?. length || 0 }
651
+ </ span >
652
+ </ GridItem >
653
+ { ( github . created_at || github . updated_at || github . pushed_at ) && (
654
+ < GridItem >
655
+ Last updated{ ' ' }
656
+ { moment
657
+ . max ( [
658
+ moment ( github . created_at ) ,
659
+ moment ( github . updated_at ) ,
660
+ moment ( github . pushed_at ) ,
661
+ ] )
662
+ . fromNow ( ) }
663
+ </ GridItem >
664
+ ) }
665
+ </ GridContainer >
666
+ </ div >
667
+ </ TableCell >
668
+ < TableCell align = 'right' >
669
+ < div style = { { padding : '15px' } } >
670
+ < CodeActionButton cloneURL = { cloneURL } />
671
+ </ div >
672
+ </ TableCell >
673
+ </ TableRow >
715
674
) ;
716
675
}
0 commit comments