Skip to content
This repository has been archived by the owner on Mar 27, 2019. It is now read-only.

List items filtering #106

Merged
merged 10 commits into from
Apr 27, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const checkVaultUiServer = (nextState, replace, callback) => {
window.defaultBackendPath = resp.data.defaultBackendPath;
window.suppliedAuthToken = resp.data.suppliedAuthToken;
callback();
}).catch((err) => callback())
}).catch(() => callback())
} else {
callback();
}
Expand Down
34 changes: 26 additions & 8 deletions app/components/Authentication/AwsEc2/AwsEc2.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { PropTypes } from 'react';
import Dialog from 'material-ui/Dialog';
import TextField from 'material-ui/TextField';
import IconButton from 'material-ui/IconButton';
import FontIcon from 'material-ui/FontIcon';
import { Tabs, Tab } from 'material-ui/Tabs';
import Paper from 'material-ui/Paper';
import { List, ListItem } from 'material-ui/List';
Expand All @@ -17,8 +16,7 @@ import Toggle from 'material-ui/Toggle';
// Styles
import styles from './awsec2.css';
import sharedStyles from '../../shared/styles.css';
import { green500, green400, red500, red300, yellow500, white } from 'material-ui/styles/colors.js';
import Checkbox from 'material-ui/Checkbox';
import { red500 } from 'material-ui/styles/colors.js';
import { callVaultApi, tokenHasCapabilities, history } from '../../shared/VaultUtils.jsx';
// Misc
import _ from 'lodash';
Expand All @@ -32,6 +30,10 @@ function snackBarMessage(message) {
}

