@tunghtml/strapi-plugin-filtered-relation 1.1.1 → 1.1.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.1.3] - 2024-12-02
4
+
5
+ ### Changed
6
+
7
+ - **Package cleanup**: Added `files` field to package.json to only publish necessary files
8
+ - Removed unnecessary files from npm package (push-to-github.sh, PUBLISH.md, etc.)
9
+ - Reduces package size and keeps it clean
10
+ - Only includes: admin/, server/, strapi-admin.js, strapi-server.js, README.md, CHANGELOG.md
11
+
12
+ ## [1.1.2] - 2024-12-02
13
+
14
+ ### Fixed
15
+
16
+ - **Critical Bug - Data Loss Prevention**: Fixed critical bug where disconnect operation happened before validating target record existence
17
+ - Previously: Disconnected investor first, then checked if target exists → data loss if target missing
18
+ - Now: Validates ALL conditions first (target exists, data valid), then performs disconnect/connect
19
+ - Prevents "Investor not found in current record" error on subsequent operations
20
+ - Users can now safely perform multiple status changes without page refresh
21
+ - **Improved Error Notifications**: Changed error notification type from "warning" to "danger"
22
+ - Makes errors more visible and distinguishable from warnings
23
+ - Helps users quickly identify critical issues that need attention
24
+
25
+ ### Changed
26
+
27
+ - Reordered `handleStatusChange` logic flow:
28
+ 1. Get current record data
29
+ 2. Find investor to move
30
+ 3. **Validate target record exists** (NEW - moved before disconnect)
31
+ 4. **Validate target data is valid** (NEW)
32
+ 5. Disconnect from current record (only after validation passes)
33
+ 6. Connect to target record
34
+ 7. Refresh UI
35
+ - All error notifications now use `type: "danger"` instead of `type: "warning"`
36
+
37
+ ### Technical Details
38
+
39
+ - Added validation check for target record data integrity before any mutations
40
+ - Prevents partial state updates that could leave data in inconsistent state
41
+ - Follows transaction-like pattern: validate everything, then commit changes
42
+
3
43
  ## [1.1.1] - 2024-12-02
4
44
 
5
45
  ### Fixed
@@ -172,35 +172,14 @@ const FilteredRelationInput = (props) => {
172
172
  "[FilteredRelation] Investor not found in current record"
173
173
  );
174
174
  toggleNotification({
175
- type: "warning",
175
+ type: "danger",
176
176
  message:
177
177
  "Investor not found in current record. Please refresh the page.",
178
178
  });
179
179
  return;
180
180
  }
181
181
 
182
- // Build full payload like UI admin does
183
- const updatePayload = {
184
- documentId: currentData.documentId,
185
- [displayField]: {
186
- connect: [],
187
- disconnect: [
188
- {
189
- id: investorToRemove.id,
190
- documentId: investorToRemove.documentId,
191
- },
192
- ],
193
- },
194
- participantStatus: currentData.participantStatus,
195
- };
196
-
197
- // Use disconnect with full payload
198
- const removeResponse = await put(
199
- `/content-manager/collection-types/${targetModel}/${itemId}`,
200
- updatePayload
201
- );
202
-
203
- // Step 3: Find Meeting Participation Status with new status (same meeting)
182
+ // Step 3: VALIDATE target record EXISTS BEFORE disconnecting (critical fix)
204
183
  const newFilterParams = {};
