Improve delete device UI

merge-requests/299/head
shamalka 5 years ago
parent b92046fa3d
commit 5ba56207c9

@ -17,66 +17,90 @@
*/ */
import React from "react"; import React from "react";
import {Button, Icon, notification} from "antd"; import {Button, Tooltip, Popconfirm, Divider} from "antd";
class BulkActionBar extends React.Component { class BulkActionBar extends React.Component {
constructor(props){ constructor(props) {
super(props); super(props);
this.state = { this.state = {
selectedMultiple:false, selectedMultiple: false,
selectedSingle:false selectedSingle: false,
deleteable: true,
} }
} }
//This method is used to trigger delete request on selected devices //This method is used to trigger delete request on selected devices
deleteDevice = () => { onDeleteDeviceCall = () => {
const deviceStatusArray = this.props.selectedRows.map(obj => obj.enrolmentInfo.status); let i;
if(deviceStatusArray.includes("ACTIVE") || deviceStatusArray.includes("INACTIVE")){ for(i=0; i < this.props.selectedRows.length; i++){
notification["error"]({ if(this.props.selectedRows[i].enrolmentInfo.status != "REMOVED"){
message: "There was a problem", this.setState({deletable:false});
duration: 0, break;
description:
"Cannot delete ACTIVE/INACTIVE devices.",
});
}else{
this.props.deleteDevice();
} }
this.setState({deletable:true});
} }
};
componentDidUpdate(prevProps, prevState, snapshot) { onConfirmDelete = () => {
if(prevProps.selectedRows !== this.props.selectedRows){ if (this.state.deletable) {
if(this.props.selectedRows.length > 1){ this.props.deleteDevice();
this.setState({selectedMultiple:true,selectedSingle:false})
}else if(this.props.selectedRows.length == 1){
this.setState({selectedSingle:true,selectedMultiple:true})
}else{
this.setState({selectedSingle:false,selectedMultiple:false})
}
}
} }
};
onConfirmDisenroll = () => {
//TODO: Implement disenrollment function
};
render() { render() {
return( const isSelected = this.props.selectedRows.length > 0;
<div style={{padding:'5px'}}> const isSelectedSingle = this.props.selectedRows.length == 1;
return (
<div
style={{display: isSelected ? "inline" : "none", padding: '11px'}}>
<Tooltip
placement="bottom"
title={"Delete Device"}
autoAdjustOverflow={true}>
<Popconfirm
placement="topLeft"
title={
this.state.deletable ?
"Are you sure you want to delete?" : "You can only delete disenrolled devices"}
onConfirm={this.onConfirmDelete}
okText="Ok"
cancelText="Cancel">
<Button <Button
type="normal" type="link"
shape="circle"
icon="delete" icon="delete"
size={'default'} size={'default'}
onClick={this.deleteDevice} onClick={this.onDeleteDeviceCall}
style={ disabled={isSelected ? false : true}
{display:this.state.selectedMultiple ? "inline" : "none"} style={{margin: "2px"}}/>
}>Delete </Popconfirm>
</Button> </Tooltip>
<Divider type="vertical"/>
<Tooltip placement="bottom" title={"Disenroll Device"}>
<Popconfirm
placement="topLeft"
title={"Are you sure?"}
onConfirm={this.onConfirmDisenroll}
okText="Ok"
disabled={isSelectedSingle ? false : true}
cancelText="Cancel">
<Button <Button
type="normal" type="link"
icon="delete" shape="circle"
icon="close"
size={'default'} size={'default'}
style={ disabled={isSelectedSingle ? false : true}
{display:this.state.selectedSingle ? "inline" : "none"} style={{margin: "2px"}}/>
}>Disenroll </Popconfirm>
</Button> </Tooltip>
</div> </div>
) )
} }

@ -118,9 +118,9 @@ const columns = [
key: 'action', key: 'action',
render: () => ( render: () => (
<span> <span>
<a><Icon type="edit" /></a> <a><Icon type="edit"/></a>
<Divider type="vertical" /> <Divider type="vertical"/>
<a><Text type="danger"><Icon type="delete" /></Text></a> <a><Text type="danger"><Icon type="delete"/></Text></a>
</span> </span>
), ),
}, },
@ -220,17 +220,10 @@ class DeviceTable extends React.Component {
config.serverConfig.invoker.deviceMgt + config.serverConfig.invoker.deviceMgt +
"/admin/devices/permanent-delete", "/admin/devices/permanent-delete",
deviceData, deviceData,
{ headers : {'Content-Type': 'application/json'}} {headers: {'Content-Type': 'application/json'}}
).then(res => { ).then(res => {
if (res.status === 200) { if (res.status === 200) {
this.fetch(); this.fetch();
const pagination = {...this.state.pagination};
this.setState({
loading: false,
data: res.data.data.devices,
pagination,
});
} }
}).catch((error) => { }).catch((error) => {
if (error.hasOwnProperty("response") && error.response.status === 401) { if (error.hasOwnProperty("response") && error.response.status === 401) {
@ -248,7 +241,7 @@ class DeviceTable extends React.Component {
this.setState({loading: false}); this.setState({loading: false});
}); });
} };
handleTableChange = (pagination, filters, sorter) => { handleTableChange = (pagination, filters, sorter) => {
const pager = {...this.state.pagination}; const pager = {...this.state.pagination};
@ -272,6 +265,7 @@ class DeviceTable extends React.Component {
<BulkActionBar <BulkActionBar
deleteDevice={this.deleteDevice} deleteDevice={this.deleteDevice}
selectedRows={this.state.selectedRows}/> selectedRows={this.state.selectedRows}/>
<div>
<Table <Table
columns={columns} columns={columns}
rowKey={record => (record.deviceIdentifier + record.enrolmentInfo.owner + record.enrolmentInfo.ownership)} rowKey={record => (record.deviceIdentifier + record.enrolmentInfo.owner + record.enrolmentInfo.ownership)}
@ -289,6 +283,7 @@ class DeviceTable extends React.Component {
scroll={{x: 1000}} scroll={{x: 1000}}
/> />
</div> </div>
</div>
); );
} }
} }

Loading…
Cancel
Save