Skip to content

Commit

Permalink
Hide hasMany input on join model when using actions on models with ha…
Browse files Browse the repository at this point in the history
…sManyThrough fields
  • Loading branch information
MillanWangGadget committed Sep 24, 2024
1 parent 394e801 commit 6b96215
Show file tree
Hide file tree
Showing 18 changed files with 4,019 additions and 927 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@gadget-client/app-with-no-user-model": "^1.10.0",
"@gadget-client/bulk-actions-test": "^1.113.0",
"@gadget-client/full-auth": "^1.9.0",
"@gadget-client/js-clients-test": "1.498.0-development.1784",
"@gadget-client/js-clients-test": "1.499.0-development.1964",
"@gadget-client/kitchen-sink": "1.5.0-development.200",
"@gadget-client/related-products-example": "^1.865.0",
"@gadget-client/zxcv-deeply-nested": "^1.212.0",
Expand Down
5 changes: 5 additions & 0 deletions packages/react/.changeset/dirty-wombats-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@gadgetinc/react": patch
---

Updated AutoForm HasManyThrough fields so that no inputs are shown. They would previously show a hasMany field for the join model, which corresponds to the API, but was confusing in an AutoForm context
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
import React from "react";
import { api } from "../../../support/api.js";
import { describeForEachAutoAdapter } from "../../../support/auto.js";

describeForEachAutoAdapter("AutoForm - HasManyThrough fields", ({ name, adapter: { AutoForm }, wrapper }) => {
beforeEach(() => {
cy.viewport("macbook-13");
});

const interceptModelActionMetadataRequest = () => {
cy.intercept(
{
method: "POST",
url: `${api.connection.endpoint}?operation=ModelActionMetadata`,
},
modelActionMetadataResponse
).as("ModelActionMetadata");
};

it("does not render the hasMany->joinModel input field", () => {
interceptModelActionMetadataRequest();

cy.mountWithWrapper(<AutoForm action={api.widget.create} />, wrapper);
cy.wait("@ModelActionMetadata");

// Name field input is shown
cy.contains("Base model name");

// hasMany->joinModel input is filtered out
cy.contains("Joiner models").should("not.exist");

// HasManyThrough field input is not shown - TODO: This is not yet implemented yet
cy.contains("Base model hmt field").should("not.exist");
});
});

