From 81334a0f02e62fd6d1ed900aa318993344c268d4 Mon Sep 17 00:00:00 2001 From: mshriver Date: Wed, 17 Jul 2024 09:10:08 -0400 Subject: [PATCH] DRAFT updating run and result components currently getRuns is not filtering correctly and is displaying runs from all projects. --- frontend/src/result-list.js | 10 ++++++---- frontend/src/run-list.js | 21 +++++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/frontend/src/result-list.js b/frontend/src/result-list.js index fdf9496b..7fba5e4b 100644 --- a/frontend/src/result-list.js +++ b/frontend/src/result-list.js @@ -28,7 +28,6 @@ import { HttpClient } from './services/http'; import { Settings } from './settings'; import { buildParams, - getActiveProject, getFilterMode, getOperationMode, getOperationsFromField, @@ -38,8 +37,11 @@ import { } from './utilities'; import { FilterTable, MultiValueInput } from './components'; import { OPERATIONS, RESULT_FIELDS } from './constants'; +import { IbutsuContext } from './services/context'; export class ResultList extends React.Component { + static contextType = IbutsuContext; + static propTypes = { location: PropTypes.object, navigate: PropTypes.func, @@ -378,9 +380,9 @@ export class ResultList extends React.Component { this.setState({rows: [getSpinnerRow(5)], isEmpty: false, isError: false}); let params = {filter: []}; let filters = this.state.filters; - const project = getActiveProject(); - if (project) { - filters['project_id'] = {'val': project.id, 'op': 'eq'}; + const { primaryObject } = this.context; + if (primaryObject) { + filters['project_id'] = {'val': primaryObject.id, 'op': 'eq'}; } else if (Object.prototype.hasOwnProperty.call(filters, 'project_id')) { delete filters['project_id'] diff --git a/frontend/src/run-list.js b/frontend/src/run-list.js index 9a31b812..0be1b3cc 100644 --- a/frontend/src/run-list.js +++ b/frontend/src/run-list.js @@ -28,7 +28,6 @@ import { Settings } from './settings'; import { buildBadge, buildParams, - getActiveProject, getFilterMode, getOperationMode, getOperationsFromField, @@ -38,6 +37,7 @@ import { } from './utilities'; import { MultiValueInput, FilterTable, RunSummary } from './components'; import { OPERATIONS, RUN_FIELDS } from './constants'; +import { IbutsuContext } from './services/context'; function runToRow(run, filterFunc) { @@ -85,6 +85,8 @@ function runToRow(run, filterFunc) { } export class RunList extends React.Component { + static contextType = IbutsuContext; + static propTypes = { location: PropTypes.object, navigate: PropTypes.func, @@ -136,8 +138,8 @@ export class RunList extends React.Component { isBoolOpen: false, }; this.params = new URLSearchParams(props.location.search); - props.eventEmitter.on('projectChange', () => { - this.getRuns(); + props.eventEmitter.on('projectChange', (value) => { + this.getRuns(value); }); } @@ -265,7 +267,6 @@ export class RunList extends React.Component { this.setState({filters: filters, page: 1}, callback); } - setFilter = (field, value) => { this.updateFilters(field, 'eq', value, () => { this.updateUrl(); @@ -280,7 +281,6 @@ export class RunList extends React.Component { }); } - removeFilter = id => { this.updateFilters(id, null, null, () => { this.updateUrl(); @@ -309,14 +309,15 @@ export class RunList extends React.Component { }); } - getRuns() { + getRuns = (handledOject = null) => { // First, show a spinner this.setState({rows: [getSpinnerRow(5)], isEmpty: false, isError: false}); let params = {filter: []}; let filters = this.state.filters; - const project = getActiveProject(); - if (project) { - filters['project_id'] = {'val': project.id, 'op': 'eq'}; + const { primaryObject } = this.context; + const targetObject = handledOject ?? primaryObject; + if (targetObject) { + filters['project_id'] = {'val': targetObject.id, 'op': 'eq'}; } else if (Object.prototype.hasOwnProperty.call(filters, 'project_id')) { delete filters['project_id'] @@ -346,7 +347,7 @@ export class RunList extends React.Component { console.error('Error fetching run data:', error); this.setState({rows: [], isEmpty: false, isError: true}); }); - } + }; clearFilters = () => { this.setState({