Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin: Improve Bots page, add columns #2794

Merged
merged 6 commits into from Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/components/Admin/ListBots/constants.js
Expand Up @@ -3,21 +3,35 @@ export const BOT = [
title: 'Name',
field: 'name',
cellStyle: {
width: '30%',
width: '20%',
},
},
{
title: 'Group',
field: 'group',
cellStyle: {
width: '20%',
},
},
{
title: 'Language',
field: 'language',
cellStyle: {
width: '30%',
width: '15%',
},
},
{
title: 'Group',
field: 'group',
title: 'Default Skills',
field: 'displaySkills',
cellStyle: {
width: '15%',
},
},
{
title: 'Bot Site',
field: 'botSite',
cellStyle: {
width: '35%',
width: '20%',
},
},
];
142 changes: 88 additions & 54 deletions src/components/Admin/ListBots/index.js
Expand Up @@ -5,10 +5,12 @@ import PropTypes from 'prop-types';
import uiActions from '../../../redux/actions/ui';
import { Link } from 'react-router-dom';
import MaterialTable from 'material-table';
import { fetchBots } from '../../../apis/index';
import { BOT } from './constants';
import Tabs from '@material-ui/core/Tabs';
import Tab from '@material-ui/core/Tab';
import { Container } from '../AdminStyles';
import { ActionSpan, ActionSeparator } from '../../shared/TableActionStyles';
import { deleteChatBot } from '../../../apis/index';
import { deleteChatBot, fetchBots } from '../../../apis/index';

class ListBots extends React.Component {
state = {
Expand All @@ -18,6 +20,7 @@ class ListBots extends React.Component {
language: '',
name: '',
uuid: '',
value: 0,
};

componentDidMount() {
Expand All @@ -28,7 +31,31 @@ class ListBots extends React.Component {
fetchBots()
.then(payload => {
const { chatbots } = payload;
this.setState({ loadingBots: false, bots: chatbots });
let bots = [];
chatbots.forEach(chatBot => {
const { configure } = chatBot;
chatBot.displaySkills = configure.enableDefaultSkills
? 'true'
: 'false';
let allowedSites =
configure.allowBotOnlyOnOwnSites && configure.allowedSites;
let botSites = [];
if (allowedSites) {
allowedSites = allowedSites.split(',');
allowedSites.forEach(site => {
botSites.push(
<li>
<a href={site} target="_blank" rel="noopener noreferrer">
{site}
</a>
</li>,
);
});
}
chatBot.botSite = botSites.length > 0 ? botSites : '-';
bots.push(chatBot);
});
this.setState({ loadingBots: false, bots });
})
.catch(error => {
console.log(error);
Expand Down Expand Up @@ -73,59 +100,66 @@ class ListBots extends React.Component {
});
};

handleTabChange = (event, value) => {
this.setState({ value });
};

render() {
const { loadingBots, bots } = this.state;
const { loadingBots, bots, value } = this.state;
return (
<MaterialTable
isLoading={loadingBots}
options={{
actionsColumnIndex: -1,
pageSize: 10,
}}
columns={BOT}
data={bots}
title=""
style={{
padding: '1rem',
margin: '2rem',
}}
actions={[
{
onDelete: (event, rowData) => {
this.handleDelete(
rowData.name,
rowData.language,
rowData.group,
rowData.key,
);
},
},
]}
components={{
Action: props => (
<React.Fragment>
<Link
to={
'/botWizard?name=' +
props.data.name +
'&language=' +
props.data.language +
'&group=' +
props.data.group
}
>
<ActionSpan>View</ActionSpan>
</Link>
<ActionSeparator> | </ActionSeparator>
<ActionSpan
onClick={event => props.action.onDelete(event, props.data)}
>
Delete
</ActionSpan>
</React.Fragment>
),
}}
/>
<Container>
<Tabs onChange={this.handleTabChange} value={value}>
<Tab label="Active" />
</Tabs>
{value === 0 && (
<MaterialTable
isLoading={loadingBots}
options={{
actionsColumnIndex: -1,
pageSize: 10,
}}
columns={BOT}
data={bots}
title=""
actions={[
{
onDelete: (event, rowData) => {
this.handleDelete(
rowData.name,
rowData.language,
rowData.group,
rowData.key,
);
},
},
]}
components={{
Action: props => (
<React.Fragment>
<Link
to={
'/botWizard?name=' +
props.data.name +
'&language=' +
props.data.language +
'&group=' +
props.data.group
}
>
<ActionSpan>View</ActionSpan>
</Link>
<ActionSeparator> | </ActionSeparator>
<ActionSpan
onClick={event => props.action.onDelete(event, props.data)}
>
Delete
</ActionSpan>
</React.Fragment>
),
}}
/>
)}
</Container>
);
}
}
Expand Down