diff --git a/packages/core/package.json b/packages/core/package.json index 05b146144693..68ec206a2f55 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@refinedev/devtools-internal": "1.1.16", - "@tanstack/react-query": "^4.10.1", + "@tanstack/react-query": "^5.64.2", "lodash": "^4.17.21", "lodash-es": "^4.17.21", "papaparse": "^5.3.0", @@ -72,7 +72,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@tanstack/react-query": "^4.10.1", + "@tanstack/react-query": "^5.64.2", "@types/react": "^17.0.0 || ^18.0.0", "@types/react-dom": "^17.0.0 || ^18.0.0", "react": "^17.0.0 || ^18.0.0", @@ -81,4 +81,4 @@ "publishConfig": { "access": "public" } -} +} \ No newline at end of file diff --git a/packages/core/src/components/autoSaveIndicator/index.tsx b/packages/core/src/components/autoSaveIndicator/index.tsx index 599db8f1618f..fd345620cf8a 100644 --- a/packages/core/src/components/autoSaveIndicator/index.tsx +++ b/packages/core/src/components/autoSaveIndicator/index.tsx @@ -57,7 +57,7 @@ export const AutoSaveIndicator: React.FC = ({ return <>{success}; case "error": return <>{error}; - case "loading": + case "pending": return <>{loading}; default: return <>{idle}; diff --git a/packages/core/src/components/canAccess/index.spec.tsx b/packages/core/src/components/canAccess/index.spec.tsx index 820844b881b2..1fe07b336e1f 100644 --- a/packages/core/src/components/canAccess/index.spec.tsx +++ b/packages/core/src/components/canAccess/index.spec.tsx @@ -365,11 +365,11 @@ describe("CanAccess Component", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ resource: "posts", id: undefined, - action: "list", - }) as any, + action: "list" + }) as any), }, accessControlProvider: { can: async () => { diff --git a/packages/core/src/components/containers/refine/index.tsx b/packages/core/src/components/containers/refine/index.tsx index ff382c3c5569..749098b14f4a 100644 --- a/packages/core/src/components/containers/refine/index.tsx +++ b/packages/core/src/components/containers/refine/index.tsx @@ -81,7 +81,7 @@ export const Refine: React.FC = ({ ...reactQueryWithDefaults.clientConfig.defaultOptions, queries: { refetchOnWindowFocus: false, - keepPreviousData: true, + // keepPreviousData: true, ...reactQueryWithDefaults.clientConfig.defaultOptions?.queries, }, }, diff --git a/packages/core/src/components/pages/auth/components/forgotPassword/index.tsx b/packages/core/src/components/pages/auth/components/forgotPassword/index.tsx index 90e7277e611a..999db4f5adba 100644 --- a/packages/core/src/components/pages/auth/components/forgotPassword/index.tsx +++ b/packages/core/src/components/pages/auth/components/forgotPassword/index.tsx @@ -38,7 +38,7 @@ export const ForgotPasswordPage: React.FC = ({ const [email, setEmail] = useState(""); - const { mutate: forgotPassword, isLoading } = + const { mutate: forgotPassword, isPending } = useForgotPassword(); const renderLink = (link: string, text?: string) => { @@ -81,7 +81,7 @@ export const ForgotPasswordPage: React.FC = ({ /> = ({ const translate = useTranslate(); const authProvider = useActiveAuthProvider(); - const { mutate: register, isLoading } = useRegister({ + const { mutate: register, isPending } = useRegister({ v3LegacyAuthProviderCompatible: Boolean(authProvider?.isLegacy), }); @@ -136,7 +136,7 @@ export const RegisterPage: React.FC = ({ {loginLink ?? ( <> diff --git a/packages/core/src/components/pages/auth/components/updatePassword/index.tsx b/packages/core/src/components/pages/auth/components/updatePassword/index.tsx index df5881a4284c..272d124e253b 100644 --- a/packages/core/src/components/pages/auth/components/updatePassword/index.tsx +++ b/packages/core/src/components/pages/auth/components/updatePassword/index.tsx @@ -26,7 +26,7 @@ export const UpdatePasswordPage: React.FC = ({ const translate = useTranslate(); const authProvider = useActiveAuthProvider(); - const { mutate: updatePassword, isLoading } = + const { mutate: updatePassword, isPending } = useUpdatePassword({ v3LegacyAuthProviderCompatible: Boolean(authProvider?.isLegacy), }); @@ -87,7 +87,7 @@ export const UpdatePasswordPage: React.FC = ({ /> diff --git a/packages/core/src/contexts/data/types.ts b/packages/core/src/contexts/data/types.ts index 0330f5dff12a..7ba878d42ec9 100644 --- a/packages/core/src/contexts/data/types.ts +++ b/packages/core/src/contexts/data/types.ts @@ -20,7 +20,7 @@ export type BaseOption = { /** * @deprecated Use `BaseOption` instead. */ -export interface Option extends BaseOption {} +export interface Option extends BaseOption { } export type NestedField = { operation: string; @@ -32,12 +32,12 @@ export type Fields = Array; export type VariableOptions = | { - type?: string; - name?: string; - value: any; - list?: boolean; - required?: boolean; - } + type?: string; + name?: string; + value: any; + list?: boolean; + required?: boolean; + } | { [k: string]: any }; export interface QueryBuilderOptions { @@ -209,11 +209,11 @@ export interface IQueryKeys { config?: | UseListConfig | { - pagination?: Required; - hasPagination?: boolean; - sorters?: CrudSort[]; - filters?: CrudFilter[]; - } + pagination?: Required; + hasPagination?: boolean; + sorters?: CrudSort[]; + filters?: CrudFilter[]; + } | undefined, ) => QueryKey; many: (ids?: BaseKey[]) => QueryKey; @@ -223,10 +223,10 @@ export interface IQueryKeys { export interface ValidationErrors { [field: string]: - | string - | string[] - | boolean - | { key: string; message: string }; + | string + | string[] + | boolean + | { key: string; message: string }; } export interface HttpError extends Record { diff --git a/packages/core/src/contexts/router/legacy/index.tsx b/packages/core/src/contexts/router/legacy/index.tsx index 949c5b41deff..d151ad358706 100644 --- a/packages/core/src/contexts/router/legacy/index.tsx +++ b/packages/core/src/contexts/router/legacy/index.tsx @@ -5,7 +5,7 @@ import type { ILegacyRouterContext } from "./types"; export const defaultProvider: ILegacyRouterContext = { useHistory: () => false, useLocation: () => false, - useParams: () => ({}) as any, + useParams: () => (({}) as any), Prompt: () => null, Link: () => null, }; diff --git a/packages/core/src/definitions/helpers/prepare-query-context/index.ts b/packages/core/src/definitions/helpers/prepare-query-context/index.ts index 67a803e88a97..6e572b120277 100644 --- a/packages/core/src/definitions/helpers/prepare-query-context/index.ts +++ b/packages/core/src/definitions/helpers/prepare-query-context/index.ts @@ -15,5 +15,11 @@ export const prepareQueryContext = ( }, }); - return queryContext; + Object.defineProperty(queryContext, "direction", { + enumerable: true, + get: () => { + return context.direction; + }, + }); + return queryContext as QueryFunctionContext; }; diff --git a/packages/core/src/hooks/auditLog/useLog/index.ts b/packages/core/src/hooks/auditLog/useLog/index.ts index 72dfdb8e4029..3a0f007405f1 100644 --- a/packages/core/src/hooks/auditLog/useLog/index.ts +++ b/packages/core/src/hooks/auditLog/useLog/index.ts @@ -21,8 +21,8 @@ import type { BaseKey } from "../../../contexts/data/types"; type LogRenameData = | { - resource?: string; - } + resource?: string; + } | undefined; export type UseLogReturnType = { @@ -81,16 +81,17 @@ export const useLog = < const { data: identityData, refetch, - isLoading, + isPending, } = useGetIdentity({ v3LegacyAuthProviderCompatible: Boolean(authProvider?.isLegacy), queryOptions: { + queryKey: keys().auth().get(preferLegacyKeys), enabled: !!auditLogContext?.create, }, }); - const log = useMutation( - async (params) => { + const log = useMutation({ + mutationFn: async (params) => { const resource = pickResource(params.resource, resources); const logPermissions = pickNotDeprecated( resource?.meta?.audit, @@ -105,7 +106,7 @@ export const useLog = < } let authorData; - if (isLoading && !!auditLogContext?.create) { + if (isPending && !!auditLogContext?.create) { authorData = await refetch(); } @@ -114,45 +115,39 @@ export const useLog = < author: identityData ?? authorData?.data, }); }, - { - mutationKey: keys().audit().action("log").get(), - ...logMutationOptions, - meta: { - ...logMutationOptions?.meta, - ...getXRay("useLog", preferLegacyKeys), - }, - }, - ); - const rename = useMutation< - TLogRenameData, - Error, - { id: BaseKey; name: string }, - unknown - >( - async (params) => { + ...logMutationOptions, + + meta: { + ...logMutationOptions?.meta, + ...getXRay("useLog", preferLegacyKeys), + } + }); + + const rename = useMutation({ + mutationFn: async (params) => { return await auditLogContext.update?.(params); }, - { - onSuccess: (data) => { - if (data?.resource) { - queryClient.invalidateQueries( - keys() - .audit() - .resource(data?.resource ?? "") - .action("list") - .get(preferLegacyKeys), - ); - } - }, - mutationKey: keys().audit().action("rename").get(), - ...renameMutationOptions, - meta: { - ...renameMutationOptions?.meta, - ...getXRay("useLog", preferLegacyKeys), - }, + + onSuccess: (data) => { + if (data?.resource) { + queryClient.invalidateQueries({ + queryKey: keys() + .audit() + .resource(data?.resource ?? "") + .action("list") + .get(preferLegacyKeys), + }); + } }, - ); + + ...renameMutationOptions, + + meta: { + ...renameMutationOptions?.meta, + ...getXRay("useLog", preferLegacyKeys), + } + }); return { log, rename }; }; diff --git a/packages/core/src/hooks/auditLog/useLogList/index.ts b/packages/core/src/hooks/auditLog/useLogList/index.ts index 87e296a3b9b0..d53e50382d28 100644 --- a/packages/core/src/hooks/auditLog/useLogList/index.ts +++ b/packages/core/src/hooks/auditLog/useLogList/index.ts @@ -70,5 +70,5 @@ export const useLogList = < }, }); - return queryResponse; + return queryResponse as UseQueryResult; }; diff --git a/packages/core/src/hooks/auth/useInvalidateAuthStore/index.ts b/packages/core/src/hooks/auth/useInvalidateAuthStore/index.ts index b7c47f5a150e..d287117686fc 100644 --- a/packages/core/src/hooks/auth/useInvalidateAuthStore/index.ts +++ b/packages/core/src/hooks/auth/useInvalidateAuthStore/index.ts @@ -8,9 +8,9 @@ export const useInvalidateAuthStore = () => { const invalidate = async () => { await Promise.all( (["check", "identity", "permissions"] as const).map((action) => - queryClient.invalidateQueries( - keys().auth().action(action).get(preferLegacyKeys), - ), + queryClient.invalidateQueries({ + queryKey: keys().auth().action(action).get(preferLegacyKeys), + }), ), ); }; diff --git a/packages/core/src/hooks/auth/useOnError/index.ts b/packages/core/src/hooks/auth/useOnError/index.ts index 969f1122b952..a9c64aaf199d 100644 --- a/packages/core/src/hooks/auth/useOnError/index.ts +++ b/packages/core/src/hooks/auth/useOnError/index.ts @@ -98,7 +98,7 @@ export function useOnError({ }, } : { - mutationFn: () => ({}) as Promise, + mutationFn: () => (({}) as Promise), }), meta: { ...getXRay("useOnError", preferLegacyKeys), diff --git a/packages/core/src/hooks/button/button-can-access/index.tsx b/packages/core/src/hooks/button/button-can-access/index.tsx index 1bfc9b3a8f0c..6711c4d91e7d 100644 --- a/packages/core/src/hooks/button/button-can-access/index.tsx +++ b/packages/core/src/hooks/button/button-can-access/index.tsx @@ -8,7 +8,7 @@ import type { CanReturnType } from "../../../contexts/accessControl/types"; import type { IResourceItem } from "../../../contexts/resource/types"; import type { Action } from "../../../contexts/router/types"; import type { BaseKey } from "../../../contexts/data/types"; - +import { useKeys } from "../../useKeys"; type ButtonCanAccessProps = { action: Action | "delete"; resource?: IResourceItem; @@ -31,7 +31,7 @@ export const useButtonCanAccess = ( ): ButtonCanAccessValues => { const translate = useTranslate(); const accessControlContext = React.useContext(AccessControlContext); - + const { keys, preferLegacyKeys } = useKeys(); const accessControlEnabled = props.accessControl?.enabled ?? accessControlContext.options.buttons.enableAccessControl; @@ -45,6 +45,7 @@ export const useButtonCanAccess = ( action: props.action === "clone" ? "create" : props.action, params: { id: props.id, resource: props.resource }, queryOptions: { + queryKey: keys().auth().get(preferLegacyKeys), enabled: accessControlEnabled, }, }); diff --git a/packages/core/src/hooks/button/delete-button/index.tsx b/packages/core/src/hooks/button/delete-button/index.tsx index 9bb1c41512a8..3afb92621ba2 100644 --- a/packages/core/src/hooks/button/delete-button/index.tsx +++ b/packages/core/src/hooks/button/delete-button/index.tsx @@ -38,7 +38,7 @@ export type DeleteButtonValues = { export function useDeleteButton(props: DeleteButtonProps): DeleteButtonValues { const translate = useTranslate(); - const { mutate, isLoading, variables } = useDelete(); + const { mutate, isPending, variables } = useDelete(); const { setWarnWhen } = useWarnAboutChange(); const { mutationMode } = useMutationMode(props.mutationMode); @@ -62,7 +62,7 @@ export function useDeleteButton(props: DeleteButtonProps): DeleteButtonValues { const cancelLabel = translate("buttons.cancel", "Cancel"); - const loading = id === variables?.id && isLoading; + const loading = id === variables?.id && isPending; const onConfirm = () => { if (id && identifier) { @@ -92,7 +92,7 @@ export function useDeleteButton(props: DeleteButtonProps): DeleteButtonValues { hidden, disabled, canAccess, - loading, + loading: isPending, confirmOkLabel, cancelLabel, confirmTitle, diff --git a/packages/core/src/hooks/data/useCreate.ts b/packages/core/src/hooks/data/useCreate.ts index de0f1c0d90fe..9c93bb9493e6 100644 --- a/packages/core/src/hooks/data/useCreate.ts +++ b/packages/core/src/hooks/data/useCreate.ts @@ -182,7 +182,7 @@ export const useCreate = < const { resource: resourceName = resourceFromProps, successNotification: - successNotificationFromProp = successNotificationFromProps, + successNotificationFromProp = successNotificationFromProps, dataProviderName: dataProviderNameFromProp = dataProviderNameFromProps, invalidates = invalidatesFromProps ?? ["list", "many"], values = valuesFromProps, @@ -269,7 +269,7 @@ export const useCreate = < const { resource: resourceName = resourceFromProps, errorNotification: - errorNotificationFromProp = errorNotificationFromProps, + errorNotificationFromProp = errorNotificationFromProps, values = valuesFromProps, } = variables; if (!values) throw missingValuesError; @@ -316,7 +316,7 @@ export const useCreate = < const { elapsedTime } = useLoadingOvertime({ ...overtimeOptions, - isLoading: mutation.isLoading, + isLoading: mutation.isPending, }); // this function is used to make the `variables` parameter optional diff --git a/packages/core/src/hooks/data/useCreateMany.ts b/packages/core/src/hooks/data/useCreateMany.ts index d6fb6a122ece..759a877b09d5 100644 --- a/packages/core/src/hooks/data/useCreateMany.ts +++ b/packages/core/src/hooks/data/useCreateMany.ts @@ -294,7 +294,7 @@ export const useCreateMany = < const { elapsedTime } = useLoadingOvertime({ ...overtimeOptions, - isLoading: mutation.isLoading, + isLoading: mutation.isPending, }); // this function is used to make the `variables` parameter optional diff --git a/packages/core/src/hooks/data/useCustom.ts b/packages/core/src/hooks/data/useCustom.ts index 85c8d24b72f8..71a30b59094e 100644 --- a/packages/core/src/hooks/data/useCustom.ts +++ b/packages/core/src/hooks/data/useCustom.ts @@ -175,42 +175,42 @@ export const useCustom = < }, }), ...queryOptions, - onSuccess: (data) => { - queryOptions?.onSuccess?.(data); + // onSuccess: (data) => { + // queryOptions?.onSuccess?.(data); - const notificationConfig = - typeof successNotification === "function" - ? successNotification(data, { - ...config, - ...combinedMeta, - }) - : successNotification; + // const notificationConfig = + // typeof successNotification === "function" + // ? successNotification(data, { + // ...config, + // ...combinedMeta, + // }) + // : successNotification; - handleNotification(notificationConfig); - }, - onError: (err: TError) => { - checkError(err); - queryOptions?.onError?.(err); + // handleNotification(notificationConfig); + // }, + // onError: (err: TError) => { + // checkError(err); + // queryOptions?.onError?.(err); - const notificationConfig = - typeof errorNotification === "function" - ? errorNotification(err, { - ...config, - ...combinedMeta, - }) - : errorNotification; + // const notificationConfig = + // typeof errorNotification === "function" + // ? errorNotification(err, { + // ...config, + // ...combinedMeta, + // }) + // : errorNotification; - handleNotification(notificationConfig, { - key: `${method}-notification`, - message: translate( - "notifications.error", - { statusCode: err.statusCode }, - `Error (status code: ${err.statusCode})`, - ), - description: err.message, - type: "error", - }); - }, + // handleNotification(notificationConfig, { + // key: `${method}-notification`, + // message: translate( + // "notifications.error", + // { statusCode: err.statusCode }, + // `Error (status code: ${err.statusCode})`, + // ), + // description: err.message, + // type: "error", + // }); + // }, meta: { ...queryOptions?.meta, ...getXRay("useCustom", preferLegacyKeys), diff --git a/packages/core/src/hooks/data/useCustomMutation.ts b/packages/core/src/hooks/data/useCustomMutation.ts index 5f419348af0d..1d80142c8315 100644 --- a/packages/core/src/hooks/data/useCustomMutation.ts +++ b/packages/core/src/hooks/data/useCustomMutation.ts @@ -117,13 +117,8 @@ export const useCustomMutation = < const getMeta = useMeta(); const { keys, preferLegacyKeys } = useKeys(); - const mutation = useMutation< - CreateResponse, - TError, - useCustomMutationParams, - unknown - >( - ({ + const mutation = useMutation({ + mutationFn: ({ url, method, values, @@ -151,72 +146,70 @@ export const useCustomMutation = < throw Error("Not implemented custom on data provider."); }, - { - onSuccess: ( - data, - { - successNotification: successNotificationFromProp, - config, - meta, - metaData, - }, - ) => { - const notificationConfig = - typeof successNotificationFromProp === "function" - ? successNotificationFromProp(data, { - ...config, - ...(pickNotDeprecated(meta, metaData) || {}), - }) - : successNotificationFromProp; - - handleNotification(notificationConfig); - }, - onError: ( - err: TError, - { - errorNotification: errorNotificationFromProp, - method, - config, - meta, - metaData, - }, - ) => { - checkError(err); - - const notificationConfig = - typeof errorNotificationFromProp === "function" - ? errorNotificationFromProp(err, { - ...config, - ...(pickNotDeprecated(meta, metaData) || {}), - }) - : errorNotificationFromProp; - - handleNotification(notificationConfig, { - key: `${method}-notification`, - message: translate( - "notifications.error", - { statusCode: err.statusCode }, - `Error (status code: ${err.statusCode})`, - ), - description: err.message, - type: "error", - }); + + onSuccess: ( + data, + { + successNotification: successNotificationFromProp, + config, + meta, + metaData, }, - mutationKey: keys() - .data() - .mutation("customMutation") - .get(preferLegacyKeys), - ...mutationOptions, - meta: { - ...mutationOptions?.meta, - ...getXRay("useCustomMutation", preferLegacyKeys), + ) => { + const notificationConfig = + typeof successNotificationFromProp === "function" + ? successNotificationFromProp(data, { + ...config, + ...(pickNotDeprecated(meta, metaData) || {}), + }) + : successNotificationFromProp; + + handleNotification(notificationConfig); + }, + + onError: ( + err: TError, + { + errorNotification: errorNotificationFromProp, + method, + config, + meta, + metaData, }, + ) => { + checkError(err); + + const notificationConfig = + typeof errorNotificationFromProp === "function" + ? errorNotificationFromProp(err, { + ...config, + ...(pickNotDeprecated(meta, metaData) || {}), + }) + : errorNotificationFromProp; + + handleNotification(notificationConfig, { + key: `${method}-notification`, + message: translate( + "notifications.error", + { statusCode: err.statusCode }, + `Error (status code: ${err.statusCode})`, + ), + description: err.message, + type: "error", + }); }, - ); + + ...mutationOptions, + + meta: { + ...mutationOptions?.meta, + ...getXRay("useCustomMutation", preferLegacyKeys), + } + }); const { elapsedTime } = useLoadingOvertime({ ...overtimeOptions, - isLoading: mutation.isLoading, + isLoading: mutation.isPending, }); return { ...mutation, overtime: { elapsedTime } }; diff --git a/packages/core/src/hooks/data/useDelete.ts b/packages/core/src/hooks/data/useDelete.ts index a3b812524531..3020cc4e0e85 100644 --- a/packages/core/src/hooks/data/useDelete.ts +++ b/packages/core/src/hooks/data/useDelete.ts @@ -279,24 +279,24 @@ export const useDelete = < const mutationModePropOrContext = mutationMode ?? mutationModeContext; - await queryClient.cancelQueries( - resourceKeys.get(preferLegacyKeys), - undefined, - { - silent: true, - }, - ); + await queryClient.cancelQueries({ + queryKey: resourceKeys.get(preferLegacyKeys), + }); const previousQueries: PreviousQuery[] = - queryClient.getQueriesData(resourceKeys.get(preferLegacyKeys)); + queryClient.getQueriesData({ + queryKey: resourceKeys.get(preferLegacyKeys), + }); if (mutationModePropOrContext !== "pessimistic") { // Set the previous queries to the new ones: queryClient.setQueriesData( - resourceKeys - .action("list") - .params(preferredMeta ?? {}) - .get(preferLegacyKeys), + { + queryKey: resourceKeys + .action("list") + .params(preferredMeta ?? {}) + .get(preferLegacyKeys), + }, (previous?: GetListResponse | null) => { if (!previous) { return null; @@ -313,7 +313,9 @@ export const useDelete = < ); queryClient.setQueriesData( - resourceKeys.action("many").get(preferLegacyKeys), + { + queryKey: resourceKeys.action("many").get(preferLegacyKeys), + }, (previous?: GetListResponse | null) => { if (!previous) { return null; @@ -390,7 +392,9 @@ export const useDelete = < }); // Remove the queries from the cache: - queryClient.removeQueries(context?.queryKey.detail(id)); + queryClient.removeQueries({ + queryKey: context?.queryKey.detail(id), + }); const notificationConfig = typeof successNotification === "function" @@ -443,7 +447,9 @@ export const useDelete = < }); // Remove the queries from the cache: - queryClient.removeQueries(context?.queryKey.detail(id)); + queryClient.removeQueries({ + queryKey: context?.queryKey.detail(id), + }); }, onError: ( err: TError, @@ -494,7 +500,7 @@ export const useDelete = < const { elapsedTime } = useLoadingOvertime({ ...overtimeOptions, - isLoading: mutation.isLoading, + isLoading: mutation.isPending, }); return { ...mutation, overtime: { elapsedTime } }; diff --git a/packages/core/src/hooks/data/useDeleteMany.ts b/packages/core/src/hooks/data/useDeleteMany.ts index 1412a2e53834..1711356b3bac 100644 --- a/packages/core/src/hooks/data/useDeleteMany.ts +++ b/packages/core/src/hooks/data/useDeleteMany.ts @@ -288,24 +288,24 @@ export const useDeleteMany = < const mutationModePropOrContext = mutationMode ?? mutationModeContext; - await queryClient.cancelQueries( - resourceKeys.get(preferLegacyKeys), - undefined, - { - silent: true, - }, - ); + await queryClient.cancelQueries({ + queryKey: resourceKeys.get(preferLegacyKeys), + }); const previousQueries: PreviousQuery[] = - queryClient.getQueriesData(resourceKeys.get(preferLegacyKeys)); + queryClient.getQueriesData({ + queryKey: resourceKeys.get(preferLegacyKeys), + }); if (mutationModePropOrContext !== "pessimistic") { // Set the previous queries to the new ones: queryClient.setQueriesData( - resourceKeys - .action("list") - .params(preferredMeta ?? {}) - .get(preferLegacyKeys), + { + queryKey: resourceKeys + .action("list") + .params(preferredMeta ?? {}) + .get(preferLegacyKeys), + }, (previous?: GetListResponse | null) => { if (!previous) { return null; @@ -324,7 +324,9 @@ export const useDeleteMany = < ); queryClient.setQueriesData( - resourceKeys.action("many").get(preferLegacyKeys), + { + queryKey: resourceKeys.action("many").get(preferLegacyKeys), + }, (previous?: GetListResponse | null) => { if (!previous) { return null; @@ -346,11 +348,13 @@ export const useDeleteMany = < for (const id of ids) { queryClient.setQueriesData( - resourceKeys - .action("one") - .id(id) - .params(preferredMeta) - .get(preferLegacyKeys), + { + queryKey: resourceKeys + .action("one") + .id(id) + .params(preferredMeta) + .get(preferLegacyKeys), + }, (previous?: any | null) => { if (!previous || previous.data.id === id) { return null; @@ -424,7 +428,9 @@ export const useDeleteMany = < // Remove the queries from the cache: ids.forEach((id) => - queryClient.removeQueries(context?.queryKey.detail(id)), + queryClient.removeQueries({ + queryKey: context?.queryKey.detail(id), + }), ); const notificationConfig = @@ -474,7 +480,9 @@ export const useDeleteMany = < // Remove the queries from the cache: ids.forEach((id) => - queryClient.removeQueries(context?.queryKey.detail(id)), + queryClient.removeQueries({ + queryKey: context?.queryKey.detail(id), + }), ); }, onError: ( @@ -525,7 +533,7 @@ export const useDeleteMany = < const { elapsedTime } = useLoadingOvertime({ ...overtimeOptions, - isLoading: mutation.isLoading, + isLoading: mutation.isPending, }); return { ...mutation, overtime: { elapsedTime } }; diff --git a/packages/core/src/hooks/data/useInfiniteList.ts b/packages/core/src/hooks/data/useInfiniteList.ts index d1769de4ff18..e56fe3cc77f3 100644 --- a/packages/core/src/hooks/data/useInfiniteList.ts +++ b/packages/core/src/hooks/data/useInfiniteList.ts @@ -264,7 +264,7 @@ export const useInfiniteList = < return getList({ resource: resource.name, - pagination: paginationProperties, + pagination: paginationProperties as Pagination, hasPagination: isServerPagination, filters: prefferedFilters, sort: prefferedSorters, @@ -275,7 +275,7 @@ export const useInfiniteList = < return { data, total, - pagination: paginationProperties, + pagination: paginationProperties as Pagination, ...rest, }; }); diff --git a/packages/core/src/hooks/data/useMany.ts b/packages/core/src/hooks/data/useMany.ts index 992751234cb4..517b59d41381 100644 --- a/packages/core/src/hooks/data/useMany.ts +++ b/packages/core/src/hooks/data/useMany.ts @@ -203,36 +203,36 @@ export const useMany = < }, enabled: hasIds && hasResource, ...queryOptions, - onSuccess: (data) => { - queryOptions?.onSuccess?.(data); + // onSuccess: (data) => { + // queryOptions?.onSuccess?.(data); - const notificationConfig = - typeof successNotification === "function" - ? successNotification(data, ids, identifier) - : successNotification; + // const notificationConfig = + // typeof successNotification === "function" + // ? successNotification(data, ids, identifier) + // : successNotification; - handleNotification(notificationConfig); - }, - onError: (err: TError) => { - checkError(err); - queryOptions?.onError?.(err); + // handleNotification(notificationConfig); + // }, + // onError: (err: TError) => { + // checkError(err); + // queryOptions?.onError?.(err); - const notificationConfig = - typeof errorNotification === "function" - ? errorNotification(err, ids, identifier) - : errorNotification; + // const notificationConfig = + // typeof errorNotification === "function" + // ? errorNotification(err, ids, identifier) + // : errorNotification; - handleNotification(notificationConfig, { - key: `${ids[0]}-${identifier}-getMany-notification`, - message: translate( - "notifications.error", - { statusCode: err.statusCode }, - `Error (status code: ${err.statusCode})`, - ), - description: err.message, - type: "error", - }); - }, + // handleNotification(notificationConfig, { + // key: `${ids[0]}-${identifier}-getMany-notification`, + // message: translate( + // "notifications.error", + // { statusCode: err.statusCode }, + // `Error (status code: ${err.statusCode})`, + // ), + // description: err.message, + // type: "error", + // }); + // }, meta: { ...queryOptions?.meta, ...getXRay("useMany", preferLegacyKeys, resource?.name), diff --git a/packages/core/src/hooks/data/useOne.ts b/packages/core/src/hooks/data/useOne.ts index 94ccdaa1d9de..6c4f2fc0b652 100644 --- a/packages/core/src/hooks/data/useOne.ts +++ b/packages/core/src/hooks/data/useOne.ts @@ -193,50 +193,50 @@ export const useOne = < typeof queryOptions?.enabled !== "undefined" ? queryOptions?.enabled : typeof id !== "undefined", - onSuccess: (data) => { - queryOptions?.onSuccess?.(data); - - const notificationConfig = - typeof successNotification === "function" - ? successNotification( - data, - { - id, - ...combinedMeta, - }, - identifier, - ) - : successNotification; - - handleNotification(notificationConfig); - }, - onError: (err: TError) => { - checkError(err); - queryOptions?.onError?.(err); - - const notificationConfig = - typeof errorNotification === "function" - ? errorNotification( - err, - { - id, - ...combinedMeta, - }, - identifier, - ) - : errorNotification; - - handleNotification(notificationConfig, { - key: `${id}-${identifier}-getOne-notification`, - message: translate( - "notifications.error", - { statusCode: err.statusCode }, - `Error (status code: ${err.statusCode})`, - ), - description: err.message, - type: "error", - }); - }, + // onSuccess: (data) => { + // queryOptions?.onSuccess?.(data); + + // const notificationConfig = + // typeof successNotification === "function" + // ? successNotification( + // data, + // { + // id, + // ...combinedMeta, + // }, + // identifier, + // ) + // : successNotification; + + // handleNotification(notificationConfig); + // }, + // onError: (err: TError) => { + // checkError(err); + // queryOptions?.onError?.(err); + + // const notificationConfig = + // typeof errorNotification === "function" + // ? errorNotification( + // err, + // { + // id, + // ...combinedMeta, + // }, + // identifier, + // ) + // : errorNotification; + + // handleNotification(notificationConfig, { + // key: `${id}-${identifier}-getOne-notification`, + // message: translate( + // "notifications.error", + // { statusCode: err.statusCode }, + // `Error (status code: ${err.statusCode})`, + // ), + // description: err.message, + // type: "error", + // }); + // }, meta: { ...queryOptions?.meta, ...getXRay("useOne", preferLegacyKeys, resource?.name), diff --git a/packages/core/src/hooks/data/useUpdate.ts b/packages/core/src/hooks/data/useUpdate.ts index d88c3d409988..25324c415ba2 100644 --- a/packages/core/src/hooks/data/useUpdate.ts +++ b/packages/core/src/hooks/data/useUpdate.ts @@ -53,26 +53,26 @@ import { export type OptimisticUpdateMapType = { list?: - | (( - previous: GetListResponse | null | undefined, - values: TVariables, - id: BaseKey, - ) => GetListResponse | null) - | boolean; + | (( + previous: GetListResponse | null | undefined, + values: TVariables, + id: BaseKey, + ) => GetListResponse | null) + | boolean; many?: - | (( - previous: GetManyResponse | null | undefined, - values: TVariables, - id: BaseKey, - ) => GetManyResponse | null) - | boolean; + | (( + previous: GetManyResponse | null | undefined, + values: TVariables, + id: BaseKey, + ) => GetManyResponse | null) + | boolean; detail?: - | (( - previous: GetOneResponse | null | undefined, - values: TVariables, - id: BaseKey, - ) => GetOneResponse | null) - | boolean; + | (( + previous: GetOneResponse | null | undefined, + values: TVariables, + id: BaseKey, + ) => GetOneResponse | null) + | boolean; }; export type UpdateParams = { @@ -344,26 +344,27 @@ export const useUpdate = < .resource(identifier); const previousQueries: PreviousQuery[] = - queryClient.getQueriesData(resourceKeys.get(preferLegacyKeys)); + queryClient.getQueriesData({ + queryKey: resourceKeys.get(preferLegacyKeys), + }); const mutationModePropOrContext = mutationMode ?? mutationModeContext; - await queryClient.cancelQueries( - resourceKeys.get(preferLegacyKeys), + await queryClient.cancelQueries({ + queryKey: resourceKeys.get(preferLegacyKeys), undefined, - { - silent: true, - }, - ); + }); if (mutationModePropOrContext !== "pessimistic") { if (optimisticUpdateMap.list) { // Set the previous queries to the new ones: queryClient.setQueriesData( - resourceKeys - .action("list") - .params(preferredMeta ?? {}) - .get(preferLegacyKeys), + { + queryKey: resourceKeys + .action("list") + .params(preferredMeta ?? {}) + .get(preferLegacyKeys), + }, (previous?: GetListResponse | null) => { if (typeof optimisticUpdateMap.list === "function") { return optimisticUpdateMap.list(previous, values, id); @@ -394,7 +395,9 @@ export const useUpdate = < if (optimisticUpdateMap.many) { queryClient.setQueriesData( - resourceKeys.action("many").get(preferLegacyKeys), + { + queryKey: resourceKeys.action("many").get(preferLegacyKeys), + }, (previous?: GetManyResponse | null) => { if (typeof optimisticUpdateMap.many === "function") { return optimisticUpdateMap.many(previous, values, id); @@ -424,11 +427,13 @@ export const useUpdate = < if (optimisticUpdateMap.detail) { queryClient.setQueriesData( - resourceKeys - .action("one") - .id(id) - .params(preferredMeta ?? {}) - .get(preferLegacyKeys), + { + queryKey: resourceKeys + .action("one") + .id(id) + .params(preferredMeta ?? {}) + .get(preferLegacyKeys), + }, (previous?: GetOneResponse | null) => { if (typeof optimisticUpdateMap.detail === "function") { return optimisticUpdateMap.detail(previous, values, id); @@ -640,7 +645,7 @@ export const useUpdate = < const { elapsedTime } = useLoadingOvertime({ ...overtimeOptions, - isLoading: mutation.isLoading, + isLoading: mutation.isPending, }); // this function is used to make the `variables` parameter optional diff --git a/packages/core/src/hooks/data/useUpdateMany.ts b/packages/core/src/hooks/data/useUpdateMany.ts index 5eef842e7b0a..bf47e4ebf55c 100644 --- a/packages/core/src/hooks/data/useUpdateMany.ts +++ b/packages/core/src/hooks/data/useUpdateMany.ts @@ -55,26 +55,26 @@ import { ActionTypes } from "../../contexts/undoableQueue/types"; export type OptimisticUpdateManyMapType = { list?: - | (( - previous: GetListResponse | null | undefined, - values: TVariables, - ids: BaseKey[], - ) => GetListResponse | null) - | boolean; + | (( + previous: GetListResponse | null | undefined, + values: TVariables, + ids: BaseKey[], + ) => GetListResponse | null) + | boolean; many?: - | (( - previous: GetManyResponse | null | undefined, - values: TVariables, - ids: BaseKey[], - ) => GetManyResponse | null) - | boolean; + | (( + previous: GetManyResponse | null | undefined, + values: TVariables, + ids: BaseKey[], + ) => GetManyResponse | null) + | boolean; detail?: - | (( - previous: GetOneResponse | null | undefined, - values: TVariables, - id: BaseKey, - ) => GetOneResponse | null) - | boolean; + | (( + previous: GetOneResponse | null | undefined, + values: TVariables, + id: BaseKey, + ) => GetOneResponse | null) + | boolean; }; export type UpdateManyParams = { @@ -356,26 +356,23 @@ export const useUpdateMany = < const mutationModePropOrContext = mutationMode ?? mutationModeContext; - await queryClient.cancelQueries( - resourceKeys.get(preferLegacyKeys), - undefined, - { - silent: true, - }, - ); + await queryClient.cancelQueries({ + queryKey: resourceKeys.get(preferLegacyKeys), + silent: true, + }); const previousQueries = queryClient.getQueriesData>( - resourceKeys.get(preferLegacyKeys), + { + queryKey: resourceKeys.get(preferLegacyKeys), + } ); if (mutationModePropOrContext !== "pessimistic") { if (optimisticUpdateMap.list) { // Set the previous queries to the new ones: - queryClient.setQueriesData( - resourceKeys - .action("list") - .params(preferredMeta ?? {}) - .get(preferLegacyKeys), + queryClient.setQueriesData({ + queryKey: resourceKeys.action("list").params(preferredMeta ?? {}).get(preferLegacyKeys), + }, (previous?: GetListResponse | null) => { if (typeof optimisticUpdateMap.list === "function") { return optimisticUpdateMap.list(previous, values, ids); @@ -411,8 +408,9 @@ export const useUpdateMany = < } if (optimisticUpdateMap.many) { - queryClient.setQueriesData( - resourceKeys.action("many").get(preferLegacyKeys), + queryClient.setQueriesData({ + queryKey: resourceKeys.action("many").get(preferLegacyKeys), + }, (previous?: GetManyResponse | null) => { if (typeof optimisticUpdateMap.many === "function") { return optimisticUpdateMap.many(previous, values, ids); @@ -447,12 +445,9 @@ export const useUpdateMany = < if (optimisticUpdateMap.detail) { for (const id of ids) { - queryClient.setQueriesData( - resourceKeys - .action("one") - .id(id) - .params(preferredMeta ?? {}) - .get(preferLegacyKeys), + queryClient.setQueriesData({ + queryKey: resourceKeys.action("one").id(id).params(preferredMeta ?? {}).get(preferLegacyKeys), + }, (previous?: GetOneResponse | null) => { if (typeof optimisticUpdateMap.detail === "function") { return optimisticUpdateMap.detail(previous, values, id); @@ -677,7 +672,7 @@ export const useUpdateMany = < const { elapsedTime } = useLoadingOvertime({ ...overtimeOptions, - isLoading: mutation.isLoading, + isLoading: mutation.isPending, }); // this function is used to make the `variables` parameter optional diff --git a/packages/core/src/hooks/form/index.ts b/packages/core/src/hooks/form/index.ts index feffcadf2ba2..84ab062cf6c7 100644 --- a/packages/core/src/hooks/form/index.ts +++ b/packages/core/src/hooks/form/index.ts @@ -160,6 +160,7 @@ export const useForm = < resource: identifier, id, queryOptions: { + queryKey: keys().data().resource(identifier).action("one").id(id).get(), // Only enable the query if it's not a create action and the `id` is defined enabled: !isCreate && id !== undefined, ...props.queryOptions, @@ -183,7 +184,7 @@ export const useForm = < }); const mutationResult = isEdit ? updateMutation : createMutation; - const isMutationLoading = mutationResult.isLoading; + const isMutationLoading = mutationResult.isPending; const formLoading = isMutationLoading || queryResult.isFetching; const { elapsedTime } = useLoadingOvertime({ @@ -262,11 +263,11 @@ export const useForm = < // Update specific variables ...(isEdit ? { - id: id ?? "", - mutationMode, - undoableTimeout: props.undoableTimeout, - optimisticUpdateMap: props.optimisticUpdateMap, - } + id: id ?? "", + mutationMode, + undoableTimeout: props.undoableTimeout, + optimisticUpdateMap: props.optimisticUpdateMap, + } : {}), }; @@ -277,13 +278,13 @@ export const useForm = < // These callbacks will not have an effect on the submission promise onSuccess: props.onMutationSuccess ? (data, _, context) => { - props.onMutationSuccess?.(data, values, context, isAutosave); - } + props.onMutationSuccess?.(data, values, context, isAutosave); + } : undefined, onError: props.onMutationError ? (error: TResponseError, _, context) => { - props.onMutationError?.(error, values, context, isAutosave); - } + props.onMutationError?.(error, values, context, isAutosave); + } : undefined, }) // If the mutation mode is pessimistic, resolve the promise after the mutation is succeeded diff --git a/packages/core/src/hooks/invalidate/index.spec.tsx b/packages/core/src/hooks/invalidate/index.spec.tsx index 330827aa9bf9..eaf9653cf95d 100644 --- a/packages/core/src/hooks/invalidate/index.spec.tsx +++ b/packages/core/src/hooks/invalidate/index.spec.tsx @@ -13,9 +13,9 @@ describe("useInvalidate", () => { useReducerSpy.mockImplementation( () => - ({ - invalidateQueries: dispatch, - }) as any, + (({ + invalidateQueries: dispatch + }) as any), ); const { result } = renderHook(() => useInvalidate(), { @@ -38,9 +38,9 @@ describe("useInvalidate", () => { useReducerSpy.mockImplementation( () => - ({ - invalidateQueries: dispatch, - }) as any, + (({ + invalidateQueries: dispatch + }) as any), ); const { result } = renderHook(() => useInvalidate(), { @@ -63,9 +63,9 @@ describe("useInvalidate", () => { useReducerSpy.mockImplementation( () => - ({ - invalidateQueries: dispatch, - }) as any, + (({ + invalidateQueries: dispatch + }) as any), ); const { result } = renderHook(() => useInvalidate(), { @@ -91,9 +91,9 @@ describe("useInvalidate", () => { useReducerSpy.mockImplementation( () => - ({ - invalidateQueries: dispatch, - }) as any, + (({ + invalidateQueries: dispatch + }) as any), ); const { result } = renderHook(() => useInvalidate(), { @@ -126,9 +126,9 @@ describe("useInvalidate", () => { useReducerSpy.mockImplementation( () => - ({ - invalidateQueries: dispatch, - }) as any, + (({ + invalidateQueries: dispatch + }) as any), ); const { result } = renderHook(() => useInvalidate(), { @@ -175,9 +175,9 @@ describe("useInvalidate", () => { useReducerSpy.mockImplementation( () => - ({ - invalidateQueries: dispatch, - }) as any, + (({ + invalidateQueries: dispatch + }) as any), ); const { result } = renderHook(() => useInvalidate(), { diff --git a/packages/core/src/hooks/invalidate/index.tsx b/packages/core/src/hooks/invalidate/index.tsx index dc6c1538d89f..dcba8d9212d4 100644 --- a/packages/core/src/hooks/invalidate/index.tsx +++ b/packages/core/src/hooks/invalidate/index.tsx @@ -49,38 +49,36 @@ export const useInvalidate = (): (( invalidates.map((key) => { switch (key) { case "all": - return queryClient.invalidateQueries( - keys().data(dp).get(preferLegacyKeys), + return queryClient.invalidateQueries({ + queryKey: keys().data(dp).get(preferLegacyKeys), invalidationFilters, invalidationOptions, - ); + }); case "list": - return queryClient.invalidateQueries( - queryKey.action("list").get(preferLegacyKeys), + return queryClient.invalidateQueries({ + queryKey: queryKey.action("list").get(preferLegacyKeys), invalidationFilters, invalidationOptions, - ); + }); case "many": - return queryClient.invalidateQueries( - queryKey.action("many").get(preferLegacyKeys), + return queryClient.invalidateQueries({ + queryKey: queryKey.action("many").get(preferLegacyKeys), invalidationFilters, invalidationOptions, - ); + }); case "resourceAll": - return queryClient.invalidateQueries( - queryKey.get(preferLegacyKeys), + return queryClient.invalidateQueries({ + queryKey: queryKey.get(preferLegacyKeys), invalidationFilters, invalidationOptions, - ); + }); case "detail": - return queryClient.invalidateQueries( - queryKey + return queryClient.invalidateQueries({ + queryKey: queryKey .action("one") .id(id || "") .get(preferLegacyKeys), - invalidationFilters, - invalidationOptions, - ); + }); default: return; } diff --git a/packages/core/src/hooks/resource/useResource/index.spec.tsx b/packages/core/src/hooks/resource/useResource/index.spec.tsx index ec75db438655..c7ae4eee33e8 100644 --- a/packages/core/src/hooks/resource/useResource/index.spec.tsx +++ b/packages/core/src/hooks/resource/useResource/index.spec.tsx @@ -190,10 +190,10 @@ describe("legacy router provider", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ resource: "posts", - action: "list", - }) as any, + action: "list" + }) as any), }, }), }, @@ -210,11 +210,11 @@ describe("legacy router provider", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ resource: "posts", action: "show", - id: "1", - }) as any, + id: "1" + }) as any), }, }), }); diff --git a/packages/core/src/hooks/show/index.spec.tsx b/packages/core/src/hooks/show/index.spec.tsx index 6bf1193c911b..aac960d1b08f 100644 --- a/packages/core/src/hooks/show/index.spec.tsx +++ b/packages/core/src/hooks/show/index.spec.tsx @@ -352,10 +352,10 @@ describe("useShow Hook", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ resource: "posts", - id: "1", - }) as any, + id: "1" + }) as any), }, }), }); diff --git a/packages/core/src/hooks/show/index.ts b/packages/core/src/hooks/show/index.ts index c7721b4311bd..746f768f5f82 100644 --- a/packages/core/src/hooks/show/index.ts +++ b/packages/core/src/hooks/show/index.ts @@ -1,6 +1,6 @@ import warnOnce from "warn-once"; import { useMeta, useOne, useResourceParams } from "@hooks"; -import { pickNotDeprecated } from "@definitions/helpers"; +import { keys, pickNotDeprecated } from "@definitions/helpers"; import type { UseShowProps, UseShowReturnType } from "./types"; import type { BaseKey, BaseRecord, HttpError } from "../../contexts/data/types"; @@ -51,7 +51,7 @@ export const useShow = < }); const getMeta = useMeta(); - + // const { keys, preferLegacyKeys } = useKeys(); const combinedMeta = getMeta({ resource, meta: pickNotDeprecated(meta, metaData), @@ -66,6 +66,7 @@ export const useShow = < resource: identifier, id: showId ?? "", queryOptions: { + queryKey: keys().data().resource(identifier).action("one").id(showId ?? "").get(), enabled: showId !== undefined, ...queryOptions, }, diff --git a/packages/core/src/hooks/use-resource-params/index.spec.ts b/packages/core/src/hooks/use-resource-params/index.spec.ts index 6b7ef4bd8eea..913bd00e3685 100644 --- a/packages/core/src/hooks/use-resource-params/index.spec.ts +++ b/packages/core/src/hooks/use-resource-params/index.spec.ts @@ -582,11 +582,11 @@ describe("useResourceParams Hook", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ resource: "posts", action: "edit", - id: 123, - }) as any, + id: 123 + }) as any), }, }), }); @@ -608,9 +608,9 @@ describe("useResourceParams Hook", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ - resource: "posts", - }) as any, + (({ + resource: "posts" + }) as any), }, }), }); @@ -632,10 +632,10 @@ describe("useResourceParams Hook", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ resource: "posts", - action: "list", - }) as any, + action: "list" + }) as any), }, }), }); @@ -681,10 +681,10 @@ describe("useResourceParams Hook", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ resource: "posts", - id: "456", - }) as any, + id: "456" + }) as any), }, }), }); @@ -706,10 +706,10 @@ describe("useResourceParams Hook", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ resource: "posts", - id: "123", - }) as any, + id: "123" + }) as any), }, }), }); @@ -733,10 +733,10 @@ describe("useResourceParams Hook", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ resource: "posts", - id: "123", - }) as any, + id: "123" + }) as any), }, resources: [{ name: "posts", identifier: "posts" }], }), @@ -762,10 +762,10 @@ describe("useResourceParams Hook", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ resource: "posts", - id: "123", - }) as any, + id: "123" + }) as any), }, resources: [{ name: "categories", identifier: "categories" }], }), @@ -815,11 +815,11 @@ describe("useResourceParams Hook", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ resource: "posts", action: "edit", - id: "123", - }) as any, + id: "123" + }) as any), }, resources: [{ name: "categories", identifier: "categories" }], }), @@ -845,11 +845,11 @@ describe("useResourceParams Hook", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ resource: "posts", id: "123", - action: "edit", - }) as any, + action: "edit" + }) as any), }, resources: [{ name: "posts", identifier: "posts" }], }), @@ -873,11 +873,11 @@ describe("useResourceParams Hook", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ id: "123", action: "edit", - resource: "posts", - }) as any, + resource: "posts" + }) as any), }, resources: [{ name: "posts", identifier: "posts" }], }), @@ -900,11 +900,11 @@ describe("useResourceParams Hook", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ resource: "posts", id: 123, - action: "edit", - }) as any, + action: "edit" + }) as any), }, }), }); diff --git a/packages/core/src/hooks/use-resource-params/use-action/index.spec.ts b/packages/core/src/hooks/use-resource-params/use-action/index.spec.ts index 2b2c82da7d81..3d2deefd2a09 100644 --- a/packages/core/src/hooks/use-resource-params/use-action/index.spec.ts +++ b/packages/core/src/hooks/use-resource-params/use-action/index.spec.ts @@ -37,11 +37,11 @@ describe("useAction Hook", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ resource: "posts", action: "edit", - id: 123, - }) as any, + id: 123 + }) as any), }, }), }); @@ -67,11 +67,11 @@ describe("useAction Hook", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ resource: "posts", action: "edit", - id: 456, - }) as any, + id: 456 + }) as any), }, }), }); diff --git a/packages/core/src/hooks/use-resource-params/use-id/index.spec.tsx b/packages/core/src/hooks/use-resource-params/use-id/index.spec.tsx index 49fe693dc199..00941ea29c9b 100644 --- a/packages/core/src/hooks/use-resource-params/use-id/index.spec.tsx +++ b/packages/core/src/hooks/use-resource-params/use-id/index.spec.tsx @@ -39,11 +39,11 @@ describe("useId Hook", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ resource: "posts", action: "edit", - id: 123, - }) as any, + id: 123 + }) as any), }, }), }); @@ -69,11 +69,11 @@ describe("useId Hook", () => { legacyRouterProvider: { ...mockLegacyRouterProvider(), useParams: () => - ({ + (({ resource: "posts", action: "edit", - id: 456, - }) as any, + id: 456 + }) as any), }, }), }); diff --git a/packages/core/src/hooks/useSelect/index.ts b/packages/core/src/hooks/useSelect/index.ts index 01f500fb86ac..6d79b13ab7a9 100644 --- a/packages/core/src/hooks/useSelect/index.ts +++ b/packages/core/src/hooks/useSelect/index.ts @@ -46,15 +46,15 @@ export type UseSelectProps = { * @default `"title"` */ optionLabel?: - | (keyof TData extends string ? keyof TData : never) - | ((item: TData) => string); + | (keyof TData extends string ? keyof TData : never) + | ((item: TData) => string); /** * Set the option's value * @default `"id"` */ optionValue?: - | (keyof TData extends string ? keyof TData : never) - | ((item: TData) => string); + | (keyof TData extends string ? keyof TData : never) + | ((item: TData) => string); /** * Field name to search for. * @description If provided `optionLabel` is a string, uses `optionLabel`'s value. @@ -167,11 +167,11 @@ export type UseSelectProps = { export type UseSelectReturnType< TData extends BaseRecord = BaseRecord, - TError extends HttpError = HttpError, + TError = HttpError, TOption extends BaseOption = BaseOption, > = { query: QueryObserverResult, TError>; - defaultValueQuery: QueryObserverResult>; + defaultValueQuery: QueryObserverResult, TError>; /** * @deprecated Use `query` instead */ @@ -179,7 +179,7 @@ export type UseSelectReturnType< /** * @deprecated Use `defaultValueQuery` instead */ - defaultValueQueryResult: QueryObserverResult>; + defaultValueQueryResult: QueryObserverResult, TError>; onSearch: (value: string) => void; options: TOption[]; } & UseLoadingOvertimeReturnType; @@ -278,10 +278,10 @@ export const useSelect = < setSelectedOptions( data.data.map( (item) => - ({ - label: getOptionLabel(item), - value: getOptionValue(item), - }) as TOption, + (({ + label: getOptionLabel(item), + value: getOptionValue(item) + }) as TOption), ), ); }, @@ -298,10 +298,10 @@ export const useSelect = < ...defaultValueQueryOptions, enabled: defaultValues.length > 0 && (defaultValueQueryOptions?.enabled ?? true), - onSuccess: (data) => { - defaultValueQueryOnSuccess(data); - defaultValueQueryOptions?.onSuccess?.(data); - }, + // onSuccess: (data) => { + // defaultValueQueryOnSuccess(data); + // defaultValueQueryOptions?.onSuccess?.(data); + // }, }, overtimeOptions: { enabled: false }, meta: combinedMeta, @@ -315,10 +315,10 @@ export const useSelect = < setOptions( data.data.map( (item) => - ({ - label: getOptionLabel(item), - value: getOptionValue(item), - }) as TOption, + (({ + label: getOptionLabel(item), + value: getOptionValue(item) + }) as TOption), ), ); }, @@ -335,13 +335,14 @@ export const useSelect = < mode: pagination?.mode, }, hasPagination, - queryOptions: { - ...queryOptions, - onSuccess: (data) => { - defaultQueryOnSuccess(data); - queryOptions?.onSuccess?.(data); - }, - }, + // TODO: fix this? + // queryOptions: { + // ...queryOptions, + // onSuccess: (data) => { + // defaultQueryOnSuccess(data); + // queryOptions?.onSuccess?.(data); + // }, + // }, overtimeOptions: { enabled: false }, successNotification, errorNotification,