@refinedev/core 4.14.3 → 4.15.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@refinedev/core",
3
- "version": "4.14.3",
3
+ "version": "4.15.0",
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
  "main": "dist/index.js",
@@ -0,0 +1,48 @@
1
+ import { IResourceItem } from "@contexts/resource";
2
+ import capitalize from "lodash/capitalize";
3
+ import { userFriendlyResourceName } from "../userFriendlyResourceName";
4
+
5
+ /**
6
+ * Generates document title for the given resource and action.
7
+ */
8
+ export function generateDefaultDocumentTitle(
9
+ translate: {
10
+ (
11
+ key: string,
12
+ options?: any,
13
+ defaultMessage?: string | undefined,
14
+ ): string;
15
+ (key: string, defaultMessage?: string | undefined): string;
16
+ },
17
+ resource?: IResourceItem,
18
+ action?: string,
19
+ id?: string,
20
+ ) {
21
+ const actionPrefixMatcher = {
22
+ create: "Create new ",
23
+ edit: `#${id ?? ""} Edit `,
24
+ show: `#${id ?? ""} Show `,
25
+ list: "",
26
+ };
27
+
28
+ const resourceName = userFriendlyResourceName(
29
+ resource?.name,
30
+ action === "list" ? "plural" : "singular",
31
+ );
32
+
33
+ const defaultTitle = translate("documentTitle.default", "refine");
34
+ const suffix = translate("documentTitle.suffix", " | refine");
35
+ let autoGeneratedTitle = defaultTitle;
36
+
37
+ if (action && resource?.name) {
38
+ autoGeneratedTitle = translate(
39
+ `documentTitle.${resource.name}.${action}`,
40
+ { id },
41
+ `${
42
+ actionPrefixMatcher[action as keyof typeof actionPrefixMatcher]
43
+ }${capitalize(resourceName)}${suffix}`,
44
+ );
45
+ }
46
+
47
+ return autoGeneratedTitle;
48
+ }
@@ -24,3 +24,4 @@ export { composeRoute } from "./router/compose-route";
24
24
  export { useActiveAuthProvider } from "./useActiveAuthProvider";
25
25
  export { handlePaginationParams } from "./handlePaginationParams";
26
26
  export { useMediaQuery } from "./useMediaQuery";
27
+ export { generateDefaultDocumentTitle } from './generateDocumentTitle'
@@ -147,7 +147,7 @@ export const useCustom = <
147
147
  method,
148
148
  ...config,
149
149
  meta: {
150
- ...(combinedMeta || {}),
150
+ ...combinedMeta,
151
151
  queryContext: {
152
152
  queryKey,
153
153
  pageParam,
@@ -155,7 +155,7 @@ export const useCustom = <
155
155
  },
156
156
  },
157
157
  metaData: {
158
- ...(combinedMeta || {}),
158
+ ...combinedMeta,
159
159
  queryContext: {
160
160
  queryKey,
161
161
  pageParam,
@@ -171,7 +171,7 @@ export const useCustom = <
171
171
  typeof successNotification === "function"
172
172
  ? successNotification(data, {
173
173
  ...config,
174
- ...(combinedMeta || {}),
174
+ ...combinedMeta,
175
175
  })
176
176
  : successNotification;
177
177
 
@@ -185,7 +185,7 @@ export const useCustom = <
185
185
  typeof errorNotification === "function"
186
186
  ? errorNotification(err, {
187
187
  ...config,
188
- ...(combinedMeta || {}),
188
+ ...combinedMeta,
189
189
  })
190
190
  : errorNotification;
191
191
 
@@ -327,7 +327,7 @@ export const useDelete = <
327
327
  },
328
328
  context,
329
329
  ) => {
330
- const resourceSingular = pluralize.singular(resource ?? "");
330
+ const resourceSingular = pluralize.singular(resource);
331
331
 
332
332
  // Remove the queries from the cache:
333
333
  queryClient.removeQueries(context?.queryKey.detail(id));
@@ -357,7 +357,7 @@ export const useDelete = <
357
357
  channel: `resources/${resource}`,
358
358
  type: "deleted",
359
359
  payload: {
360
- ids: id ? [id] : [],
360
+ ids: [id],
361
361
  },
362
362
  date: new Date(),
363
363
  });
