Skip to content

Commit 54b5ff3

Browse files
authored
feat(issue): paginate issue comments and events (#848)
* refactor(issue): fetch issue and its repository by new api * fix(issue): render issue correctly * chore(issue): filter events that have no id * fix: no assigner in timeline’s self-assign event * fix: remove anchor of issueURL and fix crash caused by repository * fix: fix permissions is not defined * chore: give up union entity * chore: better loading * refactor(new-issue): read repository from navigation.state.params * refactor: edit-issue-comment doesn’t depend on old store any more * refactor: issue-settings doesn’t depend on old store any more * refactor: pull-merge doesn’t depend on old store any more
1 parent 4375a46 commit 54b5ff3

20 files changed

+240
-139
lines changed

src/api/actions/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ export const REPOS_GET_CONTRIBUTORS = createPaginationActionSet(
2121
'REPOS_GET_CONTRIBUTORS'
2222
);
2323
export const REPOS_FORK = createActionSet('REPOS_FORK');
24+
export const REPOS_GET_ISSUE = createActionSet('REPOS_GET_ISSUE');
25+
export const REPOS_GET_ISSUE_TIMELINE = createPaginationActionSet(
26+
'REPOS_GET_ISSUE_TIMELINE'
27+
);

src/api/client.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class Client {
7373
HTML: 'application/vnd.github.v3.html+json',
7474
JSON: 'application/vnd.github.v3+json',
7575
MERCY_PREVIEW: 'application/vnd.github.mercy-preview+json',
76+
MOCKINGBIRD_PREVIEW: 'application/vnd.github.mockingbird-preview+json',
7677
RAW: 'application/vnd.github.v3.raw+json',
7778
};
7879

@@ -394,6 +395,29 @@ export class Client {
394395
params,
395396
schema: Schemas.REPO,
396397
}),
398+
getIssue: (repoId: string, issueId: number, params: SpecialParameters = {}) =>
399+
this.get({
400+
endpoint: `repos/${repoId}/issues/${issueId}`,
401+
params,
402+
fetchParameters: {
403+
headers: {
404+
Accept: this.Accept.FULL,
405+
},
406+
},
407+
schema: Schemas.ISSUE,
408+
}),
409+
getIssueTimeline: (repoId: string, issueId: number, params: SpecialParameters = {}) =>
410+
this.list({
411+
endpoint: `repos/${repoId}/issues/${issueId}/timeline`,
412+
params,
413+
fetchParameters: {
414+
headers: {
415+
Accept: [this.Accept.MOCKINGBIRD_PREVIEW, this.Accept.FULL].join(','),
416+
},
417+
},
418+
schema: [Schemas.ISSUE_TIMELINE_ITEM],
419+
paginationArgs: [`${repoId}/${issueId}`],
420+
}),
397421
};
398422
orgs = {
399423
/**

src/api/queries/repo.query.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ query ($owner: String!, $name: String!) {
109109
...PullRequestsList
110110
}
111111
}
112+
viewerPermission
112113
}
113114
}
114115

src/api/reducers/entities.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export const entities = (
66
events: {},
77
orgs: {},
88
repos: {},
9+
issues: {},
10+
issueTimelineItems: {},
911
users: {},
1012
gqlRepos: {},
1113
},

src/api/reducers/pagination.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,5 @@ export const pagination = combineReducers({
8585
SEARCH_USERS: paginate(Actions.SEARCH_USERS),
8686
ORGS_GET_MEMBERS: paginate(Actions.ORGS_GET_MEMBERS),
8787
REPOS_GET_CONTRIBUTORS: paginate(Actions.REPOS_GET_CONTRIBUTORS),
88+
REPOS_GET_ISSUE_TIMELINE: paginate(Actions.REPOS_GET_ISSUE_TIMELINE),
8889
});

src/api/schemas/gql-repos.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ export const gqlRepoSchema = new schema.Entity(
99
},
1010
processStrategy: ({ repository }) => ({
1111
...repository,
12+
permissions: {
13+
admin: repository.viewerPermission === 'ADMIN',
14+
push: repository.viewerPermission === 'ADMIN' || repository.viewerPermission === 'WRITE',
15+
},
16+
full_name: repository.nameWithOwner,
1217
webUrl: `https://github.com/${repository.nameWithOwner}`,
1318
}),
1419
}

src/api/schemas/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { eventSchema } from './events';
22
import { repoSchema } from './repos';
3+
import { issueSchema, issueTimelineItemSchema } from './issues';
34
import { orgSchema } from './orgs';
45
import { userSchema } from './users';
56
import { gqlRepoSchema } from './gql-repos';
@@ -9,6 +10,8 @@ export default {
910
EVENT_ARRAY: [eventSchema],
1011
REPO: repoSchema,
1112
REPO_ARRAY: [repoSchema],
13+
ISSUE: issueSchema,
14+
ISSUE_TIMELINE_ITEM: issueTimelineItemSchema,
1215
USER: userSchema,
1316
USER_ARRAY: [userSchema],
1417
ORG: orgSchema,

src/api/schemas/issues.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { schema } from 'normalizr';
2+
3+
export const issueSchema = new schema.Entity(
4+
'issues',
5+
{},
6+
{
7+
idAttribute: issue => issue.url,
8+
}
9+
);
10+
11+
// TODO: some events have no id field, i.e. cross-referenced
12+
export const issueTimelineItemSchema = new schema.Entity('issueTimelineItems');

src/components/issue-description.component.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const MergeButtonContainer = styled.View`
8383
export class IssueDescription extends Component {
8484
props: {
8585
issue: Object,
86+
repository: Object,
8687
diff: string,
8788
isMergeable: boolean,
8889
isMerged: boolean,
@@ -104,6 +105,7 @@ export class IssueDescription extends Component {
104105
const {
105106
diff,
106107
issue,
108+
repository,
107109
isMergeable,
108110
isMerged,
109111
isPendingDiff,
@@ -219,6 +221,8 @@ export class IssueDescription extends Component {
219221
onPress={() =>
220222
navigation.navigate('PullMerge', {
221223
title: t('Merge Pull Request', locale),
224+
issue,
225+
repository,
222226
})
223227
}
224228
title={t('Merge Pull Request', locale)}

src/components/issue-event-list-item.component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export class IssueEventListItem extends Component {
212212
iconName="person"
213213
text={
214214
<Text>
215-
<ActorLink actor={event.assigner} onPress={this.onPressUser} />{' '}
215+
<ActorLink actor={event.assigner || event.actor} onPress={this.onPressUser} />{' '}
216216
{event.event}{' '}
217217
<ActorLink actor={event.assignee} onPress={this.onPressUser} />
218218
</Text>

0 commit comments

Comments
 (0)