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 ef4f8a1
Show file tree
Hide file tree
Showing 26 changed files with 6,397 additions and 2,278 deletions.
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,37 @@
"preinstall": "npx only-allow pnpm"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.1",
"@gadget-client/app-with-file-fields": "^1.5.0",
"@arethetypeswrong/cli": "^0.15.4",
"@gadget-client/app-with-file-fields": "^1.6.0",
"@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/bulk-actions-test": "^1.116.0",
"@gadget-client/full-auth": "^1.11.0",
"@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",
"@gadget-client/related-products-example": "^1.877.0",
"@gadget-client/zxcv-deeply-nested": "^1.213.0",
"@gadget-client/zxcv-manythrough-example": "1.3.0-nick-dev.3",
"@gadget-client/zxcv-simple-relationship": "^1.23.0",
"@gadget-client/zxcv-simple-relationship": "^1.24.0",
"@gadgetinc/api-client-core": "workspace:*",
"@gadgetinc/eslint-config": "^0.6.1",
"@gadgetinc/prettier-config": "^0.4.0",
"@gadgetinc/react": "workspace:*",
"@swc/core": "^1.3.90",
"@swc/core": "^1.7.26",
"@swc/jest": "^0.2.36",
"@types/jest": "^29.5.12",
"@types/node": "^16.11.7",
"@types/jest": "^29.5.13",
"@types/node": "^16.18.108",
"@types/semver": "^7.5.8",
"eslint": "^8.57.0",
"eslint": "^8.57.1",
"execa": "^5.1.1",
"gitpkg": "^1.0.0-beta.4",
"gitpkg": "1.0.0-beta.4",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-junit": "^16.0.0",
"lodash-es": "^4.17.21",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"semver": "^7.6.2",
"tsx": "^4.9.3",
"semver": "^7.6.3",
"tsx": "^4.19.1",
"typescript": "5.4.5",
"zx": "^7.2.3"
},
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",
},
};
Loading

0 comments on commit ef4f8a1

Please sign in to comment.