1- import React from "react" ;
1+ import React , { useContext } from "react" ;
22import { Button , Table } from "semantic-ui-react" ;
33import { graphql } from "@apollo/client/react/hoc" ;
44import PropTypes from "prop-types" ;
@@ -18,85 +18,73 @@ function dateFormat(timestamp) {
1818 . padStart ( 2 , "0" ) } .${ date . getUTCDate ( ) . toString ( ) . padStart ( 2 , "0" ) } `;
1919}
2020
21- class GrantsList extends React . Component {
22- constructor ( props ) {
23- super ( props ) ;
24- this . joinGrant = this . joinGrant . bind ( this ) ;
25- this . isOwner = this . isOwner . bind ( this ) ;
26- }
21+ const GrantsList = ( { createGrantPermission, data } ) => {
22+ const getTranslation = useContext ( TranslationContext ) ;
2723
28- joinGrant ( grant ) {
29- const { createGrantPermission } = this . props ;
24+ const joinGrant = grant => {
3025 createGrantPermission ( {
3126 variables : { grantId : grant . id }
3227 } ) . then ( ( ) => {
33- window . logger . suc ( this . context ( "Request has been sent to the grant's owner." ) ) ;
28+ window . logger . suc ( getTranslation ( "Request has been sent to the grant's owner." ) ) ;
3429 } ) ;
35- }
30+ } ;
3631
37- isOwner ( grant ) {
38- const {
39- data : { user }
40- } = this . props ;
32+ const isOwner = grant => {
33+ const { user } = data ;
4134 return ! ! grant . owners . find ( u => user && user . id === u . id ) ;
42- }
35+ } ;
4336
44- render ( ) {
45- const { data } = this . props ;
46- const { grants } = data ;
37+ const { grants } = data ;
4738
48- return (
49- < div style = { { overflowY : "auto" } } >
50- < Table celled padded >
51- < Table . Header >
52- < Table . Row >
53- < Table . HeaderCell > { this . context ( "Grant Issuer" ) } </ Table . HeaderCell >
54- < Table . HeaderCell > { this . context ( "Grant" ) } </ Table . HeaderCell >
55- < Table . HeaderCell > { this . context ( "Issuer URL" ) } </ Table . HeaderCell >
56- < Table . HeaderCell > { this . context ( "Grant URL" ) } </ Table . HeaderCell >
57- < Table . HeaderCell > { this . context ( "Grant Number" ) } </ Table . HeaderCell >
58- < Table . HeaderCell > { this . context ( "Begin" ) } </ Table . HeaderCell >
59- < Table . HeaderCell > { this . context ( "End" ) } </ Table . HeaderCell >
60- < Table . HeaderCell > { this . context ( "Owners" ) } </ Table . HeaderCell >
61- < Table . HeaderCell />
39+ return (
40+ < div style = { { overflowY : "auto" } } >
41+ < Table celled padded >
42+ < Table . Header >
43+ < Table . Row >
44+ < Table . HeaderCell > { getTranslation ( "Grant Issuer" ) } </ Table . HeaderCell >
45+ < Table . HeaderCell > { getTranslation ( "Grant" ) } </ Table . HeaderCell >
46+ < Table . HeaderCell > { getTranslation ( "Issuer URL" ) } </ Table . HeaderCell >
47+ < Table . HeaderCell > { getTranslation ( "Grant URL" ) } </ Table . HeaderCell >
48+ < Table . HeaderCell > { getTranslation ( "Grant Number" ) } </ Table . HeaderCell >
49+ < Table . HeaderCell > { getTranslation ( "Begin" ) } </ Table . HeaderCell >
50+ < Table . HeaderCell > { getTranslation ( "End" ) } </ Table . HeaderCell >
51+ < Table . HeaderCell > { getTranslation ( "Owners" ) } </ Table . HeaderCell >
52+ < Table . HeaderCell />
53+ </ Table . Row >
54+ </ Table . Header >
55+ < Table . Body >
56+ { grants . map ( grant => (
57+ < Table . Row key = { grant . id } >
58+ < Table . Cell > { T ( grant . issuer_translations ) } </ Table . Cell >
59+ < Table . Cell > { T ( grant . translations ) } </ Table . Cell >
60+ < Table . Cell className = "lingvo-column-issuer-url" >
61+ < a href = { grant . issuer_url } > { grant . issuer_url } </ a >
62+ </ Table . Cell >
63+ < Table . Cell className = "lingvo-column-grant-url" >
64+ < a href = { grant . grant_url } > { grant . grant_url } </ a >
65+ </ Table . Cell >
66+ < Table . Cell > { grant . grant_number } </ Table . Cell >
67+ < Table . Cell > { dateFormat ( grant . begin ) } </ Table . Cell >
68+ < Table . Cell > { dateFormat ( grant . end ) } </ Table . Cell >
69+ < Table . Cell >
70+ { grant . owners . map ( owner => (
71+ < div key = { owner . id } > { owner . name } </ div >
72+ ) ) }
73+ </ Table . Cell >
74+ < Table . Cell >
75+ { ! isOwner ( grant ) && (
76+ < Button positive onClick = { ( ) => joinGrant ( grant ) } >
77+ { getTranslation ( "Join" ) }
78+ </ Button >
79+ ) }
80+ </ Table . Cell >
6281 </ Table . Row >
63- </ Table . Header >
64- < Table . Body >
65- { grants . map ( grant => (
66- < Table . Row key = { grant . id } >
67- < Table . Cell > { T ( grant . issuer_translations ) } </ Table . Cell >
68- < Table . Cell > { T ( grant . translations ) } </ Table . Cell >
69- < Table . Cell className = "lingvo-column-issuer-url" >
70- < a href = { grant . issuer_url } > { grant . issuer_url } </ a >
71- </ Table . Cell >
72- < Table . Cell className = "lingvo-column-grant-url" >
73- < a href = { grant . grant_url } > { grant . grant_url } </ a >
74- </ Table . Cell >
75- < Table . Cell > { grant . grant_number } </ Table . Cell >
76- < Table . Cell > { dateFormat ( grant . begin ) } </ Table . Cell >
77- < Table . Cell > { dateFormat ( grant . end ) } </ Table . Cell >
78- < Table . Cell >
79- { grant . owners . map ( owner => (
80- < div key = { owner . id } > { owner . name } </ div >
81- ) ) }
82- </ Table . Cell >
83- < Table . Cell >
84- { ! this . isOwner ( grant ) && (
85- < Button positive onClick = { ( ) => this . joinGrant ( grant ) } >
86- { this . context ( "Join" ) }
87- </ Button >
88- ) }
89- </ Table . Cell >
90- </ Table . Row >
91- ) ) }
92- </ Table . Body >
93- </ Table >
94- </ div >
95- ) ;
96- }
97- }
98-
99- GrantsList . contextType = TranslationContext ;
82+ ) ) }
83+ </ Table . Body >
84+ </ Table >
85+ </ div >
86+ ) ;
87+ } ;
10088
10189GrantsList . propTypes = {
10290 data : PropTypes . shape ( {
0 commit comments