1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-22 03:47:09 +00:00

add table function

This commit is contained in:
Michael An
2019-07-03 17:31:24 +08:00
parent 1ea4079e74
commit 3abf376c0b
3 changed files with 109 additions and 51 deletions

View File

@@ -1,4 +1,4 @@
import React from 'react'; import React, { Fragment } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Select from 'react-select'; import Select from 'react-select';
import makeAnimated from 'react-select/lib/animated'; import makeAnimated from 'react-select/lib/animated';
@@ -10,6 +10,7 @@ import { gettext } from '../../utils/constants';
const propTypes = { const propTypes = {
createDTable: PropTypes.func.isRequired, createDTable: PropTypes.func.isRequired,
onAddDTable: PropTypes.func.isRequired, onAddDTable: PropTypes.func.isRequired,
currentWorkspace: PropTypes.object,
}; };
class CreateTableDialog extends React.Component { class CreateTableDialog extends React.Component {
@@ -66,16 +67,22 @@ class CreateTableDialog extends React.Component {
} }
handleSubmit = () => { handleSubmit = () => {
if (!this.state.isSubmitBtnActive) { if (!this.state.isSubmitBtnActive) return;
return; if (!this.validateInputParams()) return;
} const space = this.props.currentWorkspace;
const options = this.state.options;
let isValid = this.validateInputParams(); let email;
if (isValid) { if (space) {
let newName = this.state.tableName.trim(); for (let i = 0; i < options.length; i++) {
let owner = this.state.selectedOption; if ((space.owner_type === "Personal" && options[i].value === 'Personal') || (space.owner_type === "Group" && options[i].value === space.owner_name)) {
this.props.createDTable(newName, owner.email); email = options[i].email;
break;
}
}
} else {
email = this.state.selectedOption.email;
} }
this.props.createDTable(this.state.tableName.trim(), email);
} }
handleKeyPress = (e) => { handleKeyPress = (e) => {
@@ -106,6 +113,7 @@ class CreateTableDialog extends React.Component {
} }
render() { render() {
const { currentWorkspace } = this.props;
return ( return (
<Modal isOpen={true} toggle={this.toggle}> <Modal isOpen={true} toggle={this.toggle}>
<ModalHeader toggle={this.toggle}>{gettext('New Table')}</ModalHeader> <ModalHeader toggle={this.toggle}>{gettext('New Table')}</ModalHeader>
@@ -123,17 +131,21 @@ class CreateTableDialog extends React.Component {
</FormGroup> </FormGroup>
</Form> </Form>
{this.state.errMessage && <Alert color="danger" className="mt-2">{this.state.errMessage}</Alert>} {this.state.errMessage && <Alert color="danger" className="mt-2">{this.state.errMessage}</Alert>}
<Label>{gettext('Belong to')}</Label> {!currentWorkspace &&
<Select <Fragment>
isClearable <Label>{gettext('Belong to')}</Label>
isMulti={false} <Select
maxMenuHeight={200} isClearable
hideSelectedOptions={true} isMulti={false}
components={makeAnimated()} maxMenuHeight={200}
placeholder='' hideSelectedOptions={true}
options={this.state.options} components={makeAnimated()}
onChange={this.handleSelectChange} placeholder=''
/> options={this.state.options}
onChange={this.handleSelectChange}
/>
</Fragment>
}
</ModalBody> </ModalBody>
<ModalFooter> <ModalFooter>
<Button color="secondary" onClick={this.toggle}>{gettext('Cancel')}</Button> <Button color="secondary" onClick={this.toggle}>{gettext('Cancel')}</Button>

View File

@@ -44,4 +44,15 @@
} }
.add-workspace:hover { .add-workspace:hover {
color: #202428; color: #202428;
}
.workspace .table-heading {
padding: 0.25rem;
border-bottom: 1px solid #e6e6e6;
}
.workspace .sf3-font {
color: #949494;
font-size: 20px;
}
.workspace .add-table-range:hover {
background-color: #f8f8f8;
} }

View File

@@ -105,7 +105,7 @@ class Table extends Component {
return ( return (
<tr onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave} className={this.state.active ? 'tr-highlight' : ''}> <tr onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave} className={this.state.active ? 'tr-highlight' : ''}>
<td><img src={siteRoot + 'media/img/data-base.svg'} alt="" width="24"/></td> <td><span className="sf3-font sf3-font-form"></span></td>
<td> <td>
{this.state.isTableRenaming && {this.state.isTableRenaming &&
<Rename <Rename
@@ -217,6 +217,12 @@ class Workspace extends Component {
}); });
} }
addTable = (e) => {
e.preventDefault();
this.props.setCurrentWorkspace(this.props.workspace);
this.props.onAddDTable();
}
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (nextProps.workspace.table_list !== this.props.workspace.table_list) { if (nextProps.workspace.table_list !== this.props.workspace.table_list) {
this.setState({ this.setState({
@@ -228,32 +234,46 @@ class Workspace extends Component {
render() { render() {
let workspace = this.props.workspace; let workspace = this.props.workspace;
let isPersonal = workspace.owner_type === 'Personal'; let isPersonal = workspace.owner_type === 'Personal';
let { tableList, isItemFreezed } = this.state;
return( return(
<div className="workspace my-2"> <div className="workspace my-2">
<div>{isPersonal ? gettext('My Tables') : workspace.owner_name}</div> <div className="table-heading">{isPersonal ? gettext('My Tables') : workspace.owner_name}</div>
<table width="100%" className="table-vcenter"> {tableList.length > 0 ?
<colgroup> <table width="100%" className="table-vcenter">
<col width="4%"/><col width="31%"/><col width="30%"/><col width="27%"/><col width="8%"/> <colgroup>
</colgroup> <col width="4%"/><col width="31%"/><col width="30%"/><col width="27%"/><col width="8%"/>
<tbody> </colgroup>
{this.state.tableList.map((table, index) => { <tbody>
return ( {tableList.map((table, index) => {
<Table return (
key={index} <Table
table={table} key={index}
workspaceID={workspace.id} table={table}
renameTable={this.renameTable} workspaceID={workspace.id}
deleteTable={this.deleteTable} renameTable={this.renameTable}
onFreezedItem={this.onFreezedItem} deleteTable={this.deleteTable}
onUnfreezedItem={this.onUnfreezedItem} onFreezedItem={this.onFreezedItem}
isItemFreezed={this.state.isItemFreezed} onUnfreezedItem={this.onUnfreezedItem}
isPersonal={isPersonal} isItemFreezed={isItemFreezed}
/> isPersonal={isPersonal}
); />
})} );
</tbody> })}
</table> <tr className={isItemFreezed ? "" : "add-table-range"}>
<td><span className="sf3-font sf3-font-add"></span></td>
<td><a href="#" onClick={this.addTable}>{gettext('Add a table')}</a></td>
<td></td><td></td><td></td>
</tr>
</tbody>
</table>
:
<table width="100%" className="table-vcenter">
<tbody>
<tr><th className="text-center">{gettext('No tables')}</th></tr>
</tbody>
</table>
}
</div> </div>
); );
} }
@@ -277,13 +297,12 @@ class DTable extends Component {
workspaceList: [], workspaceList: [],
shareTableList: [], shareTableList: [],
isShowAddDTableDialog: false, isShowAddDTableDialog: false,
currentWorkspace: null,
}; };
} }
onAddDTable = () => { onAddDTable = () => {
this.setState({ this.setState({ isShowAddDTableDialog: !this.state.isShowAddDTableDialog });
isShowAddDTableDialog: !this.state.isShowAddDTableDialog,
});
} }
createDTable = (tableName, owner) => { createDTable = (tableName, owner) => {
@@ -359,6 +378,10 @@ class DTable extends Component {
}); });
}; };
setCurrentWorkspace = (currentWorkspace) => {
this.setState({ currentWorkspace: currentWorkspace });
}
componentDidMount() { componentDidMount() {
this.listWorkspaces(); this.listWorkspaces();
this.listSharedTables(); this.listSharedTables();
@@ -367,7 +390,7 @@ class DTable extends Component {
renderShareTablePanel = () => { renderShareTablePanel = () => {
return ( return (
<div className="workspace my-2"> <div className="workspace my-2">
<div>{gettext('Shared with me')}</div> <div className="table-heading">{gettext('Shared with me')}</div>
<table width="100%" className="table-vcenter"> <table width="100%" className="table-vcenter">
<colgroup> <colgroup>
<col width="4%"/><col width="31%"/><col width="30%"/><col width="27%"/><col width="8%"/> <col width="4%"/><col width="31%"/><col width="30%"/><col width="27%"/><col width="8%"/>
@@ -388,6 +411,13 @@ class DTable extends Component {
); );
}; };
newDtable = () => {
if (this.state.currentWorkspace) {
this.setState({ currentWorkspace: null });
}
this.onAddDTable();
}
render() { render() {
let personalWorkspace = this.state.workspaceList.filter(workspace => { let personalWorkspace = this.state.workspaceList.filter(workspace => {
return workspace.owner_type === 'Personal'; return workspace.owner_type === 'Personal';
@@ -404,10 +434,10 @@ class DTable extends Component {
<div className="operation"> <div className="operation">
<Fragment> <Fragment>
<MediaQuery query="(min-width: 768px)"> <MediaQuery query="(min-width: 768px)">
<Button className="btn btn-secondary operation-item" onClick={this.onAddDTable}>{gettext('New DTable')}</Button> <Button className="btn btn-secondary operation-item" onClick={this.newDtable}>{gettext('New DTable')}</Button>
</MediaQuery> </MediaQuery>
<MediaQuery query="(max-width: 767.8px)"> <MediaQuery query="(max-width: 767.8px)">
<Button className="btn btn-secondary operation-item my-1" onClick={this.onAddDTable}>{gettext('New DTable')}</Button> <Button className="btn btn-secondary operation-item my-1" onClick={this.newDtable}>{gettext('New DTable')}</Button>
</MediaQuery> </MediaQuery>
</Fragment> </Fragment>
</div> </div>
@@ -427,6 +457,8 @@ class DTable extends Component {
{!this.state.loading && {!this.state.loading &&
<Workspace <Workspace
workspace={personalWorkspace} workspace={personalWorkspace}
onAddDTable={this.onAddDTable}
setCurrentWorkspace={this.setCurrentWorkspace}
/> />
} }
{(!this.state.shareTableLoading && this.state.shareTableList.length > 0) && {(!this.state.shareTableLoading && this.state.shareTableList.length > 0) &&
@@ -438,6 +470,8 @@ class DTable extends Component {
<Workspace <Workspace
key={index} key={index}
workspace={workspace} workspace={workspace}
onAddDTable={this.onAddDTable}
setCurrentWorkspace={this.setCurrentWorkspace}
/> />
); );
}) })
@@ -447,6 +481,7 @@ class DTable extends Component {
<CreateTableDialog <CreateTableDialog
createDTable={this.createDTable} createDTable={this.createDTable}
onAddDTable={this.onAddDTable} onAddDTable={this.onAddDTable}
currentWorkspace={this.state.currentWorkspace}
/> />
</div> </div>
} }