205
184
  if (filterField1) {
206
185
  newFilterParams[filterField1] = newStatus;
@@ -229,16 +208,13 @@ const FilteredRelationInput = (props) => {
229
208
  searchResponse?.data ||
230
209
  [];
231
210
 
232
- let targetRecordId;
233
- let targetInvestors = [];
234
-
235
211
  if (targetRecords.length === 0) {
236
212
  console.error(
237
213
  "[FilteredRelation] No target record found with new status for this meeting."
238
214
  );
239
215
  const collectionDisplayName = targetModelInput || "record";
240
216
  toggleNotification({
241
- type: "warning",
217
+ type: "danger",
242
218
  message: `No ${collectionDisplayName} found with status "${newStatus}" for this meeting. Please create one first.`,
243
219
  });
244
220
  return;
@@ -246,14 +222,44 @@ const FilteredRelationInput = (props) => {
246
222
 
247
223
  // Get full target record data
248
224
  const targetRecord = targetRecords[0];
249
- targetRecordId = targetRecord.documentId || targetRecord.id;
225
+ const targetRecordId = targetRecord.documentId || targetRecord.id;
250
226
 
251
227
  // Get target record with all fields
252
228
  const targetRecordUrl = `/content-manager/collection-types/${targetModel}/${targetRecordId}?populate=*`;
253
229
  const targetRecordFull = await get(targetRecordUrl);
254
230
  const targetData = targetRecordFull?.data?.data || {};
255
231
 
256
- // Step 4: Add investor to target record
232
+ if (!targetData || !targetData.documentId) {
233
+ console.error("[FilteredRelation] Target record data is invalid");
234
+ toggleNotification({
235
+ type: "danger",
236
+ message: "Target record not found. Please refresh and try again.",
237
+ });
238
+ return;
239
+ }
240
+
241
+ // Step 4: NOW disconnect from current record (after validation passed)
242
+ const updatePayload = {
243
+ documentId: currentData.documentId,
244
+ [displayField]: {
245
+ connect: [],
246
+ disconnect: [
247
+ {
248
+ id: investorToRemove.id,
249
+ documentId: investorToRemove.documentId,
250
+ },
251
+ ],
252
+ },
253
+ participantStatus: currentData.participantStatus,
254
+ };
255
+
256
+ // Use disconnect with full payload
257
+ const removeResponse = await put(
258
+ `/content-manager/collection-types/${targetModel}/${itemId}`,
259
+ updatePayload
260
+ );
261
+
262
+ // Step 5: Add investor to target record
257
263
  // Build full payload like UI admin does
258
264
  const addPayload = {
259
265
  documentId: targetData.documentId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tunghtml/strapi-plugin-filtered-relation",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "A Strapi custom field plugin for displaying filtered relations with dynamic placeholder support and status change capability",
5
5
  "keywords": [
6
6
  "strapi",
@@ -10,6 +10,14 @@
10
10
  "filter",
11
11
  "strapi5"
12
12
  ],
13
+ "files": [
14
+ "admin",
15
+ "server",
16
+ "strapi-admin.js",
17
+ "strapi-server.js",
18
+ "README.md",
19
+ "CHANGELOG.md"
20
+ ],
13
21
  "strapi": {
14
22
  "name": "filtered-relation",
15
23
  "displayName": "Filtered Relation",
package/PUBLISH.md DELETED
@@ -1,94 +0,0 @@
1
- # Publishing Guide
2
-
3
- ## Prerequisites
4
-
5
- 1. Make sure you're logged in to npm:
6
-
7
- ```bash
8
- npm login
9
- ```
10
-
11
- 2. Verify your npm account has access to publish `@tunghtml` scoped packages
12
-
13
- ## Steps to Publish
14
-
15
- ### 1. Test Locally First
16
-
17
- The plugin is already configured as a local plugin in `backend/config/plugins.js`:
18
-
19
- ```javascript
20
- "filtered-relation": {
21
- enabled: true,
22
- resolve: "./src/plugins/filtered-relation",
23
- }
24
- ```
25
-
26
- Test thoroughly in your local Strapi instance before publishing.
27
-
28
- ### 2. Update Version
29
-
30
- Update version in `package.json`:
31
-
32
- - Patch: 1.1.0 -> 1.1.1 (bug fixes)
33
- - Minor: 1.1.0 -> 1.2.0 (new features, backward compatible)
34
- - Major: 1.1.0 -> 2.0.0 (breaking changes)
35
-
36
- ### 3. Publish to NPM
37
-
38
- From the plugin directory:
39
-
40
- ```bash
41
- cd backend/src/plugins/filtered-relation
42
- npm publish --access public
43
- ```
44
-
45
- ### 4. Update Project to Use NPM Package
46
-
47
- After publishing, you can switch back to using the npm package:
48
-
49
- 1. Update `backend/package.json`:
50
-
51
- ```json
52
- {
53
- "dependencies": {
54
- "@tunghtml/strapi-plugin-filtered-relation": "^1.1.0"
55
- }
56
- }
57
- ```
58
-
59
- 2. Update `backend/config/plugins.js`:
60
-
61
- ```javascript
62
- "filtered-relation": {
63
- enabled: true,
64
- // Remove the resolve line to use npm package
65
- }
66
- ```
67
-
68
- 3. Install the package:
69
-
70
- ```bash
71
- cd backend
72
- yarn install
73
- ```
74
-
75
- ## Current Version
76
-
77
- Version 1.1.0 includes:
78
-
79
- - Status change dropdown feature
80
- - Dynamic status options from schema
81
- - Auto-refresh on status change
82
- - Backward compatible with 1.0.0
83
-
84
- ## Testing Checklist
85
-
86
- Before publishing, verify:
87
-
88
- - [ ] Plugin loads without errors
89
- - [ ] Filtered relations display correctly
90
- - [ ] Status dropdown shows correct options
91
- - [ ] Status change updates the record
92
- - [ ] Lists refresh automatically after status change
93
- - [ ] Works with different content types (reusable)
94
- - [ ] No console errors
package/push-to-github.sh DELETED
@@ -1,52 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Script to push plugin to GitHub
4
- # Usage: ./push-to-github.sh
5
-
6
- set -e
7
-
8
- echo "🚀 Pushing strapi-plugin-filtered-relation to GitHub..."
9
-
10
- # Check if we're in the right directory
11
- if [ ! -f "package.json" ]; then
12
- echo "❌ Error: package.json not found. Are you in the plugin directory?"
13
- exit 1
14
- fi
15
-
16
- # Check if git is initialized
17
- if [ ! -d ".git" ]; then
18
- echo "📦 Initializing git repository..."
19
- git init
20
- git remote add origin https://github.com/finnwasabi/strapi-plugin-filtered-relation.git
21
- fi
22
-
23
- # Add all files
24
- echo "📝 Adding files..."
25
- git add .
26
-
27
- # Commit
28
- echo "💾 Committing changes..."
29
- git commit -m "Release v1.1.0 - Add status change dropdown feature
30
-
31
- - Add status change dropdown at end of each item
32
- - Dynamically fetch enum options from target model schema
33
- - Move items between records using connect/disconnect API
34
- - Dispatch custom events to refresh all fields without page reload
35
- - Remove all console.log statements
36
- - Update README with detailed options table and descriptions
37
- - Update CHANGELOG with technical details
38
- - Fully dynamic and reusable for any use case"
39
-
40
- # Tag the release
41
- echo "🏷️ Creating tag v1.1.0..."
42
- git tag -a v1.1.0 -m "Version 1.1.0"
43
-
44
- # Push to GitHub
45
- echo "⬆️ Pushing to GitHub..."
46
- git push origin main
47
- git push origin v1.1.0
48
-
49
- echo "✅ Successfully pushed to GitHub!"
50
- echo "📦 Package: @tunghtml/strapi-plugin-filtered-relation@1.1.0"
51
- echo "🔗 GitHub: https://github.com/finnwasabi/strapi-plugin-filtered-relation"
52
- echo "🔗 NPM: https://www.npmjs.com/package/@tunghtml/strapi-plugin-filtered-relation"