adminforth 1.0.44 → 1.0.46

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/dist/index.js CHANGED
@@ -88,6 +88,12 @@ class AdminForth {
88
88
  if (res.itemLabel && typeof res.itemLabel !== 'function') {
89
89
  errors.push(`Resource "${res.dataSource}" itemLabel is not a function`);
90
90
  }
91
+ if (!res.itemLabel) {
92
+ res.itemLabel = (item) => {
93
+ const pkVal = item[res.columns.find((col) => col.primaryKey).name];
94
+ return `${res.label} ${pkVal}`;
95
+ };
96
+ }
91
97
  res.resourceId = res.resourceId || res.table;
92
98
  res.label = res.label || res.table.charAt(0).toUpperCase() + res.table.slice(1);
93
99
  if (!res.dataSource) {
@@ -519,7 +525,7 @@ class AdminForth {
519
525
  });
520
526
  const targetDataMap = targetData.data.reduce((acc, item) => {
521
527
  acc[item[targetResourcePkField]] = {
522
- label: targetResource.itemLabel ? targetResource.itemLabel(item) : item[targetResourcePkField],
528
+ label: targetResource.itemLabel(item),
523
529
  pk: item[targetResourcePkField],
524
530
  };
525
531
  return acc;
@@ -528,6 +534,9 @@ class AdminForth {
528
534
  item[col.name] = targetDataMap[item[col.name]];
529
535
  });
530
536
  })));
