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

Reset- and Remove-Button for Powerfilter #863

Merged
merged 7 commits into from
Aug 9, 2018
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: 2 additions & 0 deletions gsa/src/gmp/models/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,8 @@ export const TAGS_FILTER_FILTER = Filter.fromString('type=tag');
export const USERS_FILTER_FILTER = Filter.fromString('type=user');
export const VULNS_FILTER_FILTER = Filter.fromString('type=vuln');

export const RESET_FILTER = Filter.fromString('first=1');

export default Filter;

// vim: set ts=2 sw=2 tw=80:
25 changes: 18 additions & 7 deletions gsa/src/web/components/powerfilter/powerfilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import _ from 'gmp/locale';

import logger from 'gmp/log';

import Filter, {RESET_FILTER} from 'gmp/models/filter';

import {KeyCode} from 'gmp/utils/event';
import {isDefined, isString} from 'gmp/utils/identity';

Expand All @@ -51,8 +53,6 @@ import Divider from 'web/components/layout/divider';
import IconDivider from 'web/components/layout/icondivider';
import Layout from 'web/components/layout/layout';

import Filter from 'gmp/models/filter';

const log = logger.getLogger('web.powerfilter');

const DEFAULT_FILTER_ID = '0';
Expand Down Expand Up @@ -140,8 +140,10 @@ class PowerFilter extends React.Component {
handleNamedFilterChange(value) {
const {filters} = this.props;

const filter = filters.find(f => f.id === value);

let filter = filters.find(f => f.id === value);
if (!isDefined(filter)) {
filter = RESET_FILTER;
}
this.updateFilter(filter);
}

Expand Down Expand Up @@ -228,6 +230,7 @@ class PowerFilter extends React.Component {
capabilities,
filters,
onEditClick,
onRemoveClick,
onResetClick,
} = this.props;
const namedfilterid = isDefined(filter) && isDefined(filter.id) ?
Expand Down Expand Up @@ -266,10 +269,17 @@ class PowerFilter extends React.Component {
onClick={this.handleUpdateFilter}
/>

{onResetClick &&
{onRemoveClick &&
<DeleteIcon
img="delete.svg"
title={_('Reset Filter')}
title={_('Remove Filter')}
active={isDefined(filter)}
onClick={isDefined(filter) ? onRemoveClick : undefined}
/>
}
{onResetClick &&
<Icon
img="first.svg"
title={_('Reset to Default Filter')}
active={isDefined(filter)}
onClick={isDefined(filter) ? onResetClick : undefined}
/>
Expand Down Expand Up @@ -333,6 +343,7 @@ PowerFilter.propTypes = {
onEditClick: PropTypes.func,
onError: PropTypes.func,
onFilterCreated: PropTypes.func,
onRemoveClick: PropTypes.func,
onResetClick: PropTypes.func,
onUpdate: PropTypes.func,
};
Expand Down
10 changes: 8 additions & 2 deletions gsa/src/web/entities/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
pluralizeType,
} from 'gmp/utils/entitytype';

import Filter from 'gmp/models/filter';
import Filter, {RESET_FILTER} from 'gmp/models/filter';

import {YES_VALUE} from 'gmp/parser';

Expand Down Expand Up @@ -97,6 +97,7 @@ class EntitiesContainer extends React.Component {
this.handleTimer = this.handleTimer.bind(this);
this.handleFilterCreated = this.handleFilterCreated.bind(this);
this.handleFilterChanged = this.handleFilterChanged.bind(this);
this.handleFilterRemoved = this.handleFilterRemoved.bind(this);
this.handleFilterReset = this.handleFilterReset.bind(this);
this.handleAddMultiTag = this.handleAddMultiTag.bind(this);
this.handleTagChange = this.handleTagChange.bind(this);
Expand Down Expand Up @@ -159,7 +160,7 @@ class EntitiesContainer extends React.Component {

reload() {
// reload data from backend
this.load(this.state.loadedFilter);
this.load(this.props.filter);
}

getRefreshInterval() {
Expand Down Expand Up @@ -339,6 +340,10 @@ class EntitiesContainer extends React.Component {
this.load(filter);
}

handleFilterRemoved() {
this.load(RESET_FILTER);
}

handleFilterReset() {
const {history, location} = this.props;
const query = {...location.query};
Expand Down Expand Up @@ -545,6 +550,7 @@ class EntitiesContainer extends React.Component {
onDownloaded: onDownload,
onError: this.handleError,
onFilterChanged: this.handleFilterChanged,
onFilterRemoved: this.handleFilterRemoved,
onFilterReset: this.handleFilterReset,
onSortChange: this.handleSortChange,
onSelectionTypeChange: this.handleSelectionTypeChange,
Expand Down
3 changes: 3 additions & 0 deletions gsa/src/web/entities/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class EntitiesPage extends React.Component {
onError,
onFilterChanged,
onFilterCreated,
onFilterRemoved,
onFilterReset,
} = this.props;

Expand All @@ -225,6 +226,7 @@ class EntitiesPage extends React.Component {
onEditClick={handler}
onError={onError}
onFilterCreated={onFilterCreated}
onRemoveClick={onFilterRemoved}
onResetClick={onFilterReset}
onUpdate={onFilterChanged}
/>
Expand Down Expand Up @@ -309,6 +311,7 @@ EntitiesPage.propTypes = {
onError: PropTypes.func.isRequired,
onFilterChanged: PropTypes.func.isRequired,
onFilterCreated: PropTypes.func.isRequired,
onFilterRemoved: PropTypes.func.isRequired,
onFilterReset: PropTypes.func.isRequired,
};

Expand Down