@nkhang1902/strapi-plugin-export-import-clsx 1.4.0 → 1.4.2

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.
@@ -0,0 +1,128 @@
1
+ import { useState, useRef } from "react";
2
+ import {
3
+ Button,
4
+ } from "@strapi/design-system";
5
+ import { Download, Upload } from "@strapi/icons";
6
+ import { useNotification } from "@strapi/strapi/admin";
7
+
8
+ const ExportButtonsEditView = (props) => {
9
+ const [isExporting, setIsExporting] = useState(false);
10
+ const { toggleNotification } = useNotification();
11
+ const allowedContentTypes = [
12
+ "api::site-visit.site-visit",
13
+ "api::lunch-attending.lunch-attending",
14
+ "api::experience-networking.experience-networking",
15
+ "api::tour.tour",
16
+ ];
17
+
18
+ // Get current content type from props or URL
19
+ const getContentType = () => {
20
+ if (props.layout?.uid) {
21
+ return props.layout.uid;
22
+ }
23
+ // Fallback: extract from URL - handle both content-manager and event-manager
24
+ const path = window.location.pathname;
25
+
26
+ // For event-manager plugin
27
+ const eventManagerMatch = path.match(
28
+ /\/admin\/plugins\/event-manager\/([^\/]+)\/([^\/]+)/
29
+ );
30
+ if (eventManagerMatch) {
31
+ return eventManagerMatch[2]; // Return the collectionType, not the eventId
32
+ }
33
+
34
+ // For content-manager
35
+ const contentManagerMatch = path.match(
36
+ /\/admin\/content-manager\/collection-types\/([^\/]+)/
37
+ );
38
+ if (contentManagerMatch) {
39
+ return contentManagerMatch[1];
40
+ }
41
+
42
+ return null;
43
+ };
44
+
45
+ const currentContentType = getContentType();
46
+
47
+ const handleExport = async () => {
48
+ const contentType = getContentType();
49
+ if (!contentType) {
50
+ toggleNotification({
51
+ type: "danger",
52
+ message: "Could not determine content type",
53
+ });
54
+ return;
55
+ }
56
+
57
+ setIsExporting(true);
58
+ try {
59
+ const parts = window.location.pathname.split('/').filter(Boolean);
60
+ const documentId = parts[parts.indexOf('event-manager') + 3];
61
+ console.log(documentId)
62
+ const queryParams = new URLSearchParams({
63
+ format: "excel",
64
+ contentType: contentType,
65
+ });
66
+
67
+ // Add event filter if we're in event manager
68
+ if (documentId) {
69
+ queryParams.set(
70
+ `filters[documentId][$eq]`,
71
+ documentId
72
+ );
73
+ }
74
+
75
+ const response = await fetch(`/export-import-clsx/export?${queryParams}&mode=participant`);
76
+
77
+ if (response.ok) {
78
+ const blob = await response.blob();
79
+ const url = window.URL.createObjectURL(blob);
80
+ const a = document.createElement("a");
81
+ a.href = url;
82
+
83
+ const filename = `${contentType.replace("api::", "")}-export-${
84
+ new Date().toISOString().split("T")[0]
85
+ }.xlsx`;
86
+
87
+ a.download = filename;
88
+ document.body.appendChild(a);
89
+ a.click();
90
+ window.URL.revokeObjectURL(url);
91
+ document.body.removeChild(a);
92
+
93
+ toggleNotification({
94
+ type: "success",
95
+ message: "Successfully exported data",
96
+ });
97
+ } else {
98
+ throw new Error("Export failed");
99
+ }
100
+ } catch (error) {
101
+ toggleNotification({
102
+ type: "danger",
103
+ message: `Export failed: ${error.message}`,
104
+ });
105
+ } finally {
106
+ setIsExporting(false);
107
+ }
108
+ };
109
+
110
+ if (!allowedContentTypes.includes(currentContentType)) {
111
+ return null
112
+ }
113
+ return (
114
+ <>
115
+ <Button
116
+ onClick={handleExport}
117
+ loading={isExporting}
118
+ startIcon={<Download />}
119
+ variant="secondary"
120
+ fullWidth
121
+ >
122
+ Export Participants
123
+ </Button>
124
+ </>
125
+ );
126
+ };
127
+
128
+ export default ExportButtonsEditView;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nkhang1902/strapi-plugin-export-import-clsx",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "A powerful Strapi plugin for exporting and importing data with Excel support and advanced filtering",
5
5
  "main": "./strapi-server.js",
6
6
  "scripts": {
@@ -1,7 +1,7 @@
1
1
  module.exports = ({ strapi }) => ({
2
2
  async export(ctx) {
3
3
  try {
4
- const { format = "excel", contentType, ...filters } = ctx.query;
4
+ const { format = "excel", contentType, mode, ...filters } = ctx.query;
5
5
  const exportService = strapi
6
6
  .plugin("export-import-clsx")
7
7
  .service("export-service");
@@ -28,7 +28,8 @@ module.exports = ({ strapi }) => ({
28
28
  const data = await exportService.exportData(
29
29
  "json",
30
30
  contentType,
31
- filters
31
+ filters,
32
+ mode
32
33
  );
33
34
 
34
35
  const filename = `${
@@ -1,7 +1,7 @@
1
1
  const XLSX = require("xlsx");
2
2
 
3
3
  module.exports = ({ strapi }) => ({
4
- async exportData(format = "json", contentType = null, rawFilters = {}) {
4
+ async exportData(format = "json", contentType = null, rawFilters = {}, mode) {
5
5
  // Normalize content type - handle both content-manager and event-manager formats
6
6
  if (contentType && !contentType.startsWith("api::")) {
7
7
  // If it's already in api:: format from event-manager, use as is
@@ -102,6 +102,7 @@ module.exports = ({ strapi }) => ({
102
102
  } catch (error) {
103
103
  strapi.log.error(`Failed to query entries:`, error);
104
104
  }
105
+ console.log({entries})
105
106
 
106
107
  strapi.log.info(
107
108
  `Final result: ${
package/strapi-admin.js CHANGED
@@ -2,6 +2,7 @@ import pluginPkg from "./package.json";
2
2
  import pluginId from "./admin/src/pluginId";
3
3
  import Initializer from "./admin/src/components/Initializer";
4
4
  import ExportImportButtons from "./admin/src/components/ExportImportButtons";
5
+ import ExportImportButtonsEditView from "./admin/src/components/ExportImportButtonsEditView";
5
6
 
6
7
  const name = pluginPkg.strapi.name;
7
8
 
@@ -20,10 +21,17 @@ export default {
20
21
  bootstrap(app) {
21
22
  const contentManager = app.getPlugin("content-manager");
22
23
  if (contentManager && contentManager.injectComponent) {
24
+ // Inject into list view
23
25
  contentManager.injectComponent("listView", "actions", {
24
26
  name: "export-import-buttons",
25
27
  Component: ExportImportButtons,
26
28
  });
29
+
30
+ // Inject into edit view
31
+ contentManager.injectComponent("editView", "right-links", {
32
+ name: "export-import-buttons-edit",
33
+ Component: ExportImportButtonsEditView,
34
+ });
27
35
  }
28
36
  },
29
- };
37
+ };