muffin-admin 8.5.5 → 8.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/buttons/ActionButton.js +3 -3
- package/dist/dataprovider.js +3 -7
- package/dist/i18n/ru.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +6 -0
- package/package.json +1 -1
- package/src/buttons/ActionButton.tsx +4 -4
- package/src/dataprovider.ts +2 -9
- package/src/i18n/ru.ts +2 -0
- package/src/index.tsx +1 -1
- package/src/utils.tsx +9 -0
package/dist/utils.d.ts
CHANGED
|
@@ -25,3 +25,4 @@ export declare function makeRequest(url: string, params?: APIParams): Promise<{
|
|
|
25
25
|
export declare function findIcon(icon?: string): any;
|
|
26
26
|
export declare function buildIcon(icon?: string): import("react/jsx-runtime").JSX.Element;
|
|
27
27
|
export declare function deepMerge(target: any, ...sources: any[]): any;
|
|
28
|
+
export declare function prepareFilters(filter: any): string;
|
package/dist/utils.js
CHANGED
|
@@ -76,3 +76,9 @@ export function deepMerge(target, ...sources) {
|
|
|
76
76
|
}
|
|
77
77
|
return deepMerge(target, ...sources);
|
|
78
78
|
}
|
|
79
|
+
export function prepareFilters(filter) {
|
|
80
|
+
return JSON.stringify(Object.entries(filter).reduce((acc, [key, value]) => {
|
|
81
|
+
acc[key] = Array.isArray(value) ? { $in: value } : value;
|
|
82
|
+
return acc;
|
|
83
|
+
}, {}));
|
|
84
|
+
}
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@ import { HelpLink } from "../common/HelpLink"
|
|
|
17
17
|
import { useMuffinAdminOpts } from "../hooks"
|
|
18
18
|
import { useAction } from "../hooks/useAction"
|
|
19
19
|
import { AdminAction, AdminPayloadProps } from "../types"
|
|
20
|
-
import { buildIcon, findBuilder, requestHeaders } from "../utils"
|
|
20
|
+
import { buildIcon, findBuilder, prepareFilters, requestHeaders } from "../utils"
|
|
21
21
|
|
|
22
22
|
export type ActionPayloadProps = {
|
|
23
23
|
active: boolean
|
|
@@ -38,9 +38,9 @@ export function ActionButton({ paths, confirm, file, ...props }: AdminAction) {
|
|
|
38
38
|
const confirmMessage =
|
|
39
39
|
typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?"
|
|
40
40
|
|
|
41
|
-
const onHandle = async (payload
|
|
41
|
+
const onHandle = async (payload?: any) => {
|
|
42
42
|
const process = confirm ? await confirmation.confirm({ message: confirmMessage }) : true
|
|
43
|
-
if (process)
|
|
43
|
+
if (process) mutate({ record, payload })
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
return <ActionButtonBase {...props} isPending={isPending} onHandle={onHandle} />
|
|
@@ -200,7 +200,7 @@ function FileButton({
|
|
|
200
200
|
if (record) url = url.replace("{id}", record.id as string)
|
|
201
201
|
const authorization = requestHeaders["Authorization"]
|
|
202
202
|
if (authorization) url += `&t=${authorization}`
|
|
203
|
-
if (Object.keys(filterValues).length) url += `&where=${
|
|
203
|
+
if (Object.keys(filterValues).length) url += `&where=${prepareFilters(filterValues)}`
|
|
204
204
|
|
|
205
205
|
return (
|
|
206
206
|
<Button href={url} label={label} component={Link}>
|
package/src/dataprovider.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TID } from "./types"
|
|
2
|
-
import { APIParams, makeRequest, setupAdmin } from "./utils"
|
|
2
|
+
import { APIParams, makeRequest, prepareFilters, setupAdmin } from "./utils"
|
|
3
3
|
|
|
4
4
|
export function MuffinDataprovider(apiUrl: string) {
|
|
5
5
|
async function request(url: string, options?: APIParams) {
|
|
@@ -13,14 +13,7 @@ export function MuffinDataprovider(apiUrl: string) {
|
|
|
13
13
|
getList: async (resource: string, params: any) => {
|
|
14
14
|
const { filter, pagination, sort } = params
|
|
15
15
|
const query: APIParams["query"] = {}
|
|
16
|
-
if (filter)
|
|
17
|
-
query.where = JSON.stringify(
|
|
18
|
-
Object.entries(filter).reduce((acc, [key, value]) => {
|
|
19
|
-
acc[key] = Array.isArray(value) ? { $in: value } : value
|
|
20
|
-
return acc
|
|
21
|
-
}, {})
|
|
22
|
-
)
|
|
23
|
-
}
|
|
16
|
+
if (filter) query.where = prepareFilters(filter)
|
|
24
17
|
if (pagination) {
|
|
25
18
|
const { page, perPage: limit } = pagination
|
|
26
19
|
query.limit = limit
|
package/src/i18n/ru.ts
CHANGED
package/src/index.tsx
CHANGED
package/src/utils.tsx
CHANGED
|
@@ -86,3 +86,12 @@ export function deepMerge(target: any, ...sources: any[]): any {
|
|
|
86
86
|
}
|
|
87
87
|
return deepMerge(target, ...sources)
|
|
88
88
|
}
|
|
89
|
+
|
|
90
|
+
export function prepareFilters(filter: any) {
|
|
91
|
+
return JSON.stringify(
|
|
92
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
|
93
|
+
acc[key] = Array.isArray(value) ? { $in: value } : value
|
|
94
|
+
return acc
|
|
95
|
+
}, {})
|
|
96
|
+
)
|
|
97
|
+
}
|