From e0fd4e1eeaed5e23befa3a1e4f1e9cd298806c18 Mon Sep 17 00:00:00 2001 From: Marcos Defendi Date: Mon, 13 Jan 2020 17:36:34 -0300 Subject: [PATCH] Integrations list was not paginated --- app/integrations/client/views/integrations.js | 25 +++++++++++++++++-- .../client/views/integrationsOutgoing.js | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/integrations/client/views/integrations.js b/app/integrations/client/views/integrations.js index 0bace131be02..c568fa9293a5 100644 --- a/app/integrations/client/views/integrations.js +++ b/app/integrations/client/views/integrations.js @@ -3,12 +3,15 @@ import { ReactiveVar } from 'meteor/reactive-var'; import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; import { Tracker } from 'meteor/tracker'; import moment from 'moment'; +import _ from 'underscore'; import { hasAtLeastOnePermission } from '../../../authorization'; import { integrations } from '../../lib/rocketchat'; import { SideNav } from '../../../ui-utils/client'; import { APIClient } from '../../../utils/client'; +const ITEMS_COUNT = 50; + Template.integrations.helpers({ hasPermission() { return hasAtLeastOnePermission([ @@ -38,7 +41,25 @@ Template.integrations.onRendered(() => { Template.integrations.onCreated(async function() { this.integrations = new ReactiveVar([]); + this.offset = new ReactiveVar(0); + this.total = new ReactiveVar(0); + + this.autorun(async () => { + const offset = this.offset.get(); + const { integrations, total } = await APIClient.v1.get(`integrations.list?count=${ ITEMS_COUNT }&offset=${ offset }`); + this.total.set(total); + this.integrations.set(this.integrations.get().concat(integrations)); + }); +}); - const { integrations } = await APIClient.v1.get('integrations.list'); - this.integrations.set(integrations); +Template.integrations.events({ + 'scroll .content': _.throttle(function(e, instance) { + if (e.target.scrollTop >= (e.target.scrollHeight - e.target.clientHeight)) { + const integrations = instance.integrations.get(); + if (instance.total.get() <= integrations.length) { + return; + } + return instance.offset.set(instance.offset.get() + ITEMS_COUNT); + } + }, 200), }); diff --git a/app/integrations/client/views/integrationsOutgoing.js b/app/integrations/client/views/integrationsOutgoing.js index 040313001063..dba874aca11b 100644 --- a/app/integrations/client/views/integrationsOutgoing.js +++ b/app/integrations/client/views/integrationsOutgoing.js @@ -51,7 +51,7 @@ Template.integrationsOutgoing.onCreated(async function _integrationsOutgoingOnCr }; const integration = await getIntegration(params.id, Meteor.userId()); - if (!integration) { + if (params.id && !integration) { toastr.error(TAPi18n.__('No_integration_found')); FlowRouter.go('admin-integrations'); return;