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

fix(frontend): Fix run comparison filter #7833

Merged
merged 5 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
22 changes: 22 additions & 0 deletions frontend/src/pages/RunList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,28 @@ describe('RunList', () => {
expect(Apis.runServiceApi.getRun).toHaveBeenCalledWith('run2');
});

it('loads given and filtered list of runs only', async () => {
mockNRuns(5, {});
const props = generateProps();
props.runIdListMask = ['filterRun1', 'filterRun2', 'notincluded'];
tree = shallow(<RunList {...props} />);
await (tree.instance() as RunListTest)._loadRuns({
zpChris marked this conversation as resolved.
Show resolved Hide resolved
filter: encodeURIComponent(
JSON.stringify({
predicates: [{ key: 'name', op: PredicateOp.ISSUBSTRING, string_value: 'filterRun' }],
}),
),
});
expect(tree.state('runs')).toMatchObject([
{
run: { name: 'run with id: filterRun1' },
},
{
run: { name: 'run with id: filterRun2' },
},
]);
});

it('adds metrics columns', async () => {
mockNRuns(2, {
run: {
Expand Down
26 changes: 21 additions & 5 deletions frontend/src/pages/RunList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,12 @@ class RunList extends React.PureComponent<RunListProps, RunListState> {

if (Array.isArray(this.props.runIdListMask)) {
displayRuns = this.props.runIdListMask.map(id => ({ run: { id } }));
// listRuns doesn't currently support batching by IDs, so in this case we retrieve each run
// individually.
await this._getAndSetRuns(displayRuns);
const filter = JSON.parse(
decodeURIComponent(request.filter || '{"predicates": []}'),
) as ApiFilter;
// listRuns doesn't currently support batching by IDs, so in this case we retrieve and filter
// each run individually.
await this._getAndSetRuns(displayRuns, filter);
zpChris marked this conversation as resolved.
Show resolved Hide resolved
} else {
// Load all runs
if (this.props.storageState) {
Expand Down Expand Up @@ -429,14 +432,27 @@ class RunList extends React.PureComponent<RunListProps, RunListState> {

/**
* For each run ID, fetch its corresponding run, and set it in DisplayRuns
* Remove the run from the list if its name does not match the filter
*/
private _getAndSetRuns(displayRuns: DisplayRun[]): Promise<DisplayRun[]> {
private _getAndSetRuns(displayRuns: DisplayRun[], filter: ApiFilter): Promise<DisplayRun[]> {
const filterSubstring =
filter.predicates &&
filter.predicates[0] &&
filter.predicates[0].key === 'name' &&
filter.predicates[0].op === PredicateOp.ISSUBSTRING &&
filter.predicates[0].string_value
? filter.predicates[0].string_value.toLowerCase()
: '';
zpChris marked this conversation as resolved.
Show resolved Hide resolved
return Promise.all(
displayRuns.map(async displayRun => {
let getRunResponse: ApiRunDetail;
try {
getRunResponse = await Apis.runServiceApi.getRun(displayRun.run!.id!);
displayRun.run = getRunResponse.run!;
if (getRunResponse.run?.name?.toLowerCase().includes(filterSubstring)) {
displayRun.run = getRunResponse.run!;
} else {
displayRuns.splice(displayRuns.indexOf(displayRun), 1);
zpChris marked this conversation as resolved.
Show resolved Hide resolved
}
} catch (err) {
displayRun.error = await errorToMessage(err);
}
Expand Down