ES6 Plato on Github
Report Home
Summary Display
components/UserManagement/InstrumentScientistTable.js
Maintainability
74.41
Lines of code
96
Difficulty
18.11
Estimated Errors
0.66
Function weight
By Complexity
By SLOC
import React from "react"; import _ from "lodash"; import Loading from "../../components/Loading.js"; import { Button } from "react-bootstrap"; import ResponsiveTable from "../Table/ResponsiveTable.js"; import { createInstrumentScientists } from "../../api/icat/icatPlus.js"; import axios from 'axios'; import Loader from 'react-loader-advanced'; class InstrumentScientistTable extends React.Component { constructor(props) { super(props); this.state = { fetching: false, fetched: false }; this.handleRevokeClick = this.handleRevokeClick.bind(this); } getColumns() { return [ { text: "id", dataField: "id", hidden: true }, { text: "User", dataField: "fullName",sort: true }, { text: "Beamline", dataField: "instrumentName", sort: true }, { dataField: 'buttons', text: '', formatExtraData: this, formatter: this.renderButtons } ]; } handleRevokeClick = (instrumentscientistsid) => { this.setState({ fetching: true }); axios.delete(createInstrumentScientists(this.props.user.sessionId), { data: { instrumentscientistsid: [instrumentscientistsid] } }) .then((response) => { this.setState({ fetching: false }); this.props.fetchInstrumentScientistsBySessionId(this.props.user.sessionId); }) .catch((error) => { this.setState({ fetching: false, message: { isError: true, text: error.message } }); }); } renderButtons = (cell, row, i, extraData) => { return <Button instrumentScientistId={row.id} bsStyle="danger" onClick={() => this.handleRevokeClick(row.id)} >Revoke</Button>; }; render() { var data = this.props.instrumentScientists.sort(function (a, b) { return a.instrument.name > b.instrument.name; }); return ( <Loader show={this.props.fetching || this.state.fetching}> <ResponsiveTable keyField="id" data={data.map(function (is) { return { id: is.id, instrumentName: is.instrument.name, fullName: is.user.fullName }; })} columns={this.getColumns()} pageOptions={{ sizePerPage: 100 }} /> </Loader> ); } } export default InstrumentScientistTable;