-
Notifications
You must be signed in to change notification settings - Fork 681
Migrate versions page to paginated list #10659
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ff5c036
app!: Drop first version hint support from the versions list
eth3lbert a04288b
versions: Replace `this.model` with `this.crate`
eth3lbert bebfe95
models/crate: Decouple getters from `loadVersionsTask`
eth3lbert 1cd1b6f
models/crate: Rename `versionsObj` getter with `loadedVersionsById`
eth3lbert 87d02e5
adapters/version: Add `query` support for `GET /api/v1/crate/{name}/v…
eth3lbert ee16f67
app: Migrate the `versions` page to a paginated list
eth3lbert 34697df
app: Handle errors for the load more task
eth3lbert 1f12bc0
app: Simplify `releaseTrackSet` using `release_tracks` meta
eth3lbert e7a1f75
models/crate: Remove obsolete getter and functions
eth3lbert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,115 @@ | ||
| import Controller from '@ember/controller'; | ||
| import { inject as service } from '@ember/service'; | ||
| import { tracked } from '@glimmer/tracking'; | ||
|
|
||
| import { didCancel, dropTask } from 'ember-concurrency'; | ||
| import { alias } from 'macro-decorators'; | ||
|
|
||
| import { AjaxError } from '../../utils/ajax'; | ||
|
|
||
| function defaultVersionsContext() { | ||
| return { data: [], next_page: undefined }; | ||
| } | ||
|
|
||
| export default class SearchController extends Controller { | ||
| queryParams = ['sort']; | ||
| @service sentry; | ||
| @service store; | ||
|
|
||
| queryParams = ['per_page', 'sort']; | ||
| @tracked sort; | ||
| @tracked per_page = 100; | ||
|
|
||
| @tracked byDate; | ||
| @tracked bySemver; | ||
| /** @type {import("../../models/crate").default} */ | ||
| @tracked crate; | ||
|
|
||
| @alias('versionsContext.data') data; | ||
| @alias('versionsContext.next_page') next_page; | ||
|
|
||
| constructor() { | ||
| super(...arguments); | ||
| this.reset(); | ||
| } | ||
|
|
||
| get currentSortBy() { | ||
| return this.sort === 'semver' ? 'SemVer' : 'Date'; | ||
| } | ||
|
|
||
| get versionsContext() { | ||
| return this.sort === 'semver' ? this.bySemver : this.byDate; | ||
| } | ||
|
|
||
| get sortedVersions() { | ||
| let { versionIdsBySemver, versionIdsByDate, versionsObj: versions } = this.model; | ||
| let { loadedVersionsById: versions } = this.crate; | ||
| return this.data.map(id => versions.get(id)); | ||
| } | ||
|
|
||
| loadMoreTask = dropTask(async () => { | ||
| let { crate, data, next_page, per_page, sort, versionsContext } = this; | ||
| let query; | ||
|
|
||
| if (next_page) { | ||
| let params = new URLSearchParams(next_page); | ||
| params.set('name', crate.name); | ||
| params.delete('include'); | ||
| query = Object.fromEntries(params.entries()); | ||
| } else { | ||
| if (sort !== 'semver') { | ||
| sort = 'date'; | ||
| } | ||
| query = { | ||
| name: crate.name, | ||
| sort, | ||
| per_page, | ||
| }; | ||
| } | ||
| if (crate.release_tracks == null) { | ||
| query.include = 'release_tracks'; | ||
| } | ||
|
|
||
| try { | ||
| let versions = await this.store.query('version', query); | ||
| let meta = versions.meta; | ||
|
|
||
| let ids = versions.map(it => it.id); | ||
| if (sort === 'semver') { | ||
| this.bySemver = { | ||
| ...versionsContext, | ||
| data: data.concat(ids), | ||
| next_page: meta.next_page, | ||
| }; | ||
| } else { | ||
| this.byDate = { | ||
| ...versionsContext, | ||
| data: data.concat(ids), | ||
| next_page: meta.next_page, | ||
| }; | ||
| } | ||
|
|
||
| // set release_tracks to crate | ||
| if (meta.release_tracks) { | ||
| let payload = { | ||
| crate: { | ||
| id: crate.id, | ||
| release_tracks: meta.release_tracks, | ||
| }, | ||
| }; | ||
| this.store.pushPayload(payload); | ||
| } | ||
|
|
||
| return versions; | ||
| } catch (error) { | ||
| // report unexpected errors to Sentry and ignore `ajax()` errors | ||
| if (!didCancel(error) && !(error instanceof AjaxError)) { | ||
| this.sentry.captureException(error); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| return (this.sort === 'semver' ? versionIdsBySemver : versionIdsByDate).map(id => versions[id]); | ||
| reset() { | ||
| this.crate = undefined; | ||
| this.byDate = defaultVersionsContext(); | ||
| this.bySemver = defaultVersionsContext(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This currently seems a bit odd, since the bolded number and name are positioned directly beside each other. There might be better wording or display methods.