add support for history_group and loading indicators to export buttons

This commit is contained in:
Gregor Vostrak
2024-10-25 18:09:28 +02:00
committed by Constantin Graf
parent 8712cfb9dc
commit ab4dbd64df
6 changed files with 74 additions and 56 deletions

View File

@@ -3,43 +3,47 @@ import { SecondaryButton } from '@/packages/ui/src';
import { ArrowDownTrayIcon } from '@heroicons/vue/20/solid'; import { ArrowDownTrayIcon } from '@heroicons/vue/20/solid';
import Dropdown from '@/packages/ui/src/Input/Dropdown.vue'; import Dropdown from '@/packages/ui/src/Input/Dropdown.vue';
import type { ExportFormat } from '@/types/reporting'; import type { ExportFormat } from '@/types/reporting';
import { ref } from 'vue';
const emit = defineEmits<{ const props = defineProps<{
submit: [ExportFormat]; download: (format: ExportFormat) => Promise<void>;
}>(); }>();
const loading = ref(false);
function triggerDownload(format: ExportFormat) {
loading.value = true;
props.download(format).finally(() => {
loading.value = false;
});
}
</script> </script>
<template> <template>
<Dropdown align="bottom-end"> <Dropdown align="bottom-end">
<template #trigger> <template #trigger>
<SecondaryButton> <SecondaryButton :icon="ArrowDownTrayIcon" :loading>
<div class="flex space-x-2 items-center"> Export
<ArrowDownTrayIcon
class="w-4 text-text-tertiary"></ArrowDownTrayIcon>
<span>Export</span>
</div>
</SecondaryButton> </SecondaryButton>
</template> </template>
<template #content> <template #content>
<div class="flex flex-col space-y-1 p-1.5"> <div class="flex flex-col space-y-1 p-1.5">
<SecondaryButton <SecondaryButton
class="border-0 px-2" class="border-0 px-2"
@click="emit('submit', 'pdf')" @click="triggerDownload('pdf')"
>Export as PDF</SecondaryButton >Export as PDF</SecondaryButton
> >
<SecondaryButton <SecondaryButton
class="border-0 px-2" class="border-0 px-2"
@click="emit('submit', 'xlsx')" @click="triggerDownload('xlsx')"
>Export as Excel</SecondaryButton >Export as Excel</SecondaryButton
> >
<SecondaryButton <SecondaryButton
class="border-0 px-2" class="border-0 px-2"
@click="emit('submit', 'csv')" @click="triggerDownload('csv')"
>Export as CSV</SecondaryButton >Export as CSV</SecondaryButton
> >
<SecondaryButton <SecondaryButton
class="border-0 px-2" class="border-0 px-2"
@click="emit('submit', 'ods')" @click="triggerDownload('ods')"
>Export as ODS >Export as ODS
</SecondaryButton> </SecondaryButton>
</div> </div>

View File

