quasar-ui-danx 0.4.41 → 0.4.43

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.
@@ -1,36 +1,99 @@
1
- import { storeObject } from "../helpers";
2
- import { ListControlsRoutes } from "../types";
1
+ import { storeObject, storeObjects } from "../helpers";
2
+ import { ActionTargetItem, ApplyActionResponse, ListControlsRoutes, PagedItems } from "../types";
3
3
  import { downloadFile } from "./downloadPdf";
4
4
  import { request } from "./request";
5
5
 
6
6
  export function useActionRoutes(baseUrl: string, extend?: object): ListControlsRoutes {
7
7
  return {
8
- list(pager?, options?) {
9
- return request.post(`${baseUrl}/list`, pager, options);
8
+ /**
9
+ * Loads a paged item list from the server
10
+ */
11
+ async list(pager?, options?) {
12
+ options = {
13
+ ...options,
14
+ ignoreAbort: true
15
+ };
16
+ const response = await request.post(`${baseUrl}/list`, pager, options) as PagedItems;
17
+
18
+ if (response.data) {
19
+ response.data = storeObjects(response.data);
20
+ }
21
+
22
+ return response;
10
23
  },
24
+ /**
25
+ * Loads a summary from the server
26
+ */
11
27
  summary(filter, options?) {
28
+ options = {
29
+ ...options,
30
+ ignoreAbort: true
31
+ };
12
32
  return request.post(`${baseUrl}/summary`, { filter }, options);
13
33
  },
14
- details(target, fields, options?) {
15
- options = options || {};
16
- fields && (options.params = { fields });
17
- return request.get(`${baseUrl}/${target.id}/details`, options);
18
- },
19
- async detailsAndStore(target, fields, options?) {
20
- options = options || {};
34
+ /**
35
+ * Loads a single item from the server.
36
+ * Optionally pass in the desired fields to load (otherwise it will load all default fields)
37
+ */
38
+ async details(target, fields, options?) {
39
+ options = {
40
+ ...options,
41
+ ignoreAbort: true
42
+ };
21
43
  fields && (options.params = { fields });
22
44
  const item = await request.get(`${baseUrl}/${target.id}/details`, options);
23
45
  return storeObject(item);
24
46
  },
47
+ /**
48
+ * Loads field options from the server
49
+ */
25
50
  fieldOptions(options?) {
26
51
  return request.get(`${baseUrl}/field-options`, options);
27
52
  },
28
- applyAction(action, target, data, options?) {
29
- return request.post(`${baseUrl}/${target ? target.id : "new"}/apply-action`, { action, data }, options);
53
+ /**
54
+ * Applies an action to a target item on the server to save to the DB and return the updated result
55
+ */
56
+ async applyAction(action, target, data, options?) {
57
+ options = {
58
+ ...options,
59
+ ignoreAbort: true,
60
+ headers: {
61
+ ...options?.headers,
62
+ // @ts-expect-error This header is fine
63
+ "X-Timestamp": Date.now()
64
+ }
65
+ };
66
+ data = data || {};
67
+ const response = await request.post(`${baseUrl}/${target ? target.id : "new"}/apply-action`, {
68
+ action,
69
+ data
70
+ }, options) as ApplyActionResponse;
71
+
72
+ // Store the response item in the reactive store if it is set
73
+ if (response.item) {
74
+ response.item = storeObject(response.item);
75
+ }
76
+
77
+ // Store the result item in the reactive store if it is set as an ActionTargetItem
78
+ if (response.result?.__type && response.result?.id) {
79
+ response.result = storeObject(response.result as ActionTargetItem);
80
+ }
81
+
82
+ return response;
30
83
  },
84
+ /**
85
+ * Applies an action to multiple target items on the server to save to the DB and return the updated result
86
+ */
31
87
  batchAction(action, targets, data, options?) {
88
+ options = {
89
+ ...options,
90
+ ignoreAbort: true
91
+ };
32
92
  return request.post(`${baseUrl}/batch-action`, { action, filter: { id: targets.map(r => r.id) }, data }, options);
33
93
  },
94
+ /**
95
+ * Exports a list of items to a CSV file
96
+ */
34
97
  export(filter, name) {
35
98
  return downloadFile(`${baseUrl}/export`, name || "export.csv", { filter });
36
99
  },
@@ -34,6 +34,7 @@ export interface ActionOptions<T = ActionTargetItem> {
34
34
  debounce?: number;
35
35
  useInputFromConfirm?: boolean;
36
36
  optimistic?: boolean | ((action: ActionOptions<T>, target: T | null, input: any) => void);
37
+ optimisticDelete?: boolean;
37
38
  vnode?: (target: ActionTarget<T>, data: any) => VNode | any;
38
39
  enabled?: (target: ActionTarget<T>) => boolean;
39
40
  batchEnabled?: (targets: T[]) => boolean;
@@ -27,11 +27,9 @@ export interface ListControlsRoutes<T = ActionTargetItem> {
27
27
 
28
28
  details?(target: T, fields?: ControlsFieldsList, options?: RequestCallOptions): Promise<T>;
29
29
 
30
- detailsAndStore?(target: T, fields?: ControlsFieldsList, options?: RequestCallOptions): Promise<T>;
31
-
32
30
  more?(pager: ListControlsPagination, options?: RequestCallOptions): Promise<T[]>;
33
31
 
34
- fieldOptions?(filter?: AnyObject, options?: RequestCallOptions): Promise<AnyObject>;
32
+ fieldOptions?(options?: RequestCallOptions): Promise<AnyObject>;
35
33
 
36
34
  applyAction?(action: string | ResourceAction | ActionOptions, target: T | null, data?: object, options?: RequestCallOptions): Promise<AnyObject>;
37
35
 
@@ -121,3 +119,9 @@ export interface ListController<T = ActionTargetItem> {
121
119
  applyFilterFromUrl: (url: string, filters?: Ref<FilterGroup[]> | null) => void;
122
120
  getFieldOptions: (field: string) => any[];
123
121
  }
122
+
123
+ export interface ApplyActionResponse<T = ActionTargetItem> {
124
+ item?: T;
125
+ result?: T | AnyObject;
126
+ success: boolean;
127
+ }
@@ -31,6 +31,7 @@ export interface RequestOptions {
31
31
 
32
32
  export interface RequestCallOptions extends RequestInit {
33
33
  abortOn?: string;
34
+ ignoreAbort?: boolean;
34
35
  params?: AnyObject;
35
36
  }
36
37