Skip to content

Commit de444a3

Browse files
authored
fix: copy paste search params in resources (#5412)
Reproduced when tried to insert the new baserow template
1 parent 021c62e commit de444a3

File tree

10 files changed

+91
-6
lines changed

10 files changed

+91
-6
lines changed

apps/builder/app/shared/copy-paste.test.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ describe("resources", () => {
578578
const resourceVariable = new ResourceValue("Box Resource", {
579579
url: expression`${boxVariable}`,
580580
method: "get",
581+
searchParams: [{ name: "filter", value: expression`${boxVariable}` }],
581582
headers: [{ name: "auth", value: expression`${boxVariable}` }],
582583
body: expression`${boxVariable}`,
583584
});
@@ -594,6 +595,7 @@ describe("resources", () => {
594595
expect(fragment.resources).toEqual([
595596
expect.objectContaining({
596597
url: "$ws$dataSource$1",
598+
searchParams: [{ name: "filter", value: "$ws$dataSource$1" }],
597599
headers: [{ name: "auth", value: "$ws$dataSource$1" }],
598600
body: "$ws$dataSource$1",
599601
}),
@@ -605,6 +607,7 @@ describe("resources", () => {
605607
const resourceVariable = new ResourceValue("Box Resource", {
606608
url: expression`${bodyVariable}`,
607609
method: "get",
610+
searchParams: [{ name: "filter", value: expression`${bodyVariable}` }],
608611
headers: [{ name: "auth", value: expression`${bodyVariable}` }],
609612
body: expression`${bodyVariable}`,
610613
});
@@ -620,6 +623,7 @@ describe("resources", () => {
620623
expect(fragment.resources).toEqual([
621624
expect.objectContaining({
622625
url: "Body$32$Variable",
626+
searchParams: [{ name: "filter", value: "Body$32$Variable" }],
623627
headers: [{ name: "auth", value: "Body$32$Variable" }],
624628
body: "Body$32$Variable",
625629
}),
@@ -631,6 +635,7 @@ describe("resources", () => {
631635
const resourceVariable = new ResourceValue("Box Resource", {
632636
url: expression`${bodyVariable}`,
633637
method: "get",
638+
searchParams: [{ name: "filter", value: expression`${bodyVariable}` }],
634639
headers: [{ name: "auth", value: expression`${bodyVariable}` }],
635640
body: expression`${bodyVariable}`,
636641
});
@@ -654,11 +659,13 @@ describe("resources", () => {
654659
expect(Array.from(data.resources.values())).toEqual([
655660
expect.objectContaining({
656661
url: "$ws$dataSource$0",
662+
searchParams: [{ name: "filter", value: "$ws$dataSource$0" }],
657663
headers: [{ name: "auth", value: "$ws$dataSource$0" }],
658664
body: "$ws$dataSource$0",
659665
}),
660666
expect.objectContaining({
661667
url: "$ws$dataSource$0",
668+
searchParams: [{ name: "filter", value: "$ws$dataSource$0" }],
662669
headers: [{ name: "auth", value: "$ws$dataSource$0" }],
663670
body: "$ws$dataSource$0",
664671
}),
@@ -670,6 +677,7 @@ describe("resources", () => {
670677
const resourceProp = new ResourceValue("Box Resource", {
671678
url: expression`${boxVariable}`,
672679
method: "get",
680+
searchParams: [{ name: "filter", value: expression`${boxVariable}` }],
673681
headers: [{ name: "auth", value: expression`${boxVariable}` }],
674682
body: expression`${boxVariable}`,
675683
});
@@ -685,6 +693,7 @@ describe("resources", () => {
685693
expect(fragment.resources).toEqual([
686694
expect.objectContaining({
687695
url: "$ws$dataSource$1",
696+
searchParams: [{ name: "filter", value: "$ws$dataSource$1" }],
688697
headers: [{ name: "auth", value: "$ws$dataSource$1" }],
689698
body: "$ws$dataSource$1",
690699
}),
@@ -696,6 +705,7 @@ describe("resources", () => {
696705
const resourceProp = new ResourceValue("Box Resource", {
697706
url: expression`${bodyVariable}`,
698707
method: "get",
708+
searchParams: [{ name: "filter", value: expression`${bodyVariable}` }],
699709
headers: [{ name: "auth", value: expression`${bodyVariable}` }],
700710
body: expression`${bodyVariable}`,
701711
});
@@ -709,6 +719,7 @@ describe("resources", () => {
709719
expect(fragment.resources).toEqual([
710720
expect.objectContaining({
711721
url: "Body$32$Variable",
722+
searchParams: [{ name: "filter", value: "Body$32$Variable" }],
712723
headers: [{ name: "auth", value: "Body$32$Variable" }],
713724
body: "Body$32$Variable",
714725
}),
@@ -720,6 +731,7 @@ describe("resources", () => {
720731
const resourceProp = new ResourceValue("Box Resource", {
721732
url: expression`${bodyVariable}`,
722733
method: "get",
734+
searchParams: [{ name: "filter", value: expression`${bodyVariable}` }],
723735
headers: [{ name: "auth", value: expression`${bodyVariable}` }],
724736
body: expression`${bodyVariable}`,
725737
});
@@ -743,11 +755,13 @@ describe("resources", () => {
743755
expect(Array.from(data.resources.values())).toEqual([
744756
expect.objectContaining({
745757
url: "$ws$dataSource$0",
758+
searchParams: [{ name: "filter", value: "$ws$dataSource$0" }],
746759
headers: [{ name: "auth", value: "$ws$dataSource$0" }],
747760
body: "$ws$dataSource$0",
748761
}),
749762
expect.objectContaining({
750763
url: "$ws$dataSource$0",
764+
searchParams: [{ name: "filter", value: "$ws$dataSource$0" }],
751765
headers: [{ name: "auth", value: "$ws$dataSource$0" }],
752766
body: "$ws$dataSource$0",
753767
}),
@@ -759,12 +773,14 @@ describe("resources", () => {
759773
const resourceProp = new ResourceValue("Box Resource", {
760774
url: expression`${boxVariable}`,
761775
method: "get",
776+
searchParams: [{ name: "filter", value: expression`${boxVariable}` }],
762777
headers: [{ name: "auth", value: expression`${boxVariable}` }],
763778
body: expression`${boxVariable}`,
764779
});
765780
const resourceVariable = new ResourceValue("Box Resource", {
766781
url: expression`${boxVariable}`,
767782
method: "get",
783+
searchParams: [{ name: "filter", value: expression`${boxVariable}` }],
768784
headers: [{ name: "auth", value: expression`${boxVariable}` }],
769785
body: expression`${boxVariable}`,
770786
});
@@ -798,12 +814,14 @@ describe("resources", () => {
798814
expect.objectContaining({
799815
id: expect.toSatisfy((value) => value !== fragment.resources[0].id),
800816
url: newVariableIdentifier,
817+
searchParams: [{ name: "filter", value: newVariableIdentifier }],
801818
headers: [{ name: "auth", value: newVariableIdentifier }],
802819
body: newVariableIdentifier,
803820
}),
804821
expect.objectContaining({
805822
id: expect.toSatisfy((value) => value !== fragment.resources[1].id),
806823
url: newVariableIdentifier,
824+
searchParams: [{ name: "filter", value: newVariableIdentifier }],
807825
headers: [{ name: "auth", value: newVariableIdentifier }],
808826
body: newVariableIdentifier,
809827
}),
@@ -822,12 +840,14 @@ describe("resources", () => {
822840
const resourceProp = new ResourceValue("Box Resource", {
823841
url: expression`${boxVariable}`,
824842
method: "get",
843+
searchParams: [{ name: "filter", value: expression`${boxVariable}` }],
825844
headers: [{ name: "auth", value: expression`${boxVariable}` }],
826845
body: expression`${boxVariable}`,
827846
});
828847
const resourceVariable = new ResourceValue("Box Resource", {
829848
url: expression`${boxVariable}`,
830849
method: "get",
850+
searchParams: [{ name: "filter", value: expression`${boxVariable}` }],
831851
headers: [{ name: "auth", value: expression`${boxVariable}` }],
832852
body: expression`${boxVariable}`,
833853
});
@@ -865,12 +885,14 @@ describe("resources", () => {
865885
expect.objectContaining({
866886
id: fragment.resources[0].id,
867887
url: oldVariableIdentifier,
888+
searchParams: [{ name: "filter", value: oldVariableIdentifier }],
868889
headers: [{ name: "auth", value: oldVariableIdentifier }],
869890
body: oldVariableIdentifier,
870891
}),
871892
expect.objectContaining({
872893
id: fragment.resources[1].id,
873894
url: oldVariableIdentifier,
895+
searchParams: [{ name: "filter", value: oldVariableIdentifier }],
874896
headers: [{ name: "auth", value: oldVariableIdentifier }],
875897
body: oldVariableIdentifier,
876898
}),

apps/builder/app/shared/data-variables.test.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,16 @@ test("find unset variable names", () => {
216216
const resourceVariable = new ResourceValue("resourceVariable", {
217217
url: expression`six`,
218218
method: "post",
219-
headers: [{ name: "auth", value: expression`seven` }],
220-
body: expression`eight`,
219+
searchParams: [{ name: "filter", value: expression`seven` }],
220+
headers: [{ name: "auth", value: expression`eight` }],
221+
body: expression`nine`,
221222
});
222223
const resourceProp = new ResourceValue("resourceProp", {
223-
url: expression`nine`,
224+
url: expression`ten`,
224225
method: "post",
225-
headers: [{ name: "auth", value: expression`ten` }],
226-
body: expression`eleven`,
226+
searchParams: [{ name: "filter", value: expression`eleven` }],
227+
headers: [{ name: "auth", value: expression`twelve` }],
228+
body: expression`thirteen`,
227229
});
228230
const data = renderData(
229231
<$.Body ws:id="body" data-prop={expression`two`}>
@@ -245,11 +247,13 @@ test("find unset variable names", () => {
245247
"three",
246248
"four",
247249
"six",
248-
"seven",
249250
"eight",
251+
"seven",
250252
"nine",
251253
"ten",
254+
"twelve",
252255
"eleven",
256+
"thirteen",
253257
]);
254258
});
255259

@@ -403,12 +407,14 @@ test("restore tree variables in resources", () => {
403407
const resourceVariable = new ResourceValue("resourceVariable", {
404408
url: expression`one + 1`,
405409
method: "post",
410+
searchParams: [{ name: "filter", value: expression`one + 1` }],
406411
headers: [{ name: "auth", value: expression`one + 1` }],
407412
body: expression`one + 1`,
408413
});
409414
const resourceProp = new ResourceValue("resourceProp", {
410415
url: expression`one + 2`,
411416
method: "post",
417+
searchParams: [{ name: "filter", value: expression`one + 2` }],
412418
headers: [{ name: "auth", value: expression`one + 2` }],
413419
body: expression`one + 2`,
414420
});
@@ -439,12 +445,14 @@ test("restore tree variables in resources", () => {
439445
expect.objectContaining({
440446
url: `${boxIdentifier} + 1`,
441447
method: "post",
448+
searchParams: [{ name: "filter", value: `${boxIdentifier} + 1` }],
442449
headers: [{ name: "auth", value: `${boxIdentifier} + 1` }],
443450
body: `${boxIdentifier} + 1`,
444451
}),
445452
expect.objectContaining({
446453
url: `${boxIdentifier} + 2`,
447454
method: "post",
455+
searchParams: [{ name: "filter", value: `${boxIdentifier} + 2` }],
448456
headers: [{ name: "auth", value: `${boxIdentifier} + 2` }],
449457
body: `${boxIdentifier} + 2`,
450458
}),
@@ -457,12 +465,14 @@ test("rebind tree variables in resources", () => {
457465
const resourceVariable = new ResourceValue("resourceVariable", {
458466
url: expression`${bodyVariable}`,
459467
method: "post",
468+
searchParams: [{ name: "filter", value: expression`${bodyVariable}` }],
460469
headers: [{ name: "auth", value: expression`${bodyVariable}` }],
461470
body: expression`${bodyVariable}`,
462471
});
463472
const resourceProp = new ResourceValue("resourceProp", {
464473
url: expression`${bodyVariable}`,
465474
method: "post",
475+
searchParams: [{ name: "filter", value: expression`${bodyVariable}` }],
466476
headers: [{ name: "auth", value: expression`${bodyVariable}` }],
467477
body: expression`${bodyVariable}`,
468478
});
@@ -493,12 +503,14 @@ test("rebind tree variables in resources", () => {
493503
expect.objectContaining({
494504
url: boxIdentifier,
495505
method: "post",
506+
searchParams: [{ name: "filter", value: boxIdentifier }],
496507
headers: [{ name: "auth", value: boxIdentifier }],
497508
body: boxIdentifier,
498509
}),
499510
expect.objectContaining({
500511
url: boxIdentifier,
501512
method: "post",
513+
searchParams: [{ name: "filter", value: boxIdentifier }],
502514
headers: [{ name: "auth", value: boxIdentifier }],
503515
body: boxIdentifier,
504516
}),
@@ -663,12 +675,14 @@ test("delete variable and unset it in resources", () => {
663675
const resourceVariable = new ResourceValue("resourceVariable", {
664676
url: expression`${bodyVariable}`,
665677
method: "post",
678+
searchParams: [{ name: "filter", value: expression`${bodyVariable}` }],
666679
headers: [{ name: "auth", value: expression`${bodyVariable}` }],
667680
body: expression`${bodyVariable}`,
668681
});
669682
const resourceProp = new ResourceValue("resourceProp", {
670683
url: expression`${bodyVariable}`,
671684
method: "post",
685+
searchParams: [{ name: "filter", value: expression`${bodyVariable}` }],
672686
headers: [{ name: "auth", value: expression`${bodyVariable}` }],
673687
body: expression`${bodyVariable}`,
674688
});
@@ -691,12 +705,14 @@ test("delete variable and unset it in resources", () => {
691705
expect.objectContaining({
692706
url: "bodyVariable",
693707
method: "post",
708+
searchParams: [{ name: "filter", value: "bodyVariable" }],
694709
headers: [{ name: "auth", value: "bodyVariable" }],
695710
body: "bodyVariable",
696711
}),
697712
expect.objectContaining({
698713
url: "bodyVariable",
699714
method: "post",
715+
searchParams: [{ name: "filter", value: "bodyVariable" }],
700716
headers: [{ name: "auth", value: "bodyVariable" }],
701717
body: "bodyVariable",
702718
}),

apps/builder/app/shared/data-variables.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,12 @@ const traverseExpressions = ({
406406
for (const header of resource.headers) {
407407
header.value = update(header.value, instanceId) ?? header.value;
408408
}
409+
if (resource.searchParams) {
410+
for (const searchParam of resource.searchParams) {
411+
searchParam.value =
412+
update(searchParam.value, instanceId) ?? searchParam.value;
413+
}
414+
}
409415
if (resource.body) {
410416
resource.body = update(resource.body, instanceId) ?? resource.body;
411417
}

apps/builder/app/shared/instance-utils.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,7 @@ describe("delete instance", () => {
932932
const myResource = new ResourceValue("My Resource", {
933933
url: expression`""`,
934934
method: "get",
935+
searchParams: [],
935936
headers: [],
936937
});
937938
const data = renderData(
@@ -953,6 +954,7 @@ describe("delete instance", () => {
953954
const myResource = new ResourceValue("My Resource", {
954955
url: expression`""`,
955956
method: "get",
957+
searchParams: [],
956958
headers: [],
957959
});
958960
const data = renderData(

apps/builder/app/shared/instance-utils.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,14 @@ export const extractWebstudioFragment = (
826826
unsetNameById,
827827
});
828828
}
829+
if (newResource.searchParams) {
830+
for (const searchParam of newResource.searchParams) {
831+
searchParam.value = unsetExpressionVariables({
832+
expression: searchParam.value,
833+
unsetNameById,
834+
});
835+
}
836+
}
829837
if (newResource.body) {
830838
newResource.body = unsetExpressionVariables({
831839
expression: newResource.body,
@@ -1174,6 +1182,18 @@ export const insertWebstudioFragmentCopy = ({
11741182
});
11751183
header.value = replaceDataSources(header.value, newDataSourceIds);
11761184
}
1185+
if (resource.searchParams) {
1186+
for (const searchParam of resource.searchParams) {
1187+
searchParam.value = restoreExpressionVariables({
1188+
expression: searchParam.value,
1189+
maskedIdByName,
1190+
});
1191+
searchParam.value = replaceDataSources(
1192+
searchParam.value,
1193+
newDataSourceIds
1194+
);
1195+
}
1196+
}
11771197
if (resource.body) {
11781198
resource.body = restoreExpressionVariables({
11791199
expression: resource.body,

apps/builder/app/shared/nano-states/props.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ test("compute resource variable values", () => {
797797
const resourceVariable = new ResourceValue("resourceVariable", {
798798
url: expression`""`,
799799
method: "get",
800+
searchParams: [],
800801
headers: [],
801802
});
802803
const data = renderData(
@@ -868,6 +869,7 @@ test("compute parameter and resource variables without values to make it availab
868869
const resourceVariable = new ResourceValue("resourceVariable", {
869870
url: expression`""`,
870871
method: "get",
872+
searchParams: [],
871873
headers: [],
872874
});
873875
const parameterVariable = new Parameter("parameterVariable");

0 commit comments

Comments
 (0)