Skip to content

Commit 7f2d31a

Browse files
authored
Merge pull request #717 from gadget-inc/alan/fix-nested-delete
Fix unable to delete values in hasMany field in useActionForm
2 parents ba5d20a + 82f7cb9 commit 7f2d31a

File tree

5 files changed

+112
-14
lines changed

5 files changed

+112
-14
lines changed

packages/react/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @gadgetinc/react
22

3+
## 0.18.6
4+
5+
### Patch Changes
6+
7+
- Fixed bug with `useActionForm` hook where it failed to properly update or delete records in `hasMany` fields if the IDs have more than 2 digits
8+
39
## 0.18.5
410

511
### Patch Changes

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gadgetinc/react",
3-
"version": "0.18.5",
3+
"version": "0.18.6",
44
"files": [
55
"README.md",
66
"dist/**/*",

packages/react/spec/__recordings__/useActionFormNested_1974165259/with-polly_2612993081/can-update-multiple-HasMany-relationships-that-are-reordered_1591436327/recording.har

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
}
165165
},
166166
{
167-
"_id": "0523aa94388d3d9c8c46302084a73ecf",
167+
"_id": "92f0993ea7a9aba2b2055384d7e2c25b",
168168
"_order": 0,
169169
"cache": {},
170170
"request": {
@@ -212,7 +212,7 @@
212212
"postData": {
213213
"mimeType": "application/json",
214214
"params": [],
215-
"text": "{\"operationName\":\"updateQuiz\",\"query\":\"mutation updateQuiz($id: GadgetID!, $quiz: UpdateQuizInput) {\\n updateQuiz(id: $id, quiz: $quiz) {\\n success\\n errors {\\n message\\n code\\n ... on InvalidRecordError {\\n model {\\n apiIdentifier\\n __typename\\n }\\n validationErrors {\\n message\\n apiIdentifier\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n quiz {\\n id\\n text\\n questions {\\n edges {\\n node {\\n id\\n text\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n gadgetMeta {\\n hydrations(modelName: \\n\\\"quiz\\\")\\n __typename\\n }\\n}\",\"variables\":{\"id\":\"168\",\"quiz\":{\"questions\":[{\"update\":{\"id\":\"1775\",\"text\":\"test question updated - 2\"}},{\"update\":{\"id\":\"1774\",\"text\":\"test question updated - 1\"}}],\"text\":\"test quiz updated\"}}}"
215+
"text": "{\"operationName\":\"updateQuiz\",\"query\":\"mutation updateQuiz($id: GadgetID!, $quiz: UpdateQuizInput) {\\n updateQuiz(id: $id, quiz: $quiz) {\\n success\\n errors {\\n message\\n code\\n ... on InvalidRecordError {\\n model {\\n apiIdentifier\\n __typename\\n }\\n validationErrors {\\n message\\n apiIdentifier\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n quiz {\\n id\\n text\\n questions {\\n edges {\\n node {\\n id\\n text\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n gadgetMeta {\\n hydrations(modelName: \\n\\\"quiz\\\")\\n __typename\\n }\\n}\",\"variables\":{\"id\":\"168\",\"quiz\":{\"questions\":[{\"update\":{\"id\":\"1774\",\"text\":\"test question updated - 1\"}},{\"update\":{\"id\":\"1775\",\"text\":\"test question updated - 2\"}}],\"text\":\"test quiz updated\"}}}"
216216
},
217217
"queryString": [
218218
{
@@ -228,13 +228,13 @@
228228
"encoding": "base64",
229229
"mimeType": "application/json; charset=utf-8",
230230
"size": 432,
231-
"text": "[\"H4sIAAAAAAAAA5yRy07DMBBFfyWatSEJpXl4VwFCLFgUwQqhyrIH1yJ1gj2R+lD+Hblpi9QoqtSlZ+6cO567AyVIAN9B2yhBOG/NNrx8KyV6D5xciwzQudp54LatKga/B5FRwCHNCmBAuCbgQOgpCu2oxykIavRkauvDCCqNHvjnDmyt8B+S5/cDSj92JEU3UQoMFgvaNGjFCoHD/KCBbqTxpDRCx4Zu08tud1e6fY10H2prUY4AzHZQ/DgF8oa+rSgItFAa6RX7yJYb5cTptNJh2HwW/vQoCN/NCoEdcj0rn3s977mzpqmM3BP3Fl3HANeE1h89qlp74LAkajyPY63ptjL2Jw71OJ0mWVLEQpRqkucqK8qJKPNpkWYqS4qs/C4nhUQZLu+ExJcQxUVx1/0BAAD//wMAgXoqlqMCAAA=\"]"
231+
"text": "[\"H4sIAAAAAAAAA5yRy2rDMBBFf8XMWq3jxk4c7UJbShddpLSrUoKQRoqoI7vSGPLA/16UVyHBBLLUzJ1zR3O3oAQJ4FtoGyUIZ63dxFdopcQQgJNvkQF6X/sA3LVVxeD3ILIKOGSjEhgQrgg4EAZKYjvZ4xRENQaytQtxBJXBAPxrC65W+A8Zj/MLyn7sSErukgwYzOe0btCJJQKH2UEDXU/jWRmEjl26FdfdHm50++7pPtbOoewB2M1F8fMUyDuGtqIoMEIZpDfcR7ZYKy9Op5Ue4+bT+KcnQfhhlwjskOtZ+dzrZcedNk1l5Y64s+g6BrgidOHoUdUmAIcFURN4mhpD95V1P2msp1kxGA3KVOvBJB9lY11qnGgtM6ELlQ9FPsxEOczjWckLia8xiqvirvsDAAD//wMADUUduqMCAAA=\"]"
232232
},
233233
"cookies": [],
234234
"headers": [
235235
{
236236
"name": "date",
237-
"value": "Fri, 06 Dec 2024 18:26:09 GMT"
237+
"value": "Tue, 07 Jan 2025 21:02:45 GMT"
238238
},
239239
{
240240
"name": "content-type",
@@ -246,7 +246,7 @@
246246
},
247247
{
248248
"name": "connection",
249-
"value": "keep-alive"
249+
"value": "close"
250250
},
251251
{
252252
"name": "vary",
@@ -266,11 +266,11 @@
266266
},
267267
{
268268
"name": "x-request-id",
269-
"value": "dd9c1c42bb00562cc941b60f9875c713"
269+
"value": "0156942aef23942a95f428e359420f1c"
270270
},
271271
{
272272
"name": "x-trace-id",
273-
"value": "aa9d377d6893a975816d60869f938cec"
273+
"value": "ff094617f8fe9ffc1af5d43a431a8342"
274274
},
275275
{
276276
"name": "strict-transport-security",
@@ -290,7 +290,7 @@
290290
},
291291
{
292292
"name": "cf-ray",
293-
"value": "8ede5285385d6a57-EWR"
293+
"value": "8fe6e3f029c6a235-YYZ"
294294
},
295295
{
296296
"name": "content-encoding",
@@ -301,22 +301,22 @@
301301
"value": "h3=\":443\"; ma=86400"
302302
}
303303
],
304-
"headersSize": 617,
304+
"headersSize": 612,
305305
"httpVersion": "HTTP/1.1",
306306
"redirectURL": "",
307307
"status": 200,
308308
"statusText": "OK"
309309
},
310-
"startedDateTime": "2024-12-06T18:26:06.129Z",
311-
"time": 3295,
310+
"startedDateTime": "2025-01-07T21:02:43.029Z",
311+
"time": 2698,
312312
"timings": {
313313
"blocked": -1,
314314
"connect": -1,
315315
"dns": -1,
316316
"receive": 0,
317317
"send": 0,
318318
"ssl": -1,
319-
"wait": 3295
319+
"wait": 2698
320320
}
321321
}
322322
],

