@adminforth/import-export 1.6.2 → 1.7.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/build.log CHANGED
@@ -11,5 +11,5 @@ custom/package.json
11
11
  custom/pnpm-lock.yaml
12
12
  custom/tsconfig.json
13
13
 
14
- sent 17,878 bytes received 134 bytes 36,024.00 bytes/sec
15
- total size is 17,389 speedup is 0.97
14
+ sent 21,367 bytes received 134 bytes 43,002.00 bytes/sec
15
+ total size is 20,878 speedup is 0.97
@@ -1,33 +1,127 @@
1
1
  <template>
2
- <div class="cursor-pointer flex gap-2 items-center">
3
- {{$t("Export")}} {{ meta.select === 'all' ? $t('All'): $t('Filtered') }} {{$t('to CSV')}}
2
+ <div ref="rootRef" class="relative" @click.stop>
3
+ <div class="cursor-pointer flex gap-2 items-center justify-between -mx-4 -my-2 px-4 py-2" @click="toggle">
4
+ <span class="flex gap-2 items-center">
5
+ {{ $t('Export to CSV') }}
4
6
 
5
- <svg v-if="inProgress"
6
- aria-hidden="true" class="w-4 h-4 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
7
+ <svg v-if="inProgress"
8
+ aria-hidden="true" class="w-4 h-4 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
9
+ </span>
10
+ <svg class="w-2 h-2 shrink-0" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 6 10">
11
+ <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 1 1 5l4 4"/>
12
+ </svg>
13
+ </div>
14
+
15
+ <div v-if="open"
16
+ class="absolute right-full top-0 mr-5 z-40 w-max bg-lightThreeDotsMenuBodyBackground dark:bg-darkThreeDotsMenuBodyBackground rounded-lg shadow border border-gray-100 dark:border-gray-600">
17
+ <ul class="py-2 text-sm text-lightThreeDotsMenuBodyText dark:text-darkThreeDotsMenuBodyText">
18
+ <li v-for="option in options" :key="option.select">
19
+ <div
20
+ class="px-4 py-1.5 text-sm whitespace-nowrap"
21
+ :class="isDisabled(option)
22
+ ? 'opacity-50 cursor-not-allowed'
23
+ : 'cursor-pointer hover:text-lightThreeDotsMenuBodyTextHover hover:bg-lightThreeDotsMenuBodyBackgroundHover dark:hover:bg-darkThreeDotsMenuBodyBackgroundHover dark:hover:text-darkThreeDotsMenuBodyTextHover'"
24
+ @click="!isDisabled(option) && run(option.select)"
25
+ >
26
+ {{ option.label() }}
27
+ </div>
28
+ </li>
29
+ </ul>
30
+ </div>
7
31
  </div>
8
32
  </template>
9
33
 
10
34
  <script setup lang="ts">
11
- import { ref } from 'vue';
35
+ import { ref, onMounted, onUnmounted } from 'vue';
12
36
  import { useCoreStore } from '@/stores/core';
13
37
  import { callAdminForthApi } from '@/utils';
14
38
  import { useFiltersStore } from '@/stores/filters';
15
39
  import adminforth from '@/adminforth';
16
40
  import Papa from 'papaparse';
41
+ import { useI18n } from 'vue-i18n';
17
42
 
43
+ const { t } = useI18n();
18
44
  const filtersStore = useFiltersStore();
19
45
  const coreStore = useCoreStore();
20
46
  const inProgress = ref(false);
47
+ const open = ref(false);
48
+ const rootRef = ref<HTMLElement | null>(null);
49
+ const allCount = ref<number | null>(null);
50
+ const filteredCount = ref<number | null>(null);
21
51
 
22
52
  defineExpose({
23
- click,
53
+ click: () => { toggle(); },
24
54
  });
25
55
 
26
56
  const props = defineProps({
27
57
  meta: Object,
28
58
  record: Object,
59
+ checkboxes: Array,
29
60
  });
30
61
 
