Skip to content
This repository was archived by the owner on Jan 14, 2023. It is now read-only.

Commit 2b74408

Browse files
authored
Merge pull request #53 from Spring3/refactor/migrate-time-entry-state
refactor: migrate issue details page to overmind
2 parents 9d80f10 + 092b48d commit 2b74408

File tree

111 files changed

+3590
-4691
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+3590
-4691
lines changed

.eslintrc.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"object-curly-newline": "warn",
2929
"no-plusplus": "off",
3030
"no-param-reassign": "warn",
31+
"prefer-destructuring": "off",
3132
"no-underscore-dangle": [
3233
"error",
3334
{
@@ -80,6 +81,7 @@
8081
"max-classes-per-file": "off",
8182
"no-use-before-define": "off",
8283
"arrow-parens": "off",
84+
"consistent-return": "off",
8385
"react/jsx-filename-extension": [
8486
2,
8587
{ "extensions": [".js", ".jsx", ".ts", ".tsx"] }

common/utils.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

main/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const { redmineClient } = require('./redmine');
1818
const Tray = require('./tray');
1919

2020
const utils = require('./utils');
21+
const { openExternalUrl } = require('./utils');
2122
require('./exceptionCatcher')();
2223

2324
app.setAppUserModelId('app.spring3.redshape');
@@ -387,6 +388,10 @@ const initialize = () => {
387388
event.reply(`system-response:${id}`, { success: true });
388389
break;
389390
}
391+
case 'open-url': {
392+
await openExternalUrl(payload.url);
393+
break;
394+
}
390395
default:
391396
break;
392397
}

main/redmine.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ const createRequestClient = () => {
3939

4040
console.log(response.statusCode, response.body);
4141

42-
const loginSuccess = response.statusCode === 200;
42+
const loginSuccess = [204, 200].includes(response.statusCode);
4343
isInitialized = loginSuccess;
4444

4545
if (loginSuccess) {
46-
const payload = transform(route, response.body);
46+
const payload = transform({ route, method: 'GET' }, response.body);
4747

4848
instance = got.extend({
4949
...configuration,
@@ -54,7 +54,7 @@ const createRequestClient = () => {
5454

5555
return {
5656
success: true,
57-
payload
57+
data: payload
5858
};
5959
}
6060

@@ -86,11 +86,17 @@ const createRequestClient = () => {
8686

8787
if (response.statusCode === 200) {
8888
return {
89-
payload: transform(data.route, response.body),
89+
data: transform({ route: data.route, method: data.method }, response.body),
9090
success: true,
9191
};
9292
}
9393

94+
if (data.method === 'PUT' && response.statusCode === 204) {
95+
return {
96+
success: true
97+
};
98+
}
99+
94100
return handleUnsuccessfulRequest(response.body);
95101
} catch (error) {
96102
return handleUnsuccessfulRequest(error);

main/storage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const eventHandlers = (event, message) => {
109109

110110
event.reply(`session-response:${id}`, {
111111
success: true,
112-
payload: sessionWithoutHash
112+
data: sessionWithoutHash
113113
});
114114
break;
115115
}

main/transformers/index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
const users = require('./users');
22
const issues = require('./issues');
3+
const issueStatuses = require('./issueStatuses');
34
const projects = require('./projects');
5+
const timeEntries = require('./timeEntries');
46

5-
const transform = (route, responseBody) => {
6-
const [entity] = route.split('/');
7+
const transform = ({ route, method }, responseBody) => {
8+
const [entity] = route.split('/')[0].split('.');
9+
10+
console.log('entity', entity);
711

812
switch (entity) {
913
case 'users':
10-
return users.transform(route, responseBody);
11-
case 'issues.json':
12-
return issues.transform(route, responseBody);
13-
case 'projects.json':
14-
return projects.transform(route, responseBody);
14+
return users.transform({ route, method }, responseBody);
15+
case 'issues':
16+
return issues.transform({ route, method }, responseBody);
17+
case 'issue_statuses':
18+
return issueStatuses.transform({ route, method }, responseBody);
19+
case 'projects':
20+
return projects.transform({ route, method }, responseBody);
21+
case 'time_entries':
22+
return timeEntries.transform({ route, method }, responseBody);
1523
default:
1624
return responseBody;
1725
}

main/transformers/issueStatuses.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const transform = ({ route }, responseBody) => {
2+
if (route === 'issue_statuses.json') {
3+
const { issue_statuses: issueStatuses } = responseBody;
4+
return {
5+
issueStatuses: issueStatuses.map((issueStatus) => ({
6+
id: issueStatus.id,
7+
name: issueStatus.name,
8+
isClosed: issueStatus.is_closed
9+
})),
10+
total: responseBody.total_count,
11+
offset: responseBody.offset,
12+
limit: responseBody.limit
13+
};
14+
}
15+
16+
return responseBody;
17+
};
18+
19+
module.exports = {
20+
transform
21+
};

main/transformers/issues.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const transform = (route, responseBody) => {
1+
const transform = ({ route }, responseBody) => {
22
if (route === 'issues.json') {
33
const { issues } = responseBody;
44
return {
@@ -22,6 +22,14 @@ const transform = (route, responseBody) => {
2222
totalSpentHours: issue.total_spent_hours,
2323
createdOn: issue.created_on,
2424
updatedOn: issue.updated_on,
25+
journals: issue.journals?.map((journal) => ({
26+
id: journal.id,
27+
user: journal.user,
28+
createdOn: journal.created_on,
29+
notes: journal.notes,
30+
privateNotes: journal.private_notes,
31+
details: journal.details
32+
})) || [],
2533
closedOn: issue.closed_on
2634
})),
2735
total: responseBody.total_count,
@@ -30,7 +38,7 @@ const transform = (route, responseBody) => {
3038
};
3139
}
3240

33-
if (/issues\/\d\.json/.test(route)) {
41+
if (/issues\/\d{1,}\.json/.test(route)) {
3442
const { issue } = responseBody;
3543
return {
3644
id: issue.id,
@@ -53,13 +61,15 @@ const transform = (route, responseBody) => {
5361
createdOn: issue.created_on,
5462
updatedOn: issue.updated_on,
5563
subTasks: issue.children,
56-
customFields: issue.custom_fields,
64+
customFields: issue.custom_fields || [],
5765
journals: issue.journals?.map((journal) => ({
5866
id: journal.id,
5967
user: journal.user,
6068
createdOn: journal.created_on,
61-
notes: journal.notes
62-
})),
69+
notes: journal.notes,
70+
privateNotes: journal.private_notes,
71+
details: journal.details
72+
})) || [],
6373
closedOn: issue.closed_on
6474
};
6575
}

main/transformers/projects.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const transform = (route, responseBody) => {
1+
const transform = ({ route }, responseBody) => {
22
if (route === 'projects.json') {
33
const { projects } = responseBody;
44
return {
@@ -19,6 +19,27 @@ const transform = (route, responseBody) => {
1919
limit: responseBody.limit
2020
};
2121
}
22+
23+
if (/projects\/\w{1,}\/versions\.json/.test(route)) {
24+
const { versions } = responseBody;
25+
return {
26+
versions: versions.map((version) => ({
27+
id: version.id,
28+
project: version.project,
29+
name: version.name,
30+
description: version.description,
31+
status: version.status,
32+
dueDate: version.due_date,
33+
sharing: version.sharing,
34+
createdOn: version.created_on,
35+
updatedOn: version.updated_on,
36+
wikiPageTitle: version.wiki_page_title
37+
})),
38+
total: responseBody.total_count,
39+
offset: responseBody.offset,
40+
limit: responseBody.limit
41+
};
42+
}
2243
return responseBody;
2344
};
2445

main/transformers/timeEntries.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const toExternalTimeEntry = (timeEntry) => ({
2+
id: timeEntry.id,
3+
project: timeEntry.project,
4+
issue: timeEntry.issue,
5+
user: timeEntry.user,
6+
activity: timeEntry.activity,
7+
hours: timeEntry.hours,
8+
comments: timeEntry.comments,
9+
spentOn: timeEntry.spent_on,
10+
createdOn: timeEntry.created_on,
11+
updatedOn: timeEntry.updated_on,
12+
});
13+
14+
const transform = ({ route, method }, responseBody) => {
15+
if (route === 'time_entries.json') {
16+
if (method === 'GET') {
17+
const { time_entries } = responseBody;
18+
return {
19+
timeEntries: time_entries.map((timeEntry) => toExternalTimeEntry(timeEntry)),
20+
total: responseBody.total_count,
21+
offset: responseBody.offset,
22+
limit: responseBody.limit
23+
};
24+
}
25+
26+
if (method === 'POST') {
27+
const { time_entry } = responseBody;
28+
return {
29+
timeEntry: toExternalTimeEntry(time_entry)
30+
};
31+
}
32+
}
33+
34+
if (/time_entries\/\d{1,}\.json/.test(route)) {
35+
const { time_entry } = responseBody;
36+
37+
return {
38+
timeEntry: toExternalTimeEntry(time_entry)
39+
};
40+
}
41+
42+
return responseBody;
43+
};
44+
45+
module.exports = {
46+
transform
47+
};

0 commit comments

Comments
 (0)