const modelActionMetadataResponse = {
data: {
gadgetMeta: {
model: {
name: "Base model",
apiIdentifier: "baseModel",
defaultRecord: {
__typename: "HasManyThroughBaseModel",
},
action: {
name: "Create",
apiIdentifier: "create",
operatesWithRecordIdentity: false,
isDeleteAction: false,
inputFields: [
{
name: "Base model",
apiIdentifier: "baseModel",
fieldType: "Object",
requiredArgumentForInput: false,
configuration: {
__typename: "GadgetObjectFieldConfig",
fieldType: "Object",
validations: [],
name: null,
fields: [
{
name: "Base model name",
apiIdentifier: "baseModelName",
fieldType: "String",
requiredArgumentForInput: false,
sortable: true,
filterable: true,
__typename: "GadgetModelField",
configuration: {
__typename: "GadgetGenericFieldConfig",
fieldType: "String",
validations: [],
},
},
{
name: "Joiner models",
apiIdentifier: "joinerModels",
fieldType: "HasMany",
requiredArgumentForInput: false,
sortable: false,
filterable: false,
__typename: "GadgetModelField",
configuration: {
__typename: "GadgetHasManyConfig",
fieldType: "HasMany",
validations: [],
isJoinModelHasManyField: true,
relatedModel: {
key: "tJDsf_FvYqsi",
apiIdentifier: "joinerModel",
namespace: ["hasManyThrough"],
defaultDisplayField: {
name: "Id",
apiIdentifier: "id",
fieldType: "ID",
__typename: "GadgetModelField",
},
__typename: "GadgetModel",
},
inverseField: {
apiIdentifier: "joinerBelongsToBase",
__typename: "GadgetModelField",
},
},
},
{
name: "Base model hmt field",
apiIdentifier: "baseModelHmtField",
fieldType: "HasManyThrough",
requiredArgumentForInput: false,
sortable: false,
filterable: false,
__typename: "GadgetModelField",
configuration: {
__typename: "GadgetHasManyThroughConfig",
fieldType: "HasManyThrough",
validations: [],
relatedModel: {
key: "Oss4sCDW-DJU",
apiIdentifier: "siblingModel",
namespace: ["hasManyThrough"],
defaultDisplayField: {
name: "Id",
apiIdentifier: "id",
fieldType: "ID",
__typename: "GadgetModelField",
},
__typename: "GadgetModel",
},
inverseField: {
apiIdentifier: "siblingModelHmtField",
__typename: "GadgetModelField",
},
joinModel: {
key: "tJDsf_FvYqsi",
apiIdentifier: "joinerModel",
namespace: ["hasManyThrough"],
defaultDisplayField: {
name: "Id",
apiIdentifier: "id",
fieldType: "ID",
__typename: "GadgetModelField",
},
__typename: "GadgetModel",
},
inverseJoinModelField: {
apiIdentifier: "joinerBelongsToBase",
__typename: "GadgetModelField",
},
inverseRelatedModelField: {
apiIdentifier: "joinerBelongsToSibling",
__typename: "GadgetModelField",
},
},
},
],
},
__typename: "GadgetObjectField",
},
],
triggers: [
{
specID: "gadget/trigger/graphql_api",
__typename: "GadgetTrigger",
},
],
__typename: "GadgetAction",
},
__typename: "GadgetModel",
},
__typename: "GadgetApplicationMeta",
},
},
extensions: {
logs: "https://ggt.link/logs/114412/baf607a14bf4d84e97c49ccd068621b5",
traceId: "baf607a14bf4d84e97c49ccd068621b5",
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@
"encoding": "base64",
"mimeType": "application/json; charset=utf-8",
"size": 656,
"text": "[\"H4sIAAAAAAAAA4RSXW/iMBD8K2ifU3DCh6jfEK0qKvWEDu6lp1Nl7E3wXbAte4OIUP77yXw0wFXcmzM7u5mZ3T0oQQL4HsLaOp3Xc29VJSlEyIkCZya38b0W4RvuaC4KBJ6LMmASsbnHrbZVuMIDCU/TygfrgQPWr+59OhvNfj/Xb/XrIySARt0rf3xQ7dCIDQKH+VlEkwCqAgPwn3uQd9qNVRglX41ZXNmDBLQCDmnWhwRWVtVx1E5sXImdrSgr7OTWdw6FBKTdOOFxQnOvJX4XJno1VVkmID0KQjUh4JCxrP+QZg9ptkxHPMt4Nuwylr5DTMqo8rPJHUVMBWFhfX0DL2vXMqtVqcP6+IMbaCFtSzxtb/qFHJYu2ZAzxhnrMsainBP7h1Nn9mkKCarC+YtE0b5x40pBuKjyXO8+UU2tq6qddi+KLRoVNxebmuTekp5VgdD8usuZWmNQkrYm3kchVIH0hseLXtfKi1gKF/d9mdCTIFzqDcJN0JcF+TX/0uwF/G+wbfXW7MtB7MS5UsuDzIPuJp75jtCEs/DSxjXAmsgF3usVBXVLbf70It5Lh2zExj21GqdS9gdjteoP+uIxG+dyhblS6SgbII4hAfJC4iwe/X/JTfMXAAD//wMAGAqYkBcEAAA=\"]"
"text": "[\"H4sIAAAAAAAAA4RSXW/aQBD8K2ifHTibmJB7QzSqiJQKFfqSqoo2vrVxa+5Od2uEhfzfq+MjBhrRt/Ps7HpmdnegkBHkDvzK2DJv5s6oOmMfIIsFzXRuwnuF/htteY4Fgcyx8hQFbO5oU5raX+Ce0fG0dt44kEDNs32dzkaz30/NS/P8CBGQVrfKb2/cWNK4JpAwP4loIyBVkAf5cwfZjXZtFAXJF2MWF/YgglKBhDgZQgTvRjVh1BbXtqLeBquaerlxvX0hgsysLTqa8NyVGX1HHbzquqoiyBwhk5owSEhEMryLk7s4WcYjmSQySftCxK8QktKq+miyBxFTZCqMa67gZWM7Zv1elX51+MEVtMhMRzxub/qJHBEvRSqFkEL0hRBBzpH9w6oT+ziFkWt/+mIsujetbYVMizrPy+0HWnLnqu6m3YpiQ1qFzYWmNrq1pCdVELS/bnKmRmvKuDQ63EeBqiB+ocNFrxrlMJT82X2fJ/QFmZblmuAq6PNC9jn/3OwZ/G+wXfXa7Ne92Im1VZntZe51t+HMt0zan4RXJqwBVszWy8GgKLhflfrPIOCDOBUjMR6ocZw/3Ks0HT+KHO+HaTqMH1J8j5Nxmo6HQRo7zGgWjv6/5Lb9CwAA//8DAFexL1YXBAAA\"]"
},
"cookies": [],
"headers": [
{
"name": "date",
"value": "Wed, 28 Aug 2024 23:51:02 GMT"
"value": "Tue, 24 Sep 2024 18:21:14 GMT"
},
{
"name": "content-type",
Expand Down Expand Up @@ -110,11 +110,11 @@
},
{
"name": "x-request-id",
"value": "58ef3bd4989ccf80ad1b72f8c1dcdbd3"
"value": "eb934bd9f0457c6622c472c04888525b"
},
{
"name": "x-trace-id",
"value": "db81cc348db343a928fcbefdd1624ee8"
"value": "d81f74d55890fa43553175ab1285583e"
},
{
"name": "strict-transport-security",
Expand All @@ -134,33 +134,29 @@
},
{
"name": "cf-ray",
"value": "8ba835033d3753ef-YYZ"
"value": "8c84cb03ebbeaae5-YYZ"
},
{
"name": "content-encoding",
"value": "gzip"
},
{
"name": "alt-svc",
"value": "h3=\":443\"; ma=86400"
}
],
"headersSize": 612,
"headersSize": 582,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2024-08-28T23:51:02.788Z",
"time": 130,
"startedDateTime": "2024-09-24T18:21:14.141Z",
"time": 709,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 130
"wait": 709
}
},
{
Expand Down Expand Up @@ -228,13 +224,13 @@
"encoding": "base64",
"mimeType": "application/json; charset=utf-8",
"size": 384,
"text": "[\"H4sIAAAAAAAAA4SQMW/CMBCF/0p1syFOnETBG2qlqkOHVkxdkGMfIcIkwT5LUJT/XjlQqrIw3um99927MxhFCuQZtENF+BHa7zj5oDV6D5JcQAboXO88yC5Yy+BwFa3XdBqwU3sECZOTQWtAQprzBbBrpFkSSMh4ls94NcuqVSZkkUou5pngX8CA8BgVhJ6eDpeUMJjHzpH9v+D51uATfbAUBY0yDdI7XjpuT8YpavvO/zW+QF4U4ard4x37tr5nvU65y2GwrZ4SJ8Q4MsAjYed/GbZvPEjYEg1eJknT0Ny23S6J+yQteMmrRBQqQ14alZZFnaIpVK6VWJha12KD1Sa+yCmNb/G1D8Xj+AMAAP//AwB5iPVT1AEAAA==\"]"
"text": "[\"H4sIAAAAAAAAA4SQzW7CMBCEX6XasyG2IT/4hlqp6qGHVpx6QZa9CREmCfZagqK8e5WEUpULx13NzLezF7CaNKgLGI+a8CPW38MUojEYAijyERmg960PoJroHIPjVbTd0rnDRh8QFIxOBrUFBSIVEtg10q4JFEgulzO+msnlRhRKCiXSOS/kFzAgPA0KwkBPxykldvaxs2f/L3i+NfjEEB0NgkrbCukdp467s/Wa6rYJf40nyIsm3NQHvGPf1ves1zF33XWuNmPiiOh7BngibMIvw7VVAAU7oi6oJKkqmru62SfDPhEpz3iRmFWGpV2YwqLURiyMzIu85DYvC4tZxocXeW3wbXjtQ3Hf/wAAAP//AwDsVySX1AEAAA==\"]"
},
"cookies": [],
"headers": [
{
"name": "date",
"value": "Wed, 28 Aug 2024 23:51:03 GMT"
"value": "Tue, 24 Sep 2024 18:21:15 GMT"
},
{
"name": "content-type",
Expand Down Expand Up @@ -266,11 +262,11 @@
},
{
"name": "x-request-id",
"value": "d7298ae1a81637917feea6c110c93b33"
"value": "620a828194efb1deac0a77ce0dddd1d8"
},
{
"name": "x-trace-id",
"value": "35a2e06da165b1ed5a4ca39dbcb3fe8f"
"value": "c96efd3c8de2ac13c2787f0d7f8de660"
},
{
"name": "strict-transport-security",
Expand All @@ -290,33 +286,29 @@
},
{
"name": "cf-ray",
"value": "8ba83504280faaf8-YYZ"
"value": "8c84cb087e79a1fe-YYZ"
},
{
"name": "content-encoding",
"value": "gzip"
},
{
"name": "alt-svc",
"value": "h3=\":443\"; ma=86400"
}
],
"headersSize": 612,
"headersSize": 582,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2024-08-28T23:51:02.946Z",
"time": 279,
"startedDateTime": "2024-09-24T18:21:14.898Z",
"time": 229,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 279
"wait": 229
}
}
],
Expand Down
Loading

0 comments on commit 6b96215

Please sign in to comment.