Skip to content

Commit

Permalink
feat: add remove product link mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
dleard committed Jun 15, 2020
1 parent e995bdb commit fc69a9e
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 12 deletions.
40 changes: 29 additions & 11 deletions app/containers/Products/ProductRowItemContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
import HeaderWidget from 'components/HeaderWidget';
import PastBenchmarks from 'components/Benchmark/PastBenchmarks';
import createProductLinkMutation from 'mutations/product_link/createProductLinkMutation';
import updateProductLinkMutation from 'mutations/product_link/updateProductLinkMutation';

interface Props {
relay: RelayProp;
Expand Down Expand Up @@ -416,7 +417,8 @@ export const ProductRowItemComponent: React.FunctionComponent<Props> = ({
input: {
productLink: {
productId: product.rowId,
linkedProductId: newLink
linkedProductId: newLink,
isDeleted: false
}
}
};
Expand All @@ -429,6 +431,26 @@ export const ProductRowItemComponent: React.FunctionComponent<Props> = ({
console.log(response);
};

// TODO: GET ID OF PRODUCT LINK (add to db function?)
const removeProductLink = async (removeLink: number) => {
const variables = {
input: {
productLink: {
productId: product.rowId,
linkedProductId: removeLink,
isDeleted: true
}
}
};

const response = await updateProductLinkMutation(
relay.environment,
variables
);
handleUpdateProductCount((productCount += 1));
console.log(response);
};

const data = [];

product.productLink.edges.forEach((edge) => {
Expand Down Expand Up @@ -457,16 +479,15 @@ export const ProductRowItemComponent: React.FunctionComponent<Props> = ({
console.log(response);
}
});
previousLinks.forEach((id) => {
if (!newLinks.includes(id)) console.log('REMOVE:', id);
previousLinks.forEach(async (id) => {
if (!newLinks.includes(id)) {
console.log('REMOVE:', id);
const response = await removeProductLink(id);
console.log(response);
}
});
};

const removeLink = () => {
data.splice(2, 1);
console.log(data);
};

const linkProductModal = (
<Modal
centered
Expand Down Expand Up @@ -514,9 +535,6 @@ export const ProductRowItemComponent: React.FunctionComponent<Props> = ({
onSubmit={saveLinkedProducts}
/>
</Col>
<Col>
<Button onClick={removeLink}>remove</Button>
</Col>
</Row>
</Container>
</Modal.Body>
Expand Down
2 changes: 1 addition & 1 deletion app/mutations/product_link/createProductLinkMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {graphql} from 'react-relay';
import {
createProductLinkMutation as createProductLinkMutationType,
createProductLinkMutationVariables
} from 'createProductMutation.graphql';
} from 'createProductLinkMutation.graphql';
import {RelayModernEnvironment} from 'relay-runtime/lib/store/RelayModernEnvironment';
import BaseMutation from 'mutations/BaseMutation';

Expand Down
33 changes: 33 additions & 0 deletions app/mutations/product_link/updateProductLinkMutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {graphql} from 'react-relay';
import {RelayModernEnvironment} from 'relay-runtime/lib/store/RelayModernEnvironment';
import {
updateProductLinkMutation as updateProductLinkMutationType,
updateProductLinkMutationVariables
} from 'updateProductLinkMutation.graphql';
import BaseMutation from 'mutations/BaseMutation';

const mutation = graphql`
mutation updateProductLinkMutation($input: UpdateProductLinkInput!) {
updateProductLink(input: $input) {
productLink {
id
productId
linkedProductId
isDeleted
}
}
}
`;

// TODO: May want to surface the onCompleted errors to the user (ie not reject, resolve & report)
const updateProductLinkMutation = async (
environment: RelayModernEnvironment,
variables: updateProductLinkMutationVariables
) => {
const m = new BaseMutation<updateProductLinkMutationType>(
'update-product-mutation'
);
return m.performMutation(environment, mutation, variables);
};

export default updateProductLinkMutation;
14 changes: 14 additions & 0 deletions app/server/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10137,6 +10137,9 @@ type ProductLink implements Node {
"""
id: ID!

"""Boolean value indicates if the link has been terminated"""
isDeleted: Boolean!

"""
The id of the product the linked required by product_id to also be reported
"""
Expand Down Expand Up @@ -10178,6 +10181,9 @@ input ProductLinkCondition {
"""Checks for equality with the object’s `deletedBy` field."""
deletedBy: Int

"""Checks for equality with the object’s `isDeleted` field."""
isDeleted: Boolean

"""Checks for equality with the object’s `linkedProductId` field."""
linkedProductId: Int

Expand Down Expand Up @@ -10208,6 +10214,9 @@ input ProductLinkInput {
"""The user who deleted the row"""
deletedBy: Int

"""Boolean value indicates if the link has been terminated"""
isDeleted: Boolean

"""
The id of the product the linked required by product_id to also be reported
"""
Expand Down Expand Up @@ -10239,6 +10248,9 @@ input ProductLinkPatch {
"""The user who deleted the row"""
deletedBy: Int

"""Boolean value indicates if the link has been terminated"""
isDeleted: Boolean

"""
The id of the product the linked required by product_id to also be reported
"""
Expand Down Expand Up @@ -10292,6 +10304,8 @@ enum ProductLinksOrderBy {
DELETED_BY_DESC
ID_ASC
ID_DESC
IS_DELETED_ASC
IS_DELETED_DESC
LINKED_PRODUCT_ID_ASC
LINKED_PRODUCT_ID_DESC
NATURAL
Expand Down
58 changes: 58 additions & 0 deletions app/server/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -13436,6 +13436,16 @@
},
"defaultValue": null
},
{
"name": "isDeleted",
"description": "Checks for equality with the object’s `isDeleted` field.",
"type": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
},
"defaultValue": null
},
{
"name": "linkedProductId",
"description": "Checks for equality with the object’s `linkedProductId` field.",
Expand Down Expand Up @@ -13559,6 +13569,18 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "IS_DELETED_ASC",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "IS_DELETED_DESC",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "LINKED_PRODUCT_ID_ASC",
"description": null,
Expand Down Expand Up @@ -13859,6 +13881,22 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "isDeleted",
"description": "Boolean value indicates if the link has been terminated",
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "linkedProductId",
"description": "The id of the product the linked required by product_id to also be reported",
Expand Down Expand Up @@ -36614,6 +36652,16 @@
},
"defaultValue": null
},
{
"name": "isDeleted",
"description": "Boolean value indicates if the link has been terminated",
"type": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
},
"defaultValue": null
},
{
"name": "linkedProductId",
"description": "The id of the product the linked required by product_id to also be reported",
Expand Down Expand Up @@ -48285,6 +48333,16 @@
},
"defaultValue": null
},
{
"name": "isDeleted",
"description": "Boolean value indicates if the link has been terminated",
"type": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
},
"defaultValue": null
},
{
"name": "linkedProductId",
"description": "The id of the product the linked required by product_id to also be reported",
Expand Down

0 comments on commit fc69a9e

Please sign in to comment.