quasar-ui-danx 0.0.40 → 0.0.42

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quasar-ui-danx",
3
- "version": "0.0.40",
3
+ "version": "0.0.42",
4
4
  "author": "Dan <dan@flytedesk.com>",
5
5
  "description": "DanX Vue / Quasar component library",
6
6
  "license": "MIT",
@@ -21,7 +21,7 @@ const props = defineProps({
21
21
  },
22
22
  target: {
23
23
  type: [Array, Object],
24
- required: true
24
+ default: () => []
25
25
  },
26
26
  tooltip: {
27
27
  type: String,
@@ -34,10 +34,13 @@ const props = defineProps({
34
34
  }
35
35
  });
36
36
 
37
- const hasTarget = computed(() => !!props.target?.length);
37
+ const hasTarget = computed(() => Array.isArray(props.target) ? props.target.length > 0 : !!props.target);
38
38
 
39
39
  const activeActions = computed(() => props.actions.filter(action => {
40
- if (action.enabled === undefined) return true;
41
- return typeof action.enabled === 'function' ? !!action.enabled(props.target) : !!action.enabled;
40
+ if (Array.isArray(props.target)) {
41
+ return action.batchEnabled ? action.batchEnabled(props.target) : true;
42
+ }
43
+
44
+ return action.enabled ? action.enabled(props.target) : true;
42
45
  }));
43
46
  </script>
@@ -61,7 +61,7 @@
61
61
  :params="[rowProps.row]"
62
62
  :component="rowProps.col.component"
63
63
  :text="rowProps.value"
64
- @action="$emit('action', $event)"
64
+ @action="action => $emit('action', {action,target: rowProps.row})"
65
65
  />
66
66
  <div v-else-if="rowProps.col.fieldList">
67
67
  <div v-for="field in rowProps.col.fieldList" :key="field">
@@ -77,8 +77,8 @@
77
77
  <ActionMenu
78
78
  :actions="rowProps.col.actions"
79
79
  :target="rowProps.row"
80
- :loading="isSavingItem?.id === rowProps.row.id"
81
- @action="(action) => $emit('action', {action, target: rowProps.row})"
80
+ :loading="isSavingRow(rowProps.row)"
81
+ @action="(action) => $emit('action', action, rowProps.row)"
82
82
  />
83
83
  </div>
84
84
  </component>
@@ -116,7 +116,7 @@ const props = defineProps({
116
116
  type: Object,
117
117
  required: true
118
118
  },
119
- isSavingItem: {
119
+ isSavingTarget: {
120
120
  type: Object,
121
121
  default: null
122
122
  },
@@ -158,6 +158,15 @@ function getColumnStyle(column) {
158
158
  }
159
159
  return null;
160
160
  }
161
+
162
+ function isSavingRow(row) {
163
+ if (!props.isSavingTarget) return false;
164
+
165
+ if (Array.isArray(props.isSavingTarget)) {
166
+ return !!props.isSavingTarget.find(t => t.id === row.id);
167
+ }
168
+ return props.isSavingTarget.id === row.id;
169
+ }
161
170
  </script>
162
171
 
163
172
  <style lang="scss" scoped>
@@ -1,9 +1,16 @@
1
1
  <template>
2
2
  <Component
3
+ v-if="content"
3
4
  :is="resolvedComponent.is"
4
5
  v-bind="{...resolvedComponent.props, ...overrideProps}"
5
6
  @action="$emit('action', $event)"
6
- >{{ resolvedComponent.value || resolvedComponent.props?.text || text }}</Component>
7
+ >{{ content }}</Component>
8
+ <Component
9
+ v-else
10
+ :is="resolvedComponent.is"
11
+ v-bind="{...resolvedComponent.props, ...overrideProps}"
12
+ @action="$emit('action', $event)"
13
+ />
7
14
  </template>
8
15
  <script setup>
9
16
  import { computed } from 'vue';
@@ -20,7 +27,7 @@ const props = defineProps({
20
27
  },
21
28
  text: {
22
29
  type: String,
23
- default: ''
30
+ default: undefined
24
31
  },
25
32
  overrideProps: {
26
33
  type: Object,
@@ -28,6 +35,7 @@ const props = defineProps({
28
35
  }
29
36
  });
30
37
 
38
+ const content = computed(() => resolvedComponent.value?.value || resolvedComponent.value?.props?.text || props.text);
31
39
  const resolvedComponent = computed(() => {
32
40
  if (typeof props.component === 'function') {
33
41
  return props.component(...props.params);
@@ -2,12 +2,15 @@ import { shallowRef } from "vue";
2
2
  import { FlashMessages } from "./index";
3
3
 
4
4
  interface ActionOptions {
5
- name: string;
6
- label: string;
5
+ name?: string;
6
+ label?: string;
7
7
  menu?: boolean;
8
8
  batch?: boolean;
9
+ category?: string;
10
+ class?: string;
9
11
  inputComponent?: (target: object[] | object) => any;
10
12
  enabled?: (target: object) => boolean;
13
+ batchEnabled?: (targets: object[]) => boolean;
11
14
  onAction?: (action: string | null, target: object, input: any) => Promise<any>;
12
15
  onBatchAction?: (action: string | null, targets: object[], input: any) => Promise<any>;
13
16
  onSuccess?: (action: string | null, targets: object, input: any) => any;
@@ -69,8 +72,6 @@ export function useActions(actions: ActionOptions[], globalOptions: ActionOption
69
72
  * TODO: HOW TO INTEGRATE optimistic updates and single item updates?
70
73
  */
71
74
  async applyAction(item, input, itemData = {}) {
72
- isSavingItem.value = item;
73
-
74
75
  setItemInPagedList({ ...item, ...input, ...itemData });
75
76
  const result = await applyActionRoute(item, input);
76
77
  if (result.success) {
@@ -85,7 +86,6 @@ export function useActions(actions: ActionOptions[], globalOptions: ActionOption
85
86
  activeItem.value = { ...activeItem.value, ...result.item };
86
87
  }
87
88
  }
88
- isSavingItem.value = null;
89
89
  return result;
90
90
  },
91
91
 
@@ -112,10 +112,19 @@ export function useActions(actions: ActionOptions[], globalOptions: ActionOption
112
112
  result = await new Promise((resolve, reject) => {
113
113
  activeActionInput.value = {
114
114
  component,
115
- confirm: async () => resolve(await onConfirmAction(action, target, input)),
116
- cancel: reject
115
+ confirm: async input => {
116
+ const result = await onConfirmAction(action, target, input);
117
+
118
+ // Only resolve when we have a non-error response, so we can show the error message w/o
119
+ // hiding the dialog / inputComponent
120
+ if (result === undefined || result === true || result?.success) {
121
+ resolve(result);
122
+ }
123
+ },
124
+ cancel: resolve
117
125
  };
118
126
  });
127
+
119
128
  activeActionInput.value = null;
120
129
  } else {
121
130
  result = await onConfirmAction(action, target, input);
@@ -145,16 +154,14 @@ async function onConfirmAction(action: ActionOptions, target: object[] | object,
145
154
  }
146
155
 
147
156
  // If there is no return value or the result marks it as successful, we show a success message
148
- if (result === undefined || result?.success) {
149
-
150
- if (result?.success) {
151
- FlashMessages.success(`The update was successful`);
157
+ if (result === undefined || result === true || result?.success) {
158
+ if (result?.success && Array.isArray(target)) {
159
+ FlashMessages.success(`Successfully performed action ${action.label} on ${target.length} items`);
152
160
  }
153
161
 
154
162
  if (action.onSuccess) {
155
163
  action.onSuccess(result, target, input);
156
164
  }
157
-
158
165
  } else {
159
166
  const errors = [];
160
167
  if (result.errors) {
@@ -176,5 +183,6 @@ async function onConfirmAction(action: ActionOptions, target: object[] | object,
176
183
  action.onFinish(result, target, input);
177
184
  }
178
185
 
186
+ console.log("onConrirm result", result);
179
187
  return result;
180
188
  }