Skip to content

Commit 1c40c46

Browse files
Add label relationship filter to build tests page (#3681)
The "new" filters interface was unable to represent relationship filters until #3671. Now that the problem has been solved, we can now add a "label" filter to the build tests page. This paves the way for the upcoming removal of the last relics of the old viewTest.php page.
1 parent 2ceba58 commit 1c40c46

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

resources/js/vue/components/shared/FilterGroup.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import {
7777
faBarsStaggered,
7878
faTrash,
7979
} from '@fortawesome/free-solid-svg-icons';
80-
import {BasicFilterField, FilterType, getEnumValues} from './Filters/FilterUtils';
80+
import {BasicFilterField, FilterType, getEnumValues, RelationshipFilterField} from './Filters/FilterUtils';
8181
8282
const AVAILABLE_FILTERS = Object.freeze({
8383
BuildTestsFiltersMultiFilterInput: (apolloClient) => [
@@ -87,6 +87,7 @@ const AVAILABLE_FILTERS = Object.freeze({
8787
new BasicFilterField('Start Time', FilterType.DATETIME, null, 'startTime'),
8888
new BasicFilterField('Status', FilterType.ENUM, () => getEnumValues(apolloClient, 'TestStatus'), 'status'),
8989
new BasicFilterField('Time Status', FilterType.ENUM, () => getEnumValues(apolloClient, 'TestTimeStatusCategory'), 'timeStatusCategory'),
90+
new RelationshipFilterField('Label', FilterType.TEXT, null, 'text', 'labels'),
9091
],
9192
BuildCoverageFiltersMultiFilterInput: () => [
9293
new BasicFilterField('Lines of Code Tested', FilterType.NUMBER, null, 'linesOfCodeTested'),

resources/js/vue/components/shared/Filters/FilterUtils.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,66 @@ export class BasicFilterField extends FilterField {
181181
}
182182
}
183183

184+
export class RelationshipFilterField extends FilterField {
185+
/**
186+
* @param {String} name
187+
* @param {FilterType} type
188+
* @param {function} values
189+
* @param {String} field
190+
* @param {String} relationship
191+
*/
192+
constructor(name, type, values, field, relationship) {
193+
super(name, type, values);
194+
this.field = field;
195+
this.relationship = relationship;
196+
}
197+
198+
/**
199+
* @param {*} data
200+
* @param {String} operator
201+
* @return Object
202+
*/
203+
getFilter(data, operator) {
204+
return {
205+
has: {
206+
[this.relationship]: {
207+
[operator]: {
208+
[this.field]: data,
209+
},
210+
},
211+
},
212+
};
213+
}
214+
215+
/**
216+
* @param {Object} filter
217+
* @return boolean
218+
*/
219+
isMatch(filter) {
220+
const relationshipObject = filter.has;
221+
if (!relationshipObject || !relationshipObject[this.relationship]) {
222+
return false;
223+
}
224+
225+
const operator = Object.keys(relationshipObject[this.relationship])[0];
226+
return operator && this.field in relationshipObject[this.relationship][operator];
227+
}
228+
229+
/**
230+
* @param {Object} filter
231+
* @return {*}
232+
*/
233+
getValueFromFilter(filter) {
234+
const operator = Object.keys(filter.has[this.relationship])[0];
235+
return filter.has[this.relationship][operator][this.field];
236+
}
237+
238+
/**
239+
* @param {Object} filter
240+
* @return {String}
241+
*/
242+
getOperatorFromFilter(filter) {
243+
return Object.keys(filter.has[this.relationship])[0];
244+
}
245+
}
246+

0 commit comments

Comments
 (0)