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
23e6e69a
Commit
23e6e69a
authored
Jul 29, 2020
by
David O'Regan
Committed by
Natalia Tepluhina
Jul 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add incident pagination
We add incident pagination allowing users to view 10 at a time
parent
a7ca4f45
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
212 additions
and
19 deletions
+212
-19
app/assets/javascripts/incidents/components/incidents_list.vue
...ssets/javascripts/incidents/components/incidents_list.vue
+69
-4
app/assets/javascripts/incidents/constants.js
app/assets/javascripts/incidents/constants.js
+1
-0
app/assets/javascripts/incidents/graphql/queries/get_incidents.query.graphql
...pts/incidents/graphql/queries/get_incidents.query.graphql
+20
-2
changelogs/unreleased/229406-incident-pagination.yml
changelogs/unreleased/229406-incident-pagination.yml
+5
-0
spec/frontend/incidents/components/incidents_list_spec.js
spec/frontend/incidents/components/incidents_list_spec.js
+117
-13
No files found.
app/assets/javascripts/incidents/components/incidents_list.vue
View file @
23e6e69a
...
@@ -10,13 +10,14 @@ import {
...
@@ -10,13 +10,14 @@ import {
GlButton
,
GlButton
,
GlSearchBoxByType
,
GlSearchBoxByType
,
GlIcon
,
GlIcon
,
GlPagination
,
}
from
'
@gitlab/ui
'
;
}
from
'
@gitlab/ui
'
;
import
{
debounce
}
from
'
lodash
'
;
import
{
debounce
}
from
'
lodash
'
;
import
TimeAgoTooltip
from
'
~/vue_shared/components/time_ago_tooltip.vue
'
;
import
TimeAgoTooltip
from
'
~/vue_shared/components/time_ago_tooltip.vue
'
;
import
{
s__
}
from
'
~/locale
'
;
import
{
s__
}
from
'
~/locale
'
;
import
{
mergeUrlParams
,
joinPaths
,
visitUrl
}
from
'
~/lib/utils/url_utility
'
;
import
{
mergeUrlParams
,
joinPaths
,
visitUrl
}
from
'
~/lib/utils/url_utility
'
;
import
getIncidents
from
'
../graphql/queries/get_incidents.query.graphql
'
;
import
getIncidents
from
'
../graphql/queries/get_incidents.query.graphql
'
;
import
{
I18N
,
INCIDENT_SEARCH_DELAY
}
from
'
../constants
'
;
import
{
I18N
,
DEFAULT_PAGE_SIZE
,
INCIDENT_SEARCH_DELAY
}
from
'
../constants
'
;
const
tdClass
=
const
tdClass
=
'
table-col gl-display-flex d-md-table-cell gl-align-items-center gl-white-space-nowrap
'
;
'
table-col gl-display-flex d-md-table-cell gl-align-items-center gl-white-space-nowrap
'
;
...
@@ -24,6 +25,14 @@ const thClass = 'gl-hover-bg-blue-50';
...
@@ -24,6 +25,14 @@ const thClass = 'gl-hover-bg-blue-50';
const
bodyTrClass
=
const
bodyTrClass
=
'
gl-border-1 gl-border-t-solid gl-border-gray-100 gl-hover-cursor-pointer gl-hover-bg-blue-50 gl-hover-border-b-solid gl-hover-border-blue-200
'
;
'
gl-border-1 gl-border-t-solid gl-border-gray-100 gl-hover-cursor-pointer gl-hover-bg-blue-50 gl-hover-border-b-solid gl-hover-border-blue-200
'
;
const
initialPaginationState
=
{
currentPage
:
1
,
prevPageCursor
:
''
,
nextPageCursor
:
''
,
firstPageSize
:
DEFAULT_PAGE_SIZE
,
lastPageSize
:
null
,
};
export
default
{
export
default
{
i18n
:
I18N
,
i18n
:
I18N
,
fields
:
[
fields
:
[
...
@@ -57,6 +66,7 @@ export default {
...
@@ -57,6 +66,7 @@ export default {
TimeAgoTooltip
,
TimeAgoTooltip
,
GlSearchBoxByType
,
GlSearchBoxByType
,
GlIcon
,
GlIcon
,
GlPagination
,
},
},
directives
:
{
directives
:
{
GlTooltip
:
GlTooltipDirective
,
GlTooltip
:
GlTooltipDirective
,
...
@@ -70,9 +80,18 @@ export default {
...
@@ -70,9 +80,18 @@ export default {
searchTerm
:
this
.
searchTerm
,
searchTerm
:
this
.
searchTerm
,
projectPath
:
this
.
projectPath
,
projectPath
:
this
.
projectPath
,
labelNames
:
[
'
incident
'
],
labelNames
:
[
'
incident
'
],
firstPageSize
:
this
.
pagination
.
firstPageSize
,
lastPageSize
:
this
.
pagination
.
lastPageSize
,
prevPageCursor
:
this
.
pagination
.
prevPageCursor
,
nextPageCursor
:
this
.
pagination
.
nextPageCursor
,
};
},
update
({
project
:
{
issues
:
{
nodes
=
[],
pageInfo
=
{}
}
=
{}
}
=
{}
})
{
return
{
list
:
nodes
,
pageInfo
,
};
};
},
},
update
:
({
project
:
{
issues
:
{
nodes
=
[]
}
=
{}
}
=
{}
})
=>
nodes
,
error
()
{
error
()
{
this
.
errored
=
true
;
this
.
errored
=
true
;
},
},
...
@@ -84,6 +103,8 @@ export default {
...
@@ -84,6 +103,8 @@ export default {
isErrorAlertDismissed
:
false
,
isErrorAlertDismissed
:
false
,
redirecting
:
false
,
redirecting
:
false
,
searchTerm
:
''
,
searchTerm
:
''
,
pagination
:
initialPaginationState
,
incidents
:
{},
};
};
},
},
computed
:
{
computed
:
{
...
@@ -94,7 +115,19 @@ export default {
...
@@ -94,7 +115,19 @@ export default {
return
this
.
$apollo
.
queries
.
incidents
.
loading
;
return
this
.
$apollo
.
queries
.
incidents
.
loading
;
},
},
hasIncidents
()
{
hasIncidents
()
{
return
this
.
incidents
?.
length
;
return
this
.
incidents
?.
list
?.
length
;
},
showPaginationControls
()
{
return
Boolean
(
this
.
incidents
?.
pageInfo
?.
hasNextPage
||
this
.
incidents
?.
pageInfo
?.
hasPreviousPage
,
);
},
prevPage
()
{
return
Math
.
max
(
this
.
pagination
.
currentPage
-
1
,
0
);
},
nextPage
()
{
const
nextPage
=
this
.
pagination
.
currentPage
+
1
;
return
this
.
incidents
?.
list
?.
length
<
DEFAULT_PAGE_SIZE
?
null
:
nextPage
;
},
},
tbodyTrClass
()
{
tbodyTrClass
()
{
return
{
return
{
...
@@ -119,6 +152,28 @@ export default {
...
@@ -119,6 +152,28 @@ export default {
navigateToIncidentDetails
({
iid
})
{
navigateToIncidentDetails
({
iid
})
{
return
visitUrl
(
joinPaths
(
this
.
issuePath
,
iid
));
return
visitUrl
(
joinPaths
(
this
.
issuePath
,
iid
));
},
},
handlePageChange
(
page
)
{
const
{
startCursor
,
endCursor
}
=
this
.
incidents
.
pageInfo
;
if
(
page
>
this
.
pagination
.
currentPage
)
{
this
.
pagination
=
{
...
initialPaginationState
,
nextPageCursor
:
endCursor
,
currentPage
:
page
,
};
}
else
{
this
.
pagination
=
{
lastPageSize
:
DEFAULT_PAGE_SIZE
,
firstPageSize
:
null
,
prevPageCursor
:
startCursor
,
nextPageCursor
:
''
,
currentPage
:
page
,
};
}
},
resetPagination
()
{
this
.
pagination
=
initialPaginationState
;
},
},
},
};
};
</
script
>
</
script
>
...
@@ -155,7 +210,7 @@ export default {
...
@@ -155,7 +210,7 @@ export default {
{{
s__
(
'
IncidentManagement|Incidents
'
)
}}
{{
s__
(
'
IncidentManagement|Incidents
'
)
}}
</h4>
</h4>
<gl-table
<gl-table
:items=
"incidents"
:items=
"incidents
.list || []
"
:fields=
"$options.fields"
:fields=
"$options.fields"
:show-empty=
"true"
:show-empty=
"true"
:busy=
"loading"
:busy=
"loading"
...
@@ -219,5 +274,15 @@ export default {
...
@@ -219,5 +274,15 @@ export default {
{{
$options
.
i18n
.
noIncidents
}}
{{
$options
.
i18n
.
noIncidents
}}
</
template
>
</
template
>
</gl-table>
</gl-table>
<gl-pagination
v-if=
"showPaginationControls"
:value=
"pagination.currentPage"
:prev-page=
"prevPage"
:next-page=
"nextPage"
align=
"center"
class=
"gl-pagination gl-mt-3"
@
input=
"handlePageChange"
/>
</div>
</div>
</template>
</template>
app/assets/javascripts/incidents/constants.js
View file @
23e6e69a
...
@@ -9,3 +9,4 @@ export const I18N = {
...
@@ -9,3 +9,4 @@ export const I18N = {
};
};
export
const
INCIDENT_SEARCH_DELAY
=
300
;
export
const
INCIDENT_SEARCH_DELAY
=
300
;
export
const
DEFAULT_PAGE_SIZE
=
10
;
app/assets/javascripts/incidents/graphql/queries/get_incidents.query.graphql
View file @
23e6e69a
query
getIncidents
(
query
getIncidents
(
$searchTerm
:
String
$projectPath
:
ID
!
$projectPath
:
ID
!
$labelNames
:
[
String
]
$labelNames
:
[
String
]
$state
:
IssuableState
$state
:
IssuableState
$firstPageSize
:
Int
$lastPageSize
:
Int
$prevPageCursor
:
String
=
""
$nextPageCursor
:
String
=
""
$searchTerm
:
String
)
{
)
{
project
(
fullPath
:
$projectPath
)
{
project
(
fullPath
:
$projectPath
)
{
issues
(
search
:
$searchTerm
,
state
:
$state
,
labelName
:
$labelNames
)
{
issues
(
search
:
$searchTerm
state
:
$state
labelName
:
$labelNames
first
:
$firstPageSize
last
:
$lastPageSize
after
:
$nextPageCursor
before
:
$prevPageCursor
)
{
nodes
{
nodes
{
iid
iid
title
title
...
@@ -26,6 +38,12 @@ query getIncidents(
...
@@ -26,6 +38,12 @@ query getIncidents(
}
}
}
}
}
}
pageInfo
{
hasNextPage
endCursor
hasPreviousPage
startCursor
}
}
}
}
}
}
}
changelogs/unreleased/229406-incident-pagination.yml
0 → 100644
View file @
23e6e69a
---
title
:
Add pagination to the incident list
merge_request
:
37993
author
:
type
:
changed
spec/frontend/incidents/components/incidents_list_spec.js
View file @
23e6e69a
import
{
mount
}
from
'
@vue/test-utils
'
;
import
{
mount
}
from
'
@vue/test-utils
'
;
import
{
GlAlert
,
GlLoadingIcon
,
GlTable
,
GlAvatar
,
GlSearchBoxByType
}
from
'
@gitlab/ui
'
;
import
{
GlAlert
,
GlLoadingIcon
,
GlTable
,
GlAvatar
,
GlPagination
,
GlSearchBoxByType
,
}
from
'
@gitlab/ui
'
;
import
{
visitUrl
,
joinPaths
}
from
'
~/lib/utils/url_utility
'
;
import
{
visitUrl
,
joinPaths
}
from
'
~/lib/utils/url_utility
'
;
import
IncidentsList
from
'
~/incidents/components/incidents_list.vue
'
;
import
IncidentsList
from
'
~/incidents/components/incidents_list.vue
'
;
import
TimeAgoTooltip
from
'
~/vue_shared/components/time_ago_tooltip.vue
'
;
import
TimeAgoTooltip
from
'
~/vue_shared/components/time_ago_tooltip.vue
'
;
...
@@ -26,6 +33,7 @@ describe('Incidents List', () => {
...
@@ -26,6 +33,7 @@ describe('Incidents List', () => {
const
findCreateIncidentBtn
=
()
=>
wrapper
.
find
(
'
[data-testid="createIncidentBtn"]
'
);
const
findCreateIncidentBtn
=
()
=>
wrapper
.
find
(
'
[data-testid="createIncidentBtn"]
'
);
const
findSearch
=
()
=>
wrapper
.
find
(
GlSearchBoxByType
);
const
findSearch
=
()
=>
wrapper
.
find
(
GlSearchBoxByType
);
const
findClosedIcon
=
()
=>
wrapper
.
findAll
(
"
[data-testid='incident-closed']
"
);
const
findClosedIcon
=
()
=>
wrapper
.
findAll
(
"
[data-testid='incident-closed']
"
);
const
findPagination
=
()
=>
wrapper
.
find
(
GlPagination
);
function
mountComponent
({
data
=
{
incidents
:
[]
},
loading
=
false
})
{
function
mountComponent
({
data
=
{
incidents
:
[]
},
loading
=
false
})
{
wrapper
=
mount
(
IncidentsList
,
{
wrapper
=
mount
(
IncidentsList
,
{
...
@@ -70,7 +78,7 @@ describe('Incidents List', () => {
...
@@ -70,7 +78,7 @@ describe('Incidents List', () => {
it
(
'
shows empty state
'
,
()
=>
{
it
(
'
shows empty state
'
,
()
=>
{
mountComponent
({
mountComponent
({
data
:
{
incidents
:
[]
},
data
:
{
incidents
:
{
list
:
[]
}
},
loading
:
false
,
loading
:
false
,
});
});
expect
(
findTable
().
text
()).
toContain
(
I18N
.
noIncidents
);
expect
(
findTable
().
text
()).
toContain
(
I18N
.
noIncidents
);
...
@@ -78,7 +86,7 @@ describe('Incidents List', () => {
...
@@ -78,7 +86,7 @@ describe('Incidents List', () => {
it
(
'
shows error state
'
,
()
=>
{
it
(
'
shows error state
'
,
()
=>
{
mountComponent
({
mountComponent
({
data
:
{
incidents
:
[]
,
errored
:
true
},
data
:
{
incidents
:
{
list
:
[]
}
,
errored
:
true
},
loading
:
false
,
loading
:
false
,
});
});
expect
(
findTable
().
text
()).
toContain
(
I18N
.
noIncidents
);
expect
(
findTable
().
text
()).
toContain
(
I18N
.
noIncidents
);
...
@@ -88,7 +96,7 @@ describe('Incidents List', () => {
...
@@ -88,7 +96,7 @@ describe('Incidents List', () => {
describe
(
'
Incident Management list
'
,
()
=>
{
describe
(
'
Incident Management list
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
mountComponent
({
mountComponent
({
data
:
{
incidents
:
mockIncidents
},
data
:
{
incidents
:
{
list
:
mockIncidents
}
},
loading
:
false
,
loading
:
false
,
});
});
});
});
...
@@ -140,7 +148,7 @@ describe('Incidents List', () => {
...
@@ -140,7 +148,7 @@ describe('Incidents List', () => {
describe
(
'
Create Incident
'
,
()
=>
{
describe
(
'
Create Incident
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
mountComponent
({
mountComponent
({
data
:
{
incidents
:
[]
},
data
:
{
incidents
:
{
list
:
[]
}
},
loading
:
false
,
loading
:
false
,
});
});
});
});
...
@@ -157,10 +165,105 @@ describe('Incidents List', () => {
...
@@ -157,10 +165,105 @@ describe('Incidents List', () => {
});
});
});
});
describe
(
'
Pagination
'
,
()
=>
{
beforeEach
(()
=>
{
mountComponent
({
data
:
{
incidents
:
{
list
:
mockIncidents
,
pageInfo
:
{
hasNextPage
:
true
,
hasPreviousPage
:
true
},
},
errored
:
false
,
},
loading
:
false
,
});
});
it
(
'
should render pagination
'
,
()
=>
{
expect
(
wrapper
.
find
(
GlPagination
).
exists
()).
toBe
(
true
);
});
describe
(
'
prevPage
'
,
()
=>
{
it
(
'
returns prevPage button
'
,
()
=>
{
findPagination
().
vm
.
$emit
(
'
input
'
,
3
);
return
wrapper
.
vm
.
$nextTick
(()
=>
{
expect
(
findPagination
()
.
findAll
(
'
.page-item
'
)
.
at
(
0
)
.
text
(),
).
toBe
(
'
Prev
'
);
});
});
it
(
'
returns prevPage number
'
,
()
=>
{
findPagination
().
vm
.
$emit
(
'
input
'
,
3
);
return
wrapper
.
vm
.
$nextTick
(()
=>
{
expect
(
wrapper
.
vm
.
prevPage
).
toBe
(
2
);
});
});
it
(
'
returns 0 when it is the first page
'
,
()
=>
{
findPagination
().
vm
.
$emit
(
'
input
'
,
1
);
return
wrapper
.
vm
.
$nextTick
(()
=>
{
expect
(
wrapper
.
vm
.
prevPage
).
toBe
(
0
);
});
});
});
describe
(
'
nextPage
'
,
()
=>
{
it
(
'
returns nextPage button
'
,
()
=>
{
findPagination
().
vm
.
$emit
(
'
input
'
,
3
);
return
wrapper
.
vm
.
$nextTick
(()
=>
{
expect
(
findPagination
()
.
findAll
(
'
.page-item
'
)
.
at
(
1
)
.
text
(),
).
toBe
(
'
Next
'
);
});
});
it
(
'
returns nextPage number
'
,
()
=>
{
mountComponent
({
data
:
{
incidents
:
{
list
:
[...
mockIncidents
,
...
mockIncidents
,
...
mockIncidents
],
pageInfo
:
{
hasNextPage
:
true
,
hasPreviousPage
:
true
},
},
errored
:
false
,
},
loading
:
false
,
});
findPagination
().
vm
.
$emit
(
'
input
'
,
1
);
return
wrapper
.
vm
.
$nextTick
(()
=>
{
expect
(
wrapper
.
vm
.
nextPage
).
toBe
(
2
);
});
});
it
(
'
returns `null` when currentPage is already last page
'
,
()
=>
{
findPagination
().
vm
.
$emit
(
'
input
'
,
1
);
return
wrapper
.
vm
.
$nextTick
(()
=>
{
expect
(
wrapper
.
vm
.
nextPage
).
toBeNull
();
});
});
});
describe
(
'
Search
'
,
()
=>
{
describe
(
'
Search
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
mountComponent
({
mountComponent
({
data
:
{
incidents
:
mockIncidents
},
data
:
{
incidents
:
{
list
:
mockIncidents
,
pageInfo
:
{
hasNextPage
:
true
,
hasPreviousPage
:
true
},
},
errored
:
false
,
},
loading
:
false
,
loading
:
false
,
});
});
});
});
...
@@ -177,4 +280,5 @@ describe('Incidents List', () => {
...
@@ -177,4 +280,5 @@ describe('Incidents List', () => {
expect
(
wrapper
.
vm
.
$data
.
searchTerm
).
toBe
(
SEARCH_TERM
);
expect
(
wrapper
.
vm
.
$data
.
searchTerm
).
toBe
(
SEARCH_TERM
);
});
});
});
});
});
});
});
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