Skip to content

Commit

Permalink
fix: Update pagination logic in the help center (#5693)
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavrajs committed Oct 21, 2022
1 parent a274a17 commit 95cc55d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 52 deletions.
48 changes: 22 additions & 26 deletions app/javascript/dashboard/components/widgets/TableFooter.vue
Expand Up @@ -83,75 +83,71 @@ export default {
},
pageSize: {
type: Number,
default: 15,
default: 25,
},
totalCount: {
type: Number,
default: 0,
},
onPageChange: {
type: Function,
default: () => {},
},
},
computed: {
isFooterVisible() {
return this.totalCount && !(this.firstIndex > this.totalCount);
},
firstIndex() {
const firstIndex = this.pageSize * (this.currentPage - 1) + 1;
return firstIndex;
return this.pageSize * (this.currentPage - 1) + 1;
},
lastIndex() {
const index = Math.min(this.totalCount, this.pageSize * this.currentPage);
return index;
return Math.min(this.totalCount, this.pageSize * this.currentPage);
},
searchButtonClass() {
return this.searchQuery !== '' ? 'show' : '';
},
hasLastPage() {
const isDisabled =
this.currentPage === Math.ceil(this.totalCount / this.pageSize);
return isDisabled;
return !!Math.ceil(this.totalCount / this.pageSize);
},
hasFirstPage() {
const isDisabled = this.currentPage === 1;
return isDisabled;
return this.currentPage === 1;
},
hasNextPage() {
const isDisabled =
this.currentPage === Math.ceil(this.totalCount / this.pageSize);
return isDisabled;
return this.currentPage === Math.ceil(this.totalCount / this.pageSize);
},
hasPrevPage() {
const isDisabled = this.currentPage === 1;
return isDisabled;
return this.currentPage === 1;
},
},
methods: {
onNextPage() {
if (this.hasNextPage) return;
if (this.hasNextPage) {
return;
}
const newPage = this.currentPage + 1;
this.onPageChange(newPage);
},
onPrevPage() {
if (this.hasPrevPage) return;
if (this.hasPrevPage) {
return;
}
const newPage = this.currentPage - 1;
this.onPageChange(newPage);
},
onFirstPage() {
if (this.hasFirstPage) return;
if (this.hasFirstPage) {
return;
}
const newPage = 1;
this.onPageChange(newPage);
},
onLastPage() {
if (this.hasLastPage) return;
if (this.hasLastPage) {
return;
}
const newPage = Math.ceil(this.totalCount / this.pageSize);
this.onPageChange(newPage);
},
onPageChange(page) {
this.$emit('page-change', page);
},
},
};
</script>
Expand Down
Expand Up @@ -29,10 +29,10 @@
</table>
<table-footer
v-if="articles.length"
:on-page-change="onPageChange"
:current-page="Number(currentPage)"
:current-page="currentPage"
:total-count="totalCount"
:page-size="pageSize"
@page-change="onPageChange"
/>
</div>
</template>
Expand Down Expand Up @@ -60,12 +60,12 @@ export default {
},
pageSize: {
type: Number,
default: 15,
default: 25,
},
},
methods: {
onPageChange(page) {
this.$emit('on-page-change', page);
this.$emit('page-change', page);
},
},
};
Expand Down
Expand Up @@ -2,16 +2,15 @@
<div class="container overflow-auto">
<article-header
:header-title="headerTitle"
:count="articleCount"
:count="meta.count"
selected-value="Published"
@newArticlePage="newArticlePage"
/>
<article-table
:articles="articles"
:article-count="articles.length"
:current-page="Number(meta.currentPage)"
:total-count="articleCount"
@on-page-change="onPageChange"
:total-count="Number(meta.count)"
@page-change="onPageChange"
/>
<div v-if="shouldShowLoader" class="articles--loader">
<spinner />
Expand Down Expand Up @@ -128,18 +127,18 @@ export default {
newArticlePage() {
this.$router.push({ name: 'new_article' });
},
fetchArticles() {
fetchArticles({ pageNumber } = {}) {
this.$store.dispatch('articles/index', {
pageNumber: this.pageNumber,
pageNumber: pageNumber || this.pageNumber,
portalSlug: this.$route.params.portalSlug,
locale: this.$route.params.locale,
status: this.status,
author_id: this.author,
category_slug: this.selectedCategorySlug,
});
},
onPageChange(page) {
this.fetchArticles({ pageNumber: page });
onPageChange(pageNumber) {
this.fetchArticles({ pageNumber });
},
},
};
Expand Down
23 changes: 11 additions & 12 deletions app/javascript/shared/helpers/AudioNotificationHelper.js
Expand Up @@ -4,6 +4,17 @@ import { IFrameHelper } from 'widget/helpers/utils';
import { showBadgeOnFavicon } from './faviconHelper';

export const initOnEvents = ['click', 'touchstart', 'keypress', 'keydown'];

export const getAudioContext = () => {
let audioCtx;
try {
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
} catch {
// AudioContext is not available.
}
return audioCtx;
};

export const getAlertAudio = async (baseUrl = '', type = 'dashboard') => {
const audioCtx = getAudioContext();

Expand Down Expand Up @@ -35,18 +46,6 @@ export const getAlertAudio = async (baseUrl = '', type = 'dashboard') => {
}
};

export const getAudioContext = () => {
let audioCtx;

try {
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
} catch {
// AudioContext is not available.
}

return audioCtx;
};

export const notificationEnabled = (enableAudioAlerts, id, userId) => {
if (enableAudioAlerts === 'mine') {
return userId === id;
Expand Down
1 change: 0 additions & 1 deletion app/views/api/v1/accounts/articles/index.json.jbuilder
Expand Up @@ -5,7 +5,6 @@ end
json.meta do
json.current_page @current_page
json.articles_count @articles_count
json.all_articles_count @articles_count
json.archived_articles_count @articles.archived.size
json.published_count @articles.published.size
json.draft_articles_count @articles.draft.size
Expand Down
1 change: 1 addition & 0 deletions app/views/api/v1/accounts/portals/_portal.json.jbuilder
Expand Up @@ -7,6 +7,7 @@ json.name portal.name
json.page_title portal.page_title
json.slug portal.slug
json.archived portal.archived
json.account_id portal.account_id

json.config do
json.allowed_locales do
Expand Down
Expand Up @@ -195,7 +195,6 @@
json_response = JSON.parse(response.body)
expect(json_response['payload'].count).to be 1
expect(json_response['meta']['articles_count']).to be 2
expect(json_response['meta']['all_articles_count']).to be 2
expect(json_response['meta']['mine_articles_count']).to be 1
end
end
Expand Down

0 comments on commit 95cc55d

Please sign in to comment.