@@ -75,7 +75,7 @@ const { aggregatedGraphTimeEntries, aggregatedTableTimeEntries } =
const { groupByOptions } = reportingStore; const { groupByOptions } = reportingStore;
function getFilterAttributes() { function getFilterAttributes(): AggregatedTimeEntriesQueryParams {
let params: AggregatedTimeEntriesQueryParams = { let params: AggregatedTimeEntriesQueryParams = {
start: getLocalizedDayJs(startDate.value).startOf('day').utc().format(), start: getLocalizedDayJs(startDate.value).startOf('day').utc().format(),
end: getLocalizedDayJs(endDate.value).endOf('day').utc().format(), end: getLocalizedDayJs(endDate.value).endOf('day').utc().format(),
@@ -103,16 +103,12 @@ function getFilterAttributes() {
} }
function updateGraphReporting() { function updateGraphReporting() {
const diffInDays = getDayJsInstance()(endDate.value).diff(
getDayJsInstance()(startDate.value),
'd'
);
const params = getFilterAttributes(); const params = getFilterAttributes();
if (getCurrentRole() === 'employee') { if (getCurrentRole() === 'employee') {
params.member_id = getCurrentMembershipId(); params.member_id = getCurrentMembershipId();
} }
params.fill_gaps_in_time_groups = 'true'; params.fill_gaps_in_time_groups = 'true';
params.group = getOptimalGroupingOption(diffInDays); params.group = getOptimalGroupingOption(startDate.value, endDate.value);
useReportingStore().fetchGraphReporting(params); useReportingStore().fetchGraphReporting(params);
} }
@@ -139,10 +135,18 @@ function updateReporting() {
updateTableReporting(); updateTableReporting();
} }
function getOptimalGroupingOption(diff: number): 'day' | 'week' | 'month' { function getOptimalGroupingOption(
if (diff <= 31) { startDate: string,
endDate: string
): 'day' | 'week' | 'month' {
const diffInDays = getDayJsInstance()(endDate).diff(
getDayJsInstance()(startDate),
'd'
);
if (diffInDays <= 31) {
return 'day'; return 'day';
} else if (diff <= 200) { } else if (diffInDays <= 200) {
return 'week'; return 'week';
} else { } else {
return 'month'; return 'month';
@@ -172,6 +176,10 @@ async function downloadExport(format: ExportFormat) {
...getFilterAttributes(), ...getFilterAttributes(),
group: group.value, group: group.value,
sub_group: subGroup.value, sub_group: subGroup.value,
history_group: getOptimalGroupingOption(
startDate.value,
endDate.value
),
format: format, format: format,
}, },
}), }),
@@ -203,7 +211,7 @@ async function downloadExport(format: ExportFormat) {
</TabBar> </TabBar>
</div> </div>
<ReportingExportButton <ReportingExportButton
@submit="downloadExport"></ReportingExportButton> :download="downloadExport"></ReportingExportButton>
</MainContainer> </MainContainer>
<div class="py-2.5 w-full border-b border-default-background-separator"> <div class="py-2.5 w-full border-b border-default-background-separator">
<MainContainer <MainContainer

View File

@@ -262,7 +262,7 @@ async function downloadExport(format: ExportFormat) {
</TabBar> </TabBar>
</div> </div>
<ReportingExportButton <ReportingExportButton
@submit="downloadExport"></ReportingExportButton> :download="downloadExport"></ReportingExportButton>
</MainContainer> </MainContainer>
<div class="py-2.5 w-full border-b border-default-background-separator"> <div class="py-2.5 w-full border-b border-default-background-separator">
<MainContainer <MainContainer

View File

@@ -123,7 +123,7 @@ export type TimeEntriesQueryParams = ZodiosQueryParamsByAlias<
export type AggregatedTimeEntriesQueryParams = ZodiosQueryParamsByAlias< export type AggregatedTimeEntriesQueryParams = ZodiosQueryParamsByAlias<
SolidTimeApi, SolidTimeApi,
'getAggregatedTimeEntries' 'getAggregatedTimeEntries'
>; > & { start: string; end: string };
export type OrganizationResponse = ZodiosResponseByAlias< export type OrganizationResponse = ZodiosResponseByAlias<
SolidTimeApi, SolidTimeApi,

View File

@@ -2675,38 +2675,39 @@ If the group parameters are all set to &#x60;null&#x60; or are all missing, the
{ {
name: 'group', name: 'group',
type: 'Query', type: 'Query',
schema: z schema: z.enum([
.enum([ 'day',
'day', 'week',
'week', 'month',
'month', 'year',
'year', 'user',
'user', 'project',
'project', 'task',
'task', 'client',
'client', 'billable',
'billable', 'description',
'description', ]),
])
.optional(),
}, },
{ {
name: 'sub_group', name: 'sub_group',
type: 'Query', type: 'Query',
schema: z schema: z.enum([
.enum([ 'day',
'day', 'week',
'week', 'month',
'month', 'year',
'year', 'user',
'user', 'project',
'project', 'task',
'task', 'client',
'client', 'billable',
'billable', 'description',
'description', ]),
]) },
.optional(), {
name: 'history_group',
type: 'Query',
schema: z.enum(['day', 'week', 'month', 'year']),
}, },
{ {
name: 'member_id', name: 'member_id',
@@ -2721,12 +2722,12 @@ If the group parameters are all set to &#x60;null&#x60; or are all missing, the
{ {
name: 'start', name: 'start',
type: 'Query', type: 'Query',
schema: start, schema: z.string(),
}, },
{ {
name: 'end', name: 'end',
type: 'Query', type: 'Query',
schema: start, schema: z.string(),
}, },
{ {
name: 'active', name: 'active',

View File

@@ -2,16 +2,19 @@
import type { HtmlButtonType } from '@/types/dom'; import type { HtmlButtonType } from '@/types/dom';
import { twMerge } from 'tailwind-merge'; import { twMerge } from 'tailwind-merge';
import { type Component } from 'vue'; import { type Component } from 'vue';
import LoadingSpinner from '../LoadingSpinner.vue';
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
type: HtmlButtonType; type: HtmlButtonType;
icon?: Component; icon?: Component;
size: 'small' | 'base'; size: 'small' | 'base';
loading: boolean;
}>(), }>(),
{ {
type: 'button', type: 'button',
size: 'base', size: 'base',
loading: false,
} }
); );
@@ -24,6 +27,7 @@ const sizeClasses = {
<template> <template>
<button <button
:type="type" :type="type"
:disabled="loading"
:class=" :class="
twMerge( twMerge(
'bg-button-secondary-background border border-button-secondary-border hover:bg-button-secondary-background-hover shadow-sm transition text-white rounded-lg font-semibold inline-flex items-center space-x-1.5 focus-visible:border-input-border-active focus:outline-none focus:ring-0 disabled:opacity-25 ease-in-out', 'bg-button-secondary-background border border-button-secondary-border hover:bg-button-secondary-background-hover shadow-sm transition text-white rounded-lg font-semibold inline-flex items-center space-x-1.5 focus-visible:border-input-border-active focus:outline-none focus:ring-0 disabled:opacity-25 ease-in-out',
@@ -34,10 +38,11 @@ const sizeClasses = {
:class=" :class="
twMerge('flex items-center ', props.icon ? 'space-x-1.5' : '') twMerge('flex items-center ', props.icon ? 'space-x-1.5' : '')
"> ">
<LoadingSpinner v-if="loading"></LoadingSpinner>
<component <component
v-if="props.icon" v-if="props.icon && !loading"
:is="props.icon" :is="props.icon"
class="w-4 sm:w-5 h-4 sm:h-5 -ml-0.5 sm:-ml-1"></component> class="text-text-tertiary w-4 -ml-0.5 mr-1"></component>
<span> <span>
<slot /> <slot />
</span> </span>