adminforth 2.27.0-next.5 → 2.27.0-next.50

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.
Files changed (81) hide show
  1. package/commands/callTsProxy.js +10 -5
  2. package/commands/createApp/templates/api.ts.hbs +12 -2
  3. package/commands/proxy.ts +18 -10
  4. package/dist/commands/proxy.js +14 -10
  5. package/dist/commands/proxy.js.map +1 -1
  6. package/dist/dataConnectors/clickhouse.d.ts +5 -2
  7. package/dist/dataConnectors/clickhouse.d.ts.map +1 -1
  8. package/dist/dataConnectors/clickhouse.js +73 -9
  9. package/dist/dataConnectors/clickhouse.js.map +1 -1
  10. package/dist/index.d.ts +4 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +17 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/modules/configValidator.d.ts.map +1 -1
  15. package/dist/modules/configValidator.js +16 -9
  16. package/dist/modules/configValidator.js.map +1 -1
  17. package/dist/modules/restApi.d.ts.map +1 -1
  18. package/dist/modules/restApi.js +515 -9
  19. package/dist/modules/restApi.js.map +1 -1
  20. package/dist/modules/styles.js +1 -1
  21. package/dist/modules/utils.d.ts +1 -1
  22. package/dist/modules/utils.d.ts.map +1 -1
  23. package/dist/modules/utils.js +3 -5
  24. package/dist/modules/utils.js.map +1 -1
  25. package/dist/servers/express.d.ts +2 -6
  26. package/dist/servers/express.d.ts.map +1 -1
  27. package/dist/servers/express.js +46 -1
  28. package/dist/servers/express.js.map +1 -1
  29. package/dist/servers/openapi.d.ts +25 -0
  30. package/dist/servers/openapi.d.ts.map +1 -0
  31. package/dist/servers/openapi.js +126 -0
  32. package/dist/servers/openapi.js.map +1 -0
  33. package/dist/spa/package-lock.json +41 -0
  34. package/dist/spa/package.json +4 -0
  35. package/dist/spa/pnpm-lock.yaml +38 -0
  36. package/dist/spa/src/App.vue +77 -76
  37. package/dist/spa/src/afcl/Button.vue +2 -3
  38. package/dist/spa/src/afcl/Dialog.vue +1 -1
  39. package/dist/spa/src/afcl/Input.vue +1 -1
  40. package/dist/spa/src/afcl/Select.vue +8 -2
  41. package/dist/spa/src/afcl/Skeleton.vue +5 -0
  42. package/dist/spa/src/afcl/Spinner.vue +1 -1
  43. package/dist/spa/src/components/CallActionWrapper.vue +1 -1
  44. package/dist/spa/src/components/ColumnValueInput.vue +16 -3
  45. package/dist/spa/src/components/ColumnValueInputWrapper.vue +25 -2
  46. package/dist/spa/src/components/CustomRangePicker.vue +16 -14
  47. package/dist/spa/src/components/Filters.vue +95 -63
  48. package/dist/spa/src/components/GroupsTable.vue +9 -6
  49. package/dist/spa/src/components/MenuLink.vue +2 -2
  50. package/dist/spa/src/components/ResourceForm.vue +101 -7
  51. package/dist/spa/src/components/ResourceListTable.vue +14 -8
  52. package/dist/spa/src/components/ShowTable.vue +1 -1
  53. package/dist/spa/src/components/Sidebar.vue +29 -8
  54. package/dist/spa/src/components/ThreeDotsMenu.vue +25 -10
  55. package/dist/spa/src/components/ValueRenderer.vue +1 -0
  56. package/dist/spa/src/spa_types/core.ts +32 -0
  57. package/dist/spa/src/stores/filters.ts +16 -12
  58. package/dist/spa/src/types/Back.ts +91 -24
  59. package/dist/spa/src/types/Common.ts +24 -5
  60. package/dist/spa/src/types/adapters/CompletionAdapter.ts +27 -5
  61. package/dist/spa/src/types/adapters/index.ts +2 -2
  62. package/dist/spa/src/utils/createEditUtils.ts +65 -0
  63. package/dist/spa/src/utils/index.ts +2 -1
  64. package/dist/spa/src/utils/utils.ts +42 -7
  65. package/dist/spa/src/utils.ts +2 -1
  66. package/dist/spa/src/views/CreateEditSkeleton.vue +78 -0
  67. package/dist/spa/src/views/CreateView.vue +24 -50
  68. package/dist/spa/src/views/EditView.vue +23 -40
  69. package/dist/spa/src/views/ListView.vue +22 -32
  70. package/dist/spa/src/views/ShowView.vue +66 -24
  71. package/dist/types/Back.d.ts +100 -30
  72. package/dist/types/Back.d.ts.map +1 -1
  73. package/dist/types/Back.js.map +1 -1
  74. package/dist/types/Common.d.ts +31 -5
  75. package/dist/types/Common.d.ts.map +1 -1
  76. package/dist/types/Common.js.map +1 -1
  77. package/dist/types/adapters/CompletionAdapter.d.ts +18 -3
  78. package/dist/types/adapters/CompletionAdapter.d.ts.map +1 -1
  79. package/dist/types/adapters/index.d.ts +1 -1
  80. package/dist/types/adapters/index.d.ts.map +1 -1
  81. package/package.json +9 -5