62
+ function formatCount(count: number) {
63
+ if (count < 1000) return `${count}`;
64
+ if (count < 1_000_000) return `${Math.floor(count / 1000)}k+`;
65
+ return `${Math.floor(count / 1_000_000)}M+`;
66
+ }
67
+
68
+ function withCount(label: string, count: number | null) {
69
+ return count === null ? `${label} (…)` : `${label} (${formatCount(count)})`;
70
+ }
71
+
72
+ const options = [
73
+ { select: 'all', label: () => withCount(t('All'), allCount.value) },
74
+ { select: 'filtered', label: () => withCount(t('Filtered'), filteredCount.value) },
75
+ { select: 'selected', label: () => `${t('Selected')} (${props.checkboxes?.length || 0})` },
76
+ ];
77
+
78
+ function isDisabled(option: { select: string }) {
79
+ return option.select === 'selected' && !(props.checkboxes?.length);
80
+ }
81
+
82
+ function handleClickOutside(e: MouseEvent) {
83
+ if (open.value && rootRef.value && !rootRef.value.contains(e.target as Node)) {
84
+ open.value = false;
85
+ }
86
+ }
87
+
88
+ onMounted(() => document.addEventListener('mousedown', handleClickOutside));
89
+ onUnmounted(() => document.removeEventListener('mousedown', handleClickOutside));
90
+
91
+ function toggle() {
92
+ open.value = !open.value;
93
+ if (open.value) {
94
+ fetchCounts();
95
+ }
96
+ }
97
+
98
+ async function fetchCounts() {
99
+ const resourceId = coreStore.resource?.resourceId;
100
+ if (!resourceId) {
101
+ return;
102
+ }
103
+ const countOnly = (filters: any) => callAdminForthApi({
104
+ path: '/get_resource_data',
105
+ method: 'POST',
106
+ body: { source: 'list', resourceId, limit: 1, offset: 0, filters, sort: [] },
107
+ });
108
+ try {
109
+ const [allResp, filteredResp] = await Promise.all([
110
+ countOnly([]),
111
+ countOnly(filtersStore.getFilters()),
112
+ ]);
113
+ allCount.value = allResp?.total ?? null;
114
+ filteredCount.value = filteredResp?.total ?? null;
115
+ } catch (e) {
116
+ // leave counts as null (renders "…") on failure
117
+ }
118
+ }
119
+
120
+ function run(select: string) {
121
+ open.value = false;
122
+ exportCsv(select);
123
+ }
124
+
31
125
  function downloadFile(data: string, filename: string) {
32
126
  const blob = new Blob([data], { type: 'text/csv' });
33
127
  const url = window.URL.createObjectURL(blob);
@@ -38,15 +132,16 @@ function downloadFile(data: string, filename: string) {
38
132
  window.URL.revokeObjectURL(url);
39
133
  }
40
134
 
41
- async function exportCsv() {
135
+ async function exportCsv(select: string) {
42
136
  inProgress.value = true;
43
137
  try {
44
138
  const resp = await callAdminForthApi({
45
- path: `/plugin/${props.meta.pluginInstanceId}/export-csv`,
139
+ path: `/plugin/${props.meta?.pluginInstanceId}/export-csv`,
46
140
  method: 'POST',
47
141
  body: {
48
- filters: props.meta.select === 'all' ? [] : filtersStore.getFilters(),
142
+ filters: select === 'filtered' ? filtersStore.getFilters() : [],
49
143
  sort: filtersStore.getSort(),
144
+ selectedIds: select === 'selected' ? props.checkboxes : undefined,
50
145
  }
51
146
  });
52
147
 
@@ -55,14 +150,14 @@ async function exportCsv() {
55
150
  }
56
151
 
57
152
  // Generate properly formatted CSV
58
- const csvContent = '\ufeff' + Papa.unparse(resp.data, {
153
+ const csvContent = '' + Papa.unparse(resp.data, {
59
154
  quotes: resp.columnsToForceQuote, // Force quotes only certain columns (!!!not all this breaks BI/Excel tasks)
60
155
  quoteChar: '"',
61
156
  escapeChar: '"',
62
157
  });
63
158
 
64
159
  // Download the file
65
- const filename = `export-${coreStore.resource.resourceId}-${new Date().toISOString()}.csv`;
160
+ const filename = `export-${coreStore.resource?.resourceId}-${new Date().toISOString()}.csv`;
66
161
  downloadFile(csvContent, filename);
67
162
 
68
163
  adminforth.alert({
@@ -78,8 +173,4 @@ async function exportCsv() {
78
173
  adminforth.list.closeThreeDotsDropdown();
79
174
  }
80
175
  }
81
-
82
- function click() {
83
- exportCsv();
84
- }
85
- </script>
176
+ </script>
@@ -1,33 +1,127 @@
1
1
  <template>
2
- <div class="cursor-pointer flex gap-2 items-center">
3
- {{$t("Export")}} {{ meta.select === 'all' ? $t('All'): $t('Filtered') }} {{$t('to CSV')}}
2
+ <div ref="rootRef" class="relative" @click.stop>
3
+ <div class="cursor-pointer flex gap-2 items-center justify-between -mx-4 -my-2 px-4 py-2" @click="toggle">
4
+ <span class="flex gap-2 items-center">
5
+ {{ $t('Export to CSV') }}
4
6
 
5
- <svg v-if="inProgress"
6
- aria-hidden="true" class="w-4 h-4 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
7
+ <svg v-if="inProgress"
8
+ aria-hidden="true" class="w-4 h-4 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
9
+ </span>
10
+ <svg class="w-2 h-2 shrink-0" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 6 10">
11
+ <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 1 1 5l4 4"/>
12
+ </svg>
13
+ </div>
14
+
15
+ <div v-if="open"
16
+ class="absolute right-full top-0 mr-5 z-40 w-max bg-lightThreeDotsMenuBodyBackground dark:bg-darkThreeDotsMenuBodyBackground rounded-lg shadow border border-gray-100 dark:border-gray-600">
17
+ <ul class="py-2 text-sm text-lightThreeDotsMenuBodyText dark:text-darkThreeDotsMenuBodyText">
18
+ <li v-for="option in options" :key="option.select">
19
+ <div
20
+ class="px-4 py-1.5 text-sm whitespace-nowrap"
21
+ :class="isDisabled(option)
22
+ ? 'opacity-50 cursor-not-allowed'
23
+ : 'cursor-pointer hover:text-lightThreeDotsMenuBodyTextHover hover:bg-lightThreeDotsMenuBodyBackgroundHover dark:hover:bg-darkThreeDotsMenuBodyBackgroundHover dark:hover:text-darkThreeDotsMenuBodyTextHover'"
24
+ @click="!isDisabled(option) && run(option.select)"
25
+ >
26
+ {{ option.label() }}
27
+ </div>
28
+ </li>
29
+ </ul>
30
+ </div>
7
31
  </div>
8
32
  </template>
9
33
 
10
34
  <script setup lang="ts">
11
- import { ref } from 'vue';
35
+ import { ref, onMounted, onUnmounted } from 'vue';
12
36
  import { useCoreStore } from '@/stores/core';
13
37
  import { callAdminForthApi } from '@/utils';
14
38
  import { useFiltersStore } from '@/stores/filters';
15
39
  import adminforth from '@/adminforth';
16
40
  import Papa from 'papaparse';
41
+ import { useI18n } from 'vue-i18n';
17
42
 
43
+ const { t } = useI18n();
18
44
  const filtersStore = useFiltersStore();
19
45
  const coreStore = useCoreStore();
20
46
  const inProgress = ref(false);
47
+ const open = ref(false);
48
+ const rootRef = ref<HTMLElement | null>(null);
49
+ const allCount = ref<number | null>(null);
50
+ const filteredCount = ref<number | null>(null);
21
51
 
22
52
  defineExpose({
23
- click,
53
+ click: () => { toggle(); },
24
54
  });
25
55
 
26
56
  const props = defineProps({
27
57
  meta: Object,
28
58
  record: Object,
59
+ checkboxes: Array,
29
60
  });
30
61
 
62
+ function formatCount(count: number) {
63
+ if (count < 1000) return `${count}`;
64
+ if (count < 1_000_000) return `${Math.floor(count / 1000)}k+`;
65
+ return `${Math.floor(count / 1_000_000)}M+`;
66
+ }
67
+
68
+ function withCount(label: string, count: number | null) {
69
+ return count === null ? `${label} (…)` : `${label} (${formatCount(count)})`;
70
+ }
71
+
72
+ const options = [
73
+ { select: 'all', label: () => withCount(t('All'), allCount.value) },
74
+ { select: 'filtered', label: () => withCount(t('Filtered'), filteredCount.value) },
75
+ { select: 'selected', label: () => `${t('Selected')} (${props.checkboxes?.length || 0})` },
76
+ ];
77
+
78
+ function isDisabled(option: { select: string }) {
79
+ return option.select === 'selected' && !(props.checkboxes?.length);
80
+ }
81
+
82
+ function handleClickOutside(e: MouseEvent) {
83
+ if (open.value && rootRef.value && !rootRef.value.contains(e.target as Node)) {
84
+ open.value = false;
85
+ }
86
+ }
87
+
88
+ onMounted(() => document.addEventListener('mousedown', handleClickOutside));
89
+ onUnmounted(() => document.removeEventListener('mousedown', handleClickOutside));
90
+
91
+ function toggle() {
92
+ open.value = !open.value;
93
+ if (open.value) {
94
+ fetchCounts();
95
+ }
96
+ }
97
+
98
+ async function fetchCounts() {
99
+ const resourceId = coreStore.resource?.resourceId;
100
+ if (!resourceId) {
101
+ return;
102
+ }
103
+ const countOnly = (filters: any) => callAdminForthApi({
104
+ path: '/get_resource_data',
105
+ method: 'POST',
106
+ body: { source: 'list', resourceId, limit: 1, offset: 0, filters, sort: [] },
107
+ });
108
+ try {
109
+ const [allResp, filteredResp] = await Promise.all([
110
+ countOnly([]),
111
+ countOnly(filtersStore.getFilters()),
112
+ ]);
113
+ allCount.value = allResp?.total ?? null;
114
+ filteredCount.value = filteredResp?.total ?? null;
115
+ } catch (e) {
116
+ // leave counts as null (renders "…") on failure
117
+ }
118
+ }
119
+
120
+ function run(select: string) {
121
+ open.value = false;
122
+ exportCsv(select);
123
+ }
124
+
31
125
  function downloadFile(data: string, filename: string) {
32
126
  const blob = new Blob([data], { type: 'text/csv' });
33
127
  const url = window.URL.createObjectURL(blob);
@@ -38,15 +132,16 @@ function downloadFile(data: string, filename: string) {
38
132
  window.URL.revokeObjectURL(url);
39
133
  }
40
134
 
41
- async function exportCsv() {
135
+ async function exportCsv(select: string) {
42
136
  inProgress.value = true;
43
137
  try {
44
138
  const resp = await callAdminForthApi({
45
- path: `/plugin/${props.meta.pluginInstanceId}/export-csv`,
139
+ path: `/plugin/${props.meta?.pluginInstanceId}/export-csv`,
46
140
  method: 'POST',
47
141
  body: {
48
- filters: props.meta.select === 'all' ? [] : filtersStore.getFilters(),
142
+ filters: select === 'filtered' ? filtersStore.getFilters() : [],
49
143
  sort: filtersStore.getSort(),
144
+ selectedIds: select === 'selected' ? props.checkboxes : undefined,
50
145
  }
51
146
  });
52
147
 
@@ -55,14 +150,14 @@ async function exportCsv() {
55
150
  }
56
151
 
57
152
  // Generate properly formatted CSV
58
- const csvContent = '\ufeff' + Papa.unparse(resp.data, {
153
+ const csvContent = '' + Papa.unparse(resp.data, {
59
154
  quotes: resp.columnsToForceQuote, // Force quotes only certain columns (!!!not all this breaks BI/Excel tasks)
60
155
  quoteChar: '"',
61
156
  escapeChar: '"',
62
157
  });
63
158
 
64
159
  // Download the file
65
- const filename = `export-${coreStore.resource.resourceId}-${new Date().toISOString()}.csv`;
160
+ const filename = `export-${coreStore.resource?.resourceId}-${new Date().toISOString()}.csv`;
66
161
  downloadFile(csvContent, filename);
67
162
 
68
163
  adminforth.alert({
@@ -78,8 +173,4 @@ async function exportCsv() {
78
173
  adminforth.list.closeThreeDotsDropdown();
79
174
  }
80
175
  }
81
-
82
- function click() {
83
- exportCsv();
84
- }
85
- </script>
176
+ </script>
package/dist/index.js CHANGED
@@ -13,6 +13,7 @@ import { z } from "zod";
13
13
  const exportCsvBodySchema = z.object({
14
14
  filters: z.any(),
15
15
  sort: z.any(),
16
+ selectedIds: z.array(z.any()).optional(),
16
17
  }).strict();
17
18
  const importCsvBodySchema = z.object({
18
19
  data: z.record(z.string(), z.array(z.unknown())),
@@ -92,10 +93,7 @@ export default class ImportExport extends AdminForthPlugin {
92
93
  }
93
94
  resourceConfig.options.pageInjections.list.threeDotsDropdownItems.push({
94
95
  file: this.componentPath('ExportCsv.vue'),
95
- meta: { pluginInstanceId: this.pluginInstanceId, select: 'all' }
96
- }, {
97
- file: this.componentPath('ExportCsv.vue'),
98
- meta: { pluginInstanceId: this.pluginInstanceId, select: 'filtered' }
96
+ meta: { pluginInstanceId: this.pluginInstanceId }
99
97
  }, {
100
98
  file: this.componentPath('ImportCsv.vue'),
101
99
  meta: { pluginInstanceId: this.pluginInstanceId }
@@ -124,7 +122,7 @@ export default class ImportExport extends AdminForthPlugin {
124
122
  request_schema: exportCsvBodySchema,
125
123
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers, response }) {
126
124
  const payload = body;
127
- const { filters, sort } = payload;
125
+ const { filters, sort, selectedIds } = payload;
128
126
  if (!filters || !sort) {
129
127
  return { ok: false, error: 'Missing filters or sort in request body' };
130
128
  }
@@ -139,11 +137,23 @@ export default class ImportExport extends AdminForthPlugin {
139
137
  if (rawFilterError) {
140
138
  return rawFilterError;
141
139
  }
140
+ let effectiveFilters = filters;
141
+ if (Array.isArray(selectedIds) && selectedIds.length > 0) {
142
+ const primaryKeyColumn = this.resourceConfig.columns.find(col => col.primaryKey);
143
+ if (!primaryKeyColumn) {
144
+ return { ok: false, error: 'Cannot export selected records: resource has no primary key' };
145
+ }
146
+ effectiveFilters = [{
147
+ field: primaryKeyColumn.name,
148
+ operator: AdminForthFilterOperators.IN,
149
+ value: selectedIds,
150
+ }];
151
+ }
142
152
  const data = yield this.adminforth.connectors[this.resourceConfig.dataSource].getData({
143
153
  resource: this.resourceConfig,
144
154
  limit: 1e6,
145
155
  offset: 0,
146
- filters: this.adminforth.connectors[this.resourceConfig.dataSource].validateAndNormalizeInputFilters(filters),
156
+ filters: this.adminforth.connectors[this.resourceConfig.dataSource].validateAndNormalizeInputFilters(effectiveFilters),
147
157
  sort,
148
158
  getTotals: true,
149
159
  });
@@ -165,7 +175,7 @@ export default class ImportExport extends AdminForthPlugin {
165
175
  return value;
166
176
  });
167
177
  });
168
- this.tryToAuditLogAction('export', `Export CSV with filters: ${JSON.stringify(filters)} and sort: ${JSON.stringify(sort)}. Total records: ${rows.length}`, adminUser, headers);
178
+ this.tryToAuditLogAction('export', `Export CSV with filters: ${JSON.stringify(effectiveFilters)} and sort: ${JSON.stringify(sort)}. Total records: ${rows.length}`, adminUser, headers);
169
179
  return {
170
180
  data: { fields, data: rows },
171
181
  columnsToForceQuote,
package/index.ts CHANGED
@@ -7,6 +7,7 @@ import { z } from "zod";
7
7
  const exportCsvBodySchema = z.object({
8
8
  filters: z.any(),
9
9
  sort: z.any(),
10
+ selectedIds: z.array(z.any()).optional(),
10
11
  }).strict();
11
12
 
12
13
  const importCsvBodySchema = z.object({
@@ -105,10 +106,7 @@ export default class ImportExport extends AdminForthPlugin {
105
106
  }
106
107
  (resourceConfig.options.pageInjections.list.threeDotsDropdownItems as AdminForthComponentDeclaration[]).push({
107
108
  file: this.componentPath('ExportCsv.vue'),
108
- meta: { pluginInstanceId: this.pluginInstanceId, select: 'all' }
109
- }, {
110
- file: this.componentPath('ExportCsv.vue'),
111
- meta: { pluginInstanceId: this.pluginInstanceId, select: 'filtered' }
109
+ meta: { pluginInstanceId: this.pluginInstanceId }
112
110
  }, {
113
111
  file: this.componentPath('ImportCsv.vue'),
114
112
  meta: { pluginInstanceId: this.pluginInstanceId }
@@ -140,7 +138,7 @@ export default class ImportExport extends AdminForthPlugin {
140
138
  request_schema: exportCsvBodySchema,
141
139
  handler: async ({ body, adminUser, headers, response }) => {
142
140
  const payload = body as z.infer<typeof exportCsvBodySchema>;
143
- const { filters, sort } = payload;
141
+ const { filters, sort, selectedIds } = payload;
144
142
  if (!filters || !sort) {
145
143
  return { ok: false, error: 'Missing filters or sort in request body' };
146
144
  }
@@ -159,11 +157,25 @@ export default class ImportExport extends AdminForthPlugin {
159
157
  if (rawFilterError) {
160
158
  return rawFilterError;
161
159
  }
160
+
161
+ let effectiveFilters = filters;
162
+ if (Array.isArray(selectedIds) && selectedIds.length > 0) {
163
+ const primaryKeyColumn = this.resourceConfig.columns.find(col => col.primaryKey);
164
+ if (!primaryKeyColumn) {
165
+ return { ok: false, error: 'Cannot export selected records: resource has no primary key' };
166
+ }
167
+ effectiveFilters = [{
168
+ field: primaryKeyColumn.name,
169
+ operator: AdminForthFilterOperators.IN,
170
+ value: selectedIds,
171
+ }];
172
+ }
173
+
162
174
  const data = await this.adminforth.connectors[this.resourceConfig.dataSource].getData({
163
175
  resource: this.resourceConfig,
164
176
  limit: 1e6,
165
177
  offset: 0,
166
- filters: this.adminforth.connectors[this.resourceConfig.dataSource].validateAndNormalizeInputFilters(filters),
178
+ filters: this.adminforth.connectors[this.resourceConfig.dataSource].validateAndNormalizeInputFilters(effectiveFilters),
167
179
  sort,
168
180
  getTotals: true,
169
181
  });
@@ -189,7 +201,7 @@ export default class ImportExport extends AdminForthPlugin {
189
201
  });
190
202
  });
191
203
 
192
- this.tryToAuditLogAction('export', `Export CSV with filters: ${JSON.stringify(filters)} and sort: ${JSON.stringify(sort)}. Total records: ${rows.length}`, adminUser, headers);
204
+ this.tryToAuditLogAction('export', `Export CSV with filters: ${JSON.stringify(effectiveFilters)} and sort: ${JSON.stringify(sort)}. Total records: ${rows.length}`, adminUser, headers);
193
205
 
194
206
  return {
195
207
  data: { fields, data: rows },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/import-export",
3
- "version": "1.6.2",
3
+ "version": "1.7.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",