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
8a7a9d1d
Commit
8a7a9d1d
authored
Nov 13, 2020
by
Emily Ring
Committed by
Natalia Tepluhina
Nov 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add pagination to Terraform list view
Updated GraphQL query and terraform_list.vue to include pagination
parent
6a4151e4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
100 additions
and
6 deletions
+100
-6
app/assets/javascripts/terraform/components/terraform_list.vue
...ssets/javascripts/terraform/components/terraform_list.vue
+51
-2
app/assets/javascripts/terraform/constants.js
app/assets/javascripts/terraform/constants.js
+1
-0
app/assets/javascripts/terraform/graphql/queries/get_states.query.graphql
...cripts/terraform/graphql/queries/get_states.query.graphql
+8
-2
changelogs/unreleased/emilyring-state-pagination.yml
changelogs/unreleased/emilyring-state-pagination.yml
+5
-0
spec/frontend/terraform/components/terraform_list_spec.js
spec/frontend/terraform/components/terraform_list_spec.js
+35
-2
No files found.
app/assets/javascripts/terraform/components/terraform_list.vue
View file @
8a7a9d1d
<
script
>
<
script
>
import
{
GlAlert
,
GlBadge
,
GlLoadingIcon
,
GlTab
,
GlTabs
}
from
'
@gitlab/ui
'
;
import
{
GlAlert
,
GlBadge
,
Gl
KeysetPagination
,
Gl
LoadingIcon
,
GlTab
,
GlTabs
}
from
'
@gitlab/ui
'
;
import
getStatesQuery
from
'
../graphql/queries/get_states.query.graphql
'
;
import
getStatesQuery
from
'
../graphql/queries/get_states.query.graphql
'
;
import
EmptyState
from
'
./empty_state.vue
'
;
import
EmptyState
from
'
./empty_state.vue
'
;
import
StatesTable
from
'
./states_table.vue
'
;
import
StatesTable
from
'
./states_table.vue
'
;
import
{
MAX_LIST_COUNT
}
from
'
../constants
'
;
export
default
{
export
default
{
apollo
:
{
apollo
:
{
...
@@ -11,12 +12,14 @@ export default {
...
@@ -11,12 +12,14 @@ export default {
variables
()
{
variables
()
{
return
{
return
{
projectPath
:
this
.
projectPath
,
projectPath
:
this
.
projectPath
,
...
this
.
cursor
,
};
};
},
},
update
:
data
=>
{
update
:
data
=>
{
return
{
return
{
count
:
data
?.
project
?.
terraformStates
?.
count
,
count
:
data
?.
project
?.
terraformStates
?.
count
,
list
:
data
?.
project
?.
terraformStates
?.
nodes
,
list
:
data
?.
project
?.
terraformStates
?.
nodes
,
pageInfo
:
data
?.
project
?.
terraformStates
?.
pageInfo
,
};
};
},
},
error
()
{
error
()
{
...
@@ -28,6 +31,7 @@ export default {
...
@@ -28,6 +31,7 @@ export default {
EmptyState
,
EmptyState
,
GlAlert
,
GlAlert
,
GlBadge
,
GlBadge
,
GlKeysetPagination
,
GlLoadingIcon
,
GlLoadingIcon
,
GlTab
,
GlTab
,
GlTabs
,
GlTabs
,
...
@@ -43,10 +47,26 @@ export default {
...
@@ -43,10 +47,26 @@ export default {
type
:
String
,
type
:
String
,
},
},
},
},
data
()
{
return
{
cursor
:
{
first
:
MAX_LIST_COUNT
,
after
:
null
,
last
:
null
,
before
:
null
,
},
};
},
computed
:
{
computed
:
{
isLoading
()
{
isLoading
()
{
return
this
.
$apollo
.
queries
.
states
.
loading
;
return
this
.
$apollo
.
queries
.
states
.
loading
;
},
},
pageInfo
()
{
return
this
.
states
?.
pageInfo
||
{};
},
showPagination
()
{
return
this
.
pageInfo
.
hasPreviousPage
||
this
.
pageInfo
.
hasNextPage
;
},
statesCount
()
{
statesCount
()
{
return
this
.
states
?.
count
;
return
this
.
states
?.
count
;
},
},
...
@@ -54,6 +74,25 @@ export default {
...
@@ -54,6 +74,25 @@ export default {
return
this
.
states
?.
list
;
return
this
.
states
?.
list
;
},
},
},
},
methods
:
{
updatePagination
(
item
)
{
if
(
item
===
this
.
pageInfo
.
endCursor
)
{
this
.
cursor
=
{
first
:
MAX_LIST_COUNT
,
after
:
item
,
last
:
null
,
before
:
null
,
};
}
else
{
this
.
cursor
=
{
first
:
null
,
after
:
null
,
last
:
MAX_LIST_COUNT
,
before
:
item
,
};
}
},
},
};
};
</
script
>
</
script
>
...
@@ -71,7 +110,17 @@ export default {
...
@@ -71,7 +110,17 @@ export default {
<gl-loading-icon
v-if=
"isLoading"
size=
"md"
class=
"gl-mt-3"
/>
<gl-loading-icon
v-if=
"isLoading"
size=
"md"
class=
"gl-mt-3"
/>
<div
v-else-if=
"statesList"
>
<div
v-else-if=
"statesList"
>
<states-table
v-if=
"statesCount"
:states=
"statesList"
/>
<div
v-if=
"statesCount"
>
<states-table
:states=
"statesList"
/>
<div
v-if=
"showPagination"
class=
"gl-display-flex gl-justify-content-center gl-mt-5"
>
<gl-keyset-pagination
v-bind=
"pageInfo"
@
prev=
"updatePagination"
@
next=
"updatePagination"
/>
</div>
</div>
<empty-state
v-else
:image=
"emptyStateImage"
/>
<empty-state
v-else
:image=
"emptyStateImage"
/>
</div>
</div>
...
...
app/assets/javascripts/terraform/constants.js
0 → 100644
View file @
8a7a9d1d
export
const
MAX_LIST_COUNT
=
25
;
app/assets/javascripts/terraform/graphql/queries/get_states.query.graphql
View file @
8a7a9d1d
#import "../fragments/state.fragment.graphql"
#import "../fragments/state.fragment.graphql"
#import "~/graphql_shared/fragments/pageInfo.fragment.graphql"
query
getStates
(
$projectPath
:
ID
!)
{
query
getStates
(
$projectPath
:
ID
!
,
$first
:
Int
,
$last
:
Int
,
$before
:
String
,
$after
:
String
)
{
project
(
fullPath
:
$projectPath
)
{
project
(
fullPath
:
$projectPath
)
{
terraformStates
{
terraformStates
(
first
:
$first
,
last
:
$last
,
before
:
$before
,
after
:
$after
)
{
count
count
nodes
{
nodes
{
...
State
...
State
}
}
pageInfo
{
...
PageInfo
}
}
}
}
}
}
}
changelogs/unreleased/emilyring-state-pagination.yml
0 → 100644
View file @
8a7a9d1d
---
title
:
Add pagination to Terraform list view
merge_request
:
47412
author
:
type
:
changed
spec/frontend/terraform/components/terraform_list_spec.js
View file @
8a7a9d1d
import
{
GlAlert
,
GlBadge
,
GlLoadingIcon
,
GlTab
}
from
'
@gitlab/ui
'
;
import
{
GlAlert
,
GlBadge
,
Gl
KeysetPagination
,
Gl
LoadingIcon
,
GlTab
}
from
'
@gitlab/ui
'
;
import
{
createLocalVue
,
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
createLocalVue
,
shallowMount
}
from
'
@vue/test-utils
'
;
import
createMockApollo
from
'
jest/helpers/mock_apollo_helper
'
;
import
createMockApollo
from
'
jest/helpers/mock_apollo_helper
'
;
import
VueApollo
from
'
vue-apollo
'
;
import
VueApollo
from
'
vue-apollo
'
;
...
@@ -39,6 +39,7 @@ describe('TerraformList', () => {
...
@@ -39,6 +39,7 @@ describe('TerraformList', () => {
const
findBadge
=
()
=>
wrapper
.
find
(
GlBadge
);
const
findBadge
=
()
=>
wrapper
.
find
(
GlBadge
);
const
findEmptyState
=
()
=>
wrapper
.
find
(
EmptyState
);
const
findEmptyState
=
()
=>
wrapper
.
find
(
EmptyState
);
const
findPaginationButtons
=
()
=>
wrapper
.
find
(
GlKeysetPagination
);
const
findStatesTable
=
()
=>
wrapper
.
find
(
StatesTable
);
const
findStatesTable
=
()
=>
wrapper
.
find
(
StatesTable
);
const
findTab
=
()
=>
wrapper
.
find
(
GlTab
);
const
findTab
=
()
=>
wrapper
.
find
(
GlTab
);
...
@@ -73,6 +74,12 @@ describe('TerraformList', () => {
...
@@ -73,6 +74,12 @@ describe('TerraformList', () => {
terraformStates
:
{
terraformStates
:
{
nodes
:
states
,
nodes
:
states
,
count
:
states
.
length
,
count
:
states
.
length
,
pageInfo
:
{
hasNextPage
:
true
,
hasPreviousPage
:
false
,
startCursor
:
'
prev
'
,
endCursor
:
'
next
'
,
},
},
},
});
});
...
@@ -84,8 +91,33 @@ describe('TerraformList', () => {
...
@@ -84,8 +91,33 @@ describe('TerraformList', () => {
expect
(
findBadge
().
text
()).
toBe
(
'
2
'
);
expect
(
findBadge
().
text
()).
toBe
(
'
2
'
);
});
});
it
(
'
renders the states table
'
,
()
=>
{
it
(
'
renders the states table
and pagination buttons
'
,
()
=>
{
expect
(
findStatesTable
().
exists
()).
toBe
(
true
);
expect
(
findStatesTable
().
exists
()).
toBe
(
true
);
expect
(
findPaginationButtons
().
exists
()).
toBe
(
true
);
});
describe
(
'
when list has no additional pages
'
,
()
=>
{
beforeEach
(()
=>
{
createWrapper
({
terraformStates
:
{
nodes
:
states
,
count
:
states
.
length
,
pageInfo
:
{
hasNextPage
:
false
,
hasPreviousPage
:
false
,
startCursor
:
''
,
endCursor
:
''
,
},
},
});
return
wrapper
.
vm
.
$nextTick
();
});
it
(
'
renders the states table without pagination buttons
'
,
()
=>
{
expect
(
findStatesTable
().
exists
()).
toBe
(
true
);
expect
(
findPaginationButtons
().
exists
()).
toBe
(
false
);
});
});
});
});
});
...
@@ -95,6 +127,7 @@ describe('TerraformList', () => {
...
@@ -95,6 +127,7 @@ describe('TerraformList', () => {
terraformStates
:
{
terraformStates
:
{
nodes
:
[],
nodes
:
[],
count
:
0
,
count
:
0
,
pageInfo
:
null
,
},
},
});
});
...
...
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