Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

fix: add sorting to bridgechains table #1737

Merged
merged 5 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const createWrapper = (component) => {
totalCount: 0,
next: null,
previous: null,
self: '/api/businesses/public-key-1/bridgechains?page=1&limit=100',
first: '/api/businesses/public-key-1/bridgechains?page=1&limit=100',
self: '/api/businesses/address-1/bridgechains?page=1&limit=100',
first: '/api/businesses/address-1/bridgechains?page=1&limit=100',
last: null
}
}))
Expand Down Expand Up @@ -159,7 +159,7 @@ describe('WalletBusinessBridgechains', () => {
wrapper.vm.fetchBridgechains()

expect(clientFetchBridgechainsMock).toHaveBeenCalledTimes(1)
expect(clientFetchBridgechainsMock).toHaveBeenCalledWith('public-key-1', {
expect(clientFetchBridgechainsMock).toHaveBeenCalledWith('address-1', {
page: params.page,
limit: params.limit,
orderBy: `${params.sort.field}:${params.sort.type}`
Expand Down Expand Up @@ -264,16 +264,16 @@ describe('WalletBusinessBridgechains', () => {

it('should update sort column', () => {
wrapper.vm.onSortChange({
source: 'from-third-party-component',
field: 'amount',
type: 'desc'
source: 'bridgechainsTab',
field: 'genesisHash',
type: 'asc'
})

expect(spyUpdateParams).toHaveBeenCalledTimes(1)
expect(spyUpdateParams).toHaveBeenCalledWith({
sort: {
field: 'amount',
type: 'desc'
field: 'genesisHash',
type: 'asc'
},
page: 1
})
Expand All @@ -282,16 +282,16 @@ describe('WalletBusinessBridgechains', () => {

it('should update sort column direction', () => {
wrapper.vm.onSortChange({
source: 'from-third-party-component',
field: 'timestamp',
type: 'asc'
source: 'bridgechainsTab',
field: 'name',
type: 'desc'
})

expect(spyUpdateParams).toHaveBeenCalledTimes(1)
expect(spyUpdateParams).toHaveBeenCalledWith({
sort: {
field: 'timestamp',
type: 'asc'
field: 'name',
type: 'desc'
},
page: 1
})
Expand All @@ -309,16 +309,27 @@ describe('WalletBusinessBridgechains', () => {
expect(spyLoadBridgechains).toHaveBeenCalledTimes(0)
})

it('should not do anything if column and direction do not change', () => {
it('should not do anything if source doesn\'t match component', () => {
wrapper.vm.onSortChange({
source: 'from-third-party-component',
field: 'timestamp',
source: 'transactionsTab',
field: 'amount',
type: 'desc'
})

expect(spyUpdateParams).toHaveBeenCalledTimes(0)
expect(spyLoadBridgechains).toHaveBeenCalledTimes(0)
})

it('should not do anything if column and direction do not change', () => {
wrapper.vm.onSortChange({
source: 'bridgechainsTab',
field: 'name',
type: 'asc'
})

expect(spyUpdateParams).toHaveBeenCalledTimes(0)
expect(spyLoadBridgechains).toHaveBeenCalledTimes(0)
})
})

describe('reset', () => {
Expand All @@ -344,8 +355,8 @@ describe('WalletBusinessBridgechains', () => {
page: 1,
limit: 10,
sort: {
field: 'timestamp',
type: 'desc'
field: 'name',
type: 'asc'
}
}

Expand All @@ -354,7 +365,7 @@ describe('WalletBusinessBridgechains', () => {
page: 10,
limit: 100,
sort: {
field: 'amount',
field: 'genesisHash',
type: 'asc'
}
}
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/services/client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ describe('Services > Client', () => {
}

nock('http://127.0.0.1:4003')
.get('/api/v2/businesses/BUSINESS_ID/bridgechains')
.get('/api/v2/businesses/BUSINESS_ID/bridgechains?page=1&limit=50&orderBy=name%3Aasc')
.reply(200, response)

expect(await client.fetchBusinessBridgechains('BUSINESS_ID')).toEqual(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export default {
page: 1,
limit: 10,
sort: {
field: 'timestamp',
type: 'desc'
field: 'name',
type: 'asc'
}
}
}),
Expand Down Expand Up @@ -89,17 +89,16 @@ export default {
return
}

let address, publicKey
let address
if (this.wallet_fromRoute) {
address = this.wallet_fromRoute.address.slice()
publicKey = this.wallet_fromRoute.publicKey
}

this.isFetching = true

try {
const { limit, page, sort } = this.queryParams
const response = await this.$client.fetchBusinessBridgechains(publicKey, {
const response = await this.$client.fetchBusinessBridgechains(address, {
page,
limit,
orderBy: `${sort.field}:${sort.type}`
Expand Down Expand Up @@ -144,7 +143,7 @@ export default {
},

onSortChange ({ source, field, type }) {
if (!source) {
if (!source || source !== 'bridgechainsTab') {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export default {
field: 'seedNodes',
formatFn: value => {
return value.length
}
},
sortable: false
},
{
label: this.$t('WALLET_BUSINESS.COLUMN.GENESIS_HASH'),
Expand Down
14 changes: 11 additions & 3 deletions src/renderer/services/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,19 @@ export default class ClientService {

/**
* Fetch bridgechains for a business.
* @param {String} publicKey
* @param {String} address
* @return {Object}
*/
async fetchBusinessBridgechains (publicKey) {
return (await this.client.api('businesses').bridgechains(publicKey)).body
async fetchBusinessBridgechains (address, options = {}) {
options.page || (options.page = 1)
options.limit || (options.limit = 50)
options.orderBy || (options.orderBy = 'name:asc')

return (await this.client.api('businesses').bridgechains(address, {
page: options.page,
limit: options.limit,
orderBy: options.orderBy
})).body
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/services/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export default class WalletService {
*/
static async hasBridgechains (wallet, vm) {
try {
const bridegchains = await vm.$client.fetchBusinessBridgechains(wallet.publicKey)
const bridegchains = await vm.$client.fetchBusinessBridgechains(wallet.address)

return bridegchains.data.filter(bridgechain => !bridgechain.isResigned).length > 0
} catch (error) {
Expand Down