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
0fd805e9
Commit
0fd805e9
authored
Dec 03, 2020
by
Brandon Labuschagne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add devops adoption cache update handlers
These are used for both adding and removing segments.
parent
ded17994
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
114 additions
and
0 deletions
+114
-0
ee/app/assets/javascripts/admin/dev_ops_report/components/devops_adoption_segment_modal.vue
...v_ops_report/components/devops_adoption_segment_modal.vue
+8
-0
ee/app/assets/javascripts/admin/dev_ops_report/graphql/mutations/create_devops_adoption_segment.mutation.graphql
...mutations/create_devops_adoption_segment.mutation.graphql
+10
-0
ee/app/assets/javascripts/admin/dev_ops_report/utils/cache_updates.js
...s/javascripts/admin/dev_ops_report/utils/cache_updates.js
+36
-0
ee/spec/frontend/admin/dev_ops_report/utils/cache_updates_spec.js
...frontend/admin/dev_ops_report/utils/cache_updates_spec.js
+60
-0
No files found.
ee/app/assets/javascripts/admin/dev_ops_report/components/devops_adoption_segment_modal.vue
View file @
0fd805e9
...
...
@@ -11,6 +11,7 @@ import { convertToGraphQLIds, TYPE_GROUP } from '~/graphql_shared/utils';
import
*
as
Sentry
from
'
~/sentry/wrapper
'
;
import
createDevopsAdoptionSegmentMutation
from
'
../graphql/mutations/create_devops_adoption_segment.mutation.graphql
'
;
import
{
DEVOPS_ADOPTION_STRINGS
,
DEVOPS_ADOPTION_SEGMENT_MODAL_ID
}
from
'
../constants
'
;
import
{
addSegmentToCache
}
from
'
../utils/cache_updates
'
;
export
default
{
name
:
'
DevopsAdoptionSegmentModal
'
,
...
...
@@ -85,6 +86,13 @@ export default {
name
:
this
.
name
,
groupIds
:
convertToGraphQLIds
(
TYPE_GROUP
,
this
.
checkboxValues
),
},
update
:
(
store
,
{
data
})
=>
{
const
{
createDevopsAdoptionSegment
:
{
segment
,
errors
:
requestErrors
},
}
=
data
;
if
(
!
requestErrors
.
length
)
addSegmentToCache
(
store
,
segment
);
},
});
if
(
errors
.
length
)
{
...
...
ee/app/assets/javascripts/admin/dev_ops_report/graphql/mutations/create_devops_adoption_segment.mutation.graphql
View file @
0fd805e9
...
...
@@ -6,6 +6,16 @@ mutation($name: String!, $groupIds: [GroupID!]!) {
groups
{
id
}
latestSnapshot
{
issueOpened
mergeRequestOpened
mergeRequestApproved
runnerConfigured
pipelineSucceeded
deploySucceeded
securityScanSucceeded
recordedAt
}
}
errors
}
...
...
ee/app/assets/javascripts/admin/dev_ops_report/utils/cache_updates.js
0 → 100644
View file @
0fd805e9
import
produce
from
'
immer
'
;
import
devopsAdoptionSegmentsQuery
from
'
../graphql/queries/devops_adoption_segments.query.graphql
'
;
export
const
addSegmentToCache
=
(
store
,
segment
)
=>
{
const
sourceData
=
store
.
readQuery
({
query
:
devopsAdoptionSegmentsQuery
,
});
const
data
=
produce
(
sourceData
,
draftData
=>
{
// eslint-disable-next-line no-param-reassign
draftData
.
devopsAdoptionSegments
.
nodes
=
[...
draftData
.
devopsAdoptionSegments
.
nodes
,
segment
];
});
store
.
writeQuery
({
query
:
devopsAdoptionSegmentsQuery
,
data
,
});
};
export
const
deleteSegmentFromCache
=
(
store
,
segmentId
)
=>
{
const
sourceData
=
store
.
readQuery
({
query
:
devopsAdoptionSegmentsQuery
,
});
const
updatedData
=
produce
(
sourceData
,
draftData
=>
{
// eslint-disable-next-line no-param-reassign
draftData
.
devopsAdoptionSegments
.
nodes
=
draftData
.
devopsAdoptionSegments
.
nodes
.
filter
(
({
id
})
=>
id
!==
segmentId
,
);
});
store
.
writeQuery
({
query
:
devopsAdoptionSegmentsQuery
,
data
:
updatedData
,
});
};
ee/spec/frontend/admin/dev_ops_report/utils/cache_updates_spec.js
0 → 100644
View file @
0fd805e9
import
{
deleteSegmentFromCache
,
addSegmentToCache
,
}
from
'
ee/admin/dev_ops_report/utils/cache_updates
'
;
import
{
devopsAdoptionSegmentsData
}
from
'
../mock_data
'
;
describe
(
'
addSegmentToCache
'
,
()
=>
{
const
store
=
{
readQuery
:
jest
.
fn
(()
=>
({
devopsAdoptionSegments
:
{
nodes
:
[]
}
})),
writeQuery
:
jest
.
fn
(),
};
it
(
'
calls writeQuery with the correct response
'
,
()
=>
{
addSegmentToCache
(
store
,
devopsAdoptionSegmentsData
.
nodes
[
0
]);
expect
(
store
.
writeQuery
).
toHaveBeenCalledWith
(
expect
.
objectContaining
({
data
:
{
devopsAdoptionSegments
:
{
nodes
:
devopsAdoptionSegmentsData
.
nodes
,
},
},
}),
);
});
});
describe
(
'
deleteSegmentFromCache
'
,
()
=>
{
const
store
=
{
readQuery
:
jest
.
fn
(()
=>
({
devopsAdoptionSegments
:
devopsAdoptionSegmentsData
})),
writeQuery
:
jest
.
fn
(),
};
it
(
'
calls writeQuery with the correct response
'
,
()
=>
{
// Remove the item at the first index
deleteSegmentFromCache
(
store
,
devopsAdoptionSegmentsData
.
nodes
[
0
].
id
);
expect
(
store
.
writeQuery
).
toHaveBeenCalledWith
(
expect
.
not
.
objectContaining
({
data
:
{
devopsAdoptionSegments
:
{
__typename
:
'
devopsAdoptionSegments
'
,
nodes
:
devopsAdoptionSegmentsData
.
nodes
,
},
},
}),
);
expect
(
store
.
writeQuery
).
toHaveBeenCalledWith
(
expect
.
objectContaining
({
data
:
{
devopsAdoptionSegments
:
{
__typename
:
'
devopsAdoptionSegments
'
,
// Remove the item at the first index
nodes
:
devopsAdoptionSegmentsData
.
nodes
.
slice
(
1
),
},
},
}),
);
});
});
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