mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-17 20:52:14 +01:00
add dynamic loading of paginated endpoints above page_limit
add request classes and fix collection typing for clients, tasks and tags
This commit is contained in:
@@ -2,29 +2,10 @@
|
||||
import MainContainer from '@/packages/ui/src/MainContainer.vue';
|
||||
import AppLayout from '@/Layouts/AppLayout.vue';
|
||||
import PageTitle from '@/Components/Common/PageTitle.vue';
|
||||
import {
|
||||
ChartBarIcon,
|
||||
ChevronLeftIcon,
|
||||
ChevronDoubleLeftIcon,
|
||||
ChevronRightIcon,
|
||||
ChevronDoubleRightIcon,
|
||||
CreditCardIcon,
|
||||
UserGroupIcon,
|
||||
} from '@heroicons/vue/20/solid';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { ChartBarIcon, CreditCardIcon, UserGroupIcon } from '@heroicons/vue/20/solid';
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { api, type ReportIndexResponse } from '@/packages/api/src';
|
||||
import {
|
||||
PaginationEllipsis,
|
||||
PaginationFirst,
|
||||
PaginationLast,
|
||||
PaginationList,
|
||||
PaginationListItem,
|
||||
PaginationNext,
|
||||
PaginationPrev,
|
||||
PaginationRoot,
|
||||
} from 'radix-vue';
|
||||
import { useQuery, useQueryClient } from '@tanstack/vue-query';
|
||||
import { useQuery } from '@tanstack/vue-query';
|
||||
import { getCurrentOrganizationId } from '@/utils/useUser';
|
||||
import ReportingTabNavbar from '@/Components/Common/Reporting/ReportingTabNavbar.vue';
|
||||
import ReportTable from '@/Components/Common/Report/ReportTable.vue';
|
||||
@@ -32,37 +13,22 @@ import { isAllowedToPerformPremiumAction, isBillingActivated } from '@/utils/bil
|
||||
import { canManageBilling, canUpdateOrganization } from '@/utils/permissions';
|
||||
import PrimaryButton from '../packages/ui/src/Buttons/PrimaryButton.vue';
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import { fetchAllReports } from '@/utils/useReportsQuery';
|
||||
|
||||
const pageLimit = 15;
|
||||
const currentPage = ref(1);
|
||||
|
||||
const { data: reportsResponse } = useQuery<ReportIndexResponse>({
|
||||
queryKey: computed(() => ['reports', getCurrentOrganizationId(), currentPage.value]),
|
||||
const { data: reportsData } = useQuery({
|
||||
queryKey: computed(() => ['reports', getCurrentOrganizationId()]),
|
||||
enabled: !!getCurrentOrganizationId(),
|
||||
queryFn: () =>
|
||||
api.getReports({
|
||||
params: {
|
||||
organization: getCurrentOrganizationId() || '',
|
||||
},
|
||||
}),
|
||||
queryFn: async () => {
|
||||
const organizationId = getCurrentOrganizationId();
|
||||
if (!organizationId) throw new Error('No organization');
|
||||
const data = await fetchAllReports(organizationId);
|
||||
return { data };
|
||||
},
|
||||
staleTime: 1000 * 30,
|
||||
});
|
||||
|
||||
const reports = computed(() => {
|
||||
return reportsResponse.value?.data ?? [];
|
||||
});
|
||||
|
||||
const totalPages = computed(() => {
|
||||
return 1;
|
||||
});
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
async function updateFilteredTimeEntries() {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: ['reports'],
|
||||
});
|
||||
}
|
||||
watch(currentPage, () => {
|
||||
updateFilteredTimeEntries();
|
||||
return reportsData.value?.data ?? [];
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -110,64 +76,5 @@ watch(currentPage, () => {
|
||||
<ReportTable
|
||||
v-if="reports.length > 0 || isAllowedToPerformPremiumAction()"
|
||||
:reports="reports"></ReportTable>
|
||||
|
||||
<PaginationRoot
|
||||
v-if="reports.length > 0 || isAllowedToPerformPremiumAction()"
|
||||
v-model:page="currentPage"
|
||||
:total="totalPages"
|
||||
:items-per-page="pageLimit"
|
||||
class="flex justify-center items-center py-8"
|
||||
:sibling-count="1"
|
||||
show-edges>
|
||||
<PaginationList v-slot="{ items }" class="flex items-center space-x-1 relative">
|
||||
<div class="pr-2 flex items-center space-x-1 border-r border-border-primary mr-1">
|
||||
<PaginationFirst class="navigation-item">
|
||||
<ChevronDoubleLeftIcon class="w-4"> </ChevronDoubleLeftIcon>
|
||||
</PaginationFirst>
|
||||
<PaginationPrev class="mr-4 navigation-item">
|
||||
<ChevronLeftIcon class="w-4 text-text-tertiary hover:text-text-primary">
|
||||
</ChevronLeftIcon>
|
||||
</PaginationPrev>
|
||||
</div>
|
||||
<template v-for="(page, index) in items">
|
||||
<PaginationListItem
|
||||
v-if="page.type === 'page'"
|
||||
:key="index"
|
||||
class="pagination-item"
|
||||
:value="page.value">
|
||||
{{ page.value }}
|
||||
</PaginationListItem>
|
||||
<PaginationEllipsis
|
||||
v-else
|
||||
:key="page.type"
|
||||
:index="index"
|
||||
class="PaginationEllipsis">
|
||||
<div class="px-2">…</div>
|
||||
</PaginationEllipsis>
|
||||
</template>
|
||||
<div class="!ml-2 pl-2 flex items-center space-x-1 border-l border-border-primary">
|
||||
<PaginationNext class="navigation-item">
|
||||
<ChevronRightIcon
|
||||
class="w-4 text-text-tertiary hover:text-text-primary"></ChevronRightIcon>
|
||||
</PaginationNext>
|
||||
<PaginationLast class="navigation-item">
|
||||
<ChevronDoubleRightIcon
|
||||
class="w-4 text-text-tertiary hover:text-text-primary"></ChevronDoubleRightIcon>
|
||||
</PaginationLast>
|
||||
</div>
|
||||
</PaginationList>
|
||||
</PaginationRoot>
|
||||
</AppLayout>
|
||||
</template>
|
||||
<style lang="postcss">
|
||||
.navigation-item {
|
||||
@apply bg-quaternary h-8 w-8 flex items-center justify-center rounded border border-border-primary text-text-tertiary hover:text-text-primary transition cursor-pointer hover:border-border-secondary hover:bg-secondary focus-visible:text-text-primary focus-visible:outline-0 focus-visible:ring-2 focus-visible:ring-ring;
|
||||
}
|
||||
|
||||
.pagination-item {
|
||||
@apply bg-secondary h-8 w-8 flex items-center justify-center rounded border border-border-tertiary text-text-secondary hover:text-text-primary transition cursor-pointer hover:border-border-secondary hover:bg-secondary focus-visible:text-text-primary focus-visible:outline-0 focus-visible:ring-2 focus-visible:ring-ring;
|
||||
}
|
||||
.pagination-item[data-selected] {
|
||||
@apply text-text-primary bg-accent-300/10 border border-accent-300/20 rounded-md font-medium hover:bg-accent-300/20 active:bg-accent-300/20 outline-0 focus-visible:ring-2 focus:ring-ring transition ease-in-out duration-150;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user