Skip to content

Commit

Permalink
Merge pull request #1953 from aziontech/dev
Browse files Browse the repository at this point in the history
Deploy 2024-11-22
  • Loading branch information
vinigfer authored Nov 22, 2024
2 parents 86f4669 + 448976f commit 09e6568
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 23 deletions.
23 changes: 22 additions & 1 deletion cypress/e2mock/edge-application/list-edge-applications.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,25 @@ describe('Edge Application List Spec', { tags: ['@dev2'] }, () => {
.its('response.body')
.should('have.property', 'count', 100)
})
})

it('should paginate correctly list', function () {
cy.intercept('GET', '/api/v4/edge_application/*', (req) => {
if (req.url.includes('page_size=10')) {
req.reply({
fixture: '/edge-application/edge-applications-paginated.json'
})
}
}).as('paginatedEdgeApplicationsListApi')

cy.get(selectors.list.rowsPerPage.dropdown).click()
cy.get(selectors.list.rowsPerPage.option('10')).click()
cy.get(selectors.list.pageNumber.option('5')).click()
cy.wait('@paginatedEdgeApplicationsListApi')
cy.get(selectors.list.pageNumber.option('6')).should('be.visible')
cy.get(selectors.list.pageNumber.option('5')).should('have.class', 'p-highlight')

cy.get(selectors.list.searchInput).type('foo 1{enter}')
cy.get(selectors.list.pageNumber.option('1')).should('be.visible')
cy.get(selectors.list.pageNumber.option('1')).should('have.class', 'p-highlight')
})
})
65 changes: 65 additions & 0 deletions cypress/fixtures/edge-application/edge-applications-paginated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"count": 100,
"results": [
{
"id": 1727808946,
"name": "foo 1",
"last_editor": "foobar@azion.com",
"last_modified": "2024-10-01T18:45:58.915153Z"
},
{
"id": 1727808947,
"name": "foo 2",
"last_editor": "foobar@azion.com",
"last_modified": "2024-10-02T18:45:58.915153Z"
},
{
"id": 1727808948,
"name": "foo 3",
"last_editor": "foobar@azion.com",
"last_modified": "2024-10-03T18:45:58.915153Z"
},
{
"id": 1727808949,
"name": "foo 4",
"last_editor": "foobar@azion.com",
"last_modified": "2024-10-04T18:45:58.915153Z"
},
{
"id": 1727808950,
"name": "foo 5",
"last_editor": "foobar@azion.com",
"last_modified": "2024-10-05T18:45:58.915153Z"
},
{
"id": 1727808951,
"name": "foo 6",
"last_editor": "foobar@azion.com",
"last_modified": "2024-10-06T18:45:58.915153Z"
},
{
"id": 1727808952,
"name": "foo 7",
"last_editor": "foobar@azion.com",
"last_modified": "2024-10-07T18:45:58.915153Z"
},
{
"id": 1727808953,
"name": "foo 8",
"last_editor": "foobar@azion.com",
"last_modified": "2024-10-08T18:45:58.915153Z"
},
{
"id": 1727808954,
"name": "foo 9",
"last_editor": "foobar@azion.com",
"last_modified": "2024-10-09T18:45:58.915153Z"
},
{
"id": 1727808955,
"name": "foo 10",
"last_editor": "foobar@azion.com",
"last_modified": "2024-10-10T18:45:58.915153Z"
}
]
}
3 changes: 3 additions & 0 deletions cypress/support/selectors/block-selectors/list-table-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export default {
dropdown: '.p-paginator-rpp-options',
option: (size) => `li.p-dropdown-item[aria-label="${size}"]`
},
pageNumber: {
option: (page) => `button.p-paginator-page[aria-label="${page}"]`
},
orderingHeader: {
firstColumn: ':nth-child(1) > .p-column-header-content > [data-pc-section="sort"] > .p-icon'
}
Expand Down
2 changes: 1 addition & 1 deletion src/templates/content-block/banner.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<section class="w-full relative">
<section class="w-full relative flex flex-col">
<div class="w-full mx-auto"></div>
<slot name="heading"></slot>
<section class="w-full flex flex-1 flex-col mx-auto mb-8">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
@row-click="editItemSelected"
@page="changeNumberOfLinesPerPage"
@sort="fetchOnSort"
:first="firstItemIndex"
>
<template
#header
Expand Down Expand Up @@ -451,6 +452,7 @@
const totalRecords = ref()
const savedSearch = ref('')
const savedOrdering = ref('')
const firstItemIndex = ref(0)
const firstLoadData = ref(true)
Expand Down Expand Up @@ -489,13 +491,14 @@
/**
* Moves an item within the original array based on updated positions in a reference array.
*
* @param {Array} originalArray - The array to be modified.
* @param {Array} originalData - The array to be modified.
* @param {Array} referenceArray - The reference array with the new order.
* @param {number} fromIndex - The index of the item to move in the reference array.
* @param {number} toIndex - The target index in the reference array.
* @returns {Array} The updated array with the item moved.
*/
const moveItem = (originalArray, referenceArray, fromIndex, toIndex) => {
const moveItem = (originalData, referenceArray, fromIndex, toIndex) => {
const originalArray = [...originalData]
const oldItemMove = toIndex + Math.sign(fromIndex - toIndex)
const itemToMoveId = referenceArray[toIndex]
const targetItemId = referenceArray[oldItemMove]
Expand Down Expand Up @@ -622,14 +625,19 @@
}
const reload = async (query = {}) => {
loadData({
const commonParams = {
page: 1,
pageSize: itemsByPage.value,
fields: props.apiFields,
search: savedSearch.value,
ordering: savedOrdering.value,
...query
})
}
if (props.lazy) {
commonParams.search = savedSearch.value
}
loadData(commonParams)
}
const extractFieldValue = (rowData, field) => {
Expand All @@ -648,7 +656,7 @@
const numberOfLinesPerPage = event.rows
tableDefinitions.setNumberOfLinesPerPage(numberOfLinesPerPage)
itemsByPage.value = numberOfLinesPerPage
firstItemIndex.value = event.first
reload({ page: event.page + 1 })
}
Expand All @@ -672,6 +680,10 @@
}
const fetchOnSearch = () => {
if (!props.lazy) return
const firstPage = 1
firstItemIndex.value = firstPage
reload()
}
Expand Down
27 changes: 12 additions & 15 deletions src/views/EdgeApplicationsRulesEngine/ListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -221,25 +221,22 @@
})
return
}
const { dragIndex: originIndex, dropIndex: destinationIndex, value: updatedTable } = event
const alterFirstItem = originIndex === 0 || destinationIndex === 0
if (alterFirstItem) {
const firstItem = updatedTable[originIndex]
const secondItem = updatedTable[destinationIndex]
const isDefaultRuleMoved =
firstItem.name === 'Default Rule' || secondItem.name === 'Default Rule'
if (isDefaultRuleMoved) {
toast.add({
closable: true,
severity: 'error',
summary: 'The default rule cannot be reordered'
})
return
}
const reorderedData = moveItem(data.value, updatedTable, originIndex, destinationIndex)
const isFirstRuleNotDefault = reorderedData[0].name !== 'Default Rule'
if (isFirstRuleNotDefault) {
toast.add({
closable: true,
severity: 'error',
summary: 'The default rule cannot be reordered'
})
return
}
const reorderedData = moveItem(data.value, updatedTable, originIndex, destinationIndex)
data.value = reorderedData
disabledOrdering.value = false
}
Expand Down

0 comments on commit 09e6568

Please sign in to comment.