@@ -397,7 +397,7 @@ export const useDelete = <
397
397
  if (err.message !== "mutationCancelled") {
398
398
  checkError(err);
399
399
 
400
- const resourceSingular = pluralize.singular(resource ?? "");
400
+ const resourceSingular = pluralize.singular(resource);
401
401
 
402
402
  const notificationConfig =
403
403
  typeof errorNotification === "function"
@@ -247,7 +247,7 @@ export const useInfiniteList = <
247
247
  sort: prefferedSorters,
248
248
  sorters: prefferedSorters,
249
249
  meta: {
250
- ...(combinedMeta || {}),
250
+ ...combinedMeta,
251
251
  queryContext: {
252
252
  queryKey,
253
253
  pageParam,
@@ -255,7 +255,7 @@ export const useInfiniteList = <
255
255
  },
256
256
  },
257
257
  metaData: {
258
- ...(combinedMeta || {}),
258
+ ...combinedMeta,
259
259
  queryContext: {
260
260
  queryKey,
261
261
  pageParam,
@@ -240,7 +240,7 @@ export const useList = <
240
240
  sort: prefferedSorters,
241
241
  sorters: prefferedSorters,
242
242
  meta: {
243
- ...(combinedMeta || {}),
243
+ ...combinedMeta,
244
244
  queryContext: {
245
245
  queryKey,
246
246
  pageParam,
@@ -248,7 +248,7 @@ export const useList = <
248
248
  },
249
249
  },
250
250
  metaData: {
251
- ...(combinedMeta || {}),
251
+ ...combinedMeta,
252
252
  queryContext: {
253
253
  queryKey,
254
254
  pageParam,
@@ -129,7 +129,7 @@ export const useMany = <
129
129
  resource,
130
130
  types: ["*"],
131
131
  params: {
132
- ids: ids ?? [],
132
+ ids: ids,
133
133
  meta: combinedMeta,
134
134
  metaData: combinedMeta,
135
135
  subscriptionType: "useMany",
@@ -153,7 +153,7 @@ export const useMany = <
153
153
  resource,
154
154
  ids,
155
155
  meta: {
156
- ...(combinedMeta || {}),
156
+ ...combinedMeta,
157
157
  queryContext: {
158
158
  queryKey,
159
159
  pageParam,
@@ -161,7 +161,7 @@ export const useMany = <
161
161
  },
162
162
  },
163
163
  metaData: {
164
- ...(combinedMeta || {}),
164
+ ...combinedMeta,
165
165
  queryContext: {
166
166
  queryKey,
167
167
  pageParam,
@@ -176,7 +176,7 @@ export const useMany = <
176
176
  resource,
177
177
  id,
178
178
  meta: {
179
- ...(combinedMeta || {}),
179
+ ...combinedMeta,
180
180
  queryContext: {
181
181
  queryKey,
182
182
  pageParam,
@@ -184,7 +184,7 @@ export const useMany = <
184
184
  },
185
185
  },
186
186
  metaData: {
187
- ...(combinedMeta || {}),
187
+ ...combinedMeta,
188
188
  queryContext: {
189
189
  queryKey,
190
190
  pageParam,
@@ -157,7 +157,7 @@ export const useOne = <
157
157
  resource: resource!,
158
158
  id: id!,
159
159
  meta: {
160
- ...(combinedMeta || {}),
160
+ ...combinedMeta,
161
161
  queryContext: {
162
162
  queryKey,
163
163
  pageParam,
@@ -165,7 +165,7 @@ export const useOne = <
165
165
  },
166
166
  },
167
167
  metaData: {
168
- ...(combinedMeta || {}),
168
+ ...combinedMeta,
169
169
  queryContext: {
170
170
  queryKey,
171
171
  pageParam,
@@ -188,7 +188,7 @@ export const useOne = <
188
188
  data,
189
189
  {
190
190
  id,
191
- ...(combinedMeta || {}),
191
+ ...combinedMeta,
192
192
  },
193
193
  resource,
194
194
  )
@@ -206,7 +206,7 @@ export const useOne = <
206
206
  err,
207
207
  {
208
208
  id,
209
- ...(combinedMeta || {}),
209
+ ...combinedMeta,
210
210
  },
211
211
  resource,
212
212
  )
package/src/index.tsx CHANGED
@@ -116,5 +116,7 @@ export {
116
116
  useActiveAuthProvider,
117
117
  } from "./definitions/helpers";
118
118
  export { file2Base64 } from "./definitions/upload";
119
+ export { generateDefaultDocumentTitle } from "./definitions";
119
120
 
120
121
  export { ResourceContext } from "./contexts/resource/index";
122
+ export { TranslationContext } from "./contexts/translation/index";