Updated to React16, restart dropdown button

pull/380/head
Piero Toffanin 2018-01-24 11:07:06 -05:00
rodzic ef74672ccd
commit 2bb43203dc
4 zmienionych plików z 50 dodań i 11 usunięć

Wyświetl plik

@ -9,6 +9,8 @@ import {
} from 'react-router-dom'; } from 'react-router-dom';
import $ from 'jquery'; import $ from 'jquery';
console.log(React.version);
class Dashboard extends React.Component { class Dashboard extends React.Component {
constructor(){ constructor(){
super(); super();

Wyświetl plik

@ -260,9 +260,9 @@ class TaskListItem extends React.Component {
memoryErrorLink = this.isMacOS() ? "http://stackoverflow.com/a/39720010" : "https://docs.docker.com/docker-for-windows/#advanced"; memoryErrorLink = this.isMacOS() ? "http://stackoverflow.com/a/39720010" : "https://docs.docker.com/docker-for-windows/#advanced";
let actionButtons = []; let actionButtons = [];
const addActionButton = (label, className, icon, onClick) => { const addActionButton = (label, className, icon, onClick, options = {}) => {
actionButtons.push({ actionButtons.push({
className, icon, label, onClick className, icon, label, onClick, options
}); });
}; };
@ -285,6 +285,8 @@ class TaskListItem extends React.Component {
(!task.processing_node)){ (!task.processing_node)){
addActionButton("Edit", "btn-primary pull-right edit-button", "glyphicon glyphicon-pencil", () => { addActionButton("Edit", "btn-primary pull-right edit-button", "glyphicon glyphicon-pencil", () => {
this.startEditing(); this.startEditing();
}, {
className: "inline"
}); });
} }
@ -295,14 +297,22 @@ class TaskListItem extends React.Component {
if ([statusCodes.FAILED, statusCodes.COMPLETED, statusCodes.CANCELED].indexOf(task.status) !== -1 && if ([statusCodes.FAILED, statusCodes.COMPLETED, statusCodes.CANCELED].indexOf(task.status) !== -1 &&
task.processing_node){ task.processing_node){
addActionButton("Restart", "btn-primary", "glyphicon glyphicon-remove-circle", this.genActionApiCall("restart", { addActionButton("Restart", "btn-primary", "glyphicon glyphicon-repeat", this.genActionApiCall("restart", {
success: () => { success: () => {
if (this.console) this.console.clear(); if (this.console) this.console.clear();
this.setState({time: -1}); this.setState({time: -1});
}, },
defaultError: "Cannot restart task." defaultError: "Cannot restart task."
} }
)); ), {
subItems: [{
label: "Meshing",
icon: "glyphicon glyphicon-remove-circle",
onClick: (cb) => {
console.log("OK");
}
}]
});
} }
addActionButton("Delete", "btn-danger", "glyphicon glyphicon-trash", this.genActionApiCall("remove", { addActionButton("Delete", "btn-danger", "glyphicon glyphicon-trash", this.genActionApiCall("remove", {
@ -317,12 +327,25 @@ class TaskListItem extends React.Component {
<AssetDownloadButtons task={this.state.task} disabled={disabled} /> <AssetDownloadButtons task={this.state.task} disabled={disabled} />
: ""} : ""}
{actionButtons.map(button => { {actionButtons.map(button => {
const subItems = button.options.subItems || [];
const className = button.options.className || "";
return ( return (
<button key={button.label} type="button" className={"btn btn-sm " + button.className} onClick={button.onClick} disabled={disabled}> <div className={"inline-block " +
<i className={button.icon}></i> (subItems.length > 0 ? "btn-group" : "") + " " +
{button.label} className}>
</button> <button key={button.label} type="button" className={"btn btn-sm " + button.className} onClick={button.onClick} disabled={disabled}>
) <i className={button.icon}></i>
{button.label}
</button>
{subItems.length > 0 &&
[<button key="dropdown-button" type="button" className={"btn btn-sm dropdown-toggle " + button.className} data-toggle="dropdown"><span className="caret"></span></button>,
<ul key="dropdown-menu" className="dropdown-menu">
{subItems.map(subItem => <li key={subItem.label}>
<a href="javascript:void(0);" onClick={subItem.onClick}><i className={subItem.icon}></i>{subItem.label}</a>
</li>)}
</ul>]}
</div>);
})} })}
</div>); </div>);

Wyświetl plik

@ -73,6 +73,12 @@
margin-right: 4px; margin-right: 4px;
} }
.btn-group{
button:first-child{
margin-right: 0;
}
}
.edit-button{ .edit-button{
margin-right: 15px; margin-right: 15px;
} }
@ -82,4 +88,12 @@
} }
} }
} }
.inline-block{
display: inline-block;
}
.inline{
display: inline;
}
} }

Wyświetl plik

@ -45,9 +45,9 @@
"object.values": "^1.0.3", "object.values": "^1.0.3",
"proj4": "^2.4.3", "proj4": "^2.4.3",
"raw-loader": "^0.5.1", "raw-loader": "^0.5.1",
"react": "^15.6.0", "react": "^16.2.0",
"react-addons-test-utils": "^15.6.0", "react-addons-test-utils": "^15.6.0",
"react-dom": "^15.6.0", "react-dom": "^16.2.0",
"react-router": "^4.1.1", "react-router": "^4.1.1",
"react-router-dom": "^4.1.1", "react-router-dom": "^4.1.1",
"react-test-renderer": "^15.6.1", "react-test-renderer": "^15.6.1",