2018-12-19 03:41:45 +00:00
import React , { Fragment } from 'react' ;
2018-10-13 09:07:54 +00:00
import PropTypes from 'prop-types' ;
2018-11-23 12:19:42 +00:00
import { gettext } from '../../utils/constants' ;
2018-10-25 05:36:06 +00:00
import Loading from '../loading' ;
2018-10-13 09:07:54 +00:00
import DirentListItem from './dirent-list-item' ;
2018-12-19 03:41:45 +00:00
import ModalPortal from '../modal-portal' ;
import CreateFile from '../../components/dialog/create-file-dialog' ;
import '../../css/tip-for-new-md.css' ;
2018-10-13 09:07:54 +00:00
const propTypes = {
2018-11-22 03:26:00 +00:00
path : PropTypes . string . isRequired ,
2018-11-28 04:41:49 +00:00
repoID : PropTypes . string . isRequired ,
isRepoOwner : PropTypes . bool ,
2018-12-18 09:21:01 +00:00
currentRepoInfo : PropTypes . object ,
2018-11-28 04:41:49 +00:00
isAllItemSelected : PropTypes . bool . isRequired ,
isDirentListLoading : PropTypes . bool . isRequired ,
2018-10-13 09:07:54 +00:00
direntList : PropTypes . array . isRequired ,
2018-12-19 03:41:45 +00:00
onAddFile : PropTypes . func . isRequired ,
2018-10-13 09:07:54 +00:00
onItemDelete : PropTypes . func . isRequired ,
2018-11-23 12:19:42 +00:00
onAllItemSelected : PropTypes . func . isRequired ,
onItemSelected : PropTypes . func . isRequired ,
2018-10-25 05:36:06 +00:00
onItemRename : PropTypes . func . isRequired ,
2018-10-13 09:07:54 +00:00
onItemClick : PropTypes . func . isRequired ,
2018-11-27 06:47:19 +00:00
onItemMove : PropTypes . func . isRequired ,
onItemCopy : PropTypes . func . isRequired ,
2018-10-25 05:36:06 +00:00
onItemDetails : PropTypes . func . isRequired ,
2018-11-22 03:26:00 +00:00
updateDirent : PropTypes . func . isRequired ,
2018-10-13 09:07:54 +00:00
} ;
class DirentListView extends React . Component {
constructor ( props ) {
super ( props ) ;
this . state = {
isItemFreezed : false ,
2018-12-19 03:41:45 +00:00
isCreateFileDialogShow : false ,
fileType : ''
2018-10-13 09:07:54 +00:00
} ;
}
2018-10-25 05:36:06 +00:00
onFreezedItem = ( ) => {
2018-10-13 09:07:54 +00:00
this . setState ( { isItemFreezed : true } ) ;
}
2018-11-22 03:26:00 +00:00
2018-10-25 05:36:06 +00:00
onUnfreezedItem = ( ) => {
2018-10-13 09:07:54 +00:00
this . setState ( { isItemFreezed : false } ) ;
}
2018-11-23 12:19:42 +00:00
onItemRenameToggle = ( ) => {
2018-10-25 05:36:06 +00:00
this . onFreezedItem ( ) ;
2018-10-13 09:07:54 +00:00
}
2018-11-29 09:55:14 +00:00
onItemDetails = ( dirent ) => {
this . props . onItemDetails ( dirent ) ;
2018-10-25 05:36:06 +00:00
}
2018-12-19 03:41:45 +00:00
onCreateFileToggle = ( ) => {
this . setState ( {
isCreateFileDialogShow : ! this . state . isCreateFileDialogShow ,
fileType : ''
} ) ;
}
onCreateMarkdownToggle = ( ) => {
this . setState ( {
isCreateFileDialogShow : ! this . state . isCreateFileDialogShow ,
fileType : '.md'
} ) ;
}
onAddFile = ( filePath , isDraft ) => {
this . setState ( { isCreateFileDialogShow : false } ) ;
this . props . onAddFile ( filePath , isDraft ) ;
}
2018-10-13 09:07:54 +00:00
render ( ) {
const { direntList } = this . props ;
2018-10-25 05:36:06 +00:00
if ( this . props . isDirentListLoading ) {
return ( < Loading / > ) ;
}
2018-12-19 03:41:45 +00:00
if ( this . props . path == '/' && ! direntList . length ) {
return (
< Fragment >
< div className = "tip-for-new-md d-flex" >
< button className = "big-new-md-button" onClick = { this . onCreateMarkdownToggle } > < span className = "sf2-icon-plus add-md-icon" > < /span><br / > { gettext ( 'Markdown Document' ) } < / b u t t o n >
< p > { gettext ( 'You can create online document using Markdown format easily. When creating a document, you can mark it as draft. After finishing the draft, you can ask others to review it. They can view the document history in the review page and leave comments on the document.' ) } < / p >
< / d i v >
{ this . state . isCreateFileDialogShow && (
< ModalPortal >
< CreateFile
parentPath = { this . props . path }
fileType = { this . state . fileType }
onAddFile = { this . onAddFile }
addFileCancel = { this . onCreateFileToggle }
/ >
< / M o d a l P o r t a l >
) }
< / F r a g m e n t >
) ;
}
2018-10-13 09:07:54 +00:00
return (
2018-11-23 12:19:42 +00:00
< table >
< thead >
< tr >
< th width = "3%" className = "select" >
< input type = "checkbox" className = "vam" onChange = { this . props . onAllItemSelected } checked = { this . props . isAllItemSelected } / >
< / t h >
2018-12-17 08:52:04 +00:00
< th width = "3%" > { /*icon */ } < / t h >
< th width = "5%" > { /*star */ } < / t h >
< th width = "39%" > { gettext ( 'Name' ) } < / t h >
< th width = "6%" > { /*tag */ } < / t h >
< th width = "20%" > { /*operation */ } < / t h >
2018-11-23 12:19:42 +00:00
< th width = "11%" > { gettext ( 'Size' ) } < / t h >
< th width = "13%" > { gettext ( 'Last Update' ) } < / t h >
< / t r >
< / t h e a d >
< tbody >
{
direntList . length !== 0 && direntList . map ( ( dirent , index ) => {
return (
< DirentListItem
key = { index }
dirent = { dirent }
path = { this . props . path }
2018-11-28 04:41:49 +00:00
repoID = { this . props . repoID }
2018-12-18 09:21:01 +00:00
currentRepoInfo = { this . props . currentRepoInfo }
2018-11-23 12:19:42 +00:00
isRepoOwner = { this . props . isRepoOwner }
onItemClick = { this . props . onItemClick }
onItemRenameToggle = { this . onItemRenameToggle }
onItemSelected = { this . props . onItemSelected }
onItemDelete = { this . props . onItemDelete }
onItemRename = { this . props . onItemRename }
2018-11-27 06:47:19 +00:00
onItemMove = { this . props . onItemMove }
onItemCopy = { this . props . onItemCopy }
2018-11-23 12:19:42 +00:00
updateDirent = { this . props . updateDirent }
isItemFreezed = { this . state . isItemFreezed }
onFreezedItem = { this . onFreezedItem }
onUnfreezedItem = { this . onUnfreezedItem }
onItemDetails = { this . onItemDetails }
/ >
) ;
} )
}
< / t b o d y >
< / t a b l e >
2018-10-13 09:07:54 +00:00
) ;
}
}
DirentListView . propTypes = propTypes ;
export default DirentListView ;