export default class AwsEc2AuthBackend extends React.Component {
static propTypes = {
params: PropTypes.object.isRequired,
location: PropTypes.object.isRequired
};

ec2ConfigSchema = {
access_key: '',
Expand Down Expand Up @@ -62,6 +64,7 @@ export default class AwsEc2AuthBackend extends React.Component {
baseUrl: `/auth/aws-ec2/${this.props.params.namespace}/`,
baseVaultPath: `auth/${this.props.params.namespace}`,
ec2Roles: [],
filteredEc2RoleList: [],
configObj: this.ec2ConfigSchema,
newConfigObj: this.ec2ConfigSchema,
newRoleConfig: this.roleConfigSchema,
Expand Down Expand Up @@ -91,13 +94,13 @@ export default class AwsEc2AuthBackend extends React.Component {
callVaultApi('get', `${this.state.baseVaultPath}/role`, { list: true }, null)
.then((resp) => {
let roles = _.get(resp, 'data.data.keys', []);
this.setState({ ec2Roles: _.valuesIn(roles) });
this.setState({ ec2Roles: _.valuesIn(roles), filteredEc2RoleList: _.valuesIn(roles) });
})
.catch((error) => {
if (error.response.status !== 404) {
snackBarMessage(error);
} else {
this.setState({ ec2Roles: [] });
this.setState({ ec2Roles: [], filteredEc2RoleList: [] });
}
});
})
Expand Down Expand Up @@ -191,7 +194,7 @@ export default class AwsEc2AuthBackend extends React.Component {
if (!tab) {
history.push(`${this.state.baseUrl}${this.state.selectedTab}/`);
} else {
this.state.selectedTab = tab.includes('/') ? tab.split('/')[0] : tab;
this.setState({selectedTab: tab.includes('/') ? tab.split('/')[0] : tab});
}
}

Expand All @@ -200,7 +203,7 @@ export default class AwsEc2AuthBackend extends React.Component {
this.getEc2AuthConfig();
let uri = this.props.location.pathname.split(this.state.baseUrl)[1];
if(uri.includes('roles/') && uri.split('roles/')[1]) {
this.state.selectedRoleId = uri.split('roles/')[1];
this.setState({selectedRoleId: uri.split('roles/')[1]});
this.displayRole();
}
}
Expand All @@ -221,6 +224,7 @@ export default class AwsEc2AuthBackend extends React.Component {
baseUrl: `/auth/aws-ec2/${nextProps.params.namespace}/`,
baseVaultPath: `auth/${nextProps.params.namespace}`,
ec2Roles: [],
filteredEc2RoleList: [],
selectedRoleId: '',
newConfigObj: this.ec2ConfigSchema,
configObj: this.ec2ConfigSchema,
Expand All @@ -234,7 +238,7 @@ export default class AwsEc2AuthBackend extends React.Component {

render() {
let renderRoleListItems = () => {
return _.map(this.state.ec2Roles, (role) => {
return _.map(this.state.filteredEc2RoleList, (role) => {
let avatar = (<Avatar icon={<ActionAccountBox />} />);
let action = (
<IconButton
Expand Down Expand Up @@ -649,6 +653,20 @@ export default class AwsEc2AuthBackend extends React.Component {
}}
/>
</ToolbarGroup>
<ToolbarGroup lastChild={true}>
<TextField
floatingLabelFixed={true}
floatingLabelText="Filter"
hintText="Filter list items"
onChange={(e, v) => {
this.setState({
filteredEc2RoleList: _.filter(this.state.ec2Roles, (item) => {
return item.includes(v);
})
})
}}
/>
</ToolbarGroup>
</Toolbar>
<List className={sharedStyles.listStyle}>
{renderRoleListItems()}
Expand Down
55 changes: 44 additions & 11 deletions app/components/Authentication/Github/Github.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { PropTypes } from 'react';
import Dialog from 'material-ui/Dialog';
import TextField from 'material-ui/TextField';
import IconButton from 'material-ui/IconButton';
import FontIcon from 'material-ui/FontIcon';
import { Tabs, Tab } from 'material-ui/Tabs';
import Paper from 'material-ui/Paper';
import { List, ListItem } from 'material-ui/List';
Expand All @@ -13,10 +12,8 @@ import Subheader from 'material-ui/Subheader';
import ActionAccountBox from 'material-ui/svg-icons/action/account-box';
import ActionDelete from 'material-ui/svg-icons/action/delete';
import ActionDeleteForever from 'material-ui/svg-icons/action/delete-forever';
import Toggle from 'material-ui/Toggle';
import Avatar from 'material-ui/Avatar';
import { green500, green400, red500, red300, yellow500, white } from 'material-ui/styles/colors.js';
import Checkbox from 'material-ui/Checkbox';
import { red500 } from 'material-ui/styles/colors.js';

// Styles
import styles from './github.css';
Expand All @@ -33,6 +30,11 @@ function snackBarMessage(message) {
}

export default class GithubAuthBackend extends React.Component {
static propTypes = {
params: PropTypes.object.isRequired,
location: PropTypes.object.isRequired
};

backendConfigSchema = {
organization: '',
base_url: undefined,
Expand All @@ -51,7 +53,9 @@ export default class GithubAuthBackend extends React.Component {
baseUrl: `/auth/github/${this.props.params.namespace}/`,
baseVaultPath: `auth/${this.props.params.namespace}`,
teams: [],
filteredTeamList: [],
users: [],
filteredUserList: [],
config: this.backendConfigSchema,
newConfig: this.backendConfigSchema,
itemConfig: this.teamConfigSchema,
Expand All @@ -78,13 +82,13 @@ export default class GithubAuthBackend extends React.Component {
callVaultApi('get', `${this.state.baseVaultPath}/map/teams`, { list: true }, null)
.then((resp) => {
let teams = _.get(resp, 'data.data.keys', []);
this.setState({ teams: _.valuesIn(teams) });
this.setState({ teams: _.valuesIn(teams), filteredTeamList: _.valuesIn(teams) });
})
.catch((error) => {
if (error.response.status !== 404) {
snackBarMessage(error);
} else {
this.setState({ teams: [] });
this.setState({ teams: [], filteredTeamList: [] });
}
});
})
Expand All @@ -99,13 +103,13 @@ export default class GithubAuthBackend extends React.Component {
callVaultApi('get', `${this.state.baseVaultPath}/map/users`, { list: true }, null)
.then((resp) => {
let users = _.get(resp, 'data.data.keys', []);
this.setState({ users: _.valuesIn(users) });
this.setState({ users: _.valuesIn(users), filteredUserList: _.valuesIn(users) });
})
.catch((error) => {
if (error.response.status !== 404) {
snackBarMessage(error);
} else {
this.setState({ users: [] });
this.setState({ users: [], filteredUserList: [] });
}
});
})
Expand Down Expand Up @@ -179,7 +183,6 @@ export default class GithubAuthBackend extends React.Component {
}

createUpdateItem(id) {
let itemId = this.state.selectedTab;
tokenHasCapabilities(['create', 'update'], `${this.state.baseVaultPath}/map/${id}`)
.then(() => {
let updateObj = _.clone(this.state.itemConfig);
Expand All @@ -204,7 +207,7 @@ export default class GithubAuthBackend extends React.Component {
if (!tab) {
history.push(`${this.state.baseUrl}${this.state.selectedTab}/`);
} else {
this.state.selectedTab = tab.includes('/') ? tab.split('/')[0] : tab;
this.setState({selectedTab: tab.includes('/') ? tab.split('/')[0] : tab});
}
}

Expand Down Expand Up @@ -237,7 +240,9 @@ export default class GithubAuthBackend extends React.Component {
baseUrl: `/auth/github/${nextProps.params.namespace}/`,
baseVaultPath: `auth/${nextProps.params.namespace}`,
users: [],
filteredUserList: [],
teams: [],
filteredTeamList: [],
selectedItemId: '',
newConfig: this.backendConfigSchema,
config: this.backendConfigSchema,
Expand All @@ -254,7 +259,7 @@ export default class GithubAuthBackend extends React.Component {

render() {
let renderListItems = () => {
let items = this.state.selectedTab === 'teams' ? this.state.teams : this.state.users;
let items = this.state.selectedTab === 'teams' ? this.state.filteredTeamList : this.state.filteredUserList;
return _.map(items, (item) => {
let avatar = (<Avatar icon={<ActionAccountBox />} />);
let action = (
Expand Down Expand Up @@ -435,6 +440,20 @@ export default class GithubAuthBackend extends React.Component {
}}
/>
</ToolbarGroup>
<ToolbarGroup lastChild={true}>
<TextField
floatingLabelFixed={true}
floatingLabelText="Filter"
hintText="Filter list items"
onChange={(e, v) => {
this.setState({
filteredTeamList: _.filter(this.state.teams, (item) => {
return item.includes(v);
})
})
}}
/>
</ToolbarGroup>
</Toolbar>
<List className={sharedStyles.listStyle}>
{renderListItems()}
Expand Down Expand Up @@ -467,6 +486,20 @@ export default class GithubAuthBackend extends React.Component {
}}
/>
</ToolbarGroup>
<ToolbarGroup lastChild={true}>
<TextField
floatingLabelFixed={true}
floatingLabelText="Filter"
hintText="Filter list items"
onChange={(e, v) => {
this.setState({
filteredUserList: _.filter(this.state.users, (item) => {
return item.includes(v);
})
})
}}
/>
</ToolbarGroup>
</Toolbar>
<List className={sharedStyles.listStyle}>
{renderListItems()}
Expand Down
22 changes: 19 additions & 3 deletions app/components/Authentication/Radius/Radius.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class RadiusAuthBackend extends React.Component {
baseUrl: `/auth/radius/${this.props.params.namespace}/`,
baseVaultPath: `auth/${this.props.params.namespace}`,
userList: [],
filteredUserList: [],
newUserId: '',
newUserObject: {},
selectedUserId: '',
Expand Down Expand Up @@ -84,7 +85,7 @@ class RadiusAuthBackend extends React.Component {
let userlist = _.map(resp.data.data.keys, (userid) => {
return { id: userid, path: `${this.state.baseVaultPath}/users/${userid}` };
})
this.setState({ userList: userlist });
this.setState({ userList: userlist, filteredUserList: userlist });
})
.catch((err) => {
// 404 is expected when no users are registered
Expand All @@ -93,7 +94,7 @@ class RadiusAuthBackend extends React.Component {
})
})
.catch(() => {
this.setState({ userList: [] })
this.setState({ userList: [], filteredUserList: [] })
snackBarMessage(new Error(`No permissions to list users`));
})
}
Expand Down Expand Up @@ -147,6 +148,7 @@ class RadiusAuthBackend extends React.Component {
baseUrl: `/auth/radius/${nextProps.params.namespace}/`,
baseVaultPath: `auth/${nextProps.params.namespace}`,
userList: [],
filteredUserList: [],
selectedUserId: '',
newConfigObj: this.radiusConfigSchema,
configObj: this.radiusConfigSchema
Expand Down Expand Up @@ -202,7 +204,7 @@ class RadiusAuthBackend extends React.Component {

render() {
let renderUserListItems = () => {
return _.map(this.state.userList, (userobj) => {
return _.map(this.state.filteredUserList, (userobj) => {
let avatar = (<Avatar icon={<ActionAccountBox />} />);
let action = (
<IconButton
Expand Down Expand Up @@ -379,6 +381,20 @@ class RadiusAuthBackend extends React.Component {
}}
/>
</ToolbarGroup>
<ToolbarGroup lastChild={true}>
<TextField
floatingLabelFixed={true}
floatingLabelText="Filter"
hintText="Filter list items"
onChange={(e, v) => {
this.setState({
filteredUserList: _.filter(this.state.userList, (item) => {
return item.id.includes(v);
})
})
}}
/>
</ToolbarGroup>
</Toolbar>
<List className={sharedStyles.listStyle}>
{renderUserListItems()}
Expand Down
Loading