packages/react/spec/useActionFormNested.spec.tsx

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,6 +2177,62 @@ describe("useActionFormNested", () => {
21772177
},
21782178
},
21792179
},
2180+
{
2181+
node: {
2182+
id: "11",
2183+
name: "John Doe",
2184+
followerFriendships: {
2185+
edges: [
2186+
{
2187+
node: {
2188+
id: "11",
2189+
follower: {
2190+
id: "1100",
2191+
name: "Jane Doe",
2192+
},
2193+
},
2194+
},
2195+
{
2196+
node: {
2197+
id: "12",
2198+
follower: {
2199+
id: "1101",
2200+
name: "John Smith",
2201+
},
2202+
},
2203+
},
2204+
],
2205+
},
2206+
},
2207+
},
2208+
{
2209+
node: {
2210+
id: "12",
2211+
name: "Bob Sacamano",
2212+
followerFriendships: {
2213+
edges: [
2214+
{
2215+
node: {
2216+
id: "13",
2217+
follower: {
2218+
id: "1102",
2219+
name: "Jim Doe",
2220+
},
2221+
},
2222+
},
2223+
{
2224+
node: {
2225+
id: "14",
2226+
follower: {
2227+
id: "1103",
2228+
name: "Jill Doe",
2229+
},
2230+
},
2231+
},
2232+
],
2233+
},
2234+
},
2235+
},
21802236
],
21812237
},
21822238
},
@@ -2198,6 +2254,7 @@ describe("useActionFormNested", () => {
21982254

21992255
await act(async () => {
22002256
tweetersFieldArrayHook.current.remove(0);
2257+
tweetersFieldArrayHook.current.remove(2);
22012258
tweetersFieldArrayHook.current.append({
22022259
name: "Joe Davola",
22032260
followerFriendships: [{ followerId: "1001" }],
@@ -2251,6 +2308,41 @@ describe("useActionFormNested", () => {
22512308
"name": "Bob Sacamano",
22522309
},
22532310
},
2311+
{
2312+
"update": {
2313+
"followerFriendships": [
2314+
{
2315+
"update": {
2316+
"follower": {
2317+
"update": {
2318+
"id": "1100",
2319+
"name": "Jane Doe",
2320+
},
2321+
},
2322+
"id": "11",
2323+
},
2324+
},
2325+
{
2326+
"update": {
2327+
"follower": {
2328+
"update": {
2329+
"id": "1101",
2330+
"name": "John Smith",
2331+
},
2332+
},
2333+
"id": "12",
2334+
},
2335+
},
2336+
],
2337+
"id": "11",
2338+
"name": "John Doe",
2339+
},
2340+
},
2341+
{
2342+
"delete": {
2343+
"id": "12",
2344+
},
2345+
},
22542346
{
22552347
"create": {
22562348
"followerFriendships": [

packages/react/src/use-action-form/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function getRecordIdsAtPath(data: any): Record<string, number[]> {
180180
}
181181

182182
if (depth > 1) {
183-
const newPath = isInArray ? path?.substring(0, path.length - 2) : path;
183+
const newPath = isInArray ? path?.split(".").slice(0, -1).join(".") : path;
184184

185185
if ("id" in input) {
186186
if (!updateList[newPath!]) {

0 commit comments

Comments
 (0)