@@ -35,7 +35,7 @@
35
35
  >
36
36
  {{ item.label }}
37
37
  </div>
38
- <span class="absolute flex items-center justify-center right-1 top-1/2 -translate-y-1/2" v-if="item.badge && showExpandedBadge">
38
+ <span class="absolute flex items-center justify-center right-1 top-1/2 -translate-y-1/2" v-if="(item.badge || item.badge === 0) && showExpandedBadge ">
39
39
  <Tooltip v-if="item.badgeTooltip">
40
40
  <div class="af-badge inline-flex items-center justify-center h-3 py-2.5 px-1 ms-3 text-xs font-medium rounded-full bg-lightAnnouncementBG dark:bg-darkAnnouncementBG
41
41
  fill-lightAnnouncementText dark:fill-darkAccent text-lightAnnouncementText dark:text-darkAccent min-w-[1.5rem] max-w-[3rem]">{{ item.badge }}</div>
@@ -48,7 +48,7 @@
48
48
  fill-lightAnnouncementText dark:fill-darkAccent text-lightAnnouncementText dark:text-darkAccent min-w-[1.5rem] max-w-[3rem]">{{ item.badge }}</div>
49
49
  </template>
50
50
  </span>
51
- <div v-if="item.badge && isSidebarIconOnly && !isSidebarHovering" class="af-badge absolute right-0.5 bottom-1 -translate-y-1/2 inline-flex items-center justify-center h-2 w-2 text-sm font-medium rounded-full bg-lightAnnouncementBG dark:bg-darkAnnouncementBG
51
+ <div v-if="(item.badge || item.badge === 0) && isSidebarIconOnly && !isSidebarHovering" class="af-badge absolute right-0.5 bottom-1 -translate-y-1/2 inline-flex items-center justify-center h-2 w-2 text-sm font-medium rounded-full bg-lightAnnouncementBG dark:bg-darkAnnouncementBG
52
52
  fill-lightAnnouncementText dark:fill-darkAccent text-lightAnnouncementText dark:text-darkAccent">
53
53
  </div>
54
54
  </RouterLink>
@@ -13,11 +13,13 @@
13
13
  :mode="mode"
14
14
  :unmasked="unmasked"
15
15
  :columnOptions="columnOptions"
16
- :validating="validating"
16
+ :validatingMode="validatingMode"
17
17
  :columnError="columnError"
18
18
  :setCurrentValue="setCurrentValue"
19
19
  @update:customComponentsInValidity="(data) => customComponentsInValidity = { ...customComponentsInValidity, ...data }"
20
20
  @update:customComponentsEmptiness="(data) => customComponentsEmptiness = { ...customComponentsEmptiness, ...data }"
21
+ :columnsWithErrors="columnsWithErrors"
22
+ :isValidating="isValidating"
21
23
  />
22
24
  </div>
23
25
  <div v-else class="flex flex-col gap-4">
@@ -31,11 +33,13 @@
31
33
  :mode="mode"
32
34
  :unmasked="unmasked"
33
35
  :columnOptions="columnOptions"
34
- :validating="validating"
36
+ :validatingMode="validatingMode"
35
37
  :columnError="columnError"
36
38
  :setCurrentValue="setCurrentValue"
37
39
  @update:customComponentsInValidity="(data) => customComponentsInValidity = { ...customComponentsInValidity, ...data }"
38
40
  @update:customComponentsEmptiness="(data) => customComponentsEmptiness = { ...customComponentsEmptiness, ...data }"
