Skip to content

Commit

Permalink
Make /job-sets accept fakeData (#3057)
Browse files Browse the repository at this point in the history
Signed-off-by: Noah Held <[email protected]>
  • Loading branch information
zuqq authored Oct 20, 2023
1 parent b89dd69 commit 3403080
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
22 changes: 9 additions & 13 deletions internal/lookout/ui/src/services/JobSetsQueryParamsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,21 @@ type JobSetsQueryParams = {
active_only?: boolean
}

function makeQueryString(state: JobSetsContainerState): string {
const queryObject: JobSetsQueryParams = {}

if (state.queue) {
queryObject.queue = state.queue
}
queryObject.newest_first = state.newestFirst
queryObject.active_only = state.activeOnly

return queryString.stringify(queryObject)
}

export default class JobSetsQueryParamsService {
constructor(private router: Router) {}

saveState(state: JobSetsContainerState) {
const params = queryString.parse(this.router.location.search, QUERY_STRING_OPTIONS) as Record<any, any>

if (state.queue) {
params.queue = state.queue
}
params.newest_first = state.newestFirst
params.active_only = state.activeOnly

this.router.navigate({
...this.router.location,
search: makeQueryString(state),
search: queryString.stringify(params, QUERY_STRING_OPTIONS),
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export default class FakeGroupJobsService implements IGroupJobsService {
filtered = filtered.filter((job) => job.queue in active && active[job.queue].includes(job.jobSet))
}
const groups = groupBy(filtered, groupedField, aggregates)
const sliced = groups.sort(comparator(order)).slice(skip, skip + take)
const sorted = groups.sort(comparator(order))
// This matches the behavior of version 2 of the Lookout API, which
// understands zero to mean "no pagination" (in order to support queries
// without pagination, such as those used by `/job-sets`).
const sliced = take == 0 ? sorted.slice(skip) : sorted.slice(skip, skip + take)
return {
groups: sliced,
count: groups.length,
Expand Down

0 comments on commit 3403080

Please sign in to comment.