Skip to content

Commit

Permalink
fix: handle pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
RitvikSardana committed Dec 3, 2024
1 parent 1f8bab8 commit c3d95c7
Showing 1 changed file with 60 additions and 14 deletions.
74 changes: 60 additions & 14 deletions desk/src/pages/desk/agent/Agents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,25 @@
<SortBy :hide-label="false" />
</div>
</div>
<div>
<div class="flex-1">
{{ agents?.data?.data }}
</div>
<div class="p-20 border-t sm:px-5 px-3 py-2">
<ListFooter
:options="{
rowCount: agents?.data?.row_count,
totalCount: agents?.data?.total_count,
}"
:pageLengthCount="defaultParams.page_length_count"
@loadMore="handlePageLength(defaultParams.page_length_count, true)"
v-model="defaultParams.page_length_count"
@update:modelValue="
(count) => {
handlePageLength(count);
}
"
/>
</div>
<AddNewAgentsDialog
:show="isDialogVisible"
@close="isDialogVisible = false"
Expand All @@ -48,22 +64,30 @@
</template>
<script setup lang="ts">
import { reactive, ref, provide } from "vue";
import { usePageMeta, Avatar, Badge, createResource } from "frappe-ui";
import {
usePageMeta,
Avatar,
Badge,
createResource,
ListFooter,
} from "frappe-ui";
import AddNewAgentsDialog from "@/components/desk/global/AddNewAgentsDialog.vue";
import LayoutHeader from "@/components/LayoutHeader.vue";
import { Filter, SortBy, QuickFilters } from "@/components/view-controls";
const isDialogVisible = ref(false);
const defaultParams = reactive({
doctype: "HD Agent",
filters: {},
order_by: "",
page_length: 20,
page_length_count: 20,
});
const agents = createResource({
url: "helpdesk.api.doc.get_list_data",
makeParams: (params) => {
return {
doctype: "HD Agent",
filters: params?.filters || {},
order_by: params?.order_by || "",
};
},
params: defaultParams,
auto: true,
});
Expand Down Expand Up @@ -120,11 +144,6 @@ provide("listViewActions", {
reload,
});
const defaultParams = {
filters: {},
order_by: "",
};
function applyFilters(filters) {
defaultParams.filters = { ...filters };
agents.submit({ ...defaultParams, filters });
Expand All @@ -143,6 +162,33 @@ function reload() {
agents.reload({ ...defaultParams });
}
function handlePageLength(count: number, loadMore: boolean = false) {
if (count >= agents.data.row_count) {
return;
}
defaultParams.page_length_count = count;
if (loadMore) {
defaultParams.page_length += count;
} else {
if (
count === defaultParams.page_length &&
count === defaultParams.page_length_count
) {
return;
}
defaultParams.page_length = count;
defaultParams.page_length_count = count;
}
agents.reload();
}
// watch(
// () => defaultParams.page_length_count,
// (count) => {
// handlePageLength(count);
// }
// );
usePageMeta(() => {
return {
title: "Agents",
Expand Down

0 comments on commit c3d95c7

Please sign in to comment.