@refinedev/core 4.44.9 → 4.44.10
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/CHANGELOG.md +35 -0
- package/dist/definitions/helpers/flatten-object-keys/index.d.ts +2 -0
- package/dist/definitions/helpers/flatten-object-keys/index.d.ts.map +1 -0
- package/dist/definitions/helpers/index.d.ts +2 -0
- package/dist/definitions/helpers/index.d.ts.map +1 -1
- package/dist/definitions/helpers/menu/create-tree.d.ts +1 -1
- package/dist/definitions/helpers/menu/create-tree.d.ts.map +1 -1
- package/dist/definitions/helpers/property-path-to-array/index.d.ts +2 -0
- package/dist/definitions/helpers/property-path-to-array/index.d.ts.map +1 -0
- package/dist/esm/index.js +6 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/hooks/menu/useMenu.d.ts +1 -1
- package/dist/hooks/menu/useMenu.d.ts.map +1 -1
- package/dist/hooks/useSelect/index.d.ts +4 -4
- package/dist/hooks/useSelect/index.d.ts.map +1 -1
- package/dist/iife/index.js +6 -6
- package/dist/iife/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.ts +8 -3
- package/dist/interfaces/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/definitions/helpers/flatten-object-keys/index.ts +36 -0
- package/src/definitions/helpers/index.ts +2 -0
- package/src/definitions/helpers/menu/create-tree.ts +1 -1
- package/src/definitions/helpers/property-path-to-array/index.ts +5 -0
- package/src/hooks/menu/useMenu.tsx +1 -1
- package/src/hooks/useSelect/index.ts +32 -24
- package/src/index.tsx +3 -0
- package/src/interfaces/index.ts +10 -4
|
@@ -30,9 +30,14 @@ export declare type BaseRecord = {
|
|
|
30
30
|
id?: BaseKey;
|
|
31
31
|
[key: string]: any;
|
|
32
32
|
};
|
|
33
|
-
export
|
|
34
|
-
label:
|
|
35
|
-
value:
|
|
33
|
+
export declare type BaseOption = {
|
|
34
|
+
label: any;
|
|
35
|
+
value: any;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated Use `BaseOption` instead.
|
|
39
|
+
*/
|
|
40
|
+
export interface Option extends BaseOption {
|
|
36
41
|
}
|
|
37
42
|
export declare type ITreeMenu = IResourceItem & {
|
|
38
43
|
key?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mCAAmC,CAAC;AAClD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,iDAAiD,CAAC;AAChE,cAAc,uCAAuC,CAAC;AACtD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,0CAA0C,CAAC;AACzD,cAAc,iDAAiD,CAAC;AAChE,cAAc,+CAA+C,CAAC;AAC9D,cAAc,uCAAuC,CAAC;AAEtD,cAAc,2BAA2B,CAAC;AAG1C,cAAc,WAAW,CAAC;AAG1B,cAAc,gBAAgB,CAAC;AAG/B,cAAc,gBAAgB,CAAC;AAG/B,cAAc,UAAU,CAAC;AAGzB,cAAc,oBAAoB,CAAC;AAGnC,cAAc,wBAAwB,CAAC;AAGvC,cAAc,6BAA6B,CAAC;AAG5C,cAAc,aAAa,CAAC;AAG5B,cAAc,4BAA4B,CAAC;AAG3C,cAAc,YAAY,CAAC;AAG3B,cAAc,YAAY,CAAC;AAG3B,cAAc,QAAQ,CAAC;AAGvB,cAAc,YAAY,CAAC;AAE3B,oBAAY,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AACtC,oBAAY,UAAU,GAAG;IACrB,EAAE,CAAC,EAAE,OAAO,CAAC;IAEb,CAAC,GAAG,EAAE,MAAM,GAAG,GAA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,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,EAAE,CAAC;CACzB,CAAC;AAEF,oBAAY,SAAS,GAAG,aAAa,GAAG;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,cAAc,mBAAmB,CAAC;AAElC,cAAc,QAAQ,CAAC;AAEvB,cAAc,YAAY,CAAC;AAE3B,cAAc,YAAY,CAAC;AAE3B,cAAc,YAAY,CAAC;AAE3B,cAAc,oBAAoB,CAAC;AAEnC,cAAc,yBAAyB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@refinedev/core",
|
|
3
|
-
"version": "4.44.
|
|
3
|
+
"version": "4.44.10",
|
|
4
4
|
"description": "refine is a React-based framework for building internal tools, rapidly. It ships with Ant Design System, an enterprise-level UI toolkit.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const isNested = (obj: any) => typeof obj === "object" && obj !== null;
|
|
2
|
+
const isArray = (obj: any) => Array.isArray(obj);
|
|
3
|
+
|
|
4
|
+
export const flattenObjectKeys = (obj: any, prefix = "") => {
|
|
5
|
+
if (!isNested(obj)) {
|
|
6
|
+
return {
|
|
7
|
+
[prefix]: obj,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
12
|
+
const currentPrefix = prefix.length ? prefix + "." : "";
|
|
13
|
+
|
|
14
|
+
if (isNested(obj[key]) && Object.keys(obj[key]).length) {
|
|
15
|
+
if (isArray(obj[key]) && obj[key].length) {
|
|
16
|
+
obj[key].forEach((item: unknown[], index: number) => {
|
|
17
|
+
Object.assign(
|
|
18
|
+
acc,
|
|
19
|
+
flattenObjectKeys(
|
|
20
|
+
item,
|
|
21
|
+
currentPrefix + key + "." + index,
|
|
22
|
+
),
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
Object.assign(
|
|
27
|
+
acc,
|
|
28
|
+
flattenObjectKeys(obj[key], currentPrefix + key),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
acc[currentPrefix + key] = obj[key];
|
|
33
|
+
}
|
|
34
|
+
return acc;
|
|
35
|
+
}, {} as Record<string, unknown>);
|
|
36
|
+
};
|
|
@@ -28,3 +28,5 @@ export { generateDefaultDocumentTitle } from "./generateDocumentTitle";
|
|
|
28
28
|
export { useUserFriendlyName } from "./useUserFriendlyName";
|
|
29
29
|
export { keys, stripUndefined } from "./keys";
|
|
30
30
|
export { KeyBuilder } from "./keys";
|
|
31
|
+
export { flattenObjectKeys } from "./flatten-object-keys";
|
|
32
|
+
export { propertyPathToArray } from "./property-path-to-array";
|
|
@@ -8,7 +8,7 @@ import { getParentResource } from "@definitions/helpers/router";
|
|
|
8
8
|
import {
|
|
9
9
|
FlatTreeItem,
|
|
10
10
|
createTree,
|
|
11
|
-
} from "
|
|
11
|
+
} from "../../definitions/helpers/menu/create-tree";
|
|
12
12
|
|
|
13
13
|
type UseMenuReturnType = {
|
|
14
14
|
defaultOpenKeys: string[];
|
|
@@ -7,7 +7,7 @@ import get from "lodash/get";
|
|
|
7
7
|
import { useList, useMany, useMeta } from "@hooks";
|
|
8
8
|
import {
|
|
9
9
|
CrudSorting,
|
|
10
|
-
|
|
10
|
+
BaseOption,
|
|
11
11
|
BaseRecord,
|
|
12
12
|
GetManyResponse,
|
|
13
13
|
GetListResponse,
|
|
@@ -38,16 +38,12 @@ export type UseSelectProps<TQueryFnData, TError, TData> = {
|
|
|
38
38
|
* Set the option's value
|
|
39
39
|
* @default `"title"`
|
|
40
40
|
*/
|
|
41
|
-
optionLabel?: keyof TData extends string
|
|
42
|
-
? keyof TData
|
|
43
|
-
: never;
|
|
41
|
+
optionLabel?: keyof TData extends string ? keyof TData : never;
|
|
44
42
|
/**
|
|
45
43
|
* Set the option's label value
|
|
46
44
|
* @default `"id"`
|
|
47
45
|
*/
|
|
48
|
-
optionValue?: keyof TData extends string
|
|
49
|
-
? keyof TData
|
|
50
|
-
: never;
|
|
46
|
+
optionValue?: keyof TData extends string ? keyof TData : never;
|
|
51
47
|
/**
|
|
52
48
|
* Allow us to sort the options
|
|
53
49
|
* @deprecated Use `sorters` instead
|
|
@@ -139,11 +135,14 @@ export type UseSelectProps<TQueryFnData, TError, TData> = {
|
|
|
139
135
|
LiveModeProps &
|
|
140
136
|
UseLoadingOvertimeOptionsProps;
|
|
141
137
|
|
|
142
|
-
export type UseSelectReturnType<
|
|
138
|
+
export type UseSelectReturnType<
|
|
139
|
+
TData extends BaseRecord = BaseRecord,
|
|
140
|
+
TOption extends BaseOption = BaseOption,
|
|
141
|
+
> = {
|
|
143
142
|
queryResult: QueryObserverResult<GetListResponse<TData>>;
|
|
144
143
|
defaultValueQueryResult: QueryObserverResult<GetManyResponse<TData>>;
|
|
145
144
|
onSearch: (value: string) => void;
|
|
146
|
-
options:
|
|
145
|
+
options: TOption[];
|
|
147
146
|
} & UseLoadingOvertimeReturnType;
|
|
148
147
|
|
|
149
148
|
/**
|
|
@@ -164,12 +163,13 @@ export const useSelect = <
|
|
|
164
163
|
TQueryFnData extends BaseRecord = BaseRecord,
|
|
165
164
|
TError extends HttpError = HttpError,
|
|
166
165
|
TData extends BaseRecord = TQueryFnData,
|
|
166
|
+
TOption extends BaseOption = BaseOption,
|
|
167
167
|
>(
|
|
168
168
|
props: UseSelectProps<TQueryFnData, TError, TData>,
|
|
169
|
-
): UseSelectReturnType<TData> => {
|
|
169
|
+
): UseSelectReturnType<TData, TOption> => {
|
|
170
170
|
const [search, setSearch] = useState<CrudFilters>([]);
|
|
171
|
-
const [options, setOptions] = useState<
|
|
172
|
-
const [selectedOptions, setSelectedOptions] = useState<
|
|
171
|
+
const [options, setOptions] = useState<TOption[]>([]);
|
|
172
|
+
const [selectedOptions, setSelectedOptions] = useState<TOption[]>([]);
|
|
173
173
|
|
|
174
174
|
const {
|
|
175
175
|
resource: resourceFromProps,
|
|
@@ -213,10 +213,13 @@ export const useSelect = <
|
|
|
213
213
|
const defaultValueQueryOnSuccess = useCallback(
|
|
214
214
|
(data: GetManyResponse<TData>) => {
|
|
215
215
|
setSelectedOptions(
|
|
216
|
-
data.data.map(
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
data.data.map(
|
|
217
|
+
(item) =>
|
|
218
|
+
({
|
|
219
|
+
label: get(item, optionLabel),
|
|
220
|
+
value: get(item, optionValue),
|
|
221
|
+
} as TOption),
|
|
222
|
+
),
|
|
220
223
|
);
|
|
221
224
|
},
|
|
222
225
|
[optionLabel, optionValue],
|
|
@@ -248,10 +251,13 @@ export const useSelect = <
|
|
|
248
251
|
(data: GetListResponse<TData>) => {
|
|
249
252
|
{
|
|
250
253
|
setOptions(
|
|
251
|
-
data.data.map(
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
254
|
+
data.data.map(
|
|
255
|
+
(item) =>
|
|
256
|
+
({
|
|
257
|
+
label: get(item, optionLabel),
|
|
258
|
+
value: get(item, optionValue),
|
|
259
|
+
} as TOption),
|
|
260
|
+
),
|
|
255
261
|
);
|
|
256
262
|
}
|
|
257
263
|
},
|
|
@@ -311,13 +317,15 @@ export const useSelect = <
|
|
|
311
317
|
onInterval: overtimeOptions?.onInterval,
|
|
312
318
|
});
|
|
313
319
|
|
|
320
|
+
const combinedOptions = useMemo(
|
|
321
|
+
() => uniqBy([...options, ...selectedOptions], "value"),
|
|
322
|
+
[options, selectedOptions],
|
|
323
|
+
);
|
|
324
|
+
|
|
314
325
|
return {
|
|
315
326
|
queryResult,
|
|
316
327
|
defaultValueQueryResult,
|
|
317
|
-
options:
|
|
318
|
-
() => uniqBy([...options, ...selectedOptions], "value"),
|
|
319
|
-
[options, selectedOptions],
|
|
320
|
-
),
|
|
328
|
+
options: combinedOptions,
|
|
321
329
|
onSearch: debounce(onSearch, debounceValue),
|
|
322
330
|
overtime: { elapsedTime },
|
|
323
331
|
};
|
package/src/index.tsx
CHANGED
|
@@ -40,6 +40,7 @@ export {
|
|
|
40
40
|
NotificationProvider,
|
|
41
41
|
OpenNotificationParams,
|
|
42
42
|
Option,
|
|
43
|
+
BaseOption,
|
|
43
44
|
Pagination,
|
|
44
45
|
PromptProps,
|
|
45
46
|
RedirectionTypes,
|
|
@@ -131,6 +132,8 @@ export {
|
|
|
131
132
|
pickDataProvider,
|
|
132
133
|
keys,
|
|
133
134
|
KeyBuilder,
|
|
135
|
+
flattenObjectKeys,
|
|
136
|
+
propertyPathToArray,
|
|
134
137
|
} from "./definitions/helpers";
|
|
135
138
|
export { file2Base64 } from "./definitions/upload";
|
|
136
139
|
export { generateDefaultDocumentTitle } from "./definitions";
|
package/src/interfaces/index.ts
CHANGED
|
@@ -61,10 +61,16 @@ export type BaseRecord = {
|
|
|
61
61
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
62
|
[key: string]: any;
|
|
63
63
|
};
|
|
64
|
-
export
|
|
65
|
-
label:
|
|
66
|
-
value:
|
|
67
|
-
}
|
|
64
|
+
export type BaseOption = {
|
|
65
|
+
label: any;
|
|
66
|
+
value: any;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated Use `BaseOption` instead.
|
|
71
|
+
*/
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
73
|
+
export interface Option extends BaseOption {}
|
|
68
74
|
|
|
69
75
|
/* Backward compatible version of 'TreeMenuItem' */
|
|
70
76
|
export type ITreeMenu = IResourceItem & {
|