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

Commit 9d80f10

Browse files
authored
refactor: bump react router and migrate projects state to overmind (#52)
issue getOne action projects state, actions, reducers migrated to overmind bump react-router-dom to v6 and fix routing
1 parent 0fad1c0 commit 9d80f10

33 files changed

+488
-766
lines changed

main/transformers/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const users = require('./users');
22
const issues = require('./issues');
3+
const projects = require('./projects');
34

45
const transform = (route, responseBody) => {
56
const [entity] = route.split('/');
@@ -9,6 +10,8 @@ const transform = (route, responseBody) => {
910
return users.transform(route, responseBody);
1011
case 'issues.json':
1112
return issues.transform(route, responseBody);
13+
case 'projects.json':
14+
return projects.transform(route, responseBody);
1215
default:
1316
return responseBody;
1417
}

main/transformers/issues.js

Lines changed: 64 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,70 @@
11
const transform = (route, responseBody) => {
2-
const { issues } = responseBody;
2+
if (route === 'issues.json') {
3+
const { issues } = responseBody;
4+
return {
5+
issues: issues.map((issue) => ({
6+
id: issue.id,
7+
project: issue.project,
8+
tracker: issue.tracker,
9+
status: issue.status,
10+
priority: issue.priority,
11+
author: issue.author,
12+
assignee: issue.assigned_to,
13+
subject: issue.subject,
14+
description: issue.description,
15+
startDate: issue.start_date,
16+
dueDate: issue.due_date,
17+
doneRatio: issue.done_ratio,
18+
isPrivate: issue.is_private,
19+
estimatedHours: issue.estimated_hours,
20+
totalEstimatedHours: issue.total_estimated_hours,
21+
spentHours: issue.spent_hours,
22+
totalSpentHours: issue.total_spent_hours,
23+
createdOn: issue.created_on,
24+
updatedOn: issue.updated_on,
25+
closedOn: issue.closed_on
26+
})),
27+
total: responseBody.total_count,
28+
offset: responseBody.offset,
29+
limit: responseBody.limit
30+
};
31+
}
332

4-
switch (route) {
5-
case 'issues.json': {
6-
return {
7-
issues: issues.map((issue) => ({
8-
id: issue.id,
9-
project: issue.project,
10-
tracker: issue.tracker,
11-
status: issue.status,
12-
priority: issue.priority,
13-
author: issue.author,
14-
assignee: issue.assigned_to,
15-
subject: issue.subject,
16-
description: issue.description,
17-
startDate: issue.start_date,
18-
dueDate: issue.due_date,
19-
doneRatio: issue.done_ratio,
20-
isPrivate: issue.is_private,
21-
estimatedHours: issue.estimated_hours,
22-
createdOn: issue.created_on,
23-
updatedOn: issue.updated_on,
24-
closedOn: issue.closed_on
25-
})),
26-
total: responseBody.total_count,
27-
offset: responseBody.offset,
28-
limit: responseBody.limit
29-
};
30-
}
31-
default:
32-
return responseBody;
33+
if (/issues\/\d\.json/.test(route)) {
34+
const { issue } = responseBody;
35+
return {
36+
id: issue.id,
37+
project: issue.project,
38+
tracker: issue.tracker,
39+
status: issue.status,
40+
priority: issue.priority,
41+
author: issue.author,
42+
assignee: issue.assigned_to,
43+
subject: issue.subject,
44+
description: issue.description,
45+
startDate: issue.start_date,
46+
dueDate: issue.due_date,
47+
doneRatio: issue.done_ratio,
48+
isPrivate: issue.is_private,
49+
estimatedHours: issue.estimated_hours,
50+
totalEstimatedHours: issue.total_estimated_hours,
51+
spentHours: issue.spent_hours,
52+
totalSpentHours: issue.total_spent_hours,
53+
createdOn: issue.created_on,
54+
updatedOn: issue.updated_on,
55+
subTasks: issue.children,
56+
customFields: issue.custom_fields,
57+
journals: issue.journals?.map((journal) => ({
58+
id: journal.id,
59+
user: journal.user,
60+
createdOn: journal.created_on,
61+
notes: journal.notes
62+
})),
63+
closedOn: issue.closed_on
64+
};
3365
}
66+
67+
return responseBody;
3468
};
3569

3670
module.exports = {

main/transformers/projects.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const transform = (route, responseBody) => {
2+
if (route === 'projects.json') {
3+
const { projects } = responseBody;
4+
return {
5+
projects: projects.map((project) => ({
6+
id: project.id,
7+
name: project.name,
8+
identifier: project.identifier,
9+
description: project.description,
10+
status: project.status,
11+
isPublic: project.isPublic,
12+
inheritMembers: project.inheritMembers,
13+
timeEntryActivities: project.time_entry_activities,
14+
createdOn: project.created_on,
15+
updatedOn: project.updated_on
16+
})),
17+
total: responseBody.total_count,
18+
offset: responseBody.offset,
19+
limit: responseBody.limit
20+
};
21+
}
22+
return responseBody;
23+
};
24+
25+
module.exports = {
26+
transform
27+
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"@types/jest": "^27.0.1",
9595
"@types/lodash": "^4.14.173",
9696
"@types/react-redux": "^7.1.18",
97-
"@types/react-router-dom": "^5.1.9",
97+
"@types/react-router-dom": "^5.3.2",
9898
"@types/styled-components": "^5.1.14",
9999
"@types/webpack-env": "^1.16.2",
100100
"@typescript-eslint/eslint-plugin": "^5.2.0",
@@ -170,7 +170,7 @@
170170
"react-focus-lock": "^2.6.0",
171171
"react-redux": "^6.0.1",
172172
"react-responsive-modal": "^3.6.0",
173-
"react-router-dom": "^5.3.0",
173+
"react-router-dom": "^6.0.2",
174174
"react-select": "^2.4.1",
175175
"react-tabs": "^3.1.0",
176176
"react-toastify": "^5.5.0",

render/App.jsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useCallback, useEffect, useState } from 'react';
22
import PropTypes from 'prop-types';
33
import debounce from 'lodash/debounce';
4-
import { Route, Switch, useHistory } from 'react-router-dom';
4+
import { Route, Routes, useNavigate } from 'react-router-dom';
55
import { toast } from 'react-toastify';
66
import 'react-toastify/dist/ReactToastify.css';
77
import cleanStack from 'clean-stack';
@@ -23,11 +23,11 @@ toast.configure({
2323
draggable: true,
2424
});
2525

26-
const Routes = ({ dispatch }) => {
26+
const App = ({ dispatch }) => {
2727
const [isReady, setIsReady] = useState(false);
2828

2929
const actions = useOvermindActions();
30-
const history = useHistory();
30+
const navigate = useNavigate();
3131

3232
const handleRejection = useCallback(debounce((event) => {
3333
event.preventDefault();
@@ -88,7 +88,7 @@ const Routes = ({ dispatch }) => {
8888
redmineEndpoint: response.payload.endpoint
8989
});
9090
if (loginResponse.success) {
91-
history.replace('/app');
91+
navigate('/issues', { replace: true });
9292
}
9393
}
9494

@@ -103,15 +103,15 @@ const Routes = ({ dispatch }) => {
103103
}
104104

105105
return (
106-
<Switch>
107-
<Route path="/" exact component={LoginView} />
108-
<Route path="/app" exact component={AppView} />
109-
</Switch>
106+
<Routes>
107+
<Route path="/" exact element={<LoginView />} />
108+
<Route path="/issues/*" element={<AppView />} />
109+
</Routes>
110110
);
111111
};
112112

113-
Routes.propTypes = {
113+
App.propTypes = {
114114
dispatch: PropTypes.func.isRequired,
115115
};
116116

117-
export default Routes;
117+
export default App;

render/actions/__tests__/index.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ describe('Actions aggregator', () => {
66
expect(actions.user).toBeTruthy();
77
expect(actions.issues).toBeTruthy();
88
expect(actions.tracking).toBeTruthy();
9-
expect(actions.projects).toBeTruthy();
109
expect(actions.timeEntry).toBeTruthy();
1110
expect(actions.settings).toBeTruthy();
1211
});

render/actions/__tests__/project.actions.spec.js

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

render/actions/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import trackingActions from './tracking.actions';
22
import issuesActions from './issues.actions';
33
import issueActions from './issue.actions';
4-
import projectActions from './project.actions';
54
import timeEntryActions from './timeEntry.actions';
65
import settingsActions from './settings.actions';
76

87
export default {
98
issues: issuesActions,
109
issue: issueActions,
1110
tracking: trackingActions,
12-
projects: projectActions,
1311
timeEntry: timeEntryActions,
1412
settings: settingsActions
1513
};

render/actions/issues.actions.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,10 @@ import moment from 'moment';
33

44
import request, { notify } from './helper';
55

6-
export const ISSUES_GET = 'ISSUES_GET';
76
export const ISSUES_COMMENTS_SEND = 'ISSUES_COMMENTS_SEND';
87
export const ISSUES_RESET_SELECTION = 'ISSUES_RESET_SELECTION';
98
export const ISSUES_TIME_ENTRY_GET = 'ISSUES_TIME_ENTRY_GET';
109

11-
const get = (id) => (dispatch) => {
12-
dispatch(notify.start(ISSUES_GET));
13-
14-
return request({
15-
url: `/issues/${id}.json`,
16-
query: {
17-
include: 'attachments,children,relations,journals'
18-
},
19-
id: `getIssueDetails:${id}`
20-
}).then(({ data }) => dispatch(notify.ok(ISSUES_GET, data)))
21-
.catch((error) => {
22-
// eslint-disable-next-line
23-
console.error(`Error when trying to get the issue with id ${id}:`, error.message);
24-
dispatch(notify.nok(ISSUES_GET, error));
25-
});
26-
};
27-
2810
const sendComments = (issueId, comments) => (dispatch, getState) => {
2911
const { user = {} } = getState();
3012

@@ -92,7 +74,6 @@ const getTimeEntriesPage = (issueId, projectId, pageNumber, batchSize) => (dispa
9274
const resetSelected = () => ({ type: ISSUES_RESET_SELECTION });
9375

9476
export default {
95-
get,
9677
getTimeEntriesPage,
9778
sendComments,
9879
resetSelected

render/actions/project.actions.js

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

0 commit comments

Comments
 (0)