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

Implement MetaFilter with separate field and value #225

Merged
merged 1 commit into from
Dec 7, 2021
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,20 @@ docs/_build/
# PyBuilder
target/

#Ipython Notebook
# Ipython Notebook
.ipynb_checkpoints

# Editors
.vscode

# NodeJS stuff
node_modules
package-lock.json

# Virtual environment
.ibutsu-env
.ibutsu_env
.ibutsu

# Frontend
frontend/public/version.json
Expand Down
124 changes: 26 additions & 98 deletions frontend/src/components/classify-failures.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import {
Checkbox,
Flex,
FlexItem,
Select,
SelectOption,
SelectVariant,
TextContent,
Text,
} from '@patternfly/react-core';
Expand All @@ -24,21 +21,23 @@ import { HttpClient } from '../services/http';
import { Settings } from '../settings';
import {
buildParams,
toAPIFilter,
getSpinnerRow,
resultToClassificationRow,
} from '../utilities';
import { OPERATIONS } from '../constants';
import { FILTERABLE_RESULT_FIELDS } from '../constants';
import {
FilterTable,
MultiClassificationDropdown,
MetaFilter,
} from './index';


export class ClassifyFailuresTable extends React.Component {
static propTypes = {
filters: PropTypes.object,
run_id: PropTypes.string
};
}

constructor(props) {
super(props);
Expand All @@ -56,9 +55,6 @@ export class ClassifyFailuresTable extends React.Component {
isError: false,
isFieldOpen: false,
isOperationOpen: false,
exceptionSelections: [],
isExceptionOpen: false,
exceptions: [],
includeSkipped: false,
filters: Object.assign({
'result': {op: 'in', val: 'failed;error'},
Expand All @@ -73,39 +69,6 @@ export class ClassifyFailuresTable extends React.Component {
this.getResultsForTable();
}

onExceptionToggle = isExpanded => {
this.setState({isExceptionOpen: isExpanded}, this.applyFilter);
}

applyExceptionFilter = () => {
let { filters, exceptionSelections } = this.state;
if (exceptionSelections.length > 0) {
filters["metadata.exception_name"] = Object.assign({op: 'in', val: exceptionSelections.join(';')});
this.setState({filters}, this.refreshResults);
}
else {
delete filters["metadata.exception_name"];
this.setState({filters}, this.refreshResults);
}
}

onExceptionSelect = (event, selection) => {
const exceptionSelections = this.state.exceptionSelections;
if (exceptionSelections.includes(selection)) {
this.setState({exceptionSelections: exceptionSelections.filter(item => item !== selection)}, this.applyExceptionFilter);
}
else {
this.setState({exceptionSelections: [...exceptionSelections, selection]}, this.applyExceptionFilter);
}
};

onExceptionClear = () => {
this.setState({
exceptionSelections: [],
isExceptionOpen: false
}, this.applyExceptionFilter);
};

onCollapse(event, rowIndex, isOpen) {
const { rows } = this.state;
rows[rowIndex].isOpen = isOpen;
Expand Down Expand Up @@ -146,7 +109,7 @@ export class ClassifyFailuresTable extends React.Component {

updateFilters(name, operator, value, callback) {
let filters = this.state.filters;
if (!value) {
if ((value === null) || (value.length === 0)) {
delete filters[name];
}
else {
Expand All @@ -156,27 +119,20 @@ export class ClassifyFailuresTable extends React.Component {
}

setFilter = (field, value) => {
this.updateFilters(field, 'eq', value, () => {
this.refreshResults();
})
};
// maybe process values array to string format here instead of expecting caller to do it?
let operator = (value.includes(";")) ? 'in' : 'eq'
this.updateFilters(field, operator, value, this.refreshResults)
}

removeFilter = id => {
if (id === "metadata.exception_name") { // only remove exception_name filter
this.updateFilters(id, null, null, () => {
this.setState({exceptionSelections: [], page: 1}, this.applyExceptionFilter);
});
if ((id !== "result") && (id !== "run_id")) { // Don't allow removal of error/failure filter
this.updateFilters(id, null, null, this.refreshResults)
}
}

onSkipCheck = (checked) => {
let { filters } = this.state;
if (checked) {
filters["result"]["val"] += ";skipped;xfailed"
}
else {
filters["result"]["val"] = "failed;error"
}
filters["result"]["val"] = ("failed;error") + ((checked) ? ";skipped;xfailed" : "")
this.setState(
{includeSkipped: checked, filters},
this.refreshResults
Expand All @@ -199,17 +155,9 @@ export class ClassifyFailuresTable extends React.Component {
this.setState({rows: [getSpinnerRow(5)], isEmpty: false, isError: false});
// get only failed results
let params = buildParams(filters);
params['filter'] = [];
params['filter'] = toAPIFilter(filters);
params['pageSize'] = this.state.pageSize;
params['page'] = this.state.page;
// Convert UI filters to API filters
for (let key in filters) {
if (Object.prototype.hasOwnProperty.call(filters, key) && !!filters[key]) {
let val = filters[key]['val'];
const op = OPERATIONS[filters[key]['op']];
params.filter.push(key + op + val);
}
}

this.setState({rows: [['Loading...', '', '', '', '']]});
HttpClient.get([Settings.serverUrl, 'result'], params)
Expand All @@ -229,17 +177,8 @@ export class ClassifyFailuresTable extends React.Component {
});
}

getExceptions() {
HttpClient.get([Settings.serverUrl, 'widget', 'result-aggregator'], {group_field: 'metadata.exception_name', run_id: this.props.run_id})
.then(response => response.json())
.then(data => {
this.setState({exceptions: data})
})
}

componentDidMount() {
this.getResultsForTable();
this.getExceptions();
}

render() {
Expand All @@ -248,35 +187,24 @@ export class ClassifyFailuresTable extends React.Component {
rows,
selectedResults,
includeSkipped,
isExceptionOpen,
exceptionSelections,
exceptions,
filters
} = this.state;
const { run_id } = this.props
const pagination = {
pageSize: this.state.pageSize,
page: this.state.page,
totalItems: this.state.totalItems
}
// filters for the exception
const exceptionFilters = [
<React.Fragment key="value">
<Select
aria-label="exception-filter"
placeholderText="Filter by exception"
variant={SelectVariant.checkbox}
isOpen={isExceptionOpen}
selections={exceptionSelections}
maxHeight={"1140%"}
isDisabled={exceptions.length < 2}
onToggle={this.onExceptionToggle}
onSelect={this.onExceptionSelect}
onClear={this.onExceptionClear}
>
{exceptions.map((option, index) => (
<SelectOption key={index} value={option._id} description={option.count + ' results'}/>
))}
</Select>
</React.Fragment>
// filters for the metadata
const resultFilters = [
<MetaFilter
key="metafilter"
// user_properties fields shouldn't be injected here
fieldOptions={FILTERABLE_RESULT_FIELDS}
runId={run_id}
setFilter={this.setFilter}
customFilters={{'result': filters['result']}}
/>,
]
return (
<Card className="pf-u-mt-lg">
Expand Down Expand Up @@ -314,7 +242,7 @@ export class ClassifyFailuresTable extends React.Component {
onRowSelect={this.onTableRowSelect}
variant={TableVariant.compact}
activeFilters={this.state.filters}
filters={exceptionFilters}
filters={resultFilters}
onRemoveFilter={this.removeFilter}
hideFilters={["run_id", "project_id"]}
/>
Expand Down
Loading