From dcdc1e5bb38b86845803fc32269af519e454a444 Mon Sep 17 00:00:00 2001 From: Demis Bellot Date: Mon, 20 May 2024 20:55:49 +0800 Subject: [PATCH] Allow useClient to wrap around a custom JsonServiceClient --- src/components/AutoQueryGrid.vue | 3 ++- src/use/client.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/AutoQueryGrid.vue b/src/components/AutoQueryGrid.vue index 60462d9..84e8c89 100644 --- a/src/components/AutoQueryGrid.vue +++ b/src/components/AutoQueryGrid.vue @@ -190,7 +190,6 @@ import { useConfig } from '@/use/config' const { config, autoQueryGridDefaults } = useConfig() const aqd = autoQueryGridDefaults -const client = inject('client')! const storage = config.value.storage! const props = withDefaults(defineProps<{ @@ -240,6 +239,8 @@ const emit = defineEmits<{ (e: "rowSelected", item:any, ev:Event): void }>() +const client = inject('client')! + const allAllow = 'filtering,queryString,queryFilters'.split(',') as GridAllowOptions[] const allShow = 'copyApiUrl,downloadCsv,filtersView,newItem,pagingInfo,pagingNav,preferences,refresh,resetPreferences,toolbar'.split(',') as GridShowOptions[] diff --git a/src/use/client.ts b/src/use/client.ts index 35f6acc..fe7ba41 100644 --- a/src/use/client.ts +++ b/src/use/client.ts @@ -4,13 +4,13 @@ import { inject, provide, ref, watchEffect } from "vue" import { ResponseError, ResponseStatus, ApiResult } from "@servicestack/client" import { unRefs, setRef, swrApi, fromCache, swrCacheKey, createDebounce } from "./utils" -export function useClient() { +export function useClient(use?:JsonServiceClient) { /** Maintain loading state whilst API Request is in transit */ const loading = ref(false) /** Maintain API Error in reactive Ref */ const error = ref() const response = ref() - const client = inject('client')! + const client = use ?? inject('client')! /** Set error state with summary or field validation error */ function setError({ message, errorCode, fieldName, errors }: IResponseStatus) {