Skip to content

Commit

Permalink
[Bug fix] Wrong behavior when clicking table rows on list pages (#3540)
Browse files Browse the repository at this point in the history
  • Loading branch information
kravets-levko authored Mar 7, 2019
1 parent 507ea61 commit be1bd28
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 99 deletions.
1 change: 0 additions & 1 deletion client/app/assets/less/redash/redash-newstyle.less
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ body {
.table-data {
tbody > tr > td {
padding-top: 5px !important;
cursor: pointer;
}

.btn-favourite, .btn-archive {
Expand Down
3 changes: 0 additions & 3 deletions client/app/components/FavoritesControl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ export class FavoritesControl extends React.Component {
};

toggleItem(event, item, callback) {
event.preventDefault();
event.stopPropagation();

const action = item.is_favorite ? item.$unfavorite.bind(item) : item.$favorite.bind(item);
const savedIsFavorite = item.is_favorite;

Expand Down
4 changes: 0 additions & 4 deletions client/app/components/groups/DeleteGroupButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import Tooltip from 'antd/lib/tooltip';
import { toastr } from '@/services/ng';

function deleteGroup(event, group, onGroupDeleted) {
// prevent default click action on table rows
event.preventDefault();
event.stopPropagation();

Modal.confirm({
title: 'Delete Group',
content: 'Are you sure you want to delete this group?',
Expand Down
18 changes: 2 additions & 16 deletions client/app/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isFunction, each, extend } from 'lodash';
import { each, extend } from 'lodash';

// eslint-disable-next-line import/prefer-default-export
export function routesToAngularRoutes(routes, template) {
const result = {};
template = extend({}, template); // convert to object
Expand All @@ -22,18 +23,3 @@ export function routesToAngularRoutes(routes, template) {
});
return result;
}

function doCancelEvent(event) {
event.stopPropagation();
event.preventDefault();
}

export function cancelEvent(handler) {
if (isFunction(handler)) {
return (event, ...rest) => {
doCancelEvent(event);
return handler(...rest);
};
}
return doCancelEvent;
}
4 changes: 0 additions & 4 deletions client/app/pages/alerts/AlertsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import LoadingState from '@/components/items-list/components/LoadingState';
import ItemsTable, { Columns } from '@/components/items-list/components/ItemsTable';

import { Alert } from '@/services/alert';
import navigateTo from '@/services/navigateTo';
import { routesToAngularRoutes } from '@/lib/utils';

const STATE_CLASS = {
Expand Down Expand Up @@ -57,8 +56,6 @@ class AlertsList extends React.Component {
width: '1%' }),
];

onTableRowClick = (event, item) => navigateTo('alerts/' + item.id);

render() {
const { controller } = this.props;

Expand All @@ -82,7 +79,6 @@ class AlertsList extends React.Component {
<ItemsTable
items={controller.pageItems}
columns={this.listColumns}
onRowClick={this.onTableRowClick}
orderByField={controller.orderByField}
orderByReverse={controller.orderByReverse}
toggleSorting={controller.toggleSorting}
Expand Down
4 changes: 0 additions & 4 deletions client/app/pages/dashboards/DashboardList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import ItemsTable, { Columns } from '@/components/items-list/components/ItemsTab
import Layout from '@/components/layouts/ContentWithSidebar';

import { Dashboard } from '@/services/dashboard';
import navigateTo from '@/services/navigateTo';
import { routesToAngularRoutes } from '@/lib/utils';

import DashboardListEmptyState from './DashboardListEmptyState';
Expand Down Expand Up @@ -68,8 +67,6 @@ class DashboardList extends React.Component {
}),
];

onTableRowClick = (event, item) => navigateTo('dashboard/' + item.slug);

render() {
const { controller } = this.props;
return (
Expand Down Expand Up @@ -107,7 +104,6 @@ class DashboardList extends React.Component {
<ItemsTable
items={controller.pageItems}
columns={this.listColumns}
onRowClick={this.onTableRowClick}
orderByField={controller.orderByField}
orderByReverse={controller.orderByReverse}
toggleSorting={controller.toggleSorting}
Expand Down
35 changes: 15 additions & 20 deletions client/app/pages/groups/GroupDataSources.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { currentUser } from '@/services/auth';
import { Group } from '@/services/group';
import { DataSource } from '@/services/data-source';
import navigateTo from '@/services/navigateTo';
import { routesToAngularRoutes, cancelEvent } from '@/lib/utils';
import { routesToAngularRoutes } from '@/lib/utils';

class GroupDataSources extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -64,7 +64,7 @@ class GroupDataSources extends React.Component {
const menu = (
<Menu
selectedKeys={[datasource.view_only ? 'viewonly' : 'full']}
onClick={item => this.setDataSourcePermissions(item.domEvent, datasource, item.key)}
onClick={item => this.setDataSourcePermissions(datasource, item.key)}
>
<Menu.Item key="full">Full Access</Menu.Item>
<Menu.Item key="viewonly">View Only</Menu.Item>
Expand All @@ -73,9 +73,7 @@ class GroupDataSources extends React.Component {

return (
<Dropdown trigger={['click']} overlay={menu}>
<Button className="w-100" onClick={cancelEvent()}>
{datasource.view_only ? 'View Only' : 'Full Access'} <Icon type="down" />
</Button>
<Button className="w-100">{datasource.view_only ? 'View Only' : 'Full Access'}<Icon type="down" /></Button>
</Dropdown>
);
}, {
Expand All @@ -84,14 +82,21 @@ class GroupDataSources extends React.Component {
isAvailable: () => currentUser.isAdmin,
}),
Columns.custom((text, datasource) => (
<Button className="w-100" type="danger" onClick={event => this.removeGroupDataSource(event, datasource)}>Remove</Button>
<Button className="w-100" type="danger" onClick={() => this.removeGroupDataSource(datasource)}>Remove</Button>
), {
width: '1%',
isAvailable: () => currentUser.isAdmin,
}),
];

removeGroupDataSource = cancelEvent((datasource) => {
componentDidMount() {
Group.get({ id: this.groupId }).$promise.then((group) => {
this.group = group;
this.forceUpdate();
});
}

removeGroupDataSource = (datasource) => {
Group.removeDataSource({ id: this.groupId, dataSourceId: datasource.id }).$promise
.then(() => {
this.props.controller.updatePagination({ page: 1 });
Expand All @@ -100,18 +105,9 @@ class GroupDataSources extends React.Component {
.catch(() => {
toastr.error('Failed to remove data source from group.');
});
});

componentDidMount() {
Group.get({ id: this.groupId }).$promise.then((group) => {
this.group = group;
this.forceUpdate();
});
}

onTableRowClick = (event, item) => navigateTo('data_sources/' + item.id);
};

setDataSourcePermissions = cancelEvent((datasource, permission) => {
setDataSourcePermissions = (datasource, permission) => {
const viewOnly = permission !== 'full';

Group.updateDataSource({ id: this.groupId, dataSourceId: datasource.id }, { view_only: viewOnly }).$promise
Expand All @@ -122,7 +118,7 @@ class GroupDataSources extends React.Component {
.catch(() => {
toastr.error('Failed change data source permissions.');
});
});
};

addDataSources = () => {
const allDataSources = DataSource.query().$promise;
Expand Down Expand Up @@ -199,7 +195,6 @@ class GroupDataSources extends React.Component {
items={controller.pageItems}
columns={this.listColumns}
showHeader={false}
onRowClick={this.onTableRowClick}
context={this.actions}
orderByField={controller.orderByField}
orderByReverse={controller.orderByReverse}
Expand Down
23 changes: 9 additions & 14 deletions client/app/pages/groups/GroupMembers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { currentUser } from '@/services/auth';
import { Group } from '@/services/group';
import { User } from '@/services/user';
import navigateTo from '@/services/navigateTo';
import { routesToAngularRoutes, cancelEvent } from '@/lib/utils';
import { routesToAngularRoutes } from '@/lib/utils';

class GroupMembers extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -73,25 +73,21 @@ class GroupMembers extends React.Component {
}),
];

removeGroupMember = cancelEvent((user) => {
Group.removeMember({ id: this.groupId, userId: user.id }).$promise
.then(() => {
this.props.controller.updatePagination({ page: 1 });
this.props.controller.update();
})
.catch(() => {
toastr.error('Failed to remove member from group.');
});
});

componentDidMount() {
Group.get({ id: this.groupId }).$promise.then((group) => {
this.group = group;
this.forceUpdate();
});
}

onTableRowClick = (event, item) => navigateTo('users/' + item.id);
removeGroupMember = (event, user) => Group.removeMember({ id: this.groupId, userId: user.id }).$promise
.then(() => {
this.props.controller.updatePagination({ page: 1 });
this.props.controller.update();
})
.catch(() => {
toastr.error('Failed to remove member from group.');
});

addMembers = () => {
const alreadyAddedUsers = map(this.props.controller.allItems, u => u.id);
Expand Down Expand Up @@ -164,7 +160,6 @@ class GroupMembers extends React.Component {
items={controller.pageItems}
columns={this.listColumns}
showHeader={false}
onRowClick={this.onTableRowClick}
context={this.actions}
orderByField={controller.orderByField}
orderByReverse={controller.orderByReverse}
Expand Down
7 changes: 2 additions & 5 deletions client/app/pages/groups/GroupsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class GroupsList extends React.Component {
}),
Columns.custom((text, group) => (
<Button.Group>
<Button href={`groups/${group.id}`} onClick={e => e.stopPropagation()}>Members</Button>
<Button href={`groups/${group.id}`}>Members</Button>
{currentUser.isAdmin && (
<Button href={`groups/${group.id}/data_sources`} onClick={e => e.stopPropagation()}>Data Sources</Button>
<Button href={`groups/${group.id}/data_sources`}>Data Sources</Button>
)}
</Button.Group>
), {
Expand Down Expand Up @@ -73,8 +73,6 @@ class GroupsList extends React.Component {
});
};

onTableRowClick = (event, item) => navigateTo('groups/' + item.id);

onGroupDeleted = () => {
this.props.controller.updatePagination({ page: 1 });
this.props.controller.update();
Expand Down Expand Up @@ -103,7 +101,6 @@ class GroupsList extends React.Component {
items={controller.pageItems}
columns={this.listColumns}
showHeader={false}
onRowClick={this.onTableRowClick}
context={this.actions}
orderByField={controller.orderByField}
orderByReverse={controller.orderByReverse}
Expand Down
4 changes: 0 additions & 4 deletions client/app/pages/queries-list/QueriesList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Layout from '@/components/layouts/ContentWithSidebar';

import { Query } from '@/services/query';
import { currentUser } from '@/services/auth';
import navigateTo from '@/services/navigateTo';
import { routesToAngularRoutes } from '@/lib/utils';

import QueriesListEmptyState from './QueriesListEmptyState';
Expand Down Expand Up @@ -84,8 +83,6 @@ class QueriesList extends React.Component {
),
];

onTableRowClick = (event, item) => navigateTo('queries/' + item.id);

render() {
const { controller } = this.props;
return (
Expand Down Expand Up @@ -123,7 +120,6 @@ class QueriesList extends React.Component {
<ItemsTable
items={controller.pageItems}
columns={this.listColumns}
onRowClick={this.onTableRowClick}
orderByField={controller.orderByField}
orderByReverse={controller.orderByReverse}
toggleSorting={controller.toggleSorting}
Expand Down
27 changes: 3 additions & 24 deletions client/app/pages/users/UsersList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,31 +161,11 @@ class UsersList extends React.Component {
}
};

onTableRowClick = (event, item) => navigateTo('users/' + item.id);
enableUser = (event, user) => User.enableUser(user).then(() => this.props.controller.update());

enableUser = (event, user) => {
// prevent default click action on table rows
event.preventDefault();
event.stopPropagation();
return User.enableUser(user)
.then(() => this.props.controller.update());
};

disableUser = (event, user) => {
// prevent default click action on table rows
event.preventDefault();
event.stopPropagation();
return User.disableUser(user)
.then(() => this.props.controller.update());
};
disableUser = (event, user) => User.disableUser(user).then(() => this.props.controller.update());

deleteUser = (event, user) => {
// prevent default click action on table rows
event.preventDefault();
event.stopPropagation();
return User.deleteUser(user)
.then(() => this.props.controller.update());
};
deleteUser = (event, user) => User.deleteUser(user).then(() => this.props.controller.update());

// eslint-disable-next-line class-methods-use-this
renderPageHeader() {
Expand Down Expand Up @@ -230,7 +210,6 @@ class UsersList extends React.Component {
<ItemsTable
items={controller.pageItems}
columns={this.listColumns}
onRowClick={this.onTableRowClick}
context={this.actions}
orderByField={controller.orderByField}
orderByReverse={controller.orderByReverse}
Expand Down

0 comments on commit be1bd28

Please sign in to comment.