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

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,24 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.1.1] - 2024-12-02
4
+
5
+ ### Fixed
6
+
7
+ - **State Refresh Issue**: Fixed "Investor not found in current record" error that occurred after status changes
8
+ - Now refreshes local state immediately after disconnect/connect operations
9
+ - Prevents stale data issues when performing multiple status changes without page reload
10
+ - Reordered refresh logic: local field first, then dispatch event to other fields
11
+ - **User Experience**: Replaced browser `alert()` with Strapi's native notification system
12
+ - Success notifications for successful status changes
13
+ - Warning notifications for missing records or data issues
14
+ - Danger notifications for errors
15
+ - All notifications use `useNotification` hook from `@strapi/strapi/admin`
16
+
17
+ ### Changed
18
+
19
+ - Improved notification messages to be more user-friendly
20
+ - Enhanced error handling with proper notification types
21
+
3
22
  ## [1.1.0] - 2024-12-02
4
23
 
5
24
  ### Added
@@ -8,12 +8,13 @@ import {
8
8
  SingleSelect,
9
9
  SingleSelectOption,
10
10
  } from "@strapi/design-system";
11
- import { useFetchClient } from "@strapi/strapi/admin";
11
+ import { useFetchClient, useNotification } from "@strapi/strapi/admin";
12
12
  import { useLocation, useNavigate } from "react-router-dom";
13
13
 
14
14
  const FilteredRelationInput = (props) => {
15
15
  const { formatMessage } = useIntl();
16
16
  const { get, put } = useFetchClient();
17
+ const { toggleNotification } = useNotification();
17
18
  const location = useLocation();
18
19
  const navigate = useNavigate();
19
20
  const [items, setItems] = React.useState([]);
@@ -96,7 +97,7 @@ const FilteredRelationInput = (props) => {
96
97
  data: {
97
98
  [name]: newValue,
98
99
  },
99
- },
100
+ }
100
101
  );
101
102
  } catch (err) {
102
103
  console.error("Error auto-saving filtered relation:", err);
@@ -116,7 +117,7 @@ const FilteredRelationInput = (props) => {
116
117
  // Try 1: Get from content-type-builder (most reliable for schema)
117
118
  try {
118
119
  const builderResponse = await get(
119
- `/content-type-builder/content-types/${targetModel}`,
120
+ `/content-type-builder/content-types/${targetModel}`
120
121
  );
121
122
  const builderSchema = builderResponse?.data?.data?.schema;
122
123
  enumValues = builderSchema?.attributes?.[statusField]?.enum;
@@ -168,9 +169,13 @@ const FilteredRelationInput = (props) => {
168
169
 
169
170
  if (!investorToRemove) {
170
171
  console.error(
171
- "[FilteredRelation] Investor not found in current record",
172
+ "[FilteredRelation] Investor not found in current record"
172
173
  );
173
- alert("Investor not found in current record");
174
+ toggleNotification({
175
+ type: "warning",
176
+ message:
177
+ "Investor not found in current record. Please refresh the page.",
178
+ });
174
179
  return;
175
180
  }
176
181
 
@@ -192,7 +197,7 @@ const FilteredRelationInput = (props) => {
192
197
  // Use disconnect with full payload
193
198
  const removeResponse = await put(
194
199
  `/content-manager/collection-types/${targetModel}/${itemId}`,
195
- updatePayload,
200
+ updatePayload
196
201
  );
197
202
 
198
203
  // Step 3: Find Meeting Participation Status with new status (same meeting)
@@ -229,12 +234,13 @@ const FilteredRelationInput = (props) => {
229
234
 
230
235
  if (targetRecords.length === 0) {
231
236
  console.error(
232
- "[FilteredRelation] No target record found with new status for this meeting.",
237
+ "[FilteredRelation] No target record found with new status for this meeting."
233
238
  );
234
239
  const collectionDisplayName = targetModelInput || "record";
235
- alert(
236
- `No ${collectionDisplayName} found with status "${newStatus}" for this meeting. Please create one first.`,
237
- );
240
+ toggleNotification({
241
+ type: "warning",
242
+ message: `No ${collectionDisplayName} found with status "${newStatus}" for this meeting. Please create one first.`,
243
+ });
238
244
  return;
239
245
  }
240
246
 
@@ -266,21 +272,29 @@ const FilteredRelationInput = (props) => {
266
272
  // Use connect with full payload
267
273
  const addResponse = await put(
268
274
  `/content-manager/collection-types/${targetModel}/${targetRecordId}`,
269
- addPayload,
275
+ addPayload
270
276
  );
271
277
 
272
- // Dispatch custom event to trigger refresh of all filtered relation fields
278
+ // Refresh current field first to update local state
279
+ await fetchFilteredData();
280
+
281
+ // Then dispatch custom event to trigger refresh of all other filtered relation fields
273
282
  window.dispatchEvent(
274
283
  new CustomEvent("filtered-relation-updated", {
275
284
  detail: { documentId, targetModel },
276
- }),
285
+ })
277
286
  );
278
287
 
279
- // Refresh current field
280
- await fetchFilteredData();
288
+ toggleNotification({
289
+ type: "success",
290
+ message: "Status changed successfully",
291
+ });
281
292
  } catch (err) {
282
293
  console.error("[FilteredRelation] Error moving investor:", err);
283
- alert("Failed to change status. Check console for details.");
294
+ toggleNotification({
295
+ type: "danger",
296
+ message: "Failed to change status. Please try again.",
297
+ });
284
298
  } finally {
285
299
  setUpdatingStatus((prev) => ({ ...prev, [itemId]: false }));
286
300
  }
@@ -387,7 +401,7 @@ const FilteredRelationInput = (props) => {
387
401
 
388
402
  // Auto-save to database
389
403
  const documentIds = formattedItems.map(
390
- (item) => item.relatedDocumentId || item.id,
404
+ (item) => item.relatedDocumentId || item.id
391
405
  );
392
406
  const newValue = JSON.stringify(documentIds);
393
407
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tunghtml/strapi-plugin-filtered-relation",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
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",
@@ -0,0 +1,52 @@
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"