Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
f7a391c7
Commit
f7a391c7
authored
May 05, 2020
by
Martin Wortschack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor merge requests actions
- Commit mutations from actions instead of dispatching actions
parent
2114a94f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
69 deletions
+27
-69
ee/app/assets/javascripts/analytics/code_review_analytics/store/modules/merge_requests/actions.js
..._review_analytics/store/modules/merge_requests/actions.js
+12
-19
ee/spec/frontend/analytics/code_review_analytics/store/modules/merge_requests/actions_spec.js
...ew_analytics/store/modules/merge_requests/actions_spec.js
+15
-50
No files found.
ee/app/assets/javascripts/analytics/code_review_analytics/store/modules/merge_requests/actions.js
View file @
f7a391c7
...
...
@@ -6,8 +6,8 @@ import { normalizeHeaders, parseIntPagination } from '~/lib/utils/common_utils';
export
const
setProjectId
=
({
commit
},
projectId
)
=>
commit
(
types
.
SET_PROJECT_ID
,
projectId
);
export
const
fetchMergeRequests
=
({
dispatch
,
state
,
rootState
})
=>
{
dispatch
(
'
requestMergeRequests
'
);
export
const
fetchMergeRequests
=
({
commit
,
state
,
rootState
})
=>
{
commit
(
types
.
REQUEST_MERGE_REQUESTS
);
const
{
projectId
,
pageInfo
}
=
state
;
...
...
@@ -24,24 +24,17 @@ export const fetchMergeRequests = ({ dispatch, state, rootState }) => {
return
API
.
codeReviewAnalytics
(
params
)
.
then
(
response
=>
{
const
{
headers
,
data
}
=
response
;
dispatch
(
'
receiveMergeRequestsSuccess
'
,
{
headers
,
data
});
const
normalizedHeaders
=
normalizeHeaders
(
headers
);
commit
(
types
.
RECEIVE_MERGE_REQUESTS_SUCCESS
,
{
pageInfo
:
parseIntPagination
(
normalizedHeaders
),
mergeRequests
:
data
,
});
})
.
catch
(
err
=>
dispatch
(
'
receiveMergeRequestsError
'
,
err
));
};
export
const
requestMergeRequests
=
({
commit
})
=>
commit
(
types
.
REQUEST_MERGE_REQUESTS
);
export
const
receiveMergeRequestsSuccess
=
({
commit
},
{
headers
,
data
:
mergeRequests
})
=>
{
const
normalizedHeaders
=
normalizeHeaders
(
headers
);
const
pageInfo
=
parseIntPagination
(
normalizedHeaders
);
commit
(
types
.
RECEIVE_MERGE_REQUESTS_SUCCESS
,
{
pageInfo
,
mergeRequests
});
};
export
const
receiveMergeRequestsError
=
({
commit
},
{
response
})
=>
{
const
{
status
}
=
response
;
commit
(
types
.
RECEIVE_MERGE_REQUESTS_ERROR
,
status
);
createFlash
(
__
(
'
An error occurred while loading merge requests.
'
));
.
catch
(({
response
})
=>
{
const
{
status
}
=
response
;
commit
(
types
.
RECEIVE_MERGE_REQUESTS_ERROR
,
status
);
createFlash
(
__
(
'
An error occurred while loading merge requests.
'
));
});
};
export
const
setPage
=
({
commit
},
page
)
=>
commit
(
types
.
SET_PAGE
,
page
);
ee/spec/frontend/analytics/code_review_analytics/store/modules/merge_requests/actions_spec.js
View file @
f7a391c7
...
...
@@ -74,11 +74,14 @@ describe('Code review analytics mergeRequests actions', () => {
actions
.
fetchMergeRequests
,
null
,
state
,
[],
[
{
type
:
'
requestMergeRequests
'
},
{
type
:
'
receiveMergeRequestsSuccess
'
,
payload
:
{
headers
,
data
:
mockMergeRequests
}
},
{
type
:
types
.
REQUEST_MERGE_REQUESTS
},
{
type
:
types
.
RECEIVE_MERGE_REQUESTS_SUCCESS
,
payload
:
{
pageInfo
,
mergeRequests
:
mockMergeRequests
},
},
],
[],
);
});
});
...
...
@@ -88,66 +91,28 @@ describe('Code review analytics mergeRequests actions', () => {
mock
.
onGet
(
/api
\/(
.*
)\/
analytics
\/
code_review/
).
replyOnce
(
500
);
});
it
(
'
dispatches error
'
,
()
=>
{
it
(
'
dispatches error
'
,
done
=>
{
testAction
(
actions
.
fetchMergeRequests
,
null
,
state
,
[],
[
{
type
:
'
requestMergeRequests
'
},
{
type
:
types
.
REQUEST_MERGE_REQUESTS
},
{
type
:
'
receiveMergeRequestsError
'
,
payload
:
new
Error
(
'
Request failed with status code 500
'
)
,
type
:
types
.
RECEIVE_MERGE_REQUESTS_ERROR
,
payload
:
500
,
},
],
[],
()
=>
{
expect
(
createFlash
).
toHaveBeenCalled
();
done
();
},
);
});
});
});
describe
(
'
requestMergeRequests
'
,
()
=>
{
it
(
'
commits REQUEST_MERGE_REQUESTS mutation
'
,
()
=>
{
testAction
(
actions
.
requestMergeRequests
,
null
,
state
,
[{
type
:
types
.
REQUEST_MERGE_REQUESTS
}],
[],
);
});
});
describe
(
'
receiveMergeRequestsSuccess
'
,
()
=>
{
it
(
'
commits RECEIVE_MERGE_REQUESTS_SUCCESS mutation
'
,
()
=>
{
testAction
(
actions
.
receiveMergeRequestsSuccess
,
{
headers
,
data
:
mockMergeRequests
},
state
,
[
{
type
:
types
.
RECEIVE_MERGE_REQUESTS_SUCCESS
,
payload
:
{
pageInfo
,
mergeRequests
:
mockMergeRequests
},
},
],
[],
);
});
});
describe
(
'
receiveMergeRequestsError
'
,
()
=>
{
it
(
'
commits SET_MERGE_REQUEST_ERROR mutation
'
,
()
=>
testAction
(
actions
.
receiveMergeRequestsError
,
{
response
:
{
status
:
500
}
},
state
,
[{
type
:
types
.
RECEIVE_MERGE_REQUESTS_ERROR
,
payload
:
500
}],
[],
).
then
(()
=>
{
expect
(
createFlash
).
toHaveBeenCalled
();
}));
});
describe
(
'
setPage
'
,
()
=>
{
it
(
'
commits SET_PAGE mutation
'
,
()
=>
{
testAction
(
actions
.
setPage
,
2
,
state
,
[{
type
:
types
.
SET_PAGE
,
payload
:
2
}],
[]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment