Skip to content

Commit cbc4201

Browse files
committed
feat: transform page promise
1 parent 599cdc6 commit cbc4201

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

packages/common-types/src/fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ export type tHydrate<T> = (c: T, e?: unknown) => void;
4545

4646
export type iGetPage<T, C extends string | number = string> = (
4747
params?: iPagination
48-
) => Promise<iPage<T, C>>;
48+
) => Promise<iPage<T, C> | undefined>;

packages/components-vue/src/components/form/Stages.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@
134134
*/
135135
submitLabel?: string;
136136
stages?: iForm[][];
137-
showConformity?: boolean;
138137
hideRequiredDisclaimer?: boolean;
139138
stagesClasses?: tProps<string>;
140139
/**

packages/components-vue/src/components/loader/ContentFetch.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@
124124
125125
// success, clear errors
126126
errors.value = undefined;
127-
} else {
128-
throw new Error("No data source url or promise provided");
129-
}
127+
} else console.warn("No data source url or promise provided");
130128
} catch (err) {
131129
console.error(err);
132130
fetchedContent.value = undefined;

packages/components-vue/src/components/pagination/Content.vue

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<LoaderContentFetch
33
v-slot="{ content, refresh }"
4-
:promise="page"
4+
:promise="patchedPromise"
55
:payload="[{ ...pagination, ...defaults }]"
66
v-bind="{ ...$attrs, preventAutoload, theme, label }"
77
>
@@ -21,11 +21,16 @@
2121
</LoaderContentFetch>
2222
</template>
2323

24-
<script setup lang="ts" generic="T, C extends string | number = string">
24+
<script
25+
setup
26+
lang="ts"
27+
generic="T, C extends string | number = string, R extends any = iPage<T, C>"
28+
>
2529
import { computed, getCurrentInstance, inject, ref } from "vue";
2630
2731
import type {
2832
iGetPage,
33+
iPage,
2934
iPagination,
3035
iPluginOptions,
3136
tOrderBy,
@@ -36,13 +41,13 @@
3641
3742
import type { iUseThemeProps } from "../../types/props";
3843
39-
export interface iPCProps<Ti, Ci extends string | number = string>
44+
export interface iPCProps<Ti, Ci extends string | number = string, Ri = iPage<Ti, Ci>>
4045
extends iPagination,
4146
iUseThemeProps {
4247
/**
4348
* Function used to fetch the page
4449
*/
45-
page: iGetPage<Ti, Ci>;
50+
page: (params?: iPagination) => Promise<Ri | undefined>;
4651
/**
4752
* paginate using route
4853
*/
@@ -60,6 +65,10 @@
6065
* Loader label
6166
*/
6267
label?: string;
68+
/**
69+
* When additional operations are required on fetched data
70+
*/
71+
transform?: (r: Ri) => iPage<Ti, Ci> | undefined;
6372
}
6473
6574
/**
@@ -73,11 +82,20 @@
7382
7483
defineOptions({ name: "PaginationContent", inheritAttrs: false });
7584
76-
const props = defineProps<iPCProps<T, C>>();
85+
const props = defineProps<iPCProps<T, C, R>>();
7786
7887
const xamuOptions = inject<iPluginOptions>("xamu");
7988
const router = getCurrentInstance()?.appContext.config.globalProperties.$router;
8089
90+
/**
91+
* Patched promise
92+
*/
93+
const patchedPromise = computed<iGetPage<T, C>>(() => {
94+
const transform: (r: any) => iPage<T, C> | undefined = props.transform || ((v) => v);
95+
96+
return async (v) => transform(await props.page(v));
97+
});
98+
8199
const propsPagination = ref<iPagination>({
82100
orderBy: props.orderBy,
83101
first: props.first ?? xamuOptions?.first,

0 commit comments

Comments
 (0)