537
+ data.data.forEach((item) => {
538
+ item._label = resource.itemLabel(item);
539
+ });
531
540
  if ((_o = (_m = resource.hooks) === null || _m === void 0 ? void 0 : _m[source]) === null || _o === void 0 ? void 0 : _o.afterDatasourceRequest) {
532
541
  const resp = yield ((_q = (_p = resource.hooks) === null || _p === void 0 ? void 0 : _p[source]) === null || _q === void 0 ? void 0 : _q.afterDatasourceRequest({ resource, response: data.data, adminUser }));
533
542
  if (!resp || (!resp.ok && !resp.error)) {
@@ -584,7 +593,7 @@ class AdminForth {
584
593
  });
585
594
  const items = dbDataItems.data.map((item) => {
586
595
  const pk = item[targetResource.columns.find((col) => col.primaryKey).name];
587
- const labler = targetResource.itemLabel || ((record) => `${targetResource.label} ${pk}`);
596
+ const labler = targetResource.itemLabel;
588
597
  return {
589
598
  value: pk,
590
599
  label: labler(item),
@@ -73,6 +73,9 @@
73
73
  <template v-for="(item, i) in coreStore.menu" :key="`menu-${i}`">
74
74
  <div v-if="item.type === 'divider'" class="border-t border-gray-200 dark:border-gray-700"></div>
75
75
  <div v-else-if="item.type === 'gap'" class="flex items-center justify-center h-8"></div>
76
+ <div v-else-if="item.type === 'heading'" class="flex items-center justify-left pl-2 h-8 opacity-40
77
+ ">{{ item.label }}</div>
78
+
76
79
 
77
80
  <li v-else-if="item.children">
78
81
  <button type="button" class="flex items-center w-full p-2 text-base text-gray-900 transition duration-75 rounded-lg group hover:bg-gray-100 dark:text-white dark:hover:bg-gray-700"
@@ -87,7 +90,7 @@
87
90
  </svg>
88
91
  </button>
89
92
 
90
- <ul :id="`dropdown-example${i}`" role="none" class="py-2 space-y-2" :class="{ 'hidden': !item.open }">
93
+ <ul :id="`dropdown-example${i}`" role="none" class="pt-1 space-y-1" :class="{ 'hidden': !item.open }">
91
94
  <template v-for="(child, j) in item.children" :key="`menu-${i}-${j}`">
92
95
  <li>
93
96
  <MenuLink :item="child" isChild="true" />
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <RouterLink
3
3
  :to="{name: item.resourceId ? 'resource-list' : item.path, params: item.resourceId ? { resourceId: item.resourceId }: {}}"
4
- class="flex items-center py-2 text-sm text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-600 dark:hover:text-white" role="menuitem"
4
+ class="flex items-center py-2 text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-600 dark:hover:text-white" role="menuitem"
5
5
  :class="{
6
6
  'px-4': isChild,
7
7
  'px-2': !isChild,
package/index.ts CHANGED
@@ -110,6 +110,12 @@ class AdminForth {
110
110
  if (res.itemLabel && typeof res.itemLabel !== 'function') {
111
111
  errors.push(`Resource "${res.dataSource}" itemLabel is not a function`);
112
112
  }
113
+ if (!res.itemLabel) {
114
+ res.itemLabel = (item) => {
115
+ const pkVal = item[res.columns.find((col) => col.primaryKey).name];
116
+ return `${res.label} ${pkVal}`;
117
+ }
118
+ }
113
119
 
114
120
 
115
121
  res.resourceId = res.resourceId || res.table;
@@ -589,7 +595,7 @@ class AdminForth {
589
595
  });
590
596
  const targetDataMap = targetData.data.reduce((acc, item) => {
591
597
  acc[item[targetResourcePkField]] = {
592
- label: targetResource.itemLabel ? targetResource.itemLabel(item) : item[targetResourcePkField],
598
+ label: targetResource.itemLabel(item),
593
599
  pk: item[targetResourcePkField],
594
600
  }
595
601
  return acc;
@@ -600,6 +606,10 @@ class AdminForth {
600
606
  })
601
607
  );
602
608
 
609
+ data.data.forEach((item) => {
610
+ item._label = resource.itemLabel(item)
611
+ })
612
+
603
613
 
604
614
  if (resource.hooks?.[source]?.afterDatasourceRequest) {
605
615
  const resp = await resource.hooks?.[source]?.afterDatasourceRequest({ resource, response: data.data, adminUser });
@@ -659,7 +669,7 @@ class AdminForth {
659
669
  });
660
670
  const items = dbDataItems.data.map((item) => {
661
671
  const pk = item[targetResource.columns.find((col) => col.primaryKey).name];
662
- const labler = targetResource.itemLabel || ((record) => `${targetResource.label} ${pk}`);
672
+ const labler = targetResource.itemLabel;
663
673
  return {
664
674
  value: pk,
665
675
  label: labler(item),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminforth",
3
- "version": "1.0.44",
3
+ "version": "1.0.46",
4
4
  "description": "OpenSource Vue3 powered forth-generation admin panel",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/spa/src/App.vue CHANGED
@@ -73,6 +73,9 @@
73
73
  <template v-for="(item, i) in coreStore.menu" :key="`menu-${i}`">
74
74
  <div v-if="item.type === 'divider'" class="border-t border-gray-200 dark:border-gray-700"></div>
75
75
  <div v-else-if="item.type === 'gap'" class="flex items-center justify-center h-8"></div>
76
+ <div v-else-if="item.type === 'heading'" class="flex items-center justify-left pl-2 h-8 opacity-40
77
+ ">{{ item.label }}</div>
78
+
76
79
 
77
80
  <li v-else-if="item.children">
78
81
  <button type="button" class="flex items-center w-full p-2 text-base text-gray-900 transition duration-75 rounded-lg group hover:bg-gray-100 dark:text-white dark:hover:bg-gray-700"
@@ -87,7 +90,7 @@
87
90
  </svg>
88
91
  </button>
89
92
 
90
- <ul :id="`dropdown-example${i}`" role="none" class="py-2 space-y-2" :class="{ 'hidden': !item.open }">
93
+ <ul :id="`dropdown-example${i}`" role="none" class="pt-1 space-y-1" :class="{ 'hidden': !item.open }">
91
94
  <template v-for="(child, j) in item.children" :key="`menu-${i}-${j}`">
92
95
  <li>
93
96
  <MenuLink :item="child" isChild="true" />
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <RouterLink
3
3
  :to="{name: item.resourceId ? 'resource-list' : item.path, params: item.resourceId ? { resourceId: item.resourceId }: {}}"
4
- class="flex items-center py-2 text-sm text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-600 dark:hover:text-white" role="menuitem"
4
+ class="flex items-center py-2 text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-600 dark:hover:text-white" role="menuitem"
5
5
  :class="{
6
6
  'px-4': isChild,
7
7
  'px-2': !isChild,
@@ -1,6 +1,7 @@
1
1
 
2
2
 
3
3
  export type AdminForthConfigMenuItem = {
4
+ type: 'heading' | 'group' | 'resource' | 'page' | undefined,
4
5
  label: string,
5
6
  icon?: string,
6
7
  path?: string,