fix: Update pagination logic in the help center (#5693)
This commit is contained in:
parent
a274a1702a
commit
95cc55d043
7 changed files with 45 additions and 52 deletions
|
@ -83,75 +83,71 @@ export default {
|
||||||
},
|
},
|
||||||
pageSize: {
|
pageSize: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 15,
|
default: 25,
|
||||||
},
|
},
|
||||||
totalCount: {
|
totalCount: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
onPageChange: {
|
|
||||||
type: Function,
|
|
||||||
default: () => {},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
isFooterVisible() {
|
isFooterVisible() {
|
||||||
return this.totalCount && !(this.firstIndex > this.totalCount);
|
return this.totalCount && !(this.firstIndex > this.totalCount);
|
||||||
},
|
},
|
||||||
firstIndex() {
|
firstIndex() {
|
||||||
const firstIndex = this.pageSize * (this.currentPage - 1) + 1;
|
return this.pageSize * (this.currentPage - 1) + 1;
|
||||||
return firstIndex;
|
|
||||||
},
|
},
|
||||||
lastIndex() {
|
lastIndex() {
|
||||||
const index = Math.min(this.totalCount, this.pageSize * this.currentPage);
|
return Math.min(this.totalCount, this.pageSize * this.currentPage);
|
||||||
return index;
|
|
||||||
},
|
},
|
||||||
searchButtonClass() {
|
searchButtonClass() {
|
||||||
return this.searchQuery !== '' ? 'show' : '';
|
return this.searchQuery !== '' ? 'show' : '';
|
||||||
},
|
},
|
||||||
hasLastPage() {
|
hasLastPage() {
|
||||||
const isDisabled =
|
return !!Math.ceil(this.totalCount / this.pageSize);
|
||||||
this.currentPage === Math.ceil(this.totalCount / this.pageSize);
|
|
||||||
return isDisabled;
|
|
||||||
},
|
},
|
||||||
hasFirstPage() {
|
hasFirstPage() {
|
||||||
const isDisabled = this.currentPage === 1;
|
return this.currentPage === 1;
|
||||||
return isDisabled;
|
|
||||||
},
|
},
|
||||||
hasNextPage() {
|
hasNextPage() {
|
||||||
const isDisabled =
|
return this.currentPage === Math.ceil(this.totalCount / this.pageSize);
|
||||||
this.currentPage === Math.ceil(this.totalCount / this.pageSize);
|
|
||||||
return isDisabled;
|
|
||||||
},
|
},
|
||||||
hasPrevPage() {
|
hasPrevPage() {
|
||||||
const isDisabled = this.currentPage === 1;
|
return this.currentPage === 1;
|
||||||
return isDisabled;
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onNextPage() {
|
onNextPage() {
|
||||||
if (this.hasNextPage) return;
|
if (this.hasNextPage) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const newPage = this.currentPage + 1;
|
const newPage = this.currentPage + 1;
|
||||||
this.onPageChange(newPage);
|
this.onPageChange(newPage);
|
||||||
},
|
},
|
||||||
onPrevPage() {
|
onPrevPage() {
|
||||||
if (this.hasPrevPage) return;
|
if (this.hasPrevPage) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const newPage = this.currentPage - 1;
|
const newPage = this.currentPage - 1;
|
||||||
this.onPageChange(newPage);
|
this.onPageChange(newPage);
|
||||||
},
|
},
|
||||||
onFirstPage() {
|
onFirstPage() {
|
||||||
if (this.hasFirstPage) return;
|
if (this.hasFirstPage) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const newPage = 1;
|
const newPage = 1;
|
||||||
this.onPageChange(newPage);
|
this.onPageChange(newPage);
|
||||||
},
|
},
|
||||||
onLastPage() {
|
onLastPage() {
|
||||||
if (this.hasLastPage) return;
|
if (this.hasLastPage) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const newPage = Math.ceil(this.totalCount / this.pageSize);
|
const newPage = Math.ceil(this.totalCount / this.pageSize);
|
||||||
this.onPageChange(newPage);
|
this.onPageChange(newPage);
|
||||||
},
|
},
|
||||||
|
onPageChange(page) {
|
||||||
|
this.$emit('page-change', page);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -29,10 +29,10 @@
|
||||||
</table>
|
</table>
|
||||||
<table-footer
|
<table-footer
|
||||||
v-if="articles.length"
|
v-if="articles.length"
|
||||||
:on-page-change="onPageChange"
|
:current-page="currentPage"
|
||||||
:current-page="Number(currentPage)"
|
|
||||||
:total-count="totalCount"
|
:total-count="totalCount"
|
||||||
:page-size="pageSize"
|
:page-size="pageSize"
|
||||||
|
@page-change="onPageChange"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -60,12 +60,12 @@ export default {
|
||||||
},
|
},
|
||||||
pageSize: {
|
pageSize: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 15,
|
default: 25,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onPageChange(page) {
|
onPageChange(page) {
|
||||||
this.$emit('on-page-change', page);
|
this.$emit('page-change', page);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,16 +2,15 @@
|
||||||
<div class="container overflow-auto">
|
<div class="container overflow-auto">
|
||||||
<article-header
|
<article-header
|
||||||
:header-title="headerTitle"
|
:header-title="headerTitle"
|
||||||
:count="articleCount"
|
:count="meta.count"
|
||||||
selected-value="Published"
|
selected-value="Published"
|
||||||
@newArticlePage="newArticlePage"
|
@newArticlePage="newArticlePage"
|
||||||
/>
|
/>
|
||||||
<article-table
|
<article-table
|
||||||
:articles="articles"
|
:articles="articles"
|
||||||
:article-count="articles.length"
|
|
||||||
:current-page="Number(meta.currentPage)"
|
:current-page="Number(meta.currentPage)"
|
||||||
:total-count="articleCount"
|
:total-count="Number(meta.count)"
|
||||||
@on-page-change="onPageChange"
|
@page-change="onPageChange"
|
||||||
/>
|
/>
|
||||||
<div v-if="shouldShowLoader" class="articles--loader">
|
<div v-if="shouldShowLoader" class="articles--loader">
|
||||||
<spinner />
|
<spinner />
|
||||||
|
@ -128,9 +127,9 @@ export default {
|
||||||
newArticlePage() {
|
newArticlePage() {
|
||||||
this.$router.push({ name: 'new_article' });
|
this.$router.push({ name: 'new_article' });
|
||||||
},
|
},
|
||||||
fetchArticles() {
|
fetchArticles({ pageNumber } = {}) {
|
||||||
this.$store.dispatch('articles/index', {
|
this.$store.dispatch('articles/index', {
|
||||||
pageNumber: this.pageNumber,
|
pageNumber: pageNumber || this.pageNumber,
|
||||||
portalSlug: this.$route.params.portalSlug,
|
portalSlug: this.$route.params.portalSlug,
|
||||||
locale: this.$route.params.locale,
|
locale: this.$route.params.locale,
|
||||||
status: this.status,
|
status: this.status,
|
||||||
|
@ -138,8 +137,8 @@ export default {
|
||||||
category_slug: this.selectedCategorySlug,
|
category_slug: this.selectedCategorySlug,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onPageChange(page) {
|
onPageChange(pageNumber) {
|
||||||
this.fetchArticles({ pageNumber: page });
|
this.fetchArticles({ pageNumber });
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,6 +4,17 @@ import { IFrameHelper } from 'widget/helpers/utils';
|
||||||
import { showBadgeOnFavicon } from './faviconHelper';
|
import { showBadgeOnFavicon } from './faviconHelper';
|
||||||
|
|
||||||
export const initOnEvents = ['click', 'touchstart', 'keypress', 'keydown'];
|
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') => {
|
export const getAlertAudio = async (baseUrl = '', type = 'dashboard') => {
|
||||||
const audioCtx = getAudioContext();
|
const audioCtx = getAudioContext();
|
||||||
|
|
||||||
|
@ -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) => {
|
export const notificationEnabled = (enableAudioAlerts, id, userId) => {
|
||||||
if (enableAudioAlerts === 'mine') {
|
if (enableAudioAlerts === 'mine') {
|
||||||
return userId === id;
|
return userId === id;
|
||||||
|
|
|
@ -5,7 +5,6 @@ end
|
||||||
json.meta do
|
json.meta do
|
||||||
json.current_page @current_page
|
json.current_page @current_page
|
||||||
json.articles_count @articles_count
|
json.articles_count @articles_count
|
||||||
json.all_articles_count @articles_count
|
|
||||||
json.archived_articles_count @articles.archived.size
|
json.archived_articles_count @articles.archived.size
|
||||||
json.published_count @articles.published.size
|
json.published_count @articles.published.size
|
||||||
json.draft_articles_count @articles.draft.size
|
json.draft_articles_count @articles.draft.size
|
||||||
|
|
|
@ -7,6 +7,7 @@ json.name portal.name
|
||||||
json.page_title portal.page_title
|
json.page_title portal.page_title
|
||||||
json.slug portal.slug
|
json.slug portal.slug
|
||||||
json.archived portal.archived
|
json.archived portal.archived
|
||||||
|
json.account_id portal.account_id
|
||||||
|
|
||||||
json.config do
|
json.config do
|
||||||
json.allowed_locales do
|
json.allowed_locales do
|
||||||
|
|
|
@ -195,7 +195,6 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||||
json_response = JSON.parse(response.body)
|
json_response = JSON.parse(response.body)
|
||||||
expect(json_response['payload'].count).to be 1
|
expect(json_response['payload'].count).to be 1
|
||||||
expect(json_response['meta']['articles_count']).to be 2
|
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
|
expect(json_response['meta']['mine_articles_count']).to be 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue