feat: Add per-page support for agent and team overview report pagination (#11110)
# Pull Request Template ## Description This PR includes per-page support for table pagination in agent and team overview reports. ## Type of change - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? ### Loom video https://www.loom.com/share/8c9668fe129c452986d8813a156dd3b8?sid=d637f4fe-ad0c-4f18-ad90-65e50247b3c6 ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
This commit is contained in:
@@ -1,12 +1,47 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { computed } from 'vue';
|
import { computed, onMounted } from 'vue';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
|
import Button from 'dashboard/components-next/button/Button.vue';
|
||||||
|
import FilterSelect from 'dashboard/components-next/filter/inputs/FilterSelect.vue';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
table: {
|
table: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
defaultPageSize: {
|
||||||
|
type: Number,
|
||||||
|
default: 10,
|
||||||
|
},
|
||||||
|
showPageSizeSelector: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const emit = defineEmits(['pageSizeChange']);
|
||||||
|
const { t } = useI18n();
|
||||||
|
|
||||||
|
const pageSizeOptions = [
|
||||||
|
{
|
||||||
|
label: `${t('REPORT.PAGINATION.PER_PAGE_TEMPLATE', { size: 10 })}`,
|
||||||
|
value: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: `${t('REPORT.PAGINATION.PER_PAGE_TEMPLATE', { size: 20 })}`,
|
||||||
|
value: 20,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: `${t('REPORT.PAGINATION.PER_PAGE_TEMPLATE', { size: 50 })}`,
|
||||||
|
value: 50,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: `${t('REPORT.PAGINATION.PER_PAGE_TEMPLATE', { size: 100 })}`,
|
||||||
|
value: 100,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const getFormattedPages = (start, end) => {
|
const getFormattedPages = (start, end) => {
|
||||||
const formatter = new Intl.NumberFormat(navigator.language);
|
const formatter = new Intl.NumberFormat(navigator.language);
|
||||||
return Array.from({ length: end - start + 1 }, (_, i) =>
|
return Array.from({ length: end - start + 1 }, (_, i) =>
|
||||||
@@ -48,70 +83,98 @@ const end = computed(() => {
|
|||||||
total.value
|
total.value
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const currentPageSize = computed({
|
||||||
|
get() {
|
||||||
|
return props.table.getState().pagination.pageSize;
|
||||||
|
},
|
||||||
|
set(newValue) {
|
||||||
|
props.table.setPageSize(Number(newValue));
|
||||||
|
emit('pageSizeChange', Number(newValue));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (
|
||||||
|
props.showPageSizeSelector &&
|
||||||
|
props.defaultPageSize &&
|
||||||
|
props.defaultPageSize !== 10
|
||||||
|
) {
|
||||||
|
props.table.setPageSize(props.defaultPageSize);
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex items-center justify-between">
|
<div class="flex items-center justify-between">
|
||||||
<div class="flex flex-1 items-center justify-between">
|
<div class="flex flex-1 items-center gap-2 justify-between">
|
||||||
<div>
|
<p class="text-sm truncate text-n-slate-11 mb-0">
|
||||||
<p class="text-sm text-n-slate-11 mb-0">
|
{{ $t('REPORT.PAGINATION.RESULTS', { start, end, total }) }}
|
||||||
{{ $t('REPORT.PAGINATION.RESULTS', { start, end, total }) }}
|
</p>
|
||||||
</p>
|
<div class="flex items-center gap-2">
|
||||||
</div>
|
<FilterSelect
|
||||||
<nav class="isolate inline-flex gap-1">
|
v-if="showPageSizeSelector"
|
||||||
<woot-button
|
v-model="currentPageSize"
|
||||||
:disabled="!table.getCanPreviousPage()"
|
variant="outline"
|
||||||
variant="clear"
|
hide-icon
|
||||||
class="h-8 border-0 flex items-center"
|
class="[&>button]:text-n-slate-11 [&>button]:hover:text-n-slate-12 [&>button]:h-6"
|
||||||
color-scheme="secondary"
|
:options="pageSizeOptions"
|
||||||
@click="table.setPageIndex(0)"
|
/>
|
||||||
>
|
<nav class="isolate inline-flex items-center gap-1.5">
|
||||||
<span class="i-lucide-chevrons-left size-3" aria-hidden="true" />
|
<Button
|
||||||
</woot-button>
|
icon="i-lucide-chevrons-left"
|
||||||
<woot-button
|
ghost
|
||||||
variant="clear"
|
slate
|
||||||
class="h-8 border-0 flex items-center"
|
sm
|
||||||
color-scheme="secondary"
|
class="!size-6"
|
||||||
:disabled="!table.getCanPreviousPage()"
|
:disabled="!table.getCanPreviousPage()"
|
||||||
@click="table.previousPage()"
|
@click="table.setPageIndex(0)"
|
||||||
>
|
/>
|
||||||
<span class="i-lucide-chevron-left size-3" aria-hidden="true" />
|
<Button
|
||||||
</woot-button>
|
icon="i-lucide-chevron-left"
|
||||||
<woot-button
|
ghost
|
||||||
v-for="page in visiblePages"
|
slate
|
||||||
:key="page"
|
sm
|
||||||
variant="clear"
|
class="!size-6"
|
||||||
class="h-8 flex items-center justify-center text-xs leading-none text-center"
|
:disabled="!table.getCanPreviousPage()"
|
||||||
:class="page == currentPage ? 'border-n-brand' : 'border-slate-50'"
|
@click="table.previousPage()"
|
||||||
color-scheme="secondary"
|
/>
|
||||||
@click="table.setPageIndex(page - 1)"
|
<Button
|
||||||
>
|
v-for="page in visiblePages"
|
||||||
<span
|
:key="page"
|
||||||
class="text-center"
|
xs
|
||||||
:class="{ 'text-n-brand': page == currentPage }"
|
outline
|
||||||
|
:color="page == currentPage ? 'blue' : 'slate'"
|
||||||
|
class="!h-6 min-w-6"
|
||||||
|
@click="table.setPageIndex(page - 1)"
|
||||||
>
|
>
|
||||||
{{ page }}
|
<span
|
||||||
</span>
|
class="text-center"
|
||||||
</woot-button>
|
:class="{ 'text-n-brand': page == currentPage }"
|
||||||
<woot-button
|
>
|
||||||
:disabled="!table.getCanNextPage()"
|
{{ page }}
|
||||||
variant="clear"
|
</span>
|
||||||
class="h-8 border-0 flex items-center"
|
</Button>
|
||||||
color-scheme="secondary"
|
<Button
|
||||||
@click="table.nextPage()"
|
icon="i-lucide-chevron-right"
|
||||||
>
|
ghost
|
||||||
<span class="i-lucide-chevron-right size-3" aria-hidden="true" />
|
slate
|
||||||
</woot-button>
|
sm
|
||||||
<woot-button
|
class="!size-6"
|
||||||
:disabled="!table.getCanNextPage()"
|
:disabled="!table.getCanNextPage()"
|
||||||
variant="clear"
|
@click="table.nextPage()"
|
||||||
class="h-8 border-0 flex items-center"
|
/>
|
||||||
color-scheme="secondary"
|
<Button
|
||||||
@click="table.setPageIndex(table.getPageCount() - 1)"
|
icon="i-lucide-chevrons-right"
|
||||||
>
|
ghost
|
||||||
<span class="i-lucide-chevrons-right size-3" aria-hidden="true" />
|
slate
|
||||||
</woot-button>
|
sm
|
||||||
</nav>
|
class="!size-6"
|
||||||
|
:disabled="!table.getCanNextPage()"
|
||||||
|
@click="table.setPageIndex(table.getPageCount() - 1)"
|
||||||
|
/>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -119,7 +119,8 @@
|
|||||||
"EMPTY_LIST": "No results found"
|
"EMPTY_LIST": "No results found"
|
||||||
},
|
},
|
||||||
"PAGINATION": {
|
"PAGINATION": {
|
||||||
"RESULTS": "Showing {start} to {end} of {total} results"
|
"RESULTS": "Showing {start} to {end} of {total} results",
|
||||||
|
"PER_PAGE_TEMPLATE": "{size} / page"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AGENT_REPORTS": {
|
"AGENT_REPORTS": {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
getPaginationRowModel,
|
getPaginationRowModel,
|
||||||
} from '@tanstack/vue-table';
|
} from '@tanstack/vue-table';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import { useUISettings } from 'dashboard/composables/useUISettings';
|
||||||
|
|
||||||
import Spinner from 'shared/components/Spinner.vue';
|
import Spinner from 'shared/components/Spinner.vue';
|
||||||
import EmptyState from 'dashboard/components/widgets/EmptyState.vue';
|
import EmptyState from 'dashboard/components/widgets/EmptyState.vue';
|
||||||
@@ -30,6 +31,19 @@ const { agents, agentMetrics } = defineProps({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
const { uiSettings, updateUISettings } = useUISettings();
|
||||||
|
|
||||||
|
// UI Settings key for agent table page size
|
||||||
|
const AGENT_TABLE_PAGE_SIZE_KEY = 'report_overview_agent_table_page_size';
|
||||||
|
|
||||||
|
// Get the saved page size from UI settings or default to 10
|
||||||
|
const getPageSize = () => {
|
||||||
|
return uiSettings.value[AGENT_TABLE_PAGE_SIZE_KEY] || 10;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePageSizeChange = pageSize => {
|
||||||
|
updateUISettings({ [AGENT_TABLE_PAGE_SIZE_KEY]: pageSize });
|
||||||
|
};
|
||||||
|
|
||||||
const getAgentMetrics = id =>
|
const getAgentMetrics = id =>
|
||||||
agentMetrics.find(metrics => metrics.assignee_id === Number(id)) || {};
|
agentMetrics.find(metrics => metrics.assignee_id === Number(id)) || {};
|
||||||
@@ -98,13 +112,24 @@ const table = useVueTable({
|
|||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
getPaginationRowModel: getPaginationRowModel(),
|
getPaginationRowModel: getPaginationRowModel(),
|
||||||
|
initialState: {
|
||||||
|
pagination: {
|
||||||
|
pageSize: getPageSize(),
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col flex-1">
|
<div class="flex flex-col flex-1">
|
||||||
<Table :table="table" class="max-h-[calc(100vh-21.875rem)]" />
|
<Table :table="table" class="max-h-[calc(100vh-21.875rem)]" />
|
||||||
<Pagination class="mt-2" :table="table" />
|
<Pagination
|
||||||
|
class="mt-2"
|
||||||
|
:table="table"
|
||||||
|
show-page-size-selector
|
||||||
|
:default-page-size="getPageSize()"
|
||||||
|
@page-size-change="handlePageSizeChange"
|
||||||
|
/>
|
||||||
<div
|
<div
|
||||||
v-if="isLoading"
|
v-if="isLoading"
|
||||||
class="items-center flex text-base justify-center p-8"
|
class="items-center flex text-base justify-center p-8"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
getPaginationRowModel,
|
getPaginationRowModel,
|
||||||
} from '@tanstack/vue-table';
|
} from '@tanstack/vue-table';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import { useUISettings } from 'dashboard/composables/useUISettings';
|
||||||
|
|
||||||
import Spinner from 'shared/components/Spinner.vue';
|
import Spinner from 'shared/components/Spinner.vue';
|
||||||
import EmptyState from 'dashboard/components/widgets/EmptyState.vue';
|
import EmptyState from 'dashboard/components/widgets/EmptyState.vue';
|
||||||
@@ -29,6 +30,19 @@ const { teams, teamMetrics } = defineProps({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
const { uiSettings, updateUISettings } = useUISettings();
|
||||||
|
|
||||||
|
// UI Settings key for team table page size
|
||||||
|
const TEAM_TABLE_PAGE_SIZE_KEY = 'report_overview_team_table_page_size';
|
||||||
|
|
||||||
|
// Get the saved page size from UI settings or default to 10
|
||||||
|
const getPageSize = () => {
|
||||||
|
return uiSettings.value[TEAM_TABLE_PAGE_SIZE_KEY] || 10;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePageSizeChange = pageSize => {
|
||||||
|
updateUISettings({ [TEAM_TABLE_PAGE_SIZE_KEY]: pageSize });
|
||||||
|
};
|
||||||
|
|
||||||
const getTeamMetrics = id =>
|
const getTeamMetrics = id =>
|
||||||
teamMetrics.find(metrics => metrics.team_id === Number(id)) || {};
|
teamMetrics.find(metrics => metrics.team_id === Number(id)) || {};
|
||||||
@@ -92,13 +106,24 @@ const table = useVueTable({
|
|||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
getPaginationRowModel: getPaginationRowModel(),
|
getPaginationRowModel: getPaginationRowModel(),
|
||||||
|
initialState: {
|
||||||
|
pagination: {
|
||||||
|
pageSize: getPageSize(),
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col flex-1">
|
<div class="flex flex-col flex-1">
|
||||||
<Table :table="table" class="max-h-[calc(100vh-21.875rem)]" />
|
<Table :table="table" class="max-h-[calc(100vh-21.875rem)]" />
|
||||||
<Pagination class="mt-2" :table="table" />
|
<Pagination
|
||||||
|
class="mt-2"
|
||||||
|
:table="table"
|
||||||
|
show-page-size-selector
|
||||||
|
:default-page-size="getPageSize()"
|
||||||
|
@page-size-change="handlePageSizeChange"
|
||||||
|
/>
|
||||||
<div
|
<div
|
||||||
v-if="isLoading"
|
v-if="isLoading"
|
||||||
class="items-center flex text-base justify-center p-8"
|
class="items-center flex text-base justify-center p-8"
|
||||||
|
|||||||
Reference in New Issue
Block a user