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

Add new sort icon to CollectorsList #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
56 changes: 23 additions & 33 deletions src/web/collectors/CollectorsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { defaultCompare as naturalSort } from 'logic/DefaultCompare';
import styled from 'styled-components';

import { Alert, Button, Col, Row, Table } from 'components/bootstrap';
import { Icon, Spinner } from 'components/common';
import { Spinner, SortIcon } from 'components/common';

import CollectorsStore from './CollectorsStore';
import CollectorsActions from './CollectorsActions';
Expand All @@ -33,17 +33,8 @@ const StyledTable = styled(Table)`
margin-bottom: 0px;
`;

const StyledIcon = styled(Icon)(({ $isAlwaysVisible }) => `
const StyledSortIcon = styled(SortIcon)`
margin-left: 5px;
visibility: ${$isAlwaysVisible ? 'visible' : 'hidden'}
`);

const SortableTh = styled.th`
cursor: pointer;

&:hover ${StyledIcon} {
visibility: visible;
}
`;

const CollectorList = createReactClass({
Expand Down Expand Up @@ -90,11 +81,10 @@ const CollectorList = createReactClass({
return (this.state.sortDesc ? naturalSort(field2, field1) : naturalSort(field1, field2));
},

_getSortingIcon(field) {
_getSortingIcon(field, onChange) {
const { sortBy, sortDesc } = this.state;
const name = (sortBy === field ? (sortDesc ? 'sort-amount-up' : 'sort-amount-down') : 'sort');

return <StyledIcon name={name} fixedWidth $isAlwaysVisible={sortBy === field} />;
const activeDirection = (sortBy === field ? (sortDesc ? 'desc' : 'asc') : null);
return <StyledSortIcon activeDirection={activeDirection} ascId='asc' descId='desc' onChange={onChange}/>
},

_formatCollectorList(collectors) {
Expand All @@ -103,30 +93,30 @@ const CollectorList = createReactClass({
<StyledTable striped>
<thead>
<tr>
<SortableTh onClick={this.sortByNodeId}>
<th>
Name
{this._getSortingIcon('node_id')}
</SortableTh>
<SortableTh onClick={this.sortByCollectorStatus}>
{this._getSortingIcon('node_id', this.sortByNodeId)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use an actual component here.

</th>
<th>
Status
{this._getSortingIcon('collector_status')}
</SortableTh>
<SortableTh onClick={this.sortByOperatingSystem}>
{this._getSortingIcon('collector_status', this.sortByCollectorStatus)}
</th>
<th>
Operating System
{this._getSortingIcon('operating_system')}
</SortableTh>
<SortableTh onClick={this.sortByLastSeen}>
{this._getSortingIcon('operating_system', this.sortByOperatingSystem)}
</th>
<th>
Last Seen
{this._getSortingIcon('last_seen')}
</SortableTh>
<SortableTh onClick={this.sortById}>
{this._getSortingIcon('last_seen', this.sortByLastSeen)}
</th>
<th>
Collector Id
{this._getSortingIcon('id')}
</SortableTh>
<SortableTh onClick={this.sortByCollectorVersion}>
{this._getSortingIcon('id', this.sortById)}
</th>
<th>
Collector Version
{this._getSortingIcon('collector_version')}
</SortableTh>
{this._getSortingIcon('collector_version', this.sortByCollectorVersion)}
</th>
<th className="actions">&nbsp;</th>
</tr>
</thead>
Expand Down