41
+ :columnsWithErrors="columnsWithErrors"
42
+ :isValidating="isValidating"
39
43
  />
40
44
  </template>
41
45
  <div v-if="otherColumns?.length || 0 > 0">
@@ -48,11 +52,13 @@
48
52
  :mode="mode"
49
53
  :unmasked="unmasked"
50
54
  :columnOptions="columnOptions"
51
- :validating="validating"
55
+ :validatingMode="validatingMode"
52
56
  :columnError="columnError"
53
57
  :setCurrentValue="setCurrentValue"
54
58
  @update:customComponentsInValidity="(data) => customComponentsInValidity = { ...customComponentsInValidity, ...data }"
55
59
  @update:customComponentsEmptiness="(data) => customComponentsEmptiness = { ...customComponentsEmptiness, ...data }"
60
+ :columnsWithErrors="columnsWithErrors"
61
+ :isValidating="isValidating"
56
62
  />
57
63
  </div>
58
64
  </div>
@@ -71,16 +77,20 @@ import { useCoreStore } from "@/stores/core";
71
77
  import GroupsTable from '@/components/GroupsTable.vue';
72
78
  import { useI18n } from 'vue-i18n';
73
79
  import { type AdminForthResourceColumnCommon, type AdminForthResourceCommon } from '@/types/Common';
80
+ import { Mutex } from 'async-mutex';
81
+ import debounce from 'lodash.debounce';
74
82
 
75
83
  const { t } = useI18n();
76
84
 
85
+ const mutex = new Mutex();
86
+
77
87
  const coreStore = useCoreStore();
78
88
  const router = useRouter();
79
89
  const route = useRoute();
80
90
  const props = defineProps<{
81
91
  resource: AdminForthResourceCommon,
82
92
  record: any,
83
- validating: boolean,
93
+ validatingMode: boolean,
84
94
  source: 'create' | 'edit',
85
95
  readonlyColumns?: string[],
86
96
  }>();
@@ -99,6 +109,11 @@ const columnOptions = ref<Record<string, any[]>>({});
99
109
  const columnLoadingState = reactive<Record<string, { loading: boolean; hasMore: boolean }>>({});
100
110
  const columnOffsets = reactive<Record<string, number>>({});
101
111
  const columnEmptyResultsCount = reactive<Record<string, number>>({});
112
+ const columnsWithErrors = ref<Record<string, string>>({});
113
+ const isValidating = ref(false);
114
+ const blockSettingIsValidating = ref(false);
115
+ const isValid = ref(true);
116
+ const doesUserHaveCustomValidation = computed(() => props.resource.columns.some(column => column.validation && column.validation.some((val) => val.validator)));
102
117
 
103
118
  const columnError = (column: AdminForthResourceColumnCommon) => {
104
119
  const val = computed(() => {
@@ -147,7 +162,7 @@ const columnError = (column: AdminForthResourceColumnCommon) => {
147
162
  return currentValues.value[column.name] && currentValues.value[column.name].reduce((error: any, item: any) => {
148
163
  if (column.isArray) {
149
164
  return error || validateValue(column.isArray.itemType, item, column) ||
150
- (item === null || !item.toString() ? t('Array cannot contain empty items') : null);
165
+ (item === null || (!item || item.toString() === '') ? t('Array cannot contain empty items') : null);
151
166
  } else {
152
167
  return error;
153
168
  }
@@ -329,10 +344,48 @@ const editableColumns = computed(() => {
329
344
  return props.resource?.columns?.filter(column => column.showIn?.[mode.value] && (currentValues.value ? checkShowIf(column, currentValues.value, props.resource.columns) : true));
330
345
  });
331
346
 
332
- const isValid = computed(() => {
333
- return editableColumns.value?.every(column => !columnError(column));
347
+ function checkIfColumnHasError(column: AdminForthResourceColumnCommon) {
348
+ const error = columnError(column);
349
+ if (error) {
350
+ columnsWithErrors.value[column.name] = error;
351
+ } else {
352
+ delete columnsWithErrors.value[column.name];
353
+ }
354
+ }
355
+
356
+ const checkIfAnyColumnHasErrors = () => {
357
+ return Object.keys(columnsWithErrors.value).length > 0 ? false : true;
358
+ }
359
+
360
+ const debouncedValidation = debounce(async (columns: AdminForthResourceColumnCommon[]) => {
361
+ await mutex.runExclusive(async () => {
362
+ await validateUsingUserValidationFunction(columns);
363
+ });
364
+ setIsValidatingValue(false);
365
+ isValid.value = checkIfAnyColumnHasErrors();
366
+ }, 500);
367
+
368
+ watch(() => [editableColumns.value, props.validatingMode], async () => {
369
+ setIsValidatingValue(true);
370
+
371
+ editableColumns.value?.forEach(column => {
372
+ checkIfColumnHasError(column);
373
+ });
374
+
375
+ if (props.validatingMode && doesUserHaveCustomValidation.value) {
376
+ debouncedValidation(editableColumns.value);
377
+ } else {
378
+ setIsValidatingValue(false);
379
+ isValid.value = checkIfAnyColumnHasErrors();
380
+ }
334
381
  });
335
382
 
383
+ const setIsValidatingValue = (value: boolean) => {
384
+ if (!blockSettingIsValidating.value) {
385
+ isValidating.value = value;
386
+ }
387
+ }
388
+
336
389
 
337
390
  const groups = computed(() => {
338
391
  let fieldGroupType;
@@ -381,9 +434,50 @@ watch(() => isValid.value, (value) => {
381
434
  emit('update:isValid', value);
382
435
  });
383
436
 
437
+ async function validateUsingUserValidationFunction(editableColumnsInner: AdminForthResourceColumnCommon[]): Promise<void> {
438
+ if (doesUserHaveCustomValidation.value) {
439
+ try {
440
+ blockSettingIsValidating.value = true;
441
+ const res = await callAdminForthApi({
442
+ method: 'POST',
443
+ path: '/validate_columns',
444
+ body: {
445
+ resourceId: props.resource.resourceId,
446
+ editableColumns: editableColumnsInner.map(col => {return {name: col.name, value: currentValues.value?.[col.name]} }),
447
+ record: currentValues.value,
448
+ }
449
+ })
450
+ if (res.validationResults && Object.keys(res.validationResults).length > 0) {
451
+ for (const [columnName, validationResult] of Object.entries(res.validationResults) as [string, any][]) {
452
+ if (!validationResult.isValid) {
453
+ columnsWithErrors.value[columnName] = validationResult.message || 'Invalid value';
454
+ } else {
455
+ delete columnsWithErrors.value[columnName];
456
+ }
457
+ }
458
+ const columnsToProcess = editableColumns.value.filter(col => res.validationResults[col.name] === undefined);
459
+ columnsToProcess.forEach(column => {
460
+ checkIfColumnHasError(column);
461
+ });
462
+ } else {
463
+ editableColumnsInner.forEach(column => {
464
+ checkIfColumnHasError(column);
465
+ });
466
+ }
467
+ blockSettingIsValidating.value = false;
468
+ } catch (e) {
469
+ console.error('Error during custom validation', e);
470
+ blockSettingIsValidating.value = false;
471
+ }
472
+ }
473
+ }
474
+
384
475
  defineExpose({
385
476
  columnError,
386
477
  editableColumns,
478
+ columnsWithErrors,
479
+ isValidating,
480
+ validateUsingUserValidationFunction
387
481
  })
388
482
 
389
483
  </script>
@@ -200,7 +200,7 @@
200
200
  :key="action.id"
201
201
  >
202
202
  <component
203
- v-if="action.customComponent"
203
+ v-if="action"
204
204
  :is="action.customComponent ? getCustomComponent(formatComponent(action.customComponent)) : CallActionWrapper"
205
205
  :meta="formatComponent(action.customComponent).meta"
206
206
  :row="row"
@@ -211,12 +211,18 @@
211
211
  <button
212
212
  type="button"
213
213
  class="border border-gray-300 dark:border-gray-700 dark:border-opacity-0 border-opacity-0 hover:border-opacity-100 dark:hover:border-opacity-100 rounded-md hover:bg-gray-100 dark:hover:bg-gray-800 cursor-pointer"
214
+ :disabled="!!actionLoadingStates[`${action.id}_${row._primaryKeyValue}`]"
214
215
  >
215
216
  <component
216
- v-if="action.icon"
217
+ v-if="action.icon && !actionLoadingStates[`${action.id}_${row._primaryKeyValue}`]"
217
218
  :is="getIcon(action.icon)"
218
219
  class="w-6 h-6 text-lightPrimary dark:text-darkPrimary"
219
220
  />
221
+ <Spinner
222
+ v-if="actionLoadingStates[`${action.id}_${row._primaryKeyValue}`]"
223
+ class="w-5 h-5 text-gray-200 dark:text-gray-500 fill-gray-500 dark:fill-gray-300"
224
+ />
225
+ <span v-if="actionLoadingStates[`${action.id}_${row._primaryKeyValue}`]" class="sr-only">Loading...</span>
220
226
  </button>
221
227
  </component>
222
228
 
@@ -356,7 +362,7 @@ import {
356
362
  IconInboxOutline
357
363
  } from '@iconify-prerendered/vue-flowbite';
358
364
  import router from '@/router';
359
- import { Tooltip } from '@/afcl';
365
+ import { Tooltip, Spinner } from '@/afcl';
360
366
  import type { AdminForthResourceCommon, AdminForthResourceColumnCommon, AdminForthComponentDeclarationFull, AdminForthComponentDeclaration } from '@/types/Common';
361
367
  import { useAdminforth } from '@/adminforth';
362
368
  import Checkbox from '@/afcl/Checkbox.vue';
@@ -613,7 +619,7 @@ async function startCustomAction(actionId: string | number, row: any, extraData:
613
619
  recordId: row._primaryKeyValue,
614
620
  extra: extraData,
615
621
  setLoadingState: (loading: boolean) => {
616
- actionLoadingStates.value[actionId] = loading;
622
+ actionLoadingStates.value[`${actionId}_${row._primaryKeyValue}`] = loading;
617
623
  },
618
624
  onSuccess: async (data: any) => {
619
625
  emits('update:records', true);
@@ -638,10 +644,10 @@ function validatePageInput() {
638
644
  pageInput.value = validPage.toString();
639
645
  }
640
646
  /*
641
- *___________________________________________________________________
642
- * |
643
- * Virtual Scroll Implementation |
644
- *___________________________________________________________________|
647
+ * ___________________________________________________________________
648
+ *| |
649
+ *| Virtual Scroll Implementation |
650
+ *|___________________________________________________________________|
645
651
  */
646
652
  // Add throttle utility
647
653
  const throttle = (fn: Function, delay: number) => {
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div class="overflow-x-auto shadow-resourseFormShadow dark:shadow-darkResourseFormShadow"
2
+ <div class="overflow-x-auto shadow-resourseFormShadow dark:shadow-darkResourseFormShadow border dark:border-gray-700"
3
3
  :class="{'rounded-default' : isRounded}"
4
4
  >
5
5
  <div v-if="groupName && !noTitle" class="text-md font-semibold px-6 py-3 flex flex-1 items-center text-lightShowTableHeadingText bg-lightShowTableHeadingBackground dark:bg-darkShowTableHeadingBackground dark:text-darkShowTableHeadingText rounded-t-lg">
@@ -71,7 +71,7 @@
71
71
  >
72
72
  <component v-if="item.icon" :is="getIcon(item.icon)" class="w-5 h-5 text-lightSidebarIcons group-hover:text-lightSidebarIconsHover transition duration-75 dark:group-hover:text-darkSidebarIconsHover dark:text-darkSidebarIcons" ></component>
73
73
  <span class="overflow-hidden flex-1 ms-3 text-left rtl:text-right whitespace-nowrap">{{ item.label }}
74
- <span v-if="item.badge" class="inline-flex items-center justify-center w-3 h-3 p-3 ms-3 text-sm font-medium rounded-full bg-lightAnnouncementBG dark:bg-darkAnnouncementBG
74
+ <span v-if="item.badge || item.badge === 0" class="inline-flex items-center justify-center w-3 h-3 p-3 ms-3 text-sm font-medium rounded-full bg-lightAnnouncementBG dark:bg-darkAnnouncementBG
75
75
  fill-lightAnnouncementText dark:fill-darkAccent text-lightAnnouncementText dark:text-darkAccent">
76
76
  <Tooltip v-if="item.badgeTooltip">
77
77
  {{ item.badge }}
@@ -90,13 +90,15 @@
90
90
  </svg>
91
91
  </button>
92
92
 
93
- <ul :id="`dropdown-example${i}`" role="none" class="af-sidebar-dropdown pt-1 space-y-1" :class="{ 'hidden': !opened.includes(i) }">
94
- <template v-for="(child, j) in item.children" :key="`menu-${i}-${j}`">
95
- <li class="af-sidebar-menu-link">
96
- <MenuLink :item="child" isChild="true" @click="$emit('hideSidebar')"/>
93
+ <transition name="slow-drop">
94
+ <ul v-show="opened.includes(i)" :id="`dropdown-example${i}`" role="none" class="af-sidebar-dropdown pt-1 space-y-1 overflow-hidden">
95
+ <template v-for="(child, j) in item.children" :key="`menu-${i}-${j}`">
96
+ <li class="af-sidebar-menu-link">
97
+ <MenuLink :item="child" isChild="true" @click="$emit('hideSidebar')"/>
97
98
  </li>
98
- </template>
99
- </ul>
99
+ </template>
100
+ </ul>
101
+ </transition>
100
102
  </li>
101
103
  <li v-else class="af-sidebar-menu-link">
102
104
  <MenuLink :item="item" @click="$emit('hideSidebar')"/>
@@ -129,7 +131,7 @@
129
131
  } : {}"
130
132
  >{{ item.label }}
131
133
 
132
- <span v-if="item.badge" class="inline-flex items-center justify-center w-3 h-3 p-3 ms-3 text-sm font-medium rounded-full bg-lightAnnouncementBG dark:bg-darkAnnouncementBG
134
+ <span v-if="item.badge || item.badge === 0" class="inline-flex items-center justify-center w-3 h-3 p-3 ms-3 text-sm font-medium rounded-full bg-lightAnnouncementBG dark:bg-darkAnnouncementBG
133
135
  fill-lightAnnouncementText dark:fill-darkAccent text-lightAnnouncementText dark:text-darkAccent">
134
136
  <Tooltip v-if="item.badgeTooltip">
135
137
  {{ item.badge }}
@@ -292,6 +294,25 @@
292
294
  background-color: rgba(75, 85, 99, 0.4);
293
295
  }
294
296
 
297
+ /* Custom animation for dropdown */
298
+ .slow-drop-enter-active,
299
+ .slow-drop-leave-active {
300
+ overflow: hidden;
301
+ transition: opacity 0.2s ease, transform 0.2s ease;
302
+ }
303
+
304
+ .slow-drop-enter-from,
305
+ .slow-drop-leave-to {
306
+ opacity: 0;
307
+ transform: translateY(-4px);
308
+ }
309
+
310
+ .slow-drop-enter-to,
311
+ .slow-drop-leave-from {
312
+ opacity: 1;
313
+ transform: translateY(0);
314
+ }
315
+
295
316
  /* For browsers that support overlay scrollbars natively */
296
317
  @supports (overflow: overlay) {
297
318
  .sidebar-scroll {
@@ -43,21 +43,28 @@
43
43
  </div>
44
44
  </div>
45
45
  </li>
46
- <li v-for="action in customActions" :key="action.id">
47
- <div class="wrapper">
46
+ <li v-for="(action, i) in customActions" :key="action.id">
47
+ <div
48
+ class="wrapper"
49
+ @click="injectedComponentClick(threeDotsDropdownItems ? threeDotsDropdownItems.length + i : i)"
50
+ >
48
51
  <component
49
- v-if="action.customComponent"
52
+ :ref="(el: any) => setComponentRef(el, threeDotsDropdownItems ? threeDotsDropdownItems.length + i : i)"
50
53
  :is="(action.customComponent && getCustomComponent(formatComponent(action.customComponent))) || CallActionWrapper"
51
54
  :meta="formatComponent(action.customComponent).meta"
52
55
  @callAction="(payload? : Object) => handleActionClick(action, payload)"
53
- >
54
- <a @click.prevent class="block px-4 py-2 hover:text-lightThreeDotsMenuBodyTextHover hover:bg-lightThreeDotsMenuBodyBackgroundHover dark:hover:bg-darkThreeDotsMenuBodyBackgroundHover dark:hover:text-darkThreeDotsMenuBodyTextHover">
55
- <div class="flex items-center gap-2">
56
+ ] >
57
+ <a @click.prevent class="block">
58
+ <div class="flex items-center gap-2 hover:text-lightThreeDotsMenuBodyTextHover hover:bg-lightThreeDotsMenuBodyBackgroundHover dark:hover:bg-darkThreeDotsMenuBodyBackgroundHover dark:hover:text-darkThreeDotsMenuBodyTextHover">
56
59
  <component
57
- v-if="action.icon"
60
+ v-if="action.icon && !actionLoadingStates[action.id!]"
58
61
  :is="getIcon(action.icon)"
59
62
  class="w-4 h-4 text-lightPrimary dark:text-darkPrimary"
60
63
  />
64
+ <Spinner
65
+ v-if="actionLoadingStates[action.id!]"
66
+ class="w-5 h-5 text-gray-200 dark:text-gray-500 fill-gray-500 dark:fill-gray-300"
67
+ />
61
68
  {{ action.name }}
62
69
  </div>
63
70
  </a>
@@ -92,12 +99,12 @@
92
99
  import { getCustomComponent, getIcon, formatComponent, executeCustomAction } from '@/utils';
93
100
  import { useCoreStore } from '@/stores/core';
94
101
  import { useAdminforth } from '@/adminforth';
95
- import { callAdminForthApi } from '@/utils';
96
102
  import { useRoute, useRouter } from 'vue-router';
97
103
  import CallActionWrapper from '@/components/CallActionWrapper.vue'
98
104
  import { ref, type ComponentPublicInstance, onMounted, onUnmounted } from 'vue';
99
105
  import type { AdminForthActionFront, AdminForthBulkActionFront, AdminForthComponentDeclarationFull } from '@/types/Common';
100
106
  import type { AdminForthActionInput } from '@/types/Back';
107
+ import { Spinner } from '@/afcl';
101
108
 
102
109
  const { list, alert} = useAdminforth();
103
110
  const route = useRoute();
@@ -105,6 +112,7 @@ const coreStore = useCoreStore();
105
112
  const router = useRouter();
106
113
  const threeDotsDropdownItemsRefs = ref<Array<ComponentPublicInstance | null>>([]);
107
114
  const showDropdown = ref(false);
115
+ const actionLoadingStates = ref<Record<string, boolean>>({});
108
116
  const dropdownRef = ref<HTMLElement | null>(null);
109
117
  const buttonTriggerRef = ref<HTMLElement | null>(null);
110
118
 
@@ -136,6 +144,9 @@ async function handleActionClick(action: AdminForthActionInput, payload: any) {
136
144
  resourceId: route.params.resourceId as string,
137
145
  recordId: route.params.primaryKey as string,
138
146
  extra: payload || {},
147
+ setLoadingState: (loading: boolean) => {
148
+ actionLoadingStates.value[action.id!] = loading;
149
+ },
139
150
  onSuccess: async (data: any) => {
140
151
  await coreStore.fetchRecord({
141
152
  resourceId: route.params.resourceId as string,
@@ -166,6 +177,7 @@ function startBulkAction(actionId: string) {
166
177
  }
167
178
 
168
179
  async function injectedComponentClick(index: number) {
180
+ console.log('Injected component click triggered for index:', index);
169
181
  const componentRef = threeDotsDropdownItemsRefs.value[index];
170
182
  if (componentRef && 'click' in componentRef) {
171
183
  (componentRef as any).click?.();
@@ -196,8 +208,11 @@ onUnmounted(() => {
196
208
  </script>
197
209
 
198
210
  <style lang="scss" scoped>
199
- .wrapper > * {
200
- @apply px-4 py-2;
211
+ .wrapper {
212
+ @apply px-4 py-2
213
+ hover:text-lightThreeDotsMenuBodyTextHover hover:bg-lightThreeDotsMenuBodyBackgroundHover
214
+ dark:hover:bg-darkThreeDotsMenuBodyBackgroundHover dark:hover:text-darkThreeDotsMenuBodyTextHover
215
+ cursor-pointer;
201
216
  }
202
217
  </style>
203
218
 
@@ -11,6 +11,7 @@
11
11
  class="rounded-md m-0.5 bg-lightAnnouncementBG dark:bg-darkAnnouncementBG text-lightAnnouncementText dark:text-darkAnnouncementText py-0.5 px-2.5 text-sm"
12
12
  >
13
13
  <RouterLink
14
+ v-if="foreignResource && foreignResource?.pk"
14
15
  class="font-medium text-lightSidebarText dark:text-darkSidebarText hover:brightness-110 whitespace-nowrap"
15
16
  :to="{
16
17
  name: 'resource-show',
@@ -1,4 +1,6 @@
1
1
  import type { AdminForthResource, AdminForthResourceColumn } from '../types/Back.js';
2
+ import type { FilterParams } from '@/types/Common';
3
+ import type { Ref, ComputedRef } from 'vue';
2
4
 
3
5
  export type resourceById = {
4
6
  [key: string]: AdminForthResource;
@@ -61,3 +63,33 @@ export type AllowedActions = {
61
63
  delete: boolean,
62
64
  }
63
65
 
66
+
67
+ export type sortType = {
68
+ field: string,
69
+ direction: 'ask' | 'desc'
70
+ } | null;
71
+
72
+ export type AdminforthFilterStore = {
73
+ filters: Ref<FilterParams[]>,
74
+
75
+ setSort: (sort: sortType) => void,
76
+ getSort: () => sortType,
77
+
78
+ setFilter: (filters: FilterParams) => void,
79
+ setFilters: (filters: FilterParams[]) => void,
80
+
81
+ getFilters: () => FilterParams[],
82
+
83
+ clearFilter: (fieldName: string) => void,
84
+ clearFilters: () => void,
85
+
86
+ shouldFilterBeHidden: (fieldName: string) => boolean,
87
+
88
+ visibleFiltersCount: ComputedRef<number>,
89
+ }
90
+
91
+ export interface AdminforthFilterStoreUnwrapped extends Omit<AdminforthFilterStore, 'filters' | 'visibleFiltersCount'> {
92
+ filters: FilterParams[],
93
+ visibleFiltersCount: number,
94
+ }
95
+
@@ -1,40 +1,42 @@
1
1
  import { ref, computed, type Ref } from 'vue';
2
2
  import { defineStore } from 'pinia';
3
3
  import { useCoreStore } from './core';
4
+ import type { FilterParams } from '@/types/Common';
5
+ import type { AdminforthFilterStore, sortType } from '../spa_types/core';
4
6
 
5
7
  export const useFiltersStore = defineStore('filters', () => {
6
- const filters: Ref<any[]> = ref([]);
7
- const sort: Ref<any> = ref({});
8
+ const filters: Ref<FilterParams[]> = ref([]);
9
+ const sort: Ref<sortType> = ref(null);
8
10
  const coreStore = useCoreStore();
9
11
 
10
- const setSort = (s: any) => {
12
+ const setSort = (s: sortType): void => {
11
13
  sort.value = s;
12
14
  }
13
- const getSort = () => {
15
+ const getSort = (): sortType => {
14
16
  return sort.value;
15
17
  }
16
- const setFilter = (filter: any) => {
18
+ const setFilter = (filter: FilterParams) => {
17
19
  const index = filters.value.findIndex(f => f.field === filter.field);
18
- if (filters.value[index] && filters.value[index].operator === filter.value.operator) {
20
+ if (filters.value[index] && filters.value[index].operator === filter.operator) {
19
21
  filters.value[index] = filter;
20
22
  return;
21
23
  }
22
24
  filters.value.push(filter);
23
25
  }
24
- const setFilters = (f: any) => {
26
+ const setFilters = (f: FilterParams[]) => {
25
27
  filters.value = f;
26
28
  }
27
- const getFilters = () => {
29
+ const getFilters = (): FilterParams[] => {
28
30
  return filters.value;
29
31
  }
30
- const clearFilter = (fieldName: string) => {
32
+ const clearFilter = (fieldName: string): void => {
31
33
  filters.value = filters.value.filter(f => f.field !== fieldName);
32
34
  }
33
- const clearFilters = () => {
35
+ const clearFilters = (): void => {
34
36
  filters.value = [];
35
37
  }
36
38
 
37
- const shouldFilterBeHidden = (fieldName: string) => {
39
+ const shouldFilterBeHidden = (fieldName: string): boolean => {
38
40
  if (coreStore.resource?.columns) {
39
41
  const column = coreStore.resource.columns.find((col: any) => col.name === fieldName);
40
42
  if (column?.showIn?.filter !== true) {
@@ -48,7 +50,7 @@ export const useFiltersStore = defineStore('filters', () => {
48
50
  return filters.value.filter(f => !shouldFilterBeHidden(f.field)).length;
49
51
  });
50
52
 
51
- return {
53
+ const store = {
52
54
  setFilter,
53
55
  getFilters,
54
56
  clearFilters,
@@ -60,4 +62,6 @@ export const useFiltersStore = defineStore('filters', () => {
60
62
  shouldFilterBeHidden,
61
63
  clearFilter
62
64
  }
65
+
66
+ return store as AdminforthFilterStore;
63
67
  })