Skip to content

Commit 1847bd1

Browse files
committed
get the naming right with the issue state
1 parent 72ce44a commit 1847bd1

File tree

2 files changed

+35
-39
lines changed

2 files changed

+35
-39
lines changed

src/Issue/IssueList/index.js

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,41 @@ import { ButtonUnobtrusive } from '../../Button';
1212

1313
import './style.css';
1414

15-
const SHOW_STATES = {
16-
NO_ISSUES: 'NONE',
17-
OPEN_ISSUES: 'OPEN',
18-
CLOSED_ISSUES: 'CLOSED',
15+
const ISSUE_STATES = {
16+
NONE: 'NONE',
17+
OPEN: 'OPEN',
18+
CLOSED: 'CLOSED',
1919
};
2020

21-
const SHOW_TRANSITION_LABELS = {
22-
[SHOW_STATES.NO_ISSUES]: 'Show Open Issues',
23-
[SHOW_STATES.OPEN_ISSUES]: 'Show Closed Issues',
24-
[SHOW_STATES.CLOSED_ISSUES]: 'Hide Issues',
21+
const TRANSITION_LABELS = {
22+
[ISSUE_STATES.NONE]: 'Show Open Issues',
23+
[ISSUE_STATES.OPEN]: 'Show Closed Issues',
24+
[ISSUE_STATES.CLOSED]: 'Hide Issues',
2525
};
2626

27-
const SHOW_TRANSITION_STATE = {
28-
[SHOW_STATES.NO_ISSUES]: SHOW_STATES.OPEN_ISSUES,
29-
[SHOW_STATES.OPEN_ISSUES]: SHOW_STATES.CLOSED_ISSUES,
30-
[SHOW_STATES.CLOSED_ISSUES]: SHOW_STATES.NO_ISSUES,
27+
const TRANSITION_STATE = {
28+
[ISSUE_STATES.NONE]: ISSUE_STATES.OPEN,
29+
[ISSUE_STATES.OPEN]: ISSUE_STATES.CLOSED,
30+
[ISSUE_STATES.CLOSED]: ISSUE_STATES.NONE,
3131
};
3232

33-
const KIND_OF_ISSUES = {
34-
[SHOW_STATES.OPEN_ISSUES]: 'OPEN',
35-
[SHOW_STATES.CLOSED_ISSUES]: 'CLOSED',
36-
};
37-
38-
const isShow = showState => showState !== SHOW_STATES.NO_ISSUES;
33+
const isShow = issueState => issueState !== ISSUE_STATES.NONE;
3934

4035
const prefetchIssues = (
4136
client,
4237
repositoryOwner,
4338
repositoryName,
44-
showState,
39+
issueState,
4540
) => {
46-
const nextShowState = SHOW_TRANSITION_STATE[showState];
41+
const nextIssueState = TRANSITION_STATE[issueState];
4742

48-
if (isShow(nextShowState)) {
43+
if (isShow(nextIssueState)) {
4944
client.query({
5045
query: GET_ISSUES_OF_REPOSITORY,
5146
variables: {
5247
repositoryOwner,
5348
repositoryName,
54-
kindOfIssue: KIND_OF_ISSUES[nextShowState],
49+
kindOfIssue: nextIssueState,
5550
},
5651
});
5752
}
@@ -81,24 +76,24 @@ const updateQuery = (previousResult, { fetchMoreResult }) => {
8176
const Issues = ({
8277
repositoryOwner,
8378
repositoryName,
84-
showState,
85-
onChangeShowState,
79+
issueState,
80+
onChangeIssueState,
8681
}) => (
8782
<div className="Issues">
8883
<IssueFilter
8984
repositoryOwner={repositoryOwner}
9085
repositoryName={repositoryName}
91-
showState={showState}
92-
onChangeShowState={onChangeShowState}
86+
issueState={issueState}
87+
onChangeIssueState={onChangeIssueState}
9388
/>
9489

95-
{isShow(showState) && (
90+
{isShow(issueState) && (
9691
<Query
9792
query={GET_ISSUES_OF_REPOSITORY}
9893
variables={{
9994
repositoryOwner,
10095
repositoryName,
101-
kindOfIssue: KIND_OF_ISSUES[showState],
96+
kindOfIssue: issueState,
10297
}}
10398
notifyOnNetworkStatusChange={true}
10499
>
@@ -123,7 +118,7 @@ const Issues = ({
123118
loading={loading}
124119
repositoryOwner={repositoryOwner}
125120
repositoryName={repositoryName}
126-
showState={showState}
121+
issueState={issueState}
127122
fetchMore={fetchMore}
128123
/>
129124
);
@@ -136,25 +131,25 @@ const Issues = ({
136131
const IssueFilter = ({
137132
repositoryOwner,
138133
repositoryName,
139-
showState,
140-
onChangeShowState,
134+
issueState,
135+
onChangeIssueState,
141136
}) => (
142137
<ApolloConsumer>
143138
{client => (
144139
<ButtonUnobtrusive
145140
onClick={() =>
146-
onChangeShowState(SHOW_TRANSITION_STATE[showState])
141+
onChangeIssueState(TRANSITION_STATE[issueState])
147142
}
148143
onMouseOver={() =>
149144
prefetchIssues(
150145
client,
151146
repositoryOwner,
152147
repositoryName,
153-
showState,
148+
issueState,
154149
)
155150
}
156151
>
157-
{SHOW_TRANSITION_LABELS[showState]}
152+
{TRANSITION_LABELS[issueState]}
158153
</ButtonUnobtrusive>
159154
)}
160155
</ApolloConsumer>
@@ -165,7 +160,7 @@ const IssueList = ({
165160
loading,
166161
repositoryOwner,
167162
repositoryName,
168-
showState,
163+
issueState,
169164
fetchMore,
170165
}) => (
171166
<div className="IssueList">
@@ -185,7 +180,7 @@ const IssueList = ({
185180
cursor: issues.pageInfo.endCursor,
186181
repositoryOwner,
187182
repositoryName,
188-
kindOfIssue: KIND_OF_ISSUES[showState],
183+
kindOfIssue: issueState,
189184
}}
190185
updateQuery={updateQuery}
191186
fetchMore={fetchMore}
@@ -196,7 +191,7 @@ const IssueList = ({
196191
);
197192

198193
export default withState(
199-
'showState',
200-
'onChangeShowState',
201-
SHOW_STATES.NO_ISSUES,
194+
'issueState',
195+
'onChangeIssueState',
196+
ISSUE_STATES.NONE,
202197
)(Issues);

src/Issue/IssueList/queries.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const GET_ISSUES_OF_REPOSITORY = gql`
1313
node {
1414
id
1515
number
16+
state
1617
title
1718
url
1819
bodyHTML

0 commit comments